source: ttyvaders/trunk/src/common.h @ 2990

Last change on this file since 2990 was 2990, checked in by Sam Hocevar, 11 years ago

Port ttyvaders to the unified libcaca 0.99.beta15 API.

  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
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 2990 2008-10-18 21:42:24Z sam $
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15/*
16 * Compile-time limits
17 */
18#define STARS 50
19#define WEAPONS 200
20#define BONUS 30
21#define ALIENS 30
22#define EXPLOSIONS 200
23
24/*
25 * Game defines
26 */
27#define MAX_LIFE 1000
28#define MAX_SPECIAL 200
29
30#define COST_NUKE     (100*MAX_SPECIAL/100)
31#define COST_BEAM      (75*MAX_SPECIAL/100)
32#define COST_FRAGBOMB  (50*MAX_SPECIAL/100)
33
34/*
35 * Graphics primitives
36 */
37#include <caca.h>
38
39/*
40 * Useful macros
41 */
42#define GET_MAX(a,b) ((a)>(b)?(a):(b))
43#define GET_MIN(a,b) ((a)<(b)?(a):(b))
44
45/*
46 * Game structures
47 */
48typedef struct
49{
50    int w, h, *left, *right;
51
52} tunnel;
53
54typedef struct
55{
56    int x, y, z, c;
57    char ch;
58
59} starfield;
60
61typedef struct
62{
63    enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS];
64    int x[EXPLOSIONS];
65    int y[EXPLOSIONS];
66    int vx[EXPLOSIONS];
67    int vy[EXPLOSIONS];
68    int n[EXPLOSIONS];
69
70} explosions;
71
72typedef struct
73{
74    enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE, WEAPON_BEAM, WEAPON_LIGHTNING, WEAPON_BOMB, WEAPON_FRAGBOMB } type[WEAPONS];
75    int x[WEAPONS];
76    int y[WEAPONS];
77    int x2[WEAPONS];
78    int y2[WEAPONS];
79    int x3[WEAPONS];
80    int y3[WEAPONS];
81    int vx[WEAPONS];
82    int vy[WEAPONS];
83    int n[WEAPONS];
84
85} weapons;
86
87typedef struct
88{
89    enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS];
90    int x[BONUS];
91    int y[BONUS];
92    int n[BONUS];
93
94} bonus;
95
96typedef struct
97{
98    int x, y;
99    int vx, vy;
100    int weapon, special;
101    int life, dead;
102
103} player;
104
105typedef struct
106{
107    enum { ALIEN_NONE, ALIEN_FOO, ALIEN_BAR, ALIEN_BAZ } type[ALIENS];
108    int x[ALIENS];
109    int y[ALIENS];
110    int life[ALIENS];
111    int img[ALIENS];
112
113} aliens;
114
115typedef struct
116{
117    int w, h;
118    int x, y;
119    int frame;
120
121} box;
122
123typedef struct
124{
125    int w, h;
126
127    caca_canvas_t *cv;
128    caca_display_t *dp;
129
130    starfield *sf;
131    weapons *wp;
132    explosions *ex;
133    tunnel *t;
134    player *p;
135    aliens *al;
136    bonus *bo;
137
138} game;
139
140void intro(game *g);
141
142/*
143 * From aliens.c
144 */
145void init_aliens(game *, aliens *);
146void draw_aliens(game *, aliens *);
147void update_aliens(game *, aliens *);
148void add_alien(game *, aliens *, int, int, int);
149
150/*
151 * From bonus.c
152 */
153void init_bonus(game *, bonus *);
154void draw_bonus(game *, bonus *);
155void update_bonus(game *, bonus *);
156void add_bonus(game *, bonus *, int, int, int);
157
158/*
159 * From box.c
160 */
161box * create_box(game *, int, int, int, int);
162void draw_box(game *, box *);
163void free_box(box *);
164
165/*
166 * From ceo.c
167 */
168void ceo_alert(game *);
169
170/*
171 * From collide.c
172 */
173void collide_weapons_tunnel(game *, weapons *, tunnel *, explosions *);
174void collide_weapons_aliens(game *, weapons *, aliens *, explosions *);
175void collide_player_tunnel(game *, player *, tunnel *, explosions *);
176
177/*
178 * From explosions.c
179 */
180void init_explosions(game *, explosions *);
181void add_explosion(game *, explosions *, int, int, int, int, int);
182void draw_explosions(game *, explosions *);
183void update_explosions(game *, explosions *);
184
185/*
186 * From overlay.c
187 */
188void draw_status(game *);
189
190/*
191 * From player.c
192 */
193player * create_player(game *);
194void free_player(player *);
195void draw_player(game *, player *);
196void update_player(game *, player *);
197
198/*
199 * From starfield.c
200 */
201starfield * create_starfield(game *);
202void draw_starfield(game *, starfield *);
203void update_starfield(game *, starfield *);
204void free_starfield(game *, starfield *);
205
206/*
207 * From tunnel.c
208 */
209tunnel * create_tunnel(game *, int, int);
210void free_tunnel(tunnel *);
211void draw_tunnel(game *, tunnel *);
212void update_tunnel(game *, tunnel *);
213
214/*
215 * From weapons.c
216 */
217void init_weapons(game *, weapons *);
218void draw_weapons(game *, weapons *);
219void update_weapons(game *, weapons *);
220void add_weapon(game *, weapons *, int, int, int, int, int);
221
Note: See TracBrowser for help on using the repository browser.