source: libcaca/trunk/src/common.h @ 19

Last change on this file since 19 was 19, checked in by Sam Hocevar, 20 years ago
  • real Debian package files.
  • two new types of aliens. only one rules.
  • removed gfx_write in favor of gfx_putchar and gfx_putstr.
  • added bonuses at alien death. they do nothing yet.
  • seeker missiles. 'b' to test.
  • weapon resolution is now 16*char. needs to be generalized.
  • fixed the supernova bugs. center could collide with the tunnel, and the last frame was badly displayed.
  • lots of cleanups everywhere.
File size: 3.7 KB
Line 
1
2#define STARS 50
3#define WEAPONS 50
4#define BONUS 30
5#define ALIENS 30
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_putchar(x) SLsmg_write_char(x)
13#   define gfx_putstr(x) SLsmg_write_string(x)
14#else
15#   include <curses.h>
16#   define gfx_color(x) attrset(COLOR_PAIR(x))
17#   define gfx_goto(x,y) move(y,x)
18#   define gfx_putchar(x) addch(x)
19#   define gfx_putstr(x) addstr(x)
20#endif
21
22#define gfx_putcharTO(x,y,c) do{ gfx_goto(x,y); gfx_putchar(c); }while(0)
23
24#define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0)))
25
26typedef struct
27{
28    int w, h, *left, *right;
29
30} tunnel;
31
32typedef struct
33{
34    int x[STARS];
35    int y[STARS];
36    int z[STARS];
37    char ch[STARS];
38    int c[STARS];
39
40} starfield;
41
42typedef struct
43{
44    enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS];
45    int x[EXPLOSIONS];
46    int y[EXPLOSIONS];
47    int vx[EXPLOSIONS];
48    int vy[EXPLOSIONS];
49    int n[EXPLOSIONS];
50
51} explosions;
52
53typedef struct
54{
55    enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE } type[WEAPONS];
56    int x[WEAPONS];
57    int y[WEAPONS];
58    int x2[WEAPONS];
59    int y2[WEAPONS];
60    int x3[WEAPONS];
61    int y3[WEAPONS];
62    int vx[WEAPONS];
63    int vy[WEAPONS];
64    int n[WEAPONS];
65
66} weapons;
67
68typedef struct
69{
70    enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS];
71    int x[BONUS];
72    int y[BONUS];
73    int n[BONUS];
74
75} bonus;
76
77typedef struct
78{
79    int x, y;
80    int dir;
81    int weapon, nuke;
82
83} player;
84
85typedef struct
86{
87    enum { ALIEN_NONE, ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH } type[ALIENS];
88    int x[ALIENS];
89    int y[ALIENS];
90    int life[ALIENS];
91    int img[ALIENS];
92
93} aliens;
94
95typedef struct
96{
97    int w, h;
98
99    starfield *sf;
100    weapons *wp;
101    explosions *ex;
102    tunnel *t;
103    player *p;
104    aliens *al;
105    bonus *bo;
106
107} game;
108
109#define BLACK 1
110#define GREEN 2
111#define YELLOW 3
112#define WHITE 4
113#define RED 5
114#define GRAY 6
115#define LIGHTGRAY 7
116#define BLUE 8
117#define CYAN 9
118#define MAGENTA 10
119
120void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex );
121void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex );
122void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex );
123
124void init_aliens( game *g, aliens *al );
125void draw_aliens( game *g, aliens *al );
126void update_aliens( game *g, aliens *al );
127void add_alien( game *g, aliens *al, int x, int y, int type );
128
129int init_graphics( void );
130void init_game( game *g );
131char get_key( void );
132void clear_graphics( void );
133void refresh_graphics( void );
134void end_graphics( void );
135
136player * create_player( game *g );
137void free_player( player *p );
138void draw_player( game *g, player *p );
139void update_player( game *g, player *p );
140
141void init_weapons( game *g, weapons *wp );
142void draw_weapons( game *g, weapons *wp );
143void update_weapons( game *g, weapons *wp );
144void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type );
145
146void init_bonus( game *g, bonus *bo );
147void draw_bonus( game *g, bonus *bo );
148void update_bonus( game *g, bonus *bo );
149void add_bonus( game *g, bonus *bo, int x, int y, int type );
150
151void init_starfield( game *g, starfield *s );
152void draw_starfield( game *g, starfield *s );
153void update_starfield( game *g, starfield *s );
154
155tunnel * create_tunnel( game *g, int w, int h );
156void free_tunnel( tunnel *t );
157void draw_tunnel( game *g, tunnel *t );
158void update_tunnel( game *g, tunnel *t );
159
160void init_explosions( game *g, explosions *ex );
161void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type );
162void draw_explosions( game *g, explosions *ex );
163void update_explosions( game *g, explosions *ex );
164
Note: See TracBrowser for help on using the repository browser.