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

Last change on this file since 37 was 37, checked in by Sam Hocevar, 20 years ago
  • I think I fucked up the $Id tags on my previous commit.
File size: 4.6 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,v 1.7 2002/12/22 18:44:12 sam Exp $
7 *
8 *   This program is free software; you can redistribute it and/or modify
9 *   it under the terms of the GNU General Public License as published by
10 *   the Free Software Foundation; either version 2 of the License, or
11 *   (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#define STARS 50
24#define WEAPONS 100
25#define BONUS 30
26#define ALIENS 30
27#define EXPLOSIONS 100
28
29#ifdef USE_SLANG
30#   include <slang.h>
31#   define gfx_color(x) SLsmg_set_color(x)
32#   define gfx_goto(x,y) SLsmg_gotorc(y,x)
33#   define gfx_putchar(x) SLsmg_write_char(x)
34#   define gfx_putstr(x) SLsmg_write_string(x)
35#else
36#   include <curses.h>
37#   define gfx_color(x) attrset(COLOR_PAIR(x))
38#   define gfx_goto(x,y) move(y,x)
39#   define gfx_putchar(x) addch(x)
40#   define gfx_putstr(x) addstr(x)
41#endif
42
43#define gfx_putcharTO(x,y,c) do{ gfx_goto(x,y); gfx_putchar(c); }while(0)
44
45#define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0)))
46
47typedef struct
48{
49    int w, h, *left, *right;
50
51} tunnel;
52
53typedef struct
54{
55    int x[STARS];
56    int y[STARS];
57    int z[STARS];
58    char ch[STARS];
59    int c[STARS];
60
61} starfield;
62
63typedef struct
64{
65    enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS];
66    int x[EXPLOSIONS];
67    int y[EXPLOSIONS];
68    int vx[EXPLOSIONS];
69    int vy[EXPLOSIONS];
70    int n[EXPLOSIONS];
71
72} explosions;
73
74typedef struct
75{
76    enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE, WEAPON_BEAM, WEAPON_LIGHTNING, WEAPON_BOMB } type[WEAPONS];
77    int x[WEAPONS];
78    int y[WEAPONS];
79    int x2[WEAPONS];
80    int y2[WEAPONS];
81    int x3[WEAPONS];
82    int y3[WEAPONS];
83    int vx[WEAPONS];
84    int vy[WEAPONS];
85    int n[WEAPONS];
86
87} weapons;
88
89typedef struct
90{
91    enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS];
92    int x[BONUS];
93    int y[BONUS];
94    int n[BONUS];
95
96} bonus;
97
98typedef struct
99{
100    int x, y;
101    int dir;
102    int weapon, nuke;
103
104} player;
105
106typedef struct
107{
108    enum { ALIEN_NONE, ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH } type[ALIENS];
109    int x[ALIENS];
110    int y[ALIENS];
111    int life[ALIENS];
112    int img[ALIENS];
113
114} aliens;
115
116typedef struct
117{
118    int w, h;
119
120    starfield *sf;
121    weapons *wp;
122    explosions *ex;
123    tunnel *t;
124    player *p;
125    aliens *al;
126    bonus *bo;
127
128} game;
129
130#define BLACK 1
131#define GREEN 2
132#define YELLOW 3
133#define WHITE 4
134#define RED 5
135#define GRAY 6
136#define LIGHTGRAY 7
137#define BLUE 8
138#define CYAN 9
139#define MAGENTA 10
140
141void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex );
142void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex );
143void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex );
144
145void init_aliens( game *g, aliens *al );
146void draw_aliens( game *g, aliens *al );
147void update_aliens( game *g, aliens *al );
148void add_alien( game *g, aliens *al, int x, int y, int type );
149
150int init_graphics( void );
151void init_game( game *g );
152char get_key( void );
153void clear_graphics( void );
154void refresh_graphics( void );
155void end_graphics( void );
156
157player * create_player( game *g );
158void free_player( player *p );
159void draw_player( game *g, player *p );
160void update_player( game *g, player *p );
161
162void init_weapons( game *g, weapons *wp );
163void draw_weapons( game *g, weapons *wp );
164void update_weapons( game *g, weapons *wp );
165void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type );
166
167void init_bonus( game *g, bonus *bo );
168void draw_bonus( game *g, bonus *bo );
169void update_bonus( game *g, bonus *bo );
170void add_bonus( game *g, bonus *bo, int x, int y, int type );
171
172void init_starfield( game *g, starfield *s );
173void draw_starfield( game *g, starfield *s );
174void update_starfield( game *g, starfield *s );
175
176tunnel * create_tunnel( game *g, int w, int h );
177void free_tunnel( tunnel *t );
178void draw_tunnel( game *g, tunnel *t );
179void update_tunnel( game *g, tunnel *t );
180
181void init_explosions( game *g, explosions *ex );
182void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type );
183void draw_explosions( game *g, explosions *ex );
184void update_explosions( game *g, explosions *ex );
185
186void ceo_alert( void );
187
Note: See TracBrowser for help on using the repository browser.