]> icculus.org git repositories - crow/jumpnbump.git/blob - globals.h
Implemented -scaleup and -nosound options. Some fixes for first release.
[crow/jumpnbump.git] / globals.h
1 /*
2  * globals.h
3  * Copyright (C) 1998 Brainchild Design - http://brainchilddesign.com/
4  * 
5  * Copyright (C) 2001 tarzeau@space.ch
6  *
7  * Copyright (C) 2002 Florian Schulze - crow@icculus.org
8  *
9  * Portions of this code are from the MPEG software simulation group
10  * idct implementation. This code will be replaced with a new
11  * implementation soon.
12  *
13  * This file is part of Jump'n'Bump.
14  *
15  * Jump'n'Bump is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2 of the License, or
18  * (at your option) any later version.
19  *
20  * Jump'n'Bump is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28  */
29
30 #ifndef __GLOBALS_H
31 #define __GLOBALS_H
32
33 #include "config.h"
34
35 #include <assert.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #ifndef _MSC_VER
40 #include <strings.h>
41 #endif
42 #include <time.h>
43 #include <math.h>
44 #include <dj.h>
45
46 #ifdef DOS
47 # include <conio.h>
48 # include <dpmi.h>
49 # include <sys/nearptr.h>
50 # include <pc.h>
51 #endif
52
53 #ifdef _MSC_VER
54 # define WIN32_LEAN_AND_MEAN
55 # include <windows.h>
56 # include <sys/stat.h>
57 # include <io.h>
58 # include <SDL.h>
59 # include <SDL_mixer.h>
60 #else
61 # ifdef USE_SDL
62 #  include <sys/stat.h>
63 #  include <SDL/SDL.h>
64 #  include <SDL/SDL_mixer.h>
65 # endif
66 #endif
67
68 #define JNB_WIDTH 400
69 #define JNB_HEIGHT 256
70 extern int screen_width;
71 extern int screen_height;
72 extern int screen_pitch;
73 extern int scale_up;
74 extern int bytes_per_pixel;
75
76 #ifndef USE_SDL
77 #define KEY_PL1_LEFT 0xcb
78 #define KEY_PL1_RIGHT   0xcd
79 #define KEY_PL1_JUMP 0xc8
80 #define KEY_PL2_LEFT 0x1e
81 #define KEY_PL2_RIGHT   0x20
82 #define KEY_PL2_JUMP 0x11
83 #else
84 #define KEY_PL1_LEFT SDLK_LEFT
85 #define KEY_PL1_RIGHT   SDLK_RIGHT
86 #define KEY_PL1_JUMP SDLK_UP
87 #define KEY_PL2_LEFT SDLK_a
88 #define KEY_PL2_RIGHT   SDLK_d
89 #define KEY_PL2_JUMP SDLK_w
90 #define KEY_PL3_LEFT SDLK_j
91 #define KEY_PL3_RIGHT   SDLK_l
92 #define KEY_PL3_JUMP SDLK_i
93 #define KEY_PL4_LEFT SDLK_KP4
94 #define KEY_PL4_RIGHT   SDLK_KP6
95 #define KEY_PL4_JUMP SDLK_KP8
96 #endif
97
98 #define NUM_POBS 200
99 #define NUM_OBJECTS 200
100 #define NUM_FLIES 20
101 #define NUM_LEFTOVERS 50
102
103 #define OBJ_SPRING 0
104 #define OBJ_SPLASH 1
105 #define OBJ_SMOKE 2
106 #define OBJ_YEL_BUTFLY 3
107 #define OBJ_PINK_BUTFLY 4
108 #define OBJ_FUR 5
109 #define OBJ_FLESH 6
110 #define OBJ_FLESH_TRACE 7
111
112 #define OBJ_ANIM_SPRING 0
113 #define OBJ_ANIM_SPLASH 1
114 #define OBJ_ANIM_SMOKE 2
115 #define OBJ_ANIM_YEL_BUTFLY_RIGHT 3
116 #define OBJ_ANIM_YEL_BUTFLY_LEFT 4
117 #define OBJ_ANIM_PINK_BUTFLY_RIGHT 5
118 #define OBJ_ANIM_PINK_BUTFLY_LEFT 6
119 #define OBJ_ANIM_FLESH_TRACE 7
120
121 #define MOD_MENU 0
122 #define MOD_GAME 1
123 #define MOD_SCORES 2
124
125 #define SFX_JUMP 0
126 #define SFX_LAND 1
127 #define SFX_DEATH 2
128 #define SFX_SPRING 3
129 #define SFX_SPLASH 4
130 #define SFX_FLY 5
131
132 #define NUM_SFX 6
133
134 #define SFX_JUMP_FREQ 15000
135 #define SFX_LAND_FREQ 15000
136 #define SFX_DEATH_FREQ 20000
137 #define SFX_SPRING_FREQ 15000
138 #define SFX_SPLASH_FREQ 12000
139 #define SFX_FLY_FREQ 12000
140
141 #define BAN_VOID        0
142 #define BAN_SOLID       1
143 #define BAN_WATER       2
144 #define BAN_ICE         3
145 #define BAN_SPRING      4
146
147 typedef struct {
148         int num_images;
149         int *width;
150         int *height;
151         int *hs_x;
152         int *hs_y;
153         void **data;
154         void **orig_data;
155 } gob_t;
156
157 struct {
158         int joy_enabled, mouse_enabled;
159         int no_sound, no_gore, fireworks;
160         char error_str[256];
161         int draw_page, view_page;
162         struct {
163                 int num_pobs;
164                 struct {
165                         int x, y;
166                         int image;
167                         gob_t *pob_data;
168                         int back_buf_ofs;
169                 } pobs[NUM_POBS];
170         } page_info[2];
171         void *pob_backbuf[2];
172 } main_info;
173
174 struct {
175         int action_left,action_up,action_right;
176         int enabled, dead_flag;
177         int bumps;
178         int bumped[4];
179         int x, y;
180         int x_add, y_add;
181         int direction, jump_ready, jump_abort, in_water;
182         int anim, frame, frame_tick, image;
183 } player[4];
184
185 struct {
186         int num_frames;
187         int restart_frame;
188         struct {
189                 int image;
190                 int ticks;
191         } frame[4];
192 } player_anims[7];
193
194 struct {
195         int used, type;
196         int x, y;
197         int x_add, y_add;
198         int x_acc, y_acc;
199         int anim;
200         int frame, ticks;
201         int image;
202 } objects[NUM_OBJECTS];
203
204 struct {
205         int x, y;
206         int raw_x, raw_y;
207         int but1, but2;
208         struct {
209                 int x1, x2, x3;
210                 int y1, y2, y3;
211         } calib_data;
212 } joy;
213
214 struct {
215         int but1, but2, but3;
216 } mouse;
217
218 char datfile_name[2048];
219
220 char *background_pic;
221 char *mask_pic;
222
223 extern gob_t rabbit_gobs;
224 extern gob_t font_gobs;
225 extern gob_t object_gobs;
226 extern gob_t number_gobs;
227
228
229 /* fireworks.c */
230
231 void fireworks(void);
232
233
234 /* main.c */
235
236 void steer_players(void);
237 void position_player(int player_num);
238 void fireworks(void);
239 void add_object(int type, int x, int y, int x_add, int y_add, int anim, int frame);
240 void update_objects(void);
241 int add_pob(int page, int x, int y, int image, gob_t *pob_data);
242 void draw_flies(int page);
243 void draw_pobs(int page);
244 void redraw_flies_background(int page);
245 void redraw_pob_backgrounds(int page);
246 int add_leftovers(int page, int x, int y, int image, gob_t *pob_data);
247 void draw_leftovers(int page);
248 int init_level(int level, char *pal);
249 void deinit_level(void);
250 int init_program(int argc, char *argv[], char *pal);
251 void deinit_program(void);
252 unsigned short rnd(unsigned short max);
253 int read_level(void);
254 FILE *dat_open(char *file_name, char *dat_name, char *mode);
255 int dat_filelen(char *file_name, char *dat_name);
256 void write_calib_data(void);
257
258
259 /* input.c */
260
261 void update_player_actions(void);
262 void init_inputs(void);
263 int calib_joy(int type);
264
265 /* menu.c */
266
267 int menu(void);
268 int menu_init(void);
269 void menu_deinit(void);
270
271
272 /* gfx.c */
273
274 void set_scaling(int scale);
275 void open_screen(void);
276 void wait_vrt(int mix);
277 void draw_begin(void);
278 void draw_end(void);
279 void flippage(int page);
280 void draw_begin(void);
281 void draw_end(void);
282 void clear_lines(int page, int y, int count, int color);
283 int get_color(int color, char pal[768]);
284 int get_pixel(int page, int x, int y);
285 void set_pixel(int page, int x, int y, int color);
286 void setpalette(int index, int count, char *palette);
287 void fillpalette(int red, int green, int blue);
288 #ifdef DOS
289 void get_block(char page, short x, short y, short width, short height, char *buffer);
290 void put_block(char page, short x, short y, short width, short height, char *buffer);
291 #else
292 void get_block(int page, int x, int y, int width, int height, void *buffer);
293 void put_block(int page, int x, int y, int width, int height, void *buffer);
294 #endif
295 void put_text(int page, int x, int y, char *text, int align);
296 void put_pob(int page, int x, int y, int image, gob_t *gob, int mask, void *mask_pic);
297 int pob_width(int image, gob_t *gob);
298 int pob_height(int image, gob_t *gob);
299 int pob_hs_x(int image, gob_t *gob);
300 int pob_hs_y(int image, gob_t *gob);
301 int read_pcx(FILE * handle, void *buffer, int buf_len, char *pal);
302 void register_background(char *pixels, char pal[768]);
303 int register_gob(FILE *handle, gob_t *gob, int len);
304 void recalculate_gob(gob_t *gob, char pal[768]);
305 void register_mask(void *pixels);
306
307 /* gfx.c */
308
309 #ifdef USE_SDL
310 #ifndef _MSC_VER
311 long filelength(int handle);
312 #endif
313 void fs_toggle();
314 int intr_sysupdate();
315 #endif
316
317 /* interrpt.c */
318
319 extern char last_keys[50];
320
321 int hook_keyb_handler(void);
322 void remove_keyb_handler(void);
323 int key_pressed(int key);
324
325 /* sound-linux.c */
326 #ifdef LINUX
327
328
329 #endif
330
331 #endif