-
Notifications
You must be signed in to change notification settings - Fork 0
/
brillion.h
370 lines (306 loc) · 7.56 KB
/
brillion.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/* The all-in-one Header file
* vim:set cin sm ts=8 sw=8 sts=4: Sec <sec@42.org>
* $Id: brillion.h,v 1.47 2005/12/08 12:38:48 sec Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <limits.h>
#include <unistd.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include "SDL.h"
#ifdef SOUND
#include "SDL_mixer.h"
#endif
#ifdef DMALLOC
#include <dmalloc.h>
#endif
#define PROG_NAME "Brillion"
#ifndef PROG_VERSION
#define PROG_VERSION "(cvs)"
#endif
#define die(x) do{fprintf(stderr,"DIEd: \"%s\" in %s line %d\n",x,__FILE__,__LINE__);exit(EXIT_FAILURE);}while(0)
/* Colors */
#define BLACK 0
#define RED 1
#define CYAN 2
#define MAGENTA 3
#define GREEN 4
#define BLUE 5
#define YELLOW 6
#define GAME_COLORS 7
#define WHITE 7
#define BG 8
#define FG 9
#define NONE 10
#define MAX_COLORS 11
/* Block Types */
#define SPACE 0
#define BLOCK 1
#define DISK 2
#define STAR 3
#define WALL 4
#define DEATH 5
#define OUTER_WALL 6
#define MAX_PIECE 7
#define LEVEL 8 /* Level change (sound only) */
typedef enum {
A_NONE,
A_BALL,
A_DISK,
A_EXPLODE,
A_DIE,
A_TWINKLE
} anim_t;
typedef struct {
int x, y;
} coord;
#define MAX_ANIM 9
typedef struct {
anim_t type;
int color;
int duration;
coord block[2];
coord pixel[2];
} a_anim;
typedef struct {
int version; /* Version number. Always 42 */
int w,h; /* Width and height of the level */
char desc[100]; /* Level name and author */
int *pieces; /* The physical level */
int *colors; /* The colors of different pieces */
#define COLOR(x,y) lvl->colors[(x)*lvl->h+(y)]
#define PIECE(x,y) lvl->pieces[(x)*lvl->h+(y)]
int blocks; /* Blocks remaining */
int time; /* Time remaining */
int x,y; /* Ball position */
signed int dir; /* Ball direction */
int color; /* Ball color */
int ppb; /* Points/Block */
} field;
#define FONTBEG 33
#define FONTLEN (255-FONTBEG)
typedef struct {
int beg[FONTLEN+1];
int wid[FONTLEN+1];
int h;
int len;
int space;
int lineh;
SDL_Surface *font;
} a_font;
typedef struct {
SDL_Surface *display;
/* UpdateRects list */
SDL_Rect *rects;
int numrects;
Uint32 colors[MAX_COLORS];
/* For background */
/*int xoff, yoff;*//* Offset of the level area in main window */
SDL_Rect level; /* Level Area */
SDL_Surface *border;
/* block graphics */
SDL_Surface *wall;
SDL_Surface *back;
SDL_Surface *death;
SDL_Surface *ball[GAME_COLORS];
SDL_Surface *ballx[GAME_COLORS];
SDL_Surface *disk[GAME_COLORS];
SDL_Surface *block[GAME_COLORS];
SDL_Surface *blockx[GAME_COLORS];
SDL_Surface *star[GAME_COLORS];
SDL_Color *palette;
int ncolors;
/* font */
SDL_Surface *font; /* numbers */
a_font *tfont; /* text */
} graphic;
#define MAXRECTS 256 /* 164 or so for startup */
#define UPDATE(rect) do{ \
assert(g->numrects<MAXRECTS); \
memcpy(g->rects+(g->numrects++),&rect,sizeof(SDL_Rect)); \
}while(0)
#define DISPLAY do{ \
SDL_UpdateRects(g->display,g->numrects,g->rects); \
g->numrects=0; \
}while(0)
/* For development: */
/*#define DISPLAY do{SDL_Flip(g->display);g->numrects=0;}while(0) */
typedef struct {
#ifdef SOUND
Mix_Music *bg;
/* touch sounds */
Mix_Chunk *wall;
Mix_Chunk *death;
Mix_Chunk *disk;
Mix_Chunk *block;
Mix_Chunk *star;
Mix_Chunk *level;
#else
int nothing; /* To silence compiler warning */
#endif
} music;
typedef struct {
char *name; /* Background graphic */
coord pts;
coord time;
coord blocks;
coord lives;
coord level;
coord lname;
coord field;
/*coord fieldsz; // Just assume it matches :) */
} a_layout;
typedef struct { /* block, sound, music currently fixed per game. */
char *name; /* Filename of the level file */
} a_level;
typedef enum {
R_NONE,
R_PLAY,
R_RECORD
} rec_t;
typedef struct {
rec_t what;
char *game;
int len;
int pos;
} a_save;
typedef enum {
S_PLAY,
S_DIE,
S_QUIT,
S_FINISH
} status_t;
typedef struct {
graphic *g;
music *m;
field *f;
a_anim *a;
int anims;
int lives;
int points;
int level;
status_t status;
a_save *s;
a_layout *layout;
time_t starttime;
} a_play;
#define MAX_SCORES 11
#define SCORENAMELEN 8
typedef struct {
char name[SCORENAMELEN];
int score;
time_t when;
int howlong;
/* char flags[8]; */
/* int csum; */
} a_score;
typedef struct {
a_score scores[MAX_SCORES];
int maxscore;
} the_scores;
typedef struct {
a_level **levels;
int maxlevel;
int lives;
a_layout *layout;
the_scores *scores;
} a_game;
typedef struct {
int verbose; /* Debugging level */
const char *prog; /* Binary name */
char *dir; /* Data directory */
/* We can argue if they should be here... */
a_game *game; /* (constant) things from selected game */
} the_status;
#ifndef EXTERN
#define EXTERN extern
#endif
/* a (small) global */
EXTERN the_status *b; /* The game */
EXTERN a_play *play; /* we are currently playing this */
/* Function Prototypes follow here */
/* physics.c */
void move_step(signed int input);
int move_touch(int x,int y,signed int dx,signed int dy);
/* level.c */
field* read_level(char *file);
void free_level(field *lvl);
void dump_level(field *lvl);
/* graphics.c */
graphic* init_graphic(void);
void paint_level(void);
void paint_block(int x, int y);
void paint_ball(void);
void snapshot(void);
void update_scoreboard(void);
void clear_number_cache(void);
/* play.c */
void run_game(a_game* game);
#ifdef SOUND
/* music.c */
music* init_music(void);
void uninit_music(void);
void play_touch(int piece);
#else
#define init_music() NULL
#define uninit_music() NULL
#define play_touch(a)
#endif
/* game.c */
a_game* read_game(const char* file);
/* graphics.c (should be anim.c?) */
#define AFRAMES 4
a_anim* init_anim(void);
void animate(int step);
void create_moveanim(anim_t type, int color, int ox, int oy, int nx, int ny);
void create_staticanim(anim_t type, int color, int x, int y);
/* effects.c */
typedef enum {
HORIZ_IN,
HORIZ_OUT,
VERT_IN,
VERT_OUT
} split_t;
void fade (SDL_Surface* s, Uint32 ticks, int fadein);
void split (SDL_Surface* s, SDL_Rect* r_in, Uint32 ticks, split_t type);
/* save.c */
a_save* init_save(void);
signed int handle_save(signed int dir);
void print_save(a_save *s);
/* font.c */
a_font* init_font(const char *file);
void render_font(int x, int y,const char *txt);
void render_font_to(int x, int y,const char *txt,SDL_Surface *disp);
SDL_Rect *render_text(int x, int y,const char *txt,a_font *f,int maxw);
void size_text(SDL_Rect *sr,const char *txt,a_font *f);
char *input_text(SDL_Rect *in, a_font *f);
int numwidth(a_font *f);
void render_num(int x, int y, int w,int num,a_font *f);
void render_fix(int x, int y, int w,const char *txt,a_font *f);
void nice_render_text(SDL_Rect *rv,const char *txt,a_font *f,int flags);
/* score.c */
the_scores* read_scores(void);
void write_scores(the_scores* scores);
void display_scores(void);
void add_score(the_scores* scores, int points);
/* title.c */
typedef struct {
char * name;
void (*callback) (SDL_Surface *,int);
} menuentry;
int title_main(void);
SDL_Surface * create_title(menuentry *);
/* timer.c */
#define SDL_USER_NOTHING 0
#define SDL_USER_ENDOFSCORES 1
#define SDL_USER_BLINK 2
void init_timer(void);
void time_event(unsigned int centiseconds,int eventtype);
/* portab.c */
char * getuser(void);