25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

common.h 2.7 KiB

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