~ubuntu-branches/ubuntu/edgy/gnurobbo/edgy

« back to all changes in this revision

Viewing changes to game.h

  • Committer: Bazaar Package Importer
  • Author(s): Lukasz Jachowicz
  • Date: 2004-07-28 16:26:39 UTC
  • Revision ID: james.westby@ubuntu.com-20040728162639-27r5ufn149xopskq
Tags: upstream-0.57
ImportĀ upstreamĀ versionĀ 0.57

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "config.h"
 
2
 
 
3
#include <SDL/SDL.h>
 
4
#include <SDL/SDL_endian.h>
 
5
#include <stdio.h> 
 
6
#include <SDL/SDL_ttf.h>
 
7
 
 
8
#define SPEED 4                         // the less the fast...
 
9
#define FIELD_SIZE 32                   // size of one field
 
10
#define ROBBO_LIVES_START 5             // how many lifes Robbo should have at start
 
11
#define ROBBO_LEVEL_START 1             // begining level for Robbo
 
12
#define TICK_INTERVAL 10                        // Delay for SDL library
 
13
#define DELAY_BIRD 4 * SPEED            // Delays for objects
 
14
#define DELAY_BOOM 1 * SPEED
 
15
#define DELAY_BEAR 4 * SPEED
 
16
#define DELAY_BUTTERFLY 4 * SPEED
 
17
#define DELAY_BIGBOOM 3 * SPEED
 
18
#define DELAY_ROBBO  4 * SPEED
 
19
#define DELAY_TELEPORT 15 * SPEED
 
20
#define DELAY_LASER 4 * SPEED
 
21
#define DELAY_CAPSULE 10 * SPEED
 
22
#define DELAY_GUN 8 * SPEED
 
23
#define DELAY_ROTATION 20 * SPEED
 
24
#define DELAY_BLASTER 4 * SPEED
 
25
#define DELAY_PUSHBOX 4 * SPEED
 
26
#define DELAY_BARRIER 4 * SPEED
 
27
#define SCROLL_RATE 32                  // Scrolling rate
 
28
 
 
29
#define LAST_LEVEL 52
 
30
 
 
31
/* object ids */
 
32
#define EMPTY_FIELD 0
 
33
#define ROBBO 1
 
34
#define WALL 2
 
35
#define WALL_RED 3
 
36
#define SCREW 4
 
37
#define BULLET 5
 
38
#define BOX 6
 
39
#define KEY 7
 
40
#define BOMB 8
 
41
#define DOOR 9
 
42
#define QUESTIONMARK 10
 
43
#define BEAR 11
 
44
#define BIRD 13
 
45
#define CAPSULE 15
 
46
#define LIVE 20
 
47
#define LITTLE_BOOM 21
 
48
#define GROUND 24
 
49
#define WALL_GREEN 25
 
50
#define BEAR_B 26
 
51
#define BUTTERFLY 28
 
52
#define LASER_L 30
 
53
#define LASER_D 32
 
54
#define TELEPORT 40
 
55
#define BIG_BOOM 42
 
56
#define GUN 50
 
57
#define MAGNET 54
 
58
#define BLASTER 58
 
59
#define BLACK_WALL 59
 
60
#define PUSH_BOX 60
 
61
#define BARRIER 61
 
62
 
 
63
/* game limitations */
 
64
#define MAX_X 200               // max x size of the board
 
65
#define MAX_Y 200               // max y size of the board
 
66
#define MAX_TELEPORT_IDS 10     // max number of teleports of one kind at level
 
67
#define DELAY_BLINKSCREEN 2     // how long screen should blink after exit opening
 
68
#define CODE_LENGTH 5
 
69
 
 
70
/* paths to additional files */
 
71
#ifdef PACKAGE_DATA_DIR
 
72
#define BMP_ICONS (PACKAGE_DATA_DIR "pixmaps/icons.bmp")
 
73
#define BMP_CIPHERS (PACKAGE_DATA_DIR "pixmaps/ciphers.bmp")
 
74
#define BMP_BACKGROUND (PACKAGE_DATA_DIR "pixmaps/background.bmp")
 
75
#define ROBBO_FONT (PACKAGE_DATA_DIR "robbo.ttf")
 
76
#define ROBBO_LEVELS (PACKAGE_DATA_DIR "levels.dat")
 
