summaryrefslogtreecommitdiffstats
path: root/grv.h
blob: e8391f09bd33f8fbb41d10f4b49443ceb66717b7 (plain)
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
#ifndef GRV_H
#define GRV_H 1

#include <inttypes.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "graphics.h"
#ifdef SDL_SUBDIR
# include "SDL/SDL.h"
# include "SDL/SDL_keyboard.h"
#else
# include "SDL.h"
# include "SDL_keyboard.h"
#endif

#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y))

/* Get random bytes from the system */
int get_random_bytes(void *, int);
void randomize(void);

/* Get a random floating-point number between 0 and 1 */
extern void init_genrand(unsigned long);
extern double genrand_res53(void);
extern unsigned long genrand_int32(void);
extern void init_by_array(const unsigned long *, unsigned long);
#define rnd() genrand_res53()
#define irnd(n) ((int)(genrand_int32() % (n)))

/* Command-line options */
struct opts {
  int nonet;			/* Don't access the network server */
  int window;			/* Run in a window */
  int debug;			/* No parachute mode (for debugging) */
};
extern struct opts opt;

#define ELev 75			/* Ending level */

struct xy {
  int x, y;
};

struct gameparams {
  /* Yes, score can be negative, although it's highly unlikely */
  int64_t Sc;			/* Score */
  int64_t StScore;		/* Score at start of level */
  int64_t SBs;			/* Total points in Super Bonus */
  int Life;			/* Lives left */
  int Lvf;
  int GkCh;
  int Level;			/* Current level */
  int MLev;			/* Max level achieved */
  int ZLevel;
  int KulSpr;
  int Bon;			/* Bonus available right now */
  int TF;			/* double? */
  int FS;			/* Ghost speed (1 normal, -1 scared, 0 frozen) */

  int x, y;			/* Player coordinates */
  int XWk, YWk;			/* Player movement */
  int Hyp;
  int ChBd;
  int Bar;			/* Number of cherries on screen */
  int OrigBar;			/* Cherries at level start */
  int Bombs;			/* Number of bombs on the level */
  int c;			/* Main level color */
  int c2;			/* Alternate level color */
  int Cheat;			/* Cheat codes used */
  int InfLife;			/* Infinite life cheat */
  int EOLWait;			/* Standard death/end of level pause? */
  int TZero;			/* Time at start of level (ms) */
  int Speed;			/* Desired game speed ms/game round */
  double Tid;			/* Time since level start (float s) */
  enum {
    Status_Live,		/* Player alive */
    Status_Dead,		/* Player dead */
    Status_Done,		/* Player done with level */
    Status_Quit,		/* Level exit (treasure) */
  } Status;

  int nwhite;			/* Number of white cherries */
  int nextwhite;		/* Next white cherry (if any) */
  struct xy whitecherrylist[190];

  uint64_t gameid;		/* (Hopefully) unique ID for high score list */
  int have_id;			/* Is ID frozen yet? */
};
extern struct gameparams gp;

enum actions {
  act_none,			/* No action */
  act_apple,			/* Apple fall */
  act_bomb,			/* Bomb goes off */
  act_bonus_on,			/* BONUS light on */
  act_bonus_off,		/* BONUS light off */
  act_smash,			/* "Smash" */
  act_toolate,			/* Time expired */
  act_droplevel,		/* Drop one level (finale level) */
  act_door,			/* Open door */
  act_ghost_thaw,		/* Thaw frozen ghosts */
  act_ghost_normal,		/* Return ghosts to normal */
};

struct monster {
  int x, y;
  int dead;
};
#define MAXGHOST 5
extern struct monster ghost[MAXGHOST];

/* Keyboard handling */
#define NKEYS 11
extern SDLKey kbd_keys[NKEYS];

/* User-defined SDL event types */
enum user_event {
  event_next_round,		/* Next game round */
  event_blink,			/* Handle blinking */
  event_sleep,			/* Sleep expired */
};

/* Character symbols */
#define SYM_PLAYER	0x01
#define SYM_GHOST	0x02
#define SYM_ROCK	0x04
#define SYM_CLUSTER	0x0f
#define SYM_NOTHING	' '
#define SYM_DIAMOND	'*'
#define SYM_MYSTERY	'?'
#define SYM_POROUS_WALL	0xb0
#define SYM_WALL	0xb1
#define SYM_CHERRY	0xeb
#define SYM_BOMB	0xe5
#define SYM_SHOT	0xec
#define SYM_BONUS	0xf9
#define SYM_APPLE	0xfe
/* All possible doors */
#define DOORS		"\xb9\xba\xbb\xbc\xc8\xc9\xca\xcb\xcc\xcd\xce"

/* utils.c */
int fg(int r, int c);
int bg(int r, int c);
int busy(int r, int c);
Uint32 post_periodic(Uint32 interval, void *param);
Uint32 post_oneshot(Uint32 interval, void *param);
void mymssleep(int ms);
char *format_time(double t);

/* drawlevel.c */
void drawlevel(void);
void levelscreen(void);

/* grv.c */
void initscreen(int w);
void update_score(void);
void update_shots(void);
void update_power(void);
void update_jump(void);
void message(int col, const char *fmt, ...);

/* play.c */
void white2black(void);
void play(void);
void fall_rock(int x, int y);
void fall_apple(int x, int y);
void kill_ghost(int x, int y);
void take_cherry(void);
void take_diamond(void);

/* keyboard.c */
void push_key(SDL_KeyboardEvent *ke);
SDL_KeyboardEvent *poll_key(void);
SDL_KeyboardEvent *get_key(void);

/* action.c */
void reset_actions(void);
void addaction(int x, int y, double when, enum actions what);
void removeaction(int x, int y, enum actions what);
void handle_action(void);
void retime_all(double when, enum actions what);

/* bullets.c */
void add_bullet(int x, int y, int dx, int dy, int color);
void run_bullets(void);

/* mystery.c */
void mystery(void);

/* highscore.c */
void highscore_load(void);
void highscore_download(void);
void highscore_save(void);
void highscore_upload(void);
void highscore_show(int myrank, int save);
void highscore_endgame(void);

/* intro.c */
void intro(void);

/* prefs.c */
void load_prefs(void);
void set_keys(void);

/* homedir.c */
void goto_grv_dir(void);

#endif /* GRV_H */