-
Notifications
You must be signed in to change notification settings - Fork 20
/
game.h
424 lines (322 loc) · 7.85 KB
/
game.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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
#ifndef GAME_H
#define GAME_H
#include "assets.h"
#include "spec.h"
void GamePreAlloc();
struct DIALOG
{
int who;
const char* text;
};
struct LEVEL
{
char name;
char name2;
int time_limit;
int time_perfect;
ASSET* bkgnd;
unsigned char sky;
const char* sprite;
const char* height;
const DIALOG* dialog;
};
struct COURSE
{
const char* name;
const LEVEL* level;
int flags;
};
extern unsigned char cl_transp;
extern unsigned char cl_label;
extern unsigned char cl_score;
extern unsigned char cl_statbkgnd;
extern unsigned char cl_statvalue;
extern unsigned char cl_statlabel;
extern unsigned char cl_ground;
extern char ch_ground;
extern unsigned char cl_bullet;
extern char ch_bullet;
extern unsigned char cl_basher;
extern unsigned char cl_drone;
extern unsigned char cl_ufo;
extern char ch_basher;
extern char ch_drone;
extern char ch_ufo;
void SetColorMode(unsigned char cl);
extern const LEVEL beginner[];
extern const LEVEL champion[];
extern /*const*/ LEVEL test_area[];
extern const COURSE campaign[];
int InterScreenInput();
struct SCREEN : CON_OUTPUT
{
virtual ~SCREEN();
SCREEN(int _w, int _h, char transp = ' ', unsigned char _tcolor = 0);
void Clear();
virtual void Resize(int _w, int _h);
virtual void Paint(SCREEN* scr, int dx, int dy, int sx, int sy, int sw=-1, int sh=-1, bool blend=false);
int Write(int dw, int dh, int sx, int sy, int sw=-1, int sh=-1);
bool ClipTo(SCREEN* scr, int& dx, int& dy, int& sx, int& sy, int& sw, int& sh);
void BlendPage(SCREEN* scr, int dx, int dy, int sx, int sy, int sw=-1, int sh=-1);
char t;
char tcolor; // color used during clear
};
struct SPRITE
{
int data_pos;
int x_offset;
int y_offset;
int width;
int height;
int frames;
int frame;
const ASSET* data;
SPRITE* next;
SPRITE* prev;
int group_id;
int cookie;
int cookie_data[4];
const char* score_anim[2]; // mono & shade
const char* score_color[2];
ASSET asset;
char score_text[81];
char score_attr[81];
unsigned char attrib_mask;
unsigned char attrib_over;
virtual ~SPRITE();
SPRITE();
SPRITE(const ASSET* anim);
SPRITE(const char* name);
SPRITE(int _score);
void Init();
void Init(const ASSET* anim);
void Init(const char* name);
void Init(int _score);
void SetFrame(int fr);
virtual bool HitTest(int sx, int sy);
virtual void Paint(SCREEN* scr, int dx, int dy, int sx, int sy, int sw=-1, int sh=-1, char bgkey=0, bool blend=true);
static int AnimWidth(const ASSET* a);
static int AnimHeight(const ASSET* a);
static int AnimFrames(const ASSET* a);
};
struct FNT
{
SPRITE fnt;
FNT(const ASSET* f);
void Paint(SCREEN* s, int x, int y, unsigned char cl, const char* txt);
//void Paint(SCREEN* s, int x, int y, unsigned char cl, int val);
};
struct WHEEL:SPRITE
{
virtual ~WHEEL() {}
WHEEL():SPRITE(&wheel) {}
};
struct CANNON:SPRITE
{
virtual ~CANNON() {}
CANNON():SPRITE(&cannon) {}
};
struct CHASSIS:SPRITE
{
SPRITE b;
int ex;
virtual ~CHASSIS();
CHASSIS();
virtual void Paint(SCREEN* s, int dx, int dy, int sx, int sy, int sw=-1, int sh=-1, char underkey=0, bool blend=true);
void Explode(int f);
};
struct SCROLL : SCREEN
{
virtual ~SCROLL();
SCROLL(int _w, int _h, char transp=' ', unsigned char _tcolor=0x00);
virtual void Paint(SCREEN* scr, int dx, int dy, int sx, int sy, int sw=-1, int sh=-1, bool blend=false);
virtual void Resize(int _w, int _h);
virtual void Scroll(int s);
int scroll;
};
struct BACKGROUND : SCROLL
{
virtual ~BACKGROUND();
BACKGROUND(int _w, int _h, unsigned char _tcolor);
virtual void Scroll(int s);
};
struct LANDSCAPE : SCROLL
{
int len;
const ASSET* data;
virtual ~LANDSCAPE();
LANDSCAPE(int _w, int _h, const ASSET* _data, unsigned char _tcolor=0x00);
virtual void Scroll(int s);
};
struct FIG:SPRITE
{
virtual ~FIG();
FIG(const ASSET* font, const char* str);
FIG(const ASSET* font, int val, bool time);
void Update(const char* str);
virtual void Paint(SCREEN* scr, int _dx, int _dy, int _sx, int _sy, int _sw=-1, int _sh=-1, char bgkey=0, bool blend=true);
int pitch;
char* text;
};
struct BULLET
{
int x,y;
int vx,vy;
int fr;
int sx;
int oy;
void* voice;
int cookie;
};
struct TERRAIN;
struct Field
{
Field();
void Rand();
void Animate();
float field(int x, int y);
char cb(int x, int y);
static char cb(int x, int y, void* p);
float thr;
int generator[10][5]; // 10 generators each x,y,r,vx,vy
TERRAIN* t;
};
struct TERRAIN : SCROLL
{
int lives;
char* hitbin; // permanent deaths
int hitcur[256]; // 256 is max num of enemies per sublevel!
int hits;
Field fld;
int interference_size;
int interference_from;
int interference_to;
float interference_mul;
char base_point; // name of first chkpoint
int check_passed;
int check_scroll;
int check_points;
int* check_point;
int scr_height;
int group_id;
int group_len[16];
int group_mul[16];
int sprite_scroll;
int len;
char* data;
int items_len;
const char* items;
// ON GROUND
SPRITE* head; // <- inserting new sprites
SPRITE* tail; // <- reversed painting
// FLYING
SPRITE* fly_head; // <- inserting new sprites
SPRITE* fly_tail; // <- reversed painting
int bullets;
BULLET bullet[100];
virtual ~TERRAIN();
TERRAIN(int _w, int _h, int _scrh, unsigned char _tcolor, const char* sprite, const char* height, char* _hitbin, char _base_point='A', char _start_point='@', int _lives=3);
virtual void Resize(int _w, int _h);
int GetMaxHeight(int x, int n);
bool HitTest(CHASSIS* ch_spr, int x, int y, int fr);
bool BulletTest(int fr, int x, int y, int* game_score);
bool CannonTest(int x, int y, int f, int fr, int* game_score=0);
void DismissSprites(int fr, int speed);
void AnimateSprites(int fr, int speed, bool expl);
virtual void Paint(SCREEN* scr, int dx, int dy, int sx, int sy, int sw=-1, int sh=-1, bool blend=false);
virtual void Scroll(int s);
};
struct LEVEL_MODAL : MODAL
{
void rec_write(unsigned char r);
int rec_len;
unsigned char rec_buf[1024*16]; // about 10 minutes
int x;
int write_size;
int write_persec;
int w;
int h;
BACKGROUND b;
LANDSCAPE m;
LANDSCAPE d;
int speed;
TERRAIN t;
CHASSIS chassis;
WHEEL wheel[3];
int chaisis_vert;
int key_state;
/*
int tch_state;
int tch_id[32];
CON_INPUT tch_quit;
*/
int speed_id; // left / right + down
int jump_id;
int fire_id;
int exit_id;
int vely;
int posy; // grounded
int expl;
int expl_x;
int wheel_posx[3];
int wheel_vert[3];
int wheel_vely[3];
int wheel_velx[3];
int fr;
int freeze_fr;
unsigned long start_tm;
unsigned long lag_tm;
int t_scroll_div;
int d_scroll_div;
int m_scroll_div;
int b_scroll_div;
// absolute hi-res scroll position
int scroll;
CANNON c;
bool cannon_hit;
int cannon_t;
int cannon_x;
int cannon_x2;
int cannon_y;
int cannon_sx;
int bullets;
int bullet_fr;
BULLET bullet[32];
// level passed anim
int post_split;
int post_scroll;
int post_x;
SCREEN* s;
int* score;
int* level_time;
int lives;
int start_lives;
const char* player_name;
void* jump_voice;
const char* course_name;
const LEVEL* current_level;
virtual ~LEVEL_MODAL();
LEVEL_MODAL(SCREEN* _s, int _lives, int _start_lives, int* _score, int* _level_time, const char* _player_name,
const char* _course_name, const LEVEL* _current_level, int iSubLev, char* _hitbin, FILE* _rec=0);
virtual int Run();
int record_fr;
bool record_rel;
int record_cmd; // fetched command used in 'R' mode, will be dispatched when fr>=record_dr
int rec_score;
FILE* record_file;
int record_mode; // 'W' 'R' or 0
void Record(int ev, unsigned int fr, unsigned long a, unsigned long b);
int Fetch(int* _fr);
// .rec / platform input wrapper
void GetTerminalWH(int* _w, int* _h);
bool GetInputLen(int* len);
void ReadInput(CON_INPUT* ir, int n, int* r);
bool HasKeyReleases();
};
#define REC_END 0
#define REC_KEY 1
#define REC_FOC 2
#define REC_SIZ 3
extern int rec_show;
void Interference(SCREEN* s, int dist, int noise, unsigned long phase, int freq, int amp, bool sync);
#endif