77
#else
 
78
#define BMP_ICONS "pixmaps/icons.bmp"
 
79
#define BMP_CIPHERS "pixmaps/ciphers.bmp"
 
80
#define ROBBO_FONT "robbo.ttf"
 
81
#define ROBBO_LEVELS "levels.dat"
 
82
#endif
 
83
 
 
84
#define FONTSIZE 15
 
85
#define RESOURCE_FILE "/.gnurobborc"
 
86
 
 
87
char *user_home_dir;
 
88
char path_resource_file[100];
 
89
 
 
90
static Uint32 next_time;
 
91
Uint32 rmask, gmask, bmask,amask;  /* variables for creating surfaces */
 
92
int KeyPressed;                    /* Structure with information about pressed keys */
 
93
                                   /* Bits:  RDLUS      R - rigth ... etc... S - shift */
 
94
int KeyLastPressed;
 
95
 
 
96
TTF_Font* font;
 
97
 
 
98
SDL_Surface* screen;
 
99
SDL_Surface* robbo_img[8];
 
100
SDL_Surface* score_img[10];
 
101
SDL_Surface* score_screw;
 
102
SDL_Surface* score_key;
 
103
SDL_Surface* score_bullet;
 
104
SDL_Surface* score_level;
 
105
SDL_Surface* score_robbo;
 
106
SDL_Surface* icons;
 
107
SDL_Surface* ciphers;
 
108
SDL_Surface* image;
 
109
SDL_Surface* image_startscreen;
 
110
SDL_Surface* icon;
 
111
 
 
112
 
 
113
static char* Text[] = {"Robbo has been lost on unfriendly planet. Help him to get out ",
 
114
                        "of there, but remember, you have only limited number of lives...",
 
115
                        "This job is not so easy, there're many levels, killing animals, ",
 
116
                        "shooting guns and other kind things...",
 
117
                        "          Game page: http://gnurobbo.sourceforge.net",
 
118
                        " ",
 
119
                        " ",
 
120
                        " ",
 
121
                        "              Keys:",
 
122
                        "        ARROWS                 Moving",
 
123
                        "        SHIFT+ARROW   Shooting",
 
124
                        "        ESC                          Suicide",
 
125
                        "        F9                        End game",
 
126
                        " ",
 
127
                        " ",
 
128
                        " ",
 
129
                        " ",
 
130
                        " " };
 
131
static char* MenuText[] = {     "Start game",
 
132
                                "Change level",
 
133
                                "Quit game"};
 
134
 
 
135
 
 
136
static char* EndScreen[] = {"Congtatulations you have completed all levels.",
 
137
                          "Robbo can safely go home now....",
 
138
                          " ",
 
139
                          "Press RETURN to start from the begining."};
 
140
int MenuPosition;
 
141
SDL_Color bgcolor;
 
142
SDL_Color fgcolor;
 
143
 
 
144
struct Coords{
 
145
  int x;
 
146
  int y;
 
147
};
 
148
 
 
149
int game_is_started;
 
150
int offset_description;
 
151
 
 
152
struct object{
 
153
  int type;
 
154
  int state;
 
155
  int direction;     /* 0r 1d 2l 3u */
 
156
  int destroyable;   /* can be destroyed */
 
157
  int blowable;      /* can be blowed up */
 
158
  int killing;       /* is object dangerous for robbo */
 
159
  int moved;         /* When last object was moved (all movable) */
 
160
  int blowed;        /* Should object be blowed up? */
 
161
  int shooted;       /* When lately object shooted (guns) */
 
162
  int rotated;       /* When object lately was rotated (guns) */
 
163
  int solidlaser;    /* Does gun shoots solid or normal laser */
 
164
  int rotable;       /* If object can be rotated ? (guns) */
 
165
  int randomrotated; /* When object has undetermining rotation */
 
166
  int teleportnumber; /* Number of teleport (kind of theleport) */
 
167
  int teleportnumber2; /* ID of teleport (for teleports with the same number */
 
168
  int id_questionmark; /* What object is covered under questionmark */
 
169
  int direction2;      /* direction of moveing (for guns) (if direction2 for birds != (direction+-1) bird shoots */
 
170
  int movable;         /* Is object moving (only for guns all animals do) */
 
171
  int returnlaser;      /* only for solid lasers... */
 
172
  int shooting;         /* if birds can shoot */
 
173
  struct Coords icon[5];   /* Coords of left-up point of icons drawed on bitmap */
 
174
};
 
175
 
 
176
  SDL_Event event;
 
177
  struct object board[MAX_X][MAX_Y];
 
178
  struct object board_copy[MAX_X][MAX_Y];       // the copy of board - it protects from reading
 
179
  int board_changed[MAX_X][MAX_Y];              // 1 if board needs update, 0 another case 
 
180
                                                // data each time we need the same level
 
181
  int old_level;                                // what was last level?
 
182
  int score_was_changed;                        // score was changed ...
 
183
  int typing_code;                              // typing the code
 
184
  char TextBuffer[100];                         // text buffer
 
185
  char TypeBuffer[CODE_LENGTH+1];
 
186
  char TextRGBColor[7];                         // Buffer for hex RGB representation
 
187
 
 
188
 
 
189
struct{
 
190
  int x;                // actual x position
 
191
  int y;                // actual y position
 
192
  int init_x;           // init x position
 
193
  int init_y;           // init y position
 
194
  int alive;            // if Robbo is alive
 
195
  int state;            // Robbo's state (0 or 1 for exchange 2 icons for each direction) 
 
196
  int direction;        // Robbo's direction 0,2,4,6  + state => icon
 
197
  int score;            // Robbo's score
 
198
  int screws;           // Screws to collect
 
199
  int lives;            // Lives remaining
 
200
  int keys;             // Keys
 
201
  int bullets;
 
202
  int level;
 
203
  int moved;
 
204
  int shooted;
 
205
  int exitopened;
 
206
  int stepdirection;    // 0 - direction of stepping
 
207
  int mapoffsetx;
 
208
  int mapoffsety;
 
209
  int blocked;                  /* robbo cannot move - possible magnet moving */
 
210
  int blocked_direction;        /* where robbo should be moved after blocking */
 
211
} robbo;
 
212
 
 
213
struct{
 
214
  int x;
 
215
  int y;
 
216
  int number;
 
217
  int screws;
 
218
  int init_screws;              // initial number of screws to collect
 
219
  char code[CODE_LENGTH+1];
 
220
  int bullets;
 
221
  char author[50];
 
222
  int now_is_blinking;
 
223
  int now_is_scrolling_h;       // horizontal scrolling
 
224
  int now_is_scrolling_v;       // vertical scrolling
 
225
  Uint32 color;                 // color of the level
 
226
} level;
 
227
 
 
228
unsigned int next_rand;         // seed for random function
 
229
 
 
230
/******************************************/
 
231
/*********** All game functions ***********/
 
232
/******************************************/
 
233
 
 
234
void init_robbo(void);
 
235
SDL_Rect set_rect(int x, int y, int w, int h);
 
236
Uint32 getpixel(SDL_Surface *surface, int x, int y);
 
237
void load_bitmaps(void);
 
238
void draw_score(void);
 
239
void show_gamearea();
 
240
void move_robbo(int x,int y);
 
241
void shoot_robbo(int x,int y);
 
242
void update_game();
 
243
int update_coords(struct Coords *coords, int direction);
 
244
void prepare_objects();
 
245
void set_images(int type,int x, int y);
 
246
void kill_robbo();
 
247
int read_from_file(int level_number);
 
248
void create_object(int x,int y,int type);
 
249
void clear_field(struct object *obj);
 
250
int transform_char(char c);
 
251
int level_init(int level, int force_fileread);
 
252
void set_coords(struct Coords *coords,int x, int y);
 
253
void set_mapoffset();
 
254
int can_move(struct Coords coords, int direction);
 
255
int next_laserfield(struct Coords coords, int direction);
 
256
void move_object(int x, int y, struct Coords coords);
 
257
void shoot_object(int x, int y, int direction);
 
258
void blow_bomb(int x, int y);
 
259
int coords_out_of_range(struct Coords coords);
 
260
void show_startscreen();
 
261
void show_endscreen();
 
262
void open_exit();
 
263
void refresh_field(int x, int y);
 
264
void clear_screen();
 
265
int my_rand();
 
266
int my_srand(unsigned int seed);
 
267
void init_questionmarks();
 
268
void read_resource_file();
 
269
void save_resurce_file();
 
270
int test_resource_file();
 
271