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

Last change on this file since 50 was 50, checked in by Sam Hocevar, 17 years ago
  • the beam now digs the tunnel.
  • the starfield is now an array of stars.
  • fixed wall rendering (offset issues and disappearing left wall).
  • 32 seekers on fragbomb explosion, not 16.
File size: 4.7 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.10 2002/12/23 09:28:37 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 200
25#define BONUS 30
26#define ALIENS 30
27#define EXPLOSIONS 200
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#define GET_MAX(a,b) ((a)>(b)?(a):(b))
47#define GET_MIN(a,b) ((a)<(b)?(a):(b))
48
49typedef struct
50{
51    int w, h, *left, *right;
52
53} tunnel;
54
55typedef struct
56{
57    int x, y, z, c;
58    char ch;
59
60} starfield;
61
62typedef struct
63{
64    enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS];
65    int x[EXPLOSIONS];
66    int y[EXPLOSIONS];
67    int vx[EXPLOSIONS];
68    int vy[EXPLOSIONS];
69    int n[EXPLOSIONS];
70
71} explosions;
72
73typedef struct
74{
75    enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE, WEAPON_BEAM, WEAPON_LIGHTNING, WEAPON_BOMB, WEAPON_FRAGBOMB } type[WEAPONS];
76    int x[WEAPONS];
77    int y[WEAPONS];
78    int x2[WEAPONS];
79    int y2[WEAPONS];
80    int x3[WEAPONS];
81    int y3[WEAPONS];
82    int vx[WEAPONS];
83    int vy[WEAPONS];
84    int n[WEAPONS];
85
86} weapons;
87
88typedef struct
89{
90    enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS];
91    int x[BONUS];
92    int y[BONUS];
93    int n[BONUS];
94
95} bonus;
96
97typedef struct
98{
99    int x, y;
100    int dir;
101    int weapon, nuke;
102
103} player;
104
105typedef struct
106{
107    enum { ALIEN_NONE, ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH } 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
119    starfield *sf;
120    weapons *wp;
121    explosions *ex;
122    tunnel *t;
123    player *p;
124    aliens *al;
125    bonus *bo;
126
127} game;
128
129#define BLACK 1
130#define GREEN 2
131#define YELLOW 3
132#define WHITE 4
133#define RED 5
134#define GRAY 6
135#define LIGHTGRAY 7
136#define BLUE 8
137#define CYAN 9
138#define MAGENTA 10
139
140void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex );
141void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex );
142void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex );
143
144void init_aliens( game *g, aliens *al );
145void draw_aliens( game *g, aliens *al );
146void update_aliens( game *g, aliens *al );
147void add_alien( game *g, aliens *al, int x, int y, int type );
148
149int init_graphics( void );
150void init_game( game *g );
151char get_key( void );
152void clear_graphics( void );
153void refresh_graphics( void );
154void end_graphics( void );
155
156player * create_player( game *g );
157void free_player( player *p );
158void draw_player( game *g, player *p );
159void update_player( game *g, player *p );
160
161void init_weapons( game *g, weapons *wp );
162void draw_weapons( game *g, weapons *wp );
163void update_weapons( game *g, weapons *wp );
164void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type );
165
166void init_bonus( game *g, bonus *bo );
167void draw_bonus( game *g, bonus *bo );
168void update_bonus( game *g, bonus *bo );
169void add_bonus( game *g, bonus *bo, int x, int y, int type );
170
171starfield * create_starfield( game *g );
172void draw_starfield( game *g, starfield *s );
173void update_starfield( game *g, starfield *s );
174void free_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
188int r00t( int a );
189
Note: See TracBrowser for help on using the repository browser.