aboutsummaryrefslogtreecommitdiffstats
path: root/grv.h
blob: 36ca09bd88cff989ff9955e85436f244b02cc0af (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
#ifndef GRV_H
#define GRV_H 1

#include <inttypes.h>
#include "graphics.h"
#include "SDL.h"
#include "SDL_keyboard.h"

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

/* 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);
#define randomize() init_genrand(time(0))
#define rnd() genrand_res53()
#define irnd(n) ((int)(genrand_int32() % (n)))


#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 */
  int Life;			/* Lives left */
  int SBs;
  int Lvf;
  int GkCh;
  int Level;			/* Current level */
  int MLev;			/* Max level achieved */
  int ZLevel;
  int KulSpr;
  int Bon;			/* Bonus available right now */
  int FrSpok;			/* double? */
  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 c;			/* Main level color */
  int c2;			/* Alternate level color */
  int Cheat;			/* Cheat codes used */
  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;

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

  int nwhite;			/* Number of white cherries */
  int nextwhite;		/* Next white cherry (if any) */
  struct xy whitecherrylist[190];
};
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 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);

#endif /* GRV_H */