You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

135 lines
2.8 KiB

  1. #define STARS 50
  2. #define WEAPONS 50
  3. #define ROCKS 10
  4. #define ALIENS 10
  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_WRITE(x) SLsmg_write_char(x)
  11. #else
  12. # include <curses.h>
  13. # define GFX_COLOR(x) attrset(COLOR_PAIR(x))
  14. # define GFX_GOTO(x,y) move(y,x)
  15. # define GFX_WRITE(x) addch(x)
  16. #endif
  17. #define GFX_WRITETO(x,y,c) do{ GFX_GOTO(x,y); GFX_WRITE(c); }while(0)
  18. #define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0)))
  19. typedef struct
  20. {
  21. int w, h;
  22. } game;
  23. typedef struct
  24. {
  25. int w, h, *left, *right;
  26. } tunnel;
  27. typedef struct
  28. {
  29. int x[STARS];
  30. int y[STARS];
  31. int z[STARS];
  32. char ch[STARS];
  33. int c[STARS];
  34. } starfield;
  35. typedef struct
  36. {
  37. int x[EXPLOSIONS];
  38. int y[EXPLOSIONS];
  39. int vx[EXPLOSIONS];
  40. int vy[EXPLOSIONS];
  41. int type[EXPLOSIONS];
  42. int n[EXPLOSIONS];
  43. } explosions;
  44. typedef struct
  45. {
  46. int x[WEAPONS];
  47. int y[WEAPONS];
  48. int v[WEAPONS];
  49. int n[WEAPONS];
  50. int type[WEAPONS];
  51. } weapons;
  52. typedef struct
  53. {
  54. int x, y;
  55. int dir;
  56. int weapon, nuke;
  57. } player;
  58. typedef struct
  59. {
  60. int x[ALIENS];
  61. int y[ALIENS];
  62. int life[ALIENS];
  63. int img[ALIENS];
  64. } aliens;
  65. #define BLACK 1
  66. #define GREEN 2
  67. #define YELLOW 3
  68. #define WHITE 4
  69. #define RED 5
  70. #define GRAY 6
  71. #define LIGHTGRAY 7
  72. #define BLUE 8
  73. #define CYAN 9
  74. #define MAGENTA 10
  75. void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex );
  76. void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex );
  77. void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex );
  78. void init_aliens( game *g, aliens *al );
  79. void draw_aliens( game *g, aliens *al );
  80. void update_aliens( game *g, aliens *al );
  81. void add_alien( game *g, aliens *al, int x, int y );
  82. int init_graphics( void );
  83. void init_game( game *g );
  84. char get_key( void );
  85. void clear_graphics( void );
  86. void refresh_graphics( void );
  87. void end_graphics( void );
  88. player * create_player( game *g );
  89. void free_player( player *p );
  90. void draw_player( game *g, player *p );
  91. void update_player( game *g, player *p );
  92. void init_weapons( game *g, weapons *wp );
  93. void draw_weapons( game *g, weapons *wp );
  94. void update_weapons( game *g, weapons *wp );
  95. void add_weapon( game *g, weapons *wp, int x, int y, int type );
  96. void init_starfield( game *g, starfield *s );
  97. void draw_starfield( game *g, starfield *s );
  98. void update_starfield( game *g, starfield *s );
  99. tunnel * create_tunnel( game *g, int w, int h );
  100. void free_tunnel( tunnel *t );
  101. void draw_tunnel( game *g, tunnel *t );
  102. void update_tunnel( game *g, tunnel *t );
  103. void init_explosions( game *g, explosions *ex );
  104. void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type );
  105. void draw_explosions( game *g, explosions *ex );
  106. void update_explosions( game *g, explosions *ex );