]> icculus.org git repositories - crow/jumpnbump.git/blob - fireworks.c
Fix single player.
[crow/jumpnbump.git] / fireworks.c
1 /*
2  * fireworks.c
3  * Copyright (C) 1998 Brainchild Design - http://brainchilddesign.com/
4  * 
5  * Copyright (C) 2001 Chuck Mason <cemason@users.sourceforge.net>
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 #include "globals.h"
31
32 extern unsigned int ban_map[17][22];
33
34 void fireworks(void)
35 {
36         char *handle;
37         int c1, c2;
38         int s1, s2, s3;
39         char pal[768];
40         struct {
41                 int used, direction, colour;
42                 int x, y;
43                 int x_add, y_add;
44                 int timer;
45                 int anim, frame, frame_tick, image;
46         } rabbits[20];
47         struct {
48                 int x, y;
49                 int old_x, old_y;
50                 int col;
51                 int back[2];
52         } stars[300];
53
54         register_background(NULL, NULL);
55
56         if ((handle = dat_open("level.pcx", datfile_name, "rb")) == 0) {
57                 strcpy(main_info.error_str, "Error loading 'level.pcx', aborting...\n");
58                 return;
59         }
60         read_pcx(handle, mask_pic, JNB_WIDTH*JNB_HEIGHT, pal);
61
62         memset(mask_pic, 0, JNB_WIDTH*JNB_HEIGHT);
63         register_mask(mask_pic);
64
65         recalculate_gob(&rabbit_gobs, pal);
66         recalculate_gob(&object_gobs, pal);
67
68         memset(ban_map, 0, sizeof(ban_map));
69
70         fillpalette(0, 0, 0);
71
72         draw_begin();
73
74         for (c2 = JNB_HEIGHT - 63; c2 < JNB_HEIGHT; c2++) {
75                 clear_lines(0, c2, 1, get_color((c2 - 192) >> 2, pal));
76                 clear_lines(1, c2, 1, get_color((c2 - 192) >> 2, pal));
77         }
78
79         draw_end();
80
81         setpalette(0, 256, pal);
82
83         for (c1 = 0; c1 < 20; c1++)
84                 rabbits[c1].used = 0;
85
86         rabbits[0].used = 1;
87         rabbits[0].colour = rnd(4);
88         rabbits[0].x = (int) (150 + rnd(100)) << 16;
89         rabbits[0].y = 256 << 16;
90         rabbits[0].x_add = ((int) rnd(65535) << 1) - 65536;
91         if (rabbits[0].x_add > 0)
92                 rabbits[0].direction = 0;
93         else
94                 rabbits[0].direction = 1;
95         rabbits[0].y_add = -262144 + (rnd(16384) * 5);
96         rabbits[0].timer = 30 + rnd(150);
97         rabbits[0].anim = 2;
98         rabbits[0].frame = 0;
99         rabbits[0].frame_tick = 0;
100         rabbits[0].image = player_anims[rabbits[0].anim].frame[rabbits[0].frame].image + rabbits[0].colour * 18 + rabbits[0].direction * 9;
101
102         draw_begin();
103         for (c1 = 0; c1 < 300; c1++) {
104                 s1 = rnd(JNB_WIDTH);
105                 s2 = rnd(JNB_HEIGHT);
106                 s3 = 30 - rnd(7);
107                 stars[c1].x = stars[c1].old_x = (s1 << 16);
108                 stars[c1].y = stars[c1].old_y = (s2 << 16);
109                 stars[c1].col = s3;
110                 stars[c1].back[0] = stars[c1].back[1] = get_pixel(0, s1, s2);
111         }
112         draw_end();
113
114         dj_set_nosound(0);
115
116         main_info.page_info[0].num_pobs = 0;
117         main_info.page_info[1].num_pobs = 0;
118         main_info.view_page = 0;
119         main_info.draw_page = 1;
120
121         while (key_pressed(1) == 0) {
122
123                 dj_mix();
124                 intr_sysupdate();
125
126                 for (c1 = 0; c1 < 300; c1++) {
127                         stars[c1].old_x = stars[c1].x;
128                         stars[c1].old_y = stars[c1].y;
129                         stars[c1].y -= (int) (31 - stars[c1].col) * 16384;
130                         if ((stars[c1].y >> 16) < 0)
131                                 stars[c1].y += JNB_HEIGHT << 16;
132                         if ((stars[c1].y >> 16) >= JNB_HEIGHT)
133                                 stars[c1].y -= JNB_HEIGHT << 16;
134                 }
135
136                 for (c1 = 0, c2 = 0; c1 < 20; c1++) {
137                         if (rabbits[c1].used == 1)
138                                 c2++;
139                 }
140                 if ((c2 == 0 && rnd(10000) < 200) || (c2 == 1 && rnd(10000) < 150) || (c2 == 2 && rnd(10000) < 100) || (c2 == 3 && rnd(10000) < 50)) {
141                         for (c1 = 0; c1 < 20; c1++) {
142                                 if (rabbits[c1].used == 0) {
143                                         rabbits[c1].used = 1;
144                                         rabbits[c1].colour = rnd(4);
145                                         rabbits[c1].x = (int) (150 + rnd(100)) << 16;
146                                         rabbits[c1].y = 256 << 16;
147                                         rabbits[c1].x_add = ((int) rnd(65535) << 1) - 65536;
148                                         if (rabbits[c1].x_add > 0)
149                                                 rabbits[c1].direction = 0;
150                                         else
151                                                 rabbits[c1].direction = 1;
152                                         rabbits[c1].y_add = -262144 + (rnd(16384) * 5);
153                                         rabbits[c1].timer = 30 + rnd(150);
154                                         rabbits[c1].anim = 2;
155                                         rabbits[c1].frame = 0;
156                                         rabbits[c1].frame_tick = 0;
157                                         rabbits[c1].image = player_anims[rabbits[c1].anim].frame[rabbits[c1].frame].image + rabbits[c1].colour * 18 + rabbits[c1].direction * 9;
158                                         break;
159                                 }
160                         }
161                 }
162
163                 dj_mix();
164
165                 main_info.page_info[main_info.draw_page].num_pobs = 0;
166
167                 for (c1 = 0; c1 < 20; c1++) {
168                         if (rabbits[c1].used == 1) {
169                                 rabbits[c1].y_add += 2048;
170                                 if (rabbits[c1].y_add > 36864 && rabbits[c1].anim != 3) {
171                                         rabbits[c1].anim = 3;
172                                         rabbits[c1].frame = 0;
173                                         rabbits[c1].frame_tick = 0;
174                                         rabbits[c1].image = player_anims[rabbits[c1].anim].frame[rabbits[c1].frame].image + rabbits[c1].colour * 18 + rabbits[c1].direction * 9;
175                                 }
176                                 rabbits[c1].x += rabbits[c1].x_add;
177                                 rabbits[c1].y += rabbits[c1].y_add;
178                                 if ((rabbits[c1].x >> 16) < 16 || (rabbits[c1].x >> 16) > JNB_WIDTH || (rabbits[c1].y >> 16) > JNB_HEIGHT) {
179                                         rabbits[c1].used = 0;
180                                         continue;
181                                 }
182                                 rabbits[c1].timer--;
183                                 if (rabbits[c1].timer <= 0) {
184                                         rabbits[c1].used = 0;
185                                         for (c2 = 0; c2 < 6; c2++)
186                                                 add_object(OBJ_FUR, (rabbits[c1].x >> 16) + 6 + rnd(5), (rabbits[c1].y >> 16) + 6 + rnd(5), rabbits[c1].x_add + (rnd(65535) - 32768) * 3, rabbits[c1].y_add + (rnd(65535) - 32768) * 3, 0, 44 + rabbits[c1].colour * 8);
187                                         for (c2 = 0; c2 < 6; c2++)
188                                                 add_object(OBJ_FLESH, (rabbits[c1].x >> 16) + 6 + rnd(5), (rabbits[c1].y >> 16) + 6 + rnd(5), rabbits[c1].x_add + (rnd(65535) - 32768) * 3, rabbits[c1].y_add + (rnd(65535) - 32768) * 3, 0, 76);
189                                         for (c2 = 0; c2 < 6; c2++)
190                                                 add_object(OBJ_FLESH, (rabbits[c1].x >> 16) + 6 + rnd(5), (rabbits[c1].y >> 16) + 6 + rnd(5), rabbits[c1].x_add + (rnd(65535) - 32768) * 3, rabbits[c1].y_add + (rnd(65535) - 32768) * 3, 0, 77);
191                                         for (c2 = 0; c2 < 8; c2++)
192                                                 add_object(OBJ_FLESH, (rabbits[c1].x >> 16) + 6 + rnd(5), (rabbits[c1].y >> 16) + 6 + rnd(5), rabbits[c1].x_add + (rnd(65535) - 32768) * 3, rabbits[c1].y_add + (rnd(65535) - 32768) * 3, 0, 78);
193                                         for (c2 = 0; c2 < 10; c2++)
194                                                 add_object(OBJ_FLESH, (rabbits[c1].x >> 16) + 6 + rnd(5), (rabbits[c1].y >> 16) + 6 + rnd(5), rabbits[c1].x_add + (rnd(65535) - 32768) * 3, rabbits[c1].y_add + (rnd(65535) - 32768) * 3, 0, 79);
195                                         dj_play_sfx(SFX_DEATH, SFX_DEATH_FREQ, 64, 0, 0, -1);
196                                         continue;
197                                 }
198                                 rabbits[c1].frame_tick++;
199                                 if (rabbits[c1].frame_tick >= player_anims[rabbits[c1].anim].frame[rabbits[c1].frame].ticks) {
200                                         rabbits[c1].frame++;
201                                         if (rabbits[c1].frame >= player_anims[rabbits[c1].anim].num_frames)
202                                                 rabbits[c1].frame = player_anims[rabbits[c1].anim].restart_frame;
203                                         rabbits[c1].frame_tick = 0;
204                                 }
205                                 rabbits[c1].image = player_anims[rabbits[c1].anim].frame[rabbits[c1].frame].image + rabbits[c1].colour * 18 + rabbits[c1].direction * 9;
206                                 if (rabbits[c1].used == 1)
207                                         add_pob(main_info.draw_page, rabbits[c1].x >> 16, rabbits[c1].y >> 16, rabbits[c1].image, &rabbit_gobs);
208                         }
209                 }
210
211                 dj_mix();
212
213                 update_objects();
214
215                 draw_begin();
216
217                 for (c1 = 0; c1 < 300; c1++) {
218                         stars[c1].back[main_info.draw_page] = get_pixel(main_info.draw_page, stars[c1].x >> 16, stars[c1].y >> 16);
219                         set_pixel(main_info.draw_page, stars[c1].x >> 16, stars[c1].y >> 16, get_color(stars[c1].col, pal));
220                 }
221
222                 dj_mix();
223
224                 draw_pobs(main_info.draw_page);
225                 
226                 draw_end();
227
228                 main_info.draw_page ^= 1;
229                 main_info.view_page ^= 1;
230
231                 flippage(main_info.view_page);
232
233                 wait_vrt(1);
234
235                 draw_begin();
236
237                 redraw_pob_backgrounds(main_info.draw_page);
238
239                 dj_mix();
240                 intr_sysupdate();
241
242                 for (c1 = 299; c1 >= 0; c1--) {
243                         set_pixel(main_info.draw_page, stars[c1].old_x >> 16, stars[c1].old_y >> 16, stars[c1].back[main_info.draw_page]);
244                 }
245
246                 draw_end();
247
248         }
249
250         dj_set_nosound(1);
251
252 }
253