Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

231 wiersze
4.7 KiB

  1. /*
  2. * ttyvaders Textmode shoot'em up
  3. * Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. /*
  23. * Compile-time limits
  24. */
  25. #define STARS 50
  26. #define WEAPONS 200
  27. #define BONUS 30
  28. #define ALIENS 30
  29. #define EXPLOSIONS 200
  30. /*
  31. * Game defines
  32. */
  33. #define MAX_LIFE 1000
  34. #define MAX_SPECIAL 200
  35. #define COST_NUKE (100*MAX_SPECIAL/100)
  36. #define COST_BEAM (75*MAX_SPECIAL/100)
  37. #define COST_FRAGBOMB (50*MAX_SPECIAL/100)
  38. /*
  39. * Graphics primitives
  40. */
  41. #include "ee.h"
  42. /*
  43. * Useful macros
  44. */
  45. #define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0)))
  46. #define GET_MAX(a,b) ((a)>(b)?(a):(b))
  47. #define GET_MIN(a,b) ((a)<(b)?(a):(b))
  48. /*
  49. * Game structures
  50. */
  51. typedef struct
  52. {
  53. int w, h, *left, *right;
  54. } tunnel;
  55. typedef struct
  56. {
  57. int x, y, z, c;
  58. char ch;
  59. } starfield;
  60. typedef struct
  61. {
  62. enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS];
  63. int x[EXPLOSIONS];
  64. int y[EXPLOSIONS];
  65. int vx[EXPLOSIONS];
  66. int vy[EXPLOSIONS];
  67. int n[EXPLOSIONS];
  68. } explosions;
  69. typedef struct
  70. {
  71. enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE, WEAPON_BEAM, WEAPON_LIGHTNING, WEAPON_BOMB, WEAPON_FRAGBOMB } type[WEAPONS];
  72. int x[WEAPONS];
  73. int y[WEAPONS];
  74. int x2[WEAPONS];
  75. int y2[WEAPONS];
  76. int x3[WEAPONS];
  77. int y3[WEAPONS];
  78. int vx[WEAPONS];
  79. int vy[WEAPONS];
  80. int n[WEAPONS];
  81. } weapons;
  82. typedef struct
  83. {
  84. enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS];
  85. int x[BONUS];
  86. int y[BONUS];
  87. int n[BONUS];
  88. } bonus;
  89. typedef struct
  90. {
  91. int x, y;
  92. int vx, vy;
  93. int weapon, special;
  94. int life, dead;
  95. } player;
  96. typedef struct
  97. {
  98. enum { ALIEN_NONE, ALIEN_FOO, ALIEN_BAR, ALIEN_BAZ } type[ALIENS];
  99. int x[ALIENS];
  100. int y[ALIENS];
  101. int life[ALIENS];
  102. int img[ALIENS];
  103. } aliens;
  104. typedef struct
  105. {
  106. int w, h;
  107. int x, y;
  108. int frame;
  109. } box;
  110. typedef struct
  111. {
  112. int w, h;
  113. starfield *sf;
  114. weapons *wp;
  115. explosions *ex;
  116. tunnel *t;
  117. player *p;
  118. aliens *al;
  119. bonus *bo;
  120. } game;
  121. /*
  122. * From aliens.c
  123. */
  124. void init_aliens( game *g, aliens *al );
  125. void draw_aliens( game *g, aliens *al );
  126. void update_aliens( game *g, aliens *al );
  127. void add_alien( game *g, aliens *al, int x, int y, int type );
  128. /*
  129. * From bonus.c
  130. */
  131. void init_bonus( game *g, bonus *bo );
  132. void draw_bonus( game *g, bonus *bo );
  133. void update_bonus( game *g, bonus *bo );
  134. void add_bonus( game *g, bonus *bo, int x, int y, int type );
  135. /*
  136. * From box.c
  137. */
  138. box * create_box( game *g, int x, int y, int w, int h );
  139. void draw_box( game *g, box *b );
  140. void free_box( box *b );
  141. /*
  142. * From ceo.c
  143. */
  144. void ceo_alert( game *g );
  145. /*
  146. * From collide.c
  147. */
  148. void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex );
  149. void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex );
  150. void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex );
  151. /*
  152. * From explosions.c
  153. */
  154. void init_explosions( game *g, explosions *ex );
  155. void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type );
  156. void draw_explosions( game *g, explosions *ex );
  157. void update_explosions( game *g, explosions *ex );
  158. /*
  159. * From math.c
  160. */
  161. int r00t( int a );
  162. /*
  163. * From overlay.c
  164. */
  165. void draw_status( game *g );
  166. /*
  167. * From player.c
  168. */
  169. player * create_player( game *g );
  170. void free_player( player *p );
  171. void draw_player( game *g, player *p );
  172. void update_player( game *g, player *p );
  173. /*
  174. * From starfield.c
  175. */
  176. starfield * create_starfield( game *g );
  177. void draw_starfield( game *g, starfield *s );
  178. void update_starfield( game *g, starfield *s );
  179. void free_starfield( game *g, starfield *s );
  180. /*
  181. * From tunnel.c
  182. */
  183. tunnel * create_tunnel( game *g, int w, int h );
  184. void free_tunnel( tunnel *t );
  185. void draw_tunnel( game *g, tunnel *t );
  186. void update_tunnel( game *g, tunnel *t );
  187. /*
  188. * From weapons.c
  189. */
  190. void init_weapons( game *g, weapons *wp );
  191. void draw_weapons( game *g, weapons *wp );
  192. void update_weapons( game *g, weapons *wp );
  193. void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type );