]> icculus.org git repositories - crow/jumpnbump.git/blob - fireworks.c
Added AI by Ricardo Cruz. This also adds mouse controls.
[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  * This file is part of Jump'n'Bump.
10  *
11  * Jump'n'Bump is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * Jump'n'Bump is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25
26 #include "globals.h"
27
28 extern unsigned int ban_map[17][22];
29
30 void fireworks(void)
31 {
32         char *handle;
33         int c1, c2;
34         int s1, s2, s3;
35         char pal[768];
36         struct {
37                 int used, direction, colour;
38                 int x, y;
39                 int x_add, y_add;
40                 int timer;
41                 int anim, frame, frame_tick, image;
42         } rabbits[20];
43         struct {
44                 int x, y;
45                 int old_x, old_y;
46                 int col;
47                 int back[2];
48         } stars[300];
49
50         register_background(NULL, NULL);
51
52         if ((handle = dat_open("level.pcx")) == 0) {
53                 strcpy(main_info.error_str, "Error loading 'level.pcx', aborting...\n");
54                 return;
55         }
56         read_pcx(handle, mask_pic, JNB_WIDTH*JNB_HEIGHT, pal);
57
58         memset(mask_pic, 0, JNB_WIDTH*JNB_HEIGHT);
59         register_mask(mask_pic);
60
61         recalculate_gob(&rabbit_gobs, pal);
62         recalculate_gob(&object_gobs, pal);
63
64         memset(ban_map, 0, sizeof(ban_map));
65
66         fillpalette(0, 0, 0);
67
68         draw_begin();
69
70         for (c2 = JNB_HEIGHT - 63; c2 < JNB_HEIGHT; c2++) {
71                 clear_lines(0, c2, 1, get_color((c2 - 192) >> 2, pal));
72                 clear_lines(1, c2, 1, get_color((c2 - 192) >> 2, pal));
73         }
74
75         draw_end();
76
77         setpalette(0, 256, pal);
78
79         for (c1 = 0; c1 < 20; c1++)
80                 rabbits[c1].used = 0;
81
82         rabbits[0].used = 1;
83         rabbits[0].colour = rnd(4);
84         rabbits[0].x = (int) (150 + rnd(100)) << 16;
85         rabbits[0].y = 256 << 16;
86         rabbits[0].x_add = ((int) rnd(65535) << 1) - 65536;
87         if (rabbits[0].x_add > 0)
88                 rabbits[0].direction = 0;
89         else
90                 rabbits[0].direction = 1;
91         rabbits[0].y_add = -262144 + (rnd(16384) * 5);
92         rabbits[0].timer = 30 + rnd(150);
93         rabbits[0].anim = 2;
94         rabbits[0].frame = 0;
95         rabbits[0].frame_tick = 0;
96         rabbits[0].image = player_anims[rabbits[0].anim].frame[rabbits[0].frame].image + rabbits[0].colour * 18 + rabbits[0].direction * 9;
97
98         draw_begin();
99         for (c1 = 0; c1 < 300; c1++) {
100                 s1 = rnd(JNB_WIDTH);
101                 s2 = rnd(JNB_HEIGHT);
102                 s3 = 30 - rnd(7);
103                 stars[c1].x = stars[c1].old_x = (s1 << 16);
104                 stars[c1].y = stars[c1].old_y = (s2 << 16);
105                 stars[c1].col = s3;
106                 stars[c1].back[0] = stars[c1].back[1] = get_pixel(0, s1, s2);
107         }
108         draw_end();
109
110         dj_set_nosound(0);
111
112         main_info.page_info[0].num_pobs = 0;
113         main_info.page_info[1].num_pobs = 0;
114         main_info.view_page = 0;
115         main_info.draw_page = 1;
116
117         while (key_pressed(1) == 0) {
118
119                 dj_mix();
120                 intr_sysupdate();
121
122                 for (c1 = 0; c1 < 300; c1++) {
123                         stars[c1].old_x = stars[c1].x;
124                         stars[c1].old_y = stars[c1].y;
125                         stars[c1].y -= (int) (31 - stars[c1].col) * 16384;
126                         if ((stars[c1].y >> 16) < 0)
127                                 stars[c1].y += JNB_HEIGHT << 16;
128                         if ((stars[c1].y >> 16) >= JNB_HEIGHT)
129                                 stars[c1].y -= JNB_HEIGHT << 16;
130                 }
131
132                 for (c1 = 0, c2 = 0; c1 < 20; c1++) {
133                         if (rabbits[c1].used == 1)
134                                 c2++;
135                 }
136                 if ((c2 == 0 && rnd(10000) < 200) || (c2 == 1 && rnd(10000) < 150) || (c2 == 2 && rnd(10000) < 100) || (c2 == 3 && rnd(10000) < 50)) {
137                         for (c1 = 0; c1 < 20; c1++) {
138                                 if (rabbits[c1].used == 0) {
139                                         rabbits[c1].used = 1;
140                                         rabbits[c1].colour = rnd(4);
141                                         rabbits[c1].x = (int) (150 + rnd(100)) << 16;
142                                         rabbits[c1].y = 256 << 16;
143                                         rabbits[c1].x_add = ((int) rnd(65535) << 1) - 65536;
144                                         if (rabbits[c1].x_add > 0)
145                                                 rabbits[c1].direction = 0;
146                                         else
147                                                 rabbits[c1].direction = 1;
148                                         rabbits[c1].y_add = -262144 + (rnd(16384) * 5);
149                                         rabbits[c1].timer = 30 + rnd(150);
150                                         rabbits[c1].anim = 2;
151                                         rabbits[c1].frame = 0;
152                                         rabbits[c1].frame_tick = 0;
153                                         rabbits[c1].image = player_anims[rabbits[c1].anim].frame[rabbits[c1].frame].image + rabbits[c1].colour * 18 + rabbits[c1].direction * 9;
154                                         break;
155                                 }
156                         }
157                 }
158
159                 dj_mix();
160
161                 main_info.page_info[main_info.draw_page].num_pobs = 0;
162
163                 for (c1 = 0; c1 < 20; c1++) {
164                         if (rabbits[c1].used == 1) {
165                                 rabbits[c1].y_add += 2048;
166                                 if (rabbits[c1].y_add > 36864 && rabbits[c1].anim != 3) {
167                                         rabbits[c1].anim = 3;
168                                         rabbits[c1].frame = 0;
169                                         rabbits[c1].frame_tick = 0;
170                                         rabbits[c1].image = player_anims[rabbits[c1].anim].frame[rabbits[c1].frame].image + rabbits[c1].colour * 18 + rabbits[c1].direction * 9;
171                                 }
172                                 rabbits[c1].x += rabbits[c1].x_add;
173                                 rabbits[c1].y += rabbits[c1].y_add;
174                                 if ((rabbits[c1].x >> 16) < 16 || (rabbits[c1].x >> 16) > JNB_WIDTH || (rabbits[c1].y >> 16) > JNB_HEIGHT) {
175                                         rabbits[c1].used = 0;
176                                         continue;
177                                 }
178                                 rabbits[c1].timer--;
179                                 if (rabbits[c1].timer <= 0) {
180                                         rabbits[c1].used = 0;
181                                         for (c2 = 0; c2 < 6; c2++)
182                                                 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);
183                                         for (c2 = 0; c2 < 6; c2++)
184                                                 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);
185                                         for (c2 = 0; c2 < 6; c2++)
186                                                 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);
187                                         for (c2 = 0; c2 < 8; 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, 78);
189                                         for (c2 = 0; c2 < 10; 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, 79);
191                                         dj_play_sfx(SFX_DEATH, SFX_DEATH_FREQ, 64, 0, 0, -1);
192                                         continue;
193                                 }
194                                 rabbits[c1].frame_tick++;
195                                 if (rabbits[c1].frame_tick >= player_anims[rabbits[c1].anim].frame[rabbits[c1].frame].ticks) {
196                                         rabbits[c1].frame++;
197                                         if (rabbits[c1].frame >= player_anims[rabbits[c1].anim].num_frames)
198                                                 rabbits[c1].frame = player_anims[rabbits[c1].anim].restart_frame;
199                                         rabbits[c1].frame_tick = 0;
200                                 }
201                                 rabbits[c1].image = player_anims[rabbits[c1].anim].frame[rabbits[c1].frame].image + rabbits[c1].colour * 18 + rabbits[c1].direction * 9;
202                                 if (rabbits[c1].used == 1)
203                                         add_pob(main_info.draw_page, rabbits[c1].x >> 16, rabbits[c1].y >> 16, rabbits[c1].image, &rabbit_gobs);
204                         }
205                 }
206
207                 dj_mix();
208
209                 update_objects();
210
211                 draw_begin();
212
213                 for (c1 = 0; c1 < 300; c1++) {
214                         stars[c1].back[main_info.draw_page] = get_pixel(main_info.draw_page, stars[c1].x >> 16, stars[c1].y >> 16);
215                         set_pixel(main_info.draw_page, stars[c1].x >> 16, stars[c1].y >> 16, get_color(stars[c1].col, pal));
216                 }
217
218                 dj_mix();
219
220                 draw_pobs(main_info.draw_page);
221                 
222                 draw_end();
223
224                 main_info.draw_page ^= 1;
225                 main_info.view_page ^= 1;
226
227                 flippage(main_info.view_page);
228
229                 wait_vrt(1);
230
231                 draw_begin();
232
233                 redraw_pob_backgrounds(main_info.draw_page);
234
235                 dj_mix();
236                 intr_sysupdate();
237
238                 for (c1 = 299; c1 >= 0; c1--) {
239                         set_pixel(main_info.draw_page, stars[c1].old_x >> 16, stars[c1].old_y >> 16, stars[c1].back[main_info.draw_page]);
240                 }
241
242                 draw_end();
243
244         }
245
246         dj_set_nosound(1);
247
248 }
249