195 lines
4.9 KiB

  1. /*
  2. * ttyvaders Textmode shoot'em up
  3. * Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id: common.h,v 1.11 2002/12/23 10:06:27 sam Exp $
  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. #define STARS 50
  23. #define WEAPONS 200
  24. #define BONUS 30
  25. #define ALIENS 30
  26. #define EXPLOSIONS 200
  27. #ifdef USE_SLANG
  28. # include <slang.h>
  29. # define gfx_color(x) SLsmg_set_color(x)
  30. # define gfx_goto(x,y) SLsmg_gotorc(y,x)
  31. # define gfx_putchar(x) SLsmg_write_char(x)
  32. # define gfx_putstr(x) SLsmg_write_string(x)
  33. #elif USE_NCURSES
  34. # include <curses.h>
  35. # define gfx_color(x) attrset(COLOR_PAIR(x))
  36. # define gfx_goto(x,y) move(y,x)
  37. # define gfx_putchar(x) addch(x)
  38. # define gfx_putstr(x) addstr(x)
  39. #else
  40. # define gfx_color(x) do{}while(0)
  41. # define gfx_goto(x,y) do{}while(0)
  42. # define gfx_putchar(x) do{}while(0)
  43. # define gfx_putstr(x) do{}while(0)
  44. #endif
  45. #define gfx_putcharTO(x,y,c) do{ gfx_goto(x,y); gfx_putchar(c); }while(0)
  46. #define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0)))
  47. #define GET_MAX(a,b) ((a)>(b)?(a):(b))
  48. #define GET_MIN(a,b) ((a)<(b)?(a):(b))
  49. typedef struct
  50. {
  51. int w, h, *left, *right;
  52. } tunnel;
  53. typedef struct
  54. {
  55. int x, y, z, c;
  56. char ch;
  57. } starfield;
  58. typedef struct
  59. {
  60. enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS];
  61. int x[EXPLOSIONS];
  62. int y[EXPLOSIONS];
  63. int vx[EXPLOSIONS];
  64. int vy[EXPLOSIONS];
  65. int n[EXPLOSIONS];
  66. } explosions;
  67. typedef struct
  68. {
  69. enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE, WEAPON_BEAM, WEAPON_LIGHTNING, WEAPON_BOMB, WEAPON_FRAGBOMB } type[WEAPONS];
  70. int x[WEAPONS];
  71. int y[WEAPONS];
  72. int x2[WEAPONS];
  73. int y2[WEAPONS];
  74. int x3[WEAPONS];
  75. int y3[WEAPONS];
  76. int vx[WEAPONS];
  77. int vy[WEAPONS];
  78. int n[WEAPONS];
  79. } weapons;
  80. typedef struct
  81. {
  82. enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS];
  83. int x[BONUS];
  84. int y[BONUS];
  85. int n[BONUS];
  86. } bonus;
  87. typedef struct
  88. {
  89. int x, y;
  90. int dir;
  91. int weapon, nuke;
  92. } player;
  93. typedef struct
  94. {
  95. enum { ALIEN_NONE, ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH } type[ALIENS];
  96. int x[ALIENS];
  97. int y[ALIENS];
  98. int life[ALIENS];
  99. int img[ALIENS];
  100. } aliens;
  101. typedef struct
  102. {
  103. int w, h;
  104. starfield *sf;
  105. weapons *wp;
  106. explosions *ex;
  107. tunnel *t;
  108. player *p;
  109. aliens *al;
  110. bonus *bo;
  111. } game;
  112. #define BLACK 1
  113. #define GREEN 2
  114. #define YELLOW 3
  115. #define WHITE 4
  116. #define RED 5
  117. #define GRAY 6
  118. #define LIGHTGRAY 7
  119. #define BLUE 8
  120. #define CYAN 9
  121. #define MAGENTA 10
  122. void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex );
  123. void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex );
  124. void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex );
  125. void init_aliens( game *g, aliens *al );
  126. void draw_aliens( game *g, aliens *al );
  127. void update_aliens( game *g, aliens *al );
  128. void add_alien( game *g, aliens *al, int x, int y, int type );
  129. int init_graphics( void );
  130. void init_game( game *g );
  131. char get_key( void );
  132. void clear_graphics( void );
  133. void refresh_graphics( void );
  134. void end_graphics( void );
  135. player * create_player( game *g );
  136. void free_player( player *p );
  137. void draw_player( game *g, player *p );
  138. void update_player( game *g, player *p );
  139. void init_weapons( game *g, weapons *wp );
  140. void draw_weapons( game *g, weapons *wp );
  141. void update_weapons( game *g, weapons *wp );
  142. void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type );
  143. void init_bonus( game *g, bonus *bo );
  144. void draw_bonus( game *g, bonus *bo );
  145. void update_bonus( game *g, bonus *bo );
  146. void add_bonus( game *g, bonus *bo, int x, int y, int type );
  147. starfield * create_starfield( game *g );
  148. void draw_starfield( game *g, starfield *s );
  149. void update_starfield( game *g, starfield *s );
  150. void free_starfield( game *g, starfield *s );
  151. tunnel * create_tunnel( game *g, int w, int h );
  152. void free_tunnel( tunnel *t );
  153. void draw_tunnel( game *g, tunnel *t );
  154. void update_tunnel( game *g, tunnel *t );
  155. void init_explosions( game *g, explosions *ex );
  156. void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type );
  157. void draw_explosions( game *g, explosions *ex );
  158. void update_explosions( game *g, explosions *ex );
  159. void ceo_alert( void );
  160. int r00t( int a );