ORAIN1.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. // Filename : ORAIN1.CPP
  21. // Description: Class RainDrop
  22. // Ownership : Gilbert
  23. #include <ORAIN.h>
  24. #include <OVGABUF.h>
  25. #include <COLOR.h>
  26. #include <OWORLDMT.h>
  27. //--------- Begin of function RainDrop::init ------------//
  28. //
  29. void RainDrop::init(Rain *, short fromX, short fromY, short toX, short toY, short speed )
  30. {
  31. cur_x = fromX;
  32. cur_y = fromY;
  33. dest_x = toX;
  34. dest_y = toY;
  35. fall_speed = speed;
  36. }
  37. //--------- End of function RainDrop::init ------------//
  38. //--------- Begin of function RainDrop::fall ------------//
  39. //
  40. void RainDrop::fall()
  41. {
  42. if( cur_y + fall_speed >= dest_y )
  43. {
  44. cur_y = dest_y;
  45. cur_x = dest_x;
  46. }
  47. else
  48. {
  49. cur_x += (dest_x - cur_x) * fall_speed / (dest_y - cur_y);
  50. cur_y += fall_speed;
  51. }
  52. }
  53. //--------- End of function RainDrop::fall ------------//
  54. //--------- Begin of function RainDrop::is_goal ------------//
  55. //
  56. int RainDrop::is_goal()
  57. {
  58. return( cur_y + fall_speed >= dest_y);
  59. }
  60. //--------- End of function RainDrop::is_goal ------------//
  61. //--------- Begin of function RainDrop::draw_step ------------//
  62. //
  63. void RainDrop::draw_step(VgaBuf *vgabuf)
  64. {
  65. short preX = cur_x;
  66. short preY = cur_y;
  67. fall();
  68. preX = (preX + cur_x) /2;
  69. preY = (preY + cur_y) /2;
  70. // ####### begin Gilbert 8/5 ######//
  71. if( preX >= ZOOM_X1 && cur_x >= ZOOM_X1 &&
  72. preX <= ZOOM_X2 && cur_x <= ZOOM_X2 &&
  73. preY >= ZOOM_Y1 && cur_y >= ZOOM_Y1 &&
  74. preY <= ZOOM_Y2 && cur_y <= ZOOM_Y2 )
  75. {
  76. short q2X = (preX + cur_x) /2;
  77. short q2Y = (preY + cur_y) /2;
  78. short q3X = (preX + 3*cur_x) /4;
  79. short q3Y = (preY + 3*cur_y) /4;
  80. vgabuf->line(preX, preY, q2X, q2Y, VGA_GRAY+8);
  81. vgabuf->line(q2X, q2Y, q3X, q3Y, VGA_GRAY+10);
  82. vgabuf->line(q3X, q3Y, cur_x, cur_y, VGA_GRAY+12);
  83. }
  84. else
  85. {
  86. int wrap_size = ZOOM_X2 - ZOOM_X1;
  87. // if the drop goes outside the screen, come back from the other side
  88. if( cur_x < ZOOM_X1)
  89. {
  90. cur_x += wrap_size;
  91. dest_x += wrap_size;
  92. }
  93. else if( cur_x > ZOOM_X2)
  94. {
  95. cur_x -= wrap_size;
  96. dest_x -= wrap_size;
  97. }
  98. }
  99. // ####### end Gilbert 8/5 ######//
  100. }
  101. //--------- End of function RainDrop::draw_step ------------//