165 rader
3.7 KiB

  1. #define STARS 50
  2. #define WEAPONS 50
  3. #define BONUS 30
  4. #define ALIENS 30
  5. #define EXPLOSIONS 20
  6. #ifdef USE_SLANG
  7. # include <slang.h>
  8. # define gfx_color(x) SLsmg_set_color(x)
  9. # define gfx_goto(x,y) SLsmg_gotorc(y,x)
  10. # define gfx_putchar(x) SLsmg_write_char(x)
  11. # define gfx_putstr(x) SLsmg_write_string(x)
  12. #else
  13. # include <curses.h>
  14. # define gfx_color(x) attrset(COLOR_PAIR(x))
  15. # define gfx_goto(x,y) move(y,x)
  16. # define gfx_putchar(x) addch(x)
  17. # define gfx_putstr(x) addstr(x)
  18. #endif
  19. #define gfx_putcharTO(x,y,c) do{ gfx_goto(x,y); gfx_putchar(c); }while(0)
  20. #define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0)))
  21. typedef struct
  22. {
  23. int w, h, *left, *right;
  24. } tunnel;
  25. typedef struct
  26. {
  27. int x[STARS];
  28. int y[STARS];
  29. int z[STARS];
  30. char ch[STARS];
  31. int c[STARS];
  32. } starfield;
  33. typedef struct
  34. {
  35. enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS];
  36. int x[EXPLOSIONS];
  37. int y[EXPLOSIONS];
  38. int vx[EXPLOSIONS];
  39. int vy[EXPLOSIONS];
  40. int n[EXPLOSIONS];
  41. } explosions;
  42. typedef struct
  43. {
  44. enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE, WEAPON_BEAM } type[WEAPONS];
  45. int x[WEAPONS];
  46. int y[WEAPONS];
  47. int x2[WEAPONS];
  48. int y2[WEAPONS];
  49. int x3[WEAPONS];
  50. int y3[WEAPONS];
  51. int vx[WEAPONS];
  52. int vy[WEAPONS];
  53. int n[WEAPONS];
  54. } weapons;
  55. typedef struct
  56. {
  57. enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS];
  58. int x[BONUS];
  59. int y[BONUS];
  60. int n[BONUS];
  61. } bonus;
  62. typedef struct
  63. {
  64. int x, y;
  65. int dir;
  66. int weapon, nuke;
  67. } player;
  68. typedef struct
  69. {
  70. enum { ALIEN_NONE, ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH } type[ALIENS];
  71. int x[ALIENS];
  72. int y[ALIENS];
  73. int life[ALIENS];
  74. int img[ALIENS];
  75. } aliens;
  76. typedef struct
  77. {
  78. int w, h;
  79. starfield *sf;
  80. weapons *wp;
  81. explosions *ex;
  82. tunnel *t;
  83. player *p;
  84. aliens *al;
  85. bonus *bo;
  86. } game;
  87. #define BLACK 1
  88. #define GREEN 2
  89. #define YELLOW 3
  90. #define WHITE 4
  91. #define RED 5
  92. #define GRAY 6
  93. #define LIGHTGRAY 7
  94. #define BLUE 8
  95. #define CYAN 9
  96. #define MAGENTA 10
  97. void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex );
  98. void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex );
  99. void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex );
  100. void init_aliens( game *g, aliens *al );
  101. void draw_aliens( game *g, aliens *al );
  102. void update_aliens( game *g, aliens *al );
  103. void add_alien( game *g, aliens *al, int x, int y, int type );
  104. int init_graphics( void );
  105. void init_game( game *g );
  106. char get_key( void );
  107. void clear_graphics( void );
  108. void refresh_graphics( void );
  109. void end_graphics( void );
  110. player * create_player( game *g );
  111. void free_player( player *p );
  112. void draw_player( game *g, player *p );
  113. void update_player( game *g, player *p );
  114. void init_weapons( game *g, weapons *wp );
  115. void draw_weapons( game *g, weapons *wp );
  116. void update_weapons( game *g, weapons *wp );
  117. void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type );
  118. void init_bonus( game *g, bonus *bo );
  119. void draw_bonus( game *g, bonus *bo );
  120. void update_bonus( game *g, bonus *bo );
  121. void add_bonus( game *g, bonus *bo, int x, int y, int type );
  122. void init_starfield( game *g, starfield *s );
  123. void draw_starfield( game *g, starfield *s );
  124. void update_starfield( game *g, starfield *s );
  125. tunnel * create_tunnel( game *g, int w, int h );
  126. void free_tunnel( tunnel *t );
  127. void draw_tunnel( game *g, tunnel *t );
  128. void update_tunnel( game *g, tunnel *t );
  129. void init_explosions( game *g, explosions *ex );
  130. void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type );
  131. void draw_explosions( game *g, explosions *ex );
  132. void update_explosions( game *g, explosions *ex );