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