forked from iPodLinux-Community/Floydzilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kaboom.c
512 lines (385 loc) · 14.5 KB
/
kaboom.c
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
/*
KabooM - A rewrite of the game KabooM! by Activision for the iPod.
Copyright (C) 2005 Daniel Smith
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
General Game Information:
Prepare yourself for a supreme test of reflexes, coordination, and
agility. You're about to face the world's most unpredictable and
relentless "Mad Bomber." He hates losing as much as you love winning.
So, to keep him frowning, take a minute to read over these instructions.
Then, grab your buckets and bomb away!
By turning your IPod Wheel clockwise, you move your
buckets of water to the right. Turning the Wheel counterclockwise
moves buckets to the left.
Remeber: The objective of the game is to catch all of the bombs, as well as
having fun!.
*/
// KERIPO MOD
#include "_mods.h"
#include "pz.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
static GR_WINDOW_ID kaboom_wid;
static GR_WINDOW_ID kaboom_pixmap;
static GR_GC_ID kaboom_gc;
static GR_TIMER_ID kaboom_refresh_timer;
static GR_IMAGE_ID man_buffer;
static GR_IMAGE_ID bucket_buffer;
static GR_IMAGE_ID bomb_buffer;
typedef struct {
int x;
int y;
int width;
int height;
} rectangle;
typedef struct {
int bomb_speed;
int clust;
int bomb_amount;
} info;
static rectangle bucket[3];
static int bombdrop; /*the timer thingo for how long to drop the bomb(s), which is defined in new_kaboom window...*/
static int man_direction; /*direction for man...*/
static int direction_time; /*the time to go for direction*/
static int man_location_x; /*location x for man*/
static int man_location_y;
static int man_width;
static int bomb_size;
static int man_height;
static int bomb_caught; /*coutner for how many caught bombs*/
static int lives; /* counter for how many lives which are left*/
static int buckets_alive; /* counter for how many buckets are alive */
static info level_info[9]; /*info about the the current level*/
static int level;
static int bombs_counted; /*counter for how many bombs have been counted in that level, so that the level rotation works according to plan*/
struct bomblist{
int x;
int y;
struct bomblist *next;
};
struct bomblist *bomblist_head;
static void bomber_timeout()
{
bombs_counted = 0;
direction_time = 3000;
man_direction = 0;
bombdrop = 3000;
}
static void free_bomblist() {
struct bomblist *cur, *next;
cur = bomblist_head;
while (cur) {
next = cur->next;
free (cur);
cur = next;
}
}
static void bomb_draw() /*function to draw the bomb*/
{
struct bomblist *cur = bomblist_head;
struct bomblist *last = 0;
while (cur) {
int bucket_hits[3], bucket_hit = 0, offscreen = 0, i;
GrDrawImageToFit(kaboom_pixmap, kaboom_gc, cur->x, cur->y, bomb_size, bomb_size, bomb_buffer);
for (i = 0; i < 3; i++) {
bucket_hits[i] = (
lives &&
(bucket[i].x-(bucket[i].width/2) <= cur->x) &&
((bucket[i].x-(bucket[i].width/2) + (bucket[i].width*2)) >= (cur->x + bomb_size)) &&
(bucket[i].y <= (cur->y + bomb_size)) &&
((cur->y + bomb_size) <= (bucket[i].y + bucket[i].width))
);
}
if (cur->y >= screen_info.rows-HEADER_TOPLINE) offscreen = 1;
bucket_hit = bucket_hits[0] || bucket_hits[1] || bucket_hits[2];
if (bucket_hit) {
bomb_caught+= level_info[level].bomb_amount;
bombs_counted++;
} else if (offscreen) {
bomber_timeout();
buckets_alive--;
bombs_counted = 0;
lives--;
if (buckets_alive == 2) {
bucket[0].x = 0;
bucket[0].y = 0;
bucket[0].width = 0;
bucket[0].height = 0;
}
if (buckets_alive == 1) {
bucket[1].x = 0;
bucket[1].y = 0;
bucket[1].width = 0;
bucket[1].height = 0;
}
if (!buckets_alive) {
bucket[2].x = 0;
bucket[2].y = 0;
bucket[2].width = 0;
bucket[2].height = 0;
new_message_window ("GAME OVER!");
level = 1;
bomb_caught = 0;
bombs_counted = 0;
}
}
if (bucket_hit || offscreen) {
if (!last) {
bomblist_head = cur->next;
} else {
last->next = cur->next;
}
free(cur);
if (last) cur = last->next;
else cur = bomblist_head;
}
else {
cur->y+=level_info[level].bomb_amount;
last = cur;
cur = cur->next;
}
}
}
static void bomb_add()
{
struct bomblist *newBomb = malloc(sizeof(struct bomblist));
newBomb->x = man_location_x;
newBomb->y = (HEADER_TOPLINE+(HEADER_TOPLINE/3));
newBomb->next = bomblist_head;
bomblist_head = newBomb;
bomb_draw();
};
void wall_draw() /*function to draw the wall which the robber guy sits on, which includes the colours*/
{
GrLine(kaboom_pixmap, kaboom_gc, 0, (HEADER_TOPLINE+(HEADER_TOPLINE/3)), screen_info.cols, (HEADER_TOPLINE+(HEADER_TOPLINE/3)));
if (screen_info.bpp == 16) {
GrSetGCForeground(kaboom_gc, GREEN);
GrFillRect( kaboom_pixmap, kaboom_gc, 0, (HEADER_TOPLINE+(HEADER_TOPLINE/3)), screen_info.cols, screen_info.rows);
GrSetGCForeground(kaboom_gc, BLACK);
}
}
void bucket_draw() /*functioon to draw the bucket*/
{
if (buckets_alive == 3) {
GrDrawImageToFit(kaboom_pixmap, kaboom_gc, bucket[0].x, bucket[0].y, bucket[0].width, bucket[0].height, bucket_buffer);
GrDrawImageToFit(kaboom_pixmap, kaboom_gc, bucket[1].x, bucket[1].y, bucket[1].width, bucket[1].height, bucket_buffer);
GrDrawImageToFit(kaboom_pixmap, kaboom_gc, bucket[2].x, bucket[2].y, bucket[2].width, bucket[2].height, bucket_buffer);
}
if (buckets_alive == 2) {
GrDrawImageToFit(kaboom_pixmap, kaboom_gc, bucket[1].x, bucket[1].y, bucket[1].width, bucket[1].height, bucket_buffer);
GrDrawImageToFit(kaboom_pixmap, kaboom_gc, bucket[2].x, bucket[2].y, bucket[2].width, bucket[2].height, bucket_buffer);
}
if (buckets_alive == 1)
GrDrawImageToFit(kaboom_pixmap, kaboom_gc, bucket[2].x, bucket[2].y, bucket[2].width, bucket[2].height, bucket_buffer);
}
static void man_draw() /*function to draw the man who drops the bombs*/
{
man_location_x += man_direction;
if (man_location_x <= 0)
man_direction *= -1;
if (man_location_x >= screen_info.cols - man_width){
man_location_x = screen_info.cols - man_width;
man_direction *= -1;
}
GrDrawImageToFit(kaboom_pixmap, kaboom_gc, man_location_x, man_location_y, man_width, man_height, man_buffer);
}
static void kaboom_do_draw()
{
char text[30];
wall_draw(); /* calls the drawing of the wall (which is really a line for now)*/
bomb_draw(); /* call to draw the bomb */
bucket_draw(); /*call to draw the bucket */
man_draw(); /*call to draw the man who drops bombs */
/* Draw the counter */
sprintf(text,"%d", bomb_caught);
GrText(kaboom_pixmap,
kaboom_gc,
1, HEADER_TOPLINE, /* x, y */
text,
-1,
GR_TFASCII);
GrCopyArea (kaboom_wid, kaboom_gc, 0, 0, screen_info.cols, screen_info.rows, kaboom_pixmap, 0, 0, MWROP_SRCCOPY);
GrSetGCForeground(kaboom_gc, WHITE);
GrFillRect( kaboom_pixmap, kaboom_gc, 0, 0, screen_info.cols, screen_info.rows);
GrSetGCForeground(kaboom_gc, BLACK);
}
static void kaboom_loop()
{
if (bombs_counted == level_info[level].clust) {
level++;
bomber_timeout();
}
kaboom_do_draw();
}
static int kaboom_handle_event(GR_EVENT *event)
{
int ret = 0;
static int paused = 0;
switch (event->type) {
case GR_EVENT_TYPE_TIMER:
bombdrop -= 50;
if (bombdrop == 0){
bomb_add();
bombdrop = level_info[level].bomb_speed;
}
direction_time -= 50;
if (direction_time <= 0){
direction_time = rand()%800 + 200;
man_direction = rand()%11 - 5;
}
kaboom_do_draw();
if (!paused)
kaboom_loop();
break;
case GR_EVENT_TYPE_KEY_DOWN:
switch (event->keystroke.ch) {
case IPOD_WHEEL_COUNTERCLOCKWISE: /* Wheel left */
if (bucket[2].x <= 0)
bucket[0].x = 0, bucket[1].x = 0, bucket[2].x = 0;
else bucket[0].x -= 5, bucket[1].x -= 5, bucket[2].x -= 5;
kaboom_do_draw();
break;
case IPOD_WHEEL_CLOCKWISE: /* Wheel right */
if (bucket[2].x >=((screen_info.cols)-bucket[2].width))
bucket[0].x = bucket[1].x = bucket[2].x = ((screen_info.cols)-bucket[2].width);
else bucket[0].x += 5, bucket[1].x += 5, bucket[2].x += 5;
kaboom_do_draw();
break;
case IPOD_SWITCH_HOLD: /* hold switch on */
paused = 1; /* pause the loop */
break;
case IPOD_BUTTON_MENU: /* Menu button */
pz_close_window(kaboom_wid);
GrDestroyWindow (kaboom_pixmap);
GrDestroyTimer(kaboom_refresh_timer);
GrDestroyGC(kaboom_gc);
break;
case IPOD_BUTTON_ACTION: /* Action button */
case IPOD_BUTTON_PLAY: /* Play/pause button */
case IPOD_BUTTON_REWIND: /* Rewind button */
case IPOD_BUTTON_FORWARD: /* Fast forward button */
default:
ret |= KEY_UNUSED; /* allow a default key action */
break;
}
break;
case GR_EVENT_TYPE_KEY_UP:
switch (event->keystroke.ch) {
case IPOD_SWITCH_HOLD: /* un-held */
paused = 0;
break;
default:
ret |= KEY_UNUSED;
break;
}
default:
ret |= EVENT_UNUSED; /* we didn't ask for this event, go away */
}
return ret;
}
void new_kaboom_window (void)
{
//bombdrop = 1500; /*timer for how long to drop the bomb, which is defined in new_kaboom window....*/
bucket[0].x = bucket[1].x = bucket[2].x = ((screen_info.cols)/2); /* location x for buckets*/
bucket[0].y = (((screen_info.rows-HEADER_TOPLINE)*95)/100); /* location y for bucket0*/
bucket[1].y = (((screen_info.rows-HEADER_TOPLINE)*85)/100); /* location y for bucket1*/
bucket[2].y = (((screen_info.rows-HEADER_TOPLINE)*75)/100); /* location y for bucket0*/
bomblist_head = 0;
man_width = screen_info.cols/16;
man_height = (HEADER_TOPLINE+(HEADER_TOPLINE/3));
man_location_x = (screen_info.cols/2); /*location x for man*/
direction_time = rand()%300;
man_direction = rand()%11 - 5;
man_location_y = 1;
bomb_caught = 0; /*counter for how many caught bombs*/
bucket[0].width = bucket[1].width = bucket[2].width = screen_info.cols/10; /*bucket width*/
bucket[0].height = bucket[1].height = bucket[2].height = screen_info.cols/30; /*bucket height*/
// KERIPO MOD
//man_buffer = GrLoadImageFromFile("man.bmp", 0);
//bucket_buffer = GrLoadImageFromFile("bucket.bmp", 0);
//bomb_buffer = GrLoadImageFromFile("bomb.bmp", 0);
man_buffer = GrLoadImageFromFile(KABOOM_MAN_BMP, 0);
bucket_buffer = GrLoadImageFromFile(KABOOM_BUCKET_BMP, 0);
bomb_buffer = GrLoadImageFromFile(KABOOM_BOMB_BMP, 0);
bombdrop = 1000;
bomb_size = ((man_width * 75)/100);
buckets_alive = 3;
lives = 3;
level = 1;
bombs_counted = 0;
/****************************************************************
*****************************************************************
*****************************************************************
*****************************************************************
***********************THE NEXT PART DEFINES THE*****************
**************************AMOUNT OF BOMBS PER********************
********************************CLUSTER**************************
*****************************************************************
*****************************************************************
*****************************************************************
****************************************************************/
level_info[0].clust = 0;
level_info[1].clust = 10;
level_info[2].clust = 20;
level_info[3].clust = 30;
level_info[4].clust = 40;
level_info[5].clust = 50;
level_info[6].clust = 75;
level_info[7].clust = 100;
level_info[8].clust = 150;
/* ALL OF THIS STUFF BELOW DEFINES THE SPEED AT WHICH THE MAN RELEASES BOMBS. */
level_info[0].bomb_speed = 0;
level_info[1].bomb_speed = 1000;
level_info[2].bomb_speed = 900;
level_info[3].bomb_speed = 800;
level_info[4].bomb_speed = 700;
level_info[5].bomb_speed = 600;
level_info[6].bomb_speed = 500;
level_info[7].bomb_speed = 400;
level_info[8].bomb_speed = 300;
/* ALL OF THE STUFF BELOW THIS DEFINESE THE SPEED AT WHICH THE BOMBS FALL. */
level_info[0].bomb_amount = 0;
level_info[1].bomb_amount = 1;
level_info[2].bomb_amount = 2;
level_info[3].bomb_amount = 3;
level_info[4].bomb_amount = 4;
level_info[5].bomb_amount = 5;
level_info[6].bomb_amount = 6;
level_info[7].bomb_amount = 7;
level_info[8].bomb_amount = 8;
kaboom_gc = pz_get_gc(1); /* Get a copy of the graphics context */
/*Set foreground color */
GrSetGCUseBackground(kaboom_gc, GR_FALSE);
GrSetGCForeground(kaboom_gc, BLACK);
/* Define the pixmap to use */
kaboom_pixmap = GrNewPixmap (screen_info.cols, screen_info.rows-HEADER_TOPLINE, NULL);
free_bomblist(); /*free the bomblist*/
/* Open the window: */
kaboom_wid = pz_new_window (0, HEADER_TOPLINE + 1, /* (x, y) */
screen_info.cols,
screen_info.rows - (HEADER_TOPLINE + 1), /* Height of screen - header */
kaboom_do_draw, /* function pointer, called on an EXPOSURE event */
kaboom_handle_event); /* function pointer, called on all other selected events */
/* Select the types of events you need for your window: */
GrSelectEvents (kaboom_wid, GR_EVENT_MASK_EXPOSURE |
GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP
| GR_EVENT_MASK_TIMER );
/* Map the window to the screen: */
GrMapWindow (kaboom_wid);
pz_draw_header("KabooM!"); /*draw the header, kaboom!*/
kaboom_do_draw();
/* Create the timer used for timing the bomb drop: */
kaboom_refresh_timer = GrCreateTimer (kaboom_wid, 50); /* Timer interval, millisecs */
}