summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2009-12-05 14:08:09 +0000
committerTeruaki Kawashima <teru@rockbox.org>2009-12-05 14:08:09 +0000
commit7d36e8ee47f06c03902a55eba19c3797468c2ef9 (patch)
tree2c884005a8918bb39a32d22feceebf1725e97df4 /apps/plugins
parentf48a61f103bace510e4ab74975f2e5ea11bd135f (diff)
downloadrockbox-7d36e8ee47f06c03902a55eba19c3797468c2ef9.tar.gz
rockbox-7d36e8ee47f06c03902a55eba19c3797468c2ef9.zip
spacerocks: Fix indentation and remove trailing spaces. Fix some minor bugs.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23853 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/spacerocks.c1549
1 files changed, 740 insertions, 809 deletions
diff --git a/apps/plugins/spacerocks.c b/apps/plugins/spacerocks.c
index 0061967f8b..e4833f2c5c 100644
--- a/apps/plugins/spacerocks.c
+++ b/apps/plugins/spacerocks.c
@@ -33,7 +33,7 @@ PLUGIN_HEADER
33#define AST_QUIT BUTTON_OFF 33#define AST_QUIT BUTTON_OFF
34#define AST_THRUST BUTTON_UP 34#define AST_THRUST BUTTON_UP
35#define AST_HYPERSPACE BUTTON_DOWN 35#define AST_HYPERSPACE BUTTON_DOWN
36#define AST_LEFT BUTTON_LEFT 36#define AST_LEFT BUTTON_LEFT
37#define AST_RIGHT BUTTON_RIGHT 37#define AST_RIGHT BUTTON_RIGHT
38#define AST_FIRE BUTTON_PLAY 38#define AST_FIRE BUTTON_PLAY
39 39
@@ -42,7 +42,7 @@ PLUGIN_HEADER
42#define AST_QUIT BUTTON_OFF 42#define AST_QUIT BUTTON_OFF
43#define AST_THRUST BUTTON_UP 43#define AST_THRUST BUTTON_UP
44#define AST_HYPERSPACE BUTTON_DOWN 44#define AST_HYPERSPACE BUTTON_DOWN
45#define AST_LEFT BUTTON_LEFT 45#define AST_LEFT BUTTON_LEFT
46#define AST_RIGHT BUTTON_RIGHT 46#define AST_RIGHT BUTTON_RIGHT
47#define AST_FIRE BUTTON_SELECT 47#define AST_FIRE BUTTON_SELECT
48 48
@@ -61,7 +61,7 @@ PLUGIN_HEADER
61#define AST_QUIT BUTTON_OFF 61#define AST_QUIT BUTTON_OFF
62#define AST_THRUST BUTTON_UP 62#define AST_THRUST BUTTON_UP
63#define AST_HYPERSPACE BUTTON_DOWN 63#define AST_HYPERSPACE BUTTON_DOWN
64#define AST_LEFT BUTTON_LEFT 64#define AST_LEFT BUTTON_LEFT
65#define AST_RIGHT BUTTON_RIGHT 65#define AST_RIGHT BUTTON_RIGHT
66#define AST_FIRE BUTTON_SELECT 66#define AST_FIRE BUTTON_SELECT
67 67
@@ -72,7 +72,7 @@ PLUGIN_HEADER
72#define AST_QUIT BUTTON_POWER 72#define AST_QUIT BUTTON_POWER
73#define AST_THRUST BUTTON_UP 73#define AST_THRUST BUTTON_UP
74#define AST_HYPERSPACE BUTTON_DOWN 74#define AST_HYPERSPACE BUTTON_DOWN
75#define AST_LEFT BUTTON_LEFT 75#define AST_LEFT BUTTON_LEFT
76#define AST_RIGHT BUTTON_RIGHT 76#define AST_RIGHT BUTTON_RIGHT
77#define AST_FIRE BUTTON_SELECT 77#define AST_FIRE BUTTON_SELECT
78 78
@@ -91,7 +91,7 @@ PLUGIN_HEADER
91#define AST_QUIT BUTTON_POWER 91#define AST_QUIT BUTTON_POWER
92#define AST_THRUST BUTTON_UP 92#define AST_THRUST BUTTON_UP
93#define AST_HYPERSPACE BUTTON_DOWN 93#define AST_HYPERSPACE BUTTON_DOWN
94#define AST_LEFT BUTTON_LEFT 94#define AST_LEFT BUTTON_LEFT
95#define AST_RIGHT BUTTON_RIGHT 95#define AST_RIGHT BUTTON_RIGHT
96#define AST_FIRE BUTTON_SELECT 96#define AST_FIRE BUTTON_SELECT
97 97
@@ -145,7 +145,7 @@ PLUGIN_HEADER
145#define AST_QUIT BUTTON_POWER 145#define AST_QUIT BUTTON_POWER
146#define AST_THRUST BUTTON_SCROLL_UP 146#define AST_THRUST BUTTON_SCROLL_UP
147#define AST_HYPERSPACE BUTTON_SCROLL_DOWN 147#define AST_HYPERSPACE BUTTON_SCROLL_DOWN
148#define AST_LEFT BUTTON_LEFT 148#define AST_LEFT BUTTON_LEFT
149#define AST_RIGHT BUTTON_RIGHT 149#define AST_RIGHT BUTTON_RIGHT
150#define AST_FIRE BUTTON_REW 150#define AST_FIRE BUTTON_REW
151 151
@@ -154,7 +154,7 @@ PLUGIN_HEADER
154#define AST_QUIT BUTTON_BACK 154#define AST_QUIT BUTTON_BACK
155#define AST_THRUST BUTTON_UP 155#define AST_THRUST BUTTON_UP
156#define AST_HYPERSPACE BUTTON_DOWN 156#define AST_HYPERSPACE BUTTON_DOWN
157#define AST_LEFT BUTTON_LEFT 157#define AST_LEFT BUTTON_LEFT
158#define AST_RIGHT BUTTON_RIGHT 158#define AST_RIGHT BUTTON_RIGHT
159#define AST_FIRE BUTTON_SELECT 159#define AST_FIRE BUTTON_SELECT
160 160
@@ -163,7 +163,7 @@ PLUGIN_HEADER
163#define AST_QUIT BUTTON_POWER 163#define AST_QUIT BUTTON_POWER
164#define AST_THRUST BUTTON_UP 164#define AST_THRUST BUTTON_UP
165#define AST_HYPERSPACE BUTTON_DOWN 165#define AST_HYPERSPACE BUTTON_DOWN
166#define AST_LEFT BUTTON_LEFT 166#define AST_LEFT BUTTON_LEFT
167#define AST_RIGHT BUTTON_RIGHT 167#define AST_RIGHT BUTTON_RIGHT
168#define AST_FIRE BUTTON_SELECT 168#define AST_FIRE BUTTON_SELECT
169 169
@@ -172,7 +172,7 @@ PLUGIN_HEADER
172#define AST_QUIT BUTTON_RC_REC 172#define AST_QUIT BUTTON_RC_REC
173#define AST_THRUST BUTTON_RC_VOL_UP 173#define AST_THRUST BUTTON_RC_VOL_UP
174#define AST_HYPERSPACE BUTTON_RC_VOL_DOWN 174#define AST_HYPERSPACE BUTTON_RC_VOL_DOWN
175#define AST_LEFT BUTTON_RC_REW 175#define AST_LEFT BUTTON_RC_REW
176#define AST_RIGHT BUTTON_RC_FF 176#define AST_RIGHT BUTTON_RC_FF
177#define AST_FIRE BUTTON_RC_MODE 177#define AST_FIRE BUTTON_RC_MODE
178 178
@@ -184,7 +184,7 @@ PLUGIN_HEADER
184#define AST_QUIT BUTTON_BACK 184#define AST_QUIT BUTTON_BACK
185#define AST_THRUST BUTTON_UP 185#define AST_THRUST BUTTON_UP
186#define AST_HYPERSPACE BUTTON_DOWN 186#define AST_HYPERSPACE BUTTON_DOWN
187#define AST_LEFT BUTTON_LEFT 187#define AST_LEFT BUTTON_LEFT
188#define AST_RIGHT BUTTON_RIGHT 188#define AST_RIGHT BUTTON_RIGHT
189#define AST_FIRE BUTTON_SELECT 189#define AST_FIRE BUTTON_SELECT
190 190
@@ -208,7 +208,7 @@ CONFIG_KEYPAD == MROBE500_PAD
208#define AST_THRUST_REP (BUTTON_UP | BUTTON_REW) 208#define AST_THRUST_REP (BUTTON_UP | BUTTON_REW)
209#define AST_THRUST BUTTON_UP 209#define AST_THRUST BUTTON_UP
210#define AST_HYPERSPACE BUTTON_DOWN 210#define AST_HYPERSPACE BUTTON_DOWN
211#define AST_LEFT BUTTON_LEFT 211#define AST_LEFT BUTTON_LEFT
212#define AST_LEFT_REP (BUTTON_LEFT | BUTTON_REW) 212#define AST_LEFT_REP (BUTTON_LEFT | BUTTON_REW)
213#define AST_RIGHT BUTTON_RIGHT 213#define AST_RIGHT BUTTON_RIGHT
214#define AST_RIGHT_REP (BUTTON_RIGHT | BUTTON_REW) 214#define AST_RIGHT_REP (BUTTON_RIGHT | BUTTON_REW)
@@ -236,7 +236,7 @@ CONFIG_KEYPAD == MROBE500_PAD
236#define AST_HYPERSPACE BUTTON_TOPRIGHT 236#define AST_HYPERSPACE BUTTON_TOPRIGHT
237#endif 237#endif
238#ifndef AST_LEFT 238#ifndef AST_LEFT
239#define AST_LEFT BUTTON_MIDLEFT 239#define AST_LEFT BUTTON_MIDLEFT
240#endif 240#endif
241#ifndef AST_LEFT_REP 241#ifndef AST_LEFT_REP
242#define AST_LEFT_REP (BUTTON_MIDLEFT | BUTTON_REPEAT) 242#define AST_LEFT_REP (BUTTON_MIDLEFT | BUTTON_REPEAT)
@@ -261,43 +261,49 @@ CONFIG_KEYPAD == MROBE500_PAD
261#endif 261#endif
262#endif 262#endif
263 263
264#define RES MAX(LCD_WIDTH, LCD_HEIGHT) 264#define RES MAX(LCD_WIDTH, LCD_HEIGHT)
265#define LARGE_LCD RES >= 200 265#define LARGE_LCD (RES >= 200)
266#define ENEMY_MISSILE_SURVIVAL_LENGTH RES/2
267#define ASTEROID_SPEED RES/20
268#define MISSILE_SURVIVAL_LENGTH 40
269 266
270#define CYCLETIME 30 267#define CYCLETIME 30
271 268
272#define EXTRA_LIFE 250 269#define SHOW_COL 0
273#define SPAWN_TIME 30 270#define SCALE 5000
274#define BLINK_TIME 10 271#define MISSILE_SCALE 5000
275#define SCALE 5000
276#define MISSILE_SCALE 5000
277#define WRAP_GAP 12 272#define WRAP_GAP 12
278#define EXPLOSION_LENGTH 20 273#define POINT_SIZE 2
279#define SHOW_COL 0
280#define POINT_SIZE 2
281#define MAX_NUM_ASTEROIDS 25
282#define MAX_NUM_MISSILES 6
283#define ENEMY_BIG_PROBABILITY_START 10
284#define ENEMY_APPEAR_PROBABILITY_START 35
285#define ENEMY_APPEAR_TIMING_START 1800
286#define LITTLE_SHIP 2
287#define BIG_SHIP 1
288#define SHOW_GAME_OVER_TIME 100 274#define SHOW_GAME_OVER_TIME 100
289#define SHOW_LEVEL_TIME 50 275#define SHOW_LEVEL_TIME 50
290#define START_LIVES 3 276#define EXPLOSION_LENGTH 20
291#define START_LEVEL 1 277
278#define MAX_NUM_ASTEROIDS 25
279#define MAX_NUM_MISSILES 6
280#define MAX_LEVEL MAX_NUM_ASTEROIDS
281#define NUM_STARS 50
282#define NUM_TRAIL_POINTS 70
283#define NUM_ROTATIONS 16
284
292#define NUM_ASTEROID_VERTICES 10 285#define NUM_ASTEROID_VERTICES 10
293#define NUM_SHIP_VERTICES 4 286#define NUM_SHIP_VERTICES 4
294#define NUM_ENEMY_VERTICES 6 287#define NUM_ENEMY_VERTICES 6
295#define MAX_LEVEL MAX_NUM_ASTEROIDS 288
289#define SPAWN_TIME 30
290#define BLINK_TIME 10
291#define EXTRA_LIFE 250
292#define START_LIVES 3
293#define START_LEVEL 1
294#define MISSILE_SURVIVAL_LENGTH 40
295
296#define ASTEROID_SPEED (RES/20)
297#define SPACE_CHECK_SIZE 30*SCALE
298
299#define LITTLE_SHIP 2
300#define BIG_SHIP 1
301#define ENEMY_BIG_PROBABILITY_START 10
302#define ENEMY_APPEAR_PROBABILITY_START 35
303#define ENEMY_APPEAR_TIMING_START 1800
296#define ENEMY_SPEED 4 304#define ENEMY_SPEED 4
305#define ENEMY_MISSILE_SURVIVAL_LENGTH (RES/2)
297#define SIZE_ENEMY_COLLISION 5*SCALE 306#define SIZE_ENEMY_COLLISION 5*SCALE
298#define NUM_STARS 50
299#define NUM_TRAIL_POINTS 70
300#define NUM_ROTATIONS 16
301 307
302#define SIN_COS_SCALE 10000 308#define SIN_COS_SCALE 10000
303 309
@@ -313,19 +319,19 @@ CONFIG_KEYPAD == MROBE500_PAD
313 319
314#define SLOW_ROT_CW_SIN 350 320#define SLOW_ROT_CW_SIN 350
315#define SLOW_ROT_CW_COS 9994 321#define SLOW_ROT_CW_COS 9994
316#define SLOW_ROT_ACW_SIN - 350 322#define SLOW_ROT_ACW_SIN -350
317#define SLOW_ROT_ACW_COS 9994 323#define SLOW_ROT_ACW_COS 9994
318 324
319#ifdef HAVE_LCD_COLOR 325#ifdef HAVE_LCD_COLOR
320#define SHIP_ROT_CW_SIN 2419 326#define SHIP_ROT_CW_SIN 2419
321#define SHIP_ROT_CW_COS 9702 327#define SHIP_ROT_CW_COS 9702
322#define SHIP_ROT_ACW_SIN -2419 328#define SHIP_ROT_ACW_SIN -2419
323#define SHIP_ROT_ACW_COS 9702 329#define SHIP_ROT_ACW_COS 9702
324#else 330#else
325#define SHIP_ROT_CW_SIN 3827 331#define SHIP_ROT_CW_SIN 3827
326#define SHIP_ROT_CW_COS 9239 332#define SHIP_ROT_CW_COS 9239
327#define SHIP_ROT_ACW_SIN -3827 333#define SHIP_ROT_ACW_SIN -3827
328#define SHIP_ROT_ACW_COS 9239 334#define SHIP_ROT_ACW_COS 9239
329#endif 335#endif
330 336
331 337
@@ -339,20 +345,20 @@ CONFIG_KEYPAD == MROBE500_PAD
339#define ENEMY_EXPLOSION_COLOUR 3 345#define ENEMY_EXPLOSION_COLOUR 3
340#define THRUST_COLOUR 4 346#define THRUST_COLOUR 4
341 347
342#define ASTEROID_R 230
343#define ASTEROID_G 200
344#define ASTEROID_B 100
345#define SHIP_R 255
346#define SHIP_G 255
347#define SHIP_B 255
348#define ENEMY_R 50
349#define ENEMY_G 220
350#define ENEMY_B 50
351#define THRUST_R 200
352#define THRUST_G 200
353#define THRUST_B 0
354
355#ifdef HAVE_LCD_COLOR 348#ifdef HAVE_LCD_COLOR
349#define ASTEROID_R 230
350#define ASTEROID_G 200
351#define ASTEROID_B 100
352#define SHIP_R 255
353#define SHIP_G 255
354#define SHIP_B 255
355#define ENEMY_R 50
356#define ENEMY_G 220
357#define ENEMY_B 50
358#define THRUST_R 200
359#define THRUST_G 200
360#define THRUST_B 0
361
356#define COL_MISSILE LCD_RGBPACK(200,0,0) 362#define COL_MISSILE LCD_RGBPACK(200,0,0)
357#define COL_PLAYER LCD_RGBPACK(200,200,200) 363#define COL_PLAYER LCD_RGBPACK(200,200,200)
358#define COL_INVULN LCD_RGBPACK(100,100,200) 364#define COL_INVULN LCD_RGBPACK(100,100,200)
@@ -367,115 +373,111 @@ CONFIG_KEYPAD == MROBE500_PAD
367#define SET_BG(x) 373#define SET_BG(x)
368#endif 374#endif
369 375
370#define MARGIN 5
371
372#define HIGH_SCORE PLUGIN_GAMES_DIR "/spacerocks.score" 376#define HIGH_SCORE PLUGIN_GAMES_DIR "/spacerocks.score"
373#define NUM_SCORES 5 377#define NUM_SCORES 5
374 378
375struct highscore highest[NUM_SCORES]; 379struct highscore highscores[NUM_SCORES];
376 380
377/* The array of points that make up an asteroid */ 381/* The array of points that make up an asteroid */
378static const short asteroid_one[NUM_ASTEROID_VERTICES*2] = 382static const short asteroid_one[NUM_ASTEROID_VERTICES*2] =
379{ 383{
380 -2, -12, 384 -2, -12,
381 4, -8, 385 4, -8,
382 8, -14, 386 8, -14,
383 16, -5, 387 16, -5,
384 14, 0, 388 14, 0,
385 20, 2, 389 20, 2,
386 12, 14, 390 12, 14,
387 -4, 14, 391 -4, 14,
388 -10, 6, 392 -10, 6,
389 -10, -8 393 -10, -8,
390}; 394};
391 395
392/* The array of points that make up an asteroid */ 396/* The array of points that make up an asteroid */
393static const short asteroid_two[NUM_ASTEROID_VERTICES*2] = 397static const short asteroid_two[NUM_ASTEROID_VERTICES*2] =
394{ 398{
395 -2, -12, 399 -2, -12,
396 4, -16, 400 4, -16,
397 6, -14, 401 6, -14,
398 16, -8, 402 16, -8,
399 14, 0, 403 14, 0,
400 20, 2, 404 20, 2,
401 12, 14, 405 12, 14,
402 -4, 14, 406 -4, 14,
403 -10, 6, 407 -10, 6,
404 -10, -8 408 -10, -8,
405}; 409};
406 410
407/* The array of points that make up an asteroid */ 411/* The array of points that make up an asteroid */
408static const short asteroid_three[NUM_ASTEROID_VERTICES*2] = 412static const short asteroid_three[NUM_ASTEROID_VERTICES*2] =
409{ 413{
410 -2, -12, 414 -2, -12,
411 4, -16, 415 4, -16,
412 6, -14, 416 6, -14,
413 2, -8, 417 2, -8,
414 14, 0, 418 14, 0,
415 20, 2, 419 20, 2,
416 12, 14, 420 12, 14,
417 -4, 14, 421 -4, 14,
418 -16, 6, 422 -16, 6,
419 -10, -8 423 -10, -8,
420}; 424};
421 425
422/* The array od points the make up the ship */ 426/* The array od points the make up the ship */
423static const short ship_vertices[NUM_SHIP_VERTICES*2] = 427static const short ship_vertices[NUM_SHIP_VERTICES*2] =
424{ 428{
425 #if(LARGE_LCD) 429#if (LARGE_LCD)
426 0,-6, 430 0, -6,
427 4, 6, 431 4, 6,
428 0, 2, 432 0, 2,
429 -4, 6 433 -4, 6,
430 #else 434#else
431 0,-4, 435 0, -4,
432 3, 4, 436 3, 4,
433 0, 1, 437 0, 1,
434 -3, 4 438 -3, 4,
435 #endif 439#endif
436}; 440};
437 441
438/* The array of points the make up the bad spaceship */ 442/* The array of points the make up the bad spaceship */
439static const short enemy_vertices[NUM_ENEMY_VERTICES*2] = 443static const short enemy_vertices[NUM_ENEMY_VERTICES*2] =
440{ 444{
441 #if(LARGE_LCD) 445#if (LARGE_LCD)
442 -8, 0, 446 -8, 0,
443 -4, 4, 447 -4, 4,
444 4, 4, 448 4, 4,
445 8, 0, 449 8, 0,
446 4, -4, 450 4, -4,
447 -4, -4 451 -4, -4,
448 #else 452#else
449 -5, 0, 453 -5, 0,
450 -2, 2, 454 -2, 2,
451 2, 2, 455 2, 2,
452 5, 0, 456 5, 0,
453 2, -2, 457 2, -2,
454 -2, -2 458 -2, -2,
455 #endif 459#endif
456
457}; 460};
458 461
459enum asteroid_type 462enum asteroid_type
460{ 463{
461 #if(LARGE_LCD) 464#if (LARGE_LCD)
462 SMALL = 2, 465 SMALL = 2,
463 MEDIUM = 4, 466 MEDIUM = 4,
464 LARGE = 6, 467 LARGE = 6,
465 #else 468#else
466 SMALL = 1, 469 SMALL = 1,
467 MEDIUM = 2, 470 MEDIUM = 2,
468 LARGE = 3, 471 LARGE = 3,
469 #endif 472#endif
470
471}; 473};
472 474
473enum game_state 475enum game_state
474{ 476{
475 GAME_OVER, 477 GAME_OVER,
476 SHOW_LEVEL, 478 SHOW_LEVEL,
477 PLAY_MODE, 479 PLAY_MODE,
478 PAUSE_MODE 480 PAUSE_MODE,
479}; 481};
480 482
481struct Point 483struct Point
@@ -488,25 +490,27 @@ struct Point
488 490
489struct TrailPoint 491struct TrailPoint
490{ 492{
491 int alive; 493 int alive;
492 struct Point position; 494 struct Point position;
493 short r; 495#ifdef HAVE_LCD_COLOR
494 short g; 496 short r;
495 short b; 497 short g;
496 short dec; 498 short b;
499 short dec;
500#endif
497}; 501};
498 502
499/* Asteroid structure, contains an array of points */ 503/* Asteroid structure, contains an array of points */
500struct Asteroid 504struct Asteroid
501{ 505{
502 enum asteroid_type type; 506 struct Point position;
503 bool exists; 507 struct Point vertices[NUM_ASTEROID_VERTICES];
504 struct Point position; 508 bool exists;
505 struct Point vertices[NUM_ASTEROID_VERTICES]; 509 int explode_countdown;
510 enum asteroid_type type;
506 int radius; 511 int radius;
507 long speed_cos; 512 long speed_cos;
508 long speed_sin; 513 long speed_sin;
509 int explode_countdown;
510}; 514};
511 515
512struct Ship 516struct Ship
@@ -514,19 +518,20 @@ struct Ship
514 struct Point vertices[NUM_SHIP_VERTICES]; 518 struct Point vertices[NUM_SHIP_VERTICES];
515 struct Point position; 519 struct Point position;
516 bool waiting_for_space; 520 bool waiting_for_space;
521 int explode_countdown;
517 bool invulnerable; 522 bool invulnerable;
518 int spawn_time; 523 int spawn_time;
519 int explode_countdown;
520}; 524};
521 525
522struct Enemy 526struct Enemy
523{ 527{
524 struct Point vertices[NUM_ENEMY_VERTICES]; 528 struct Point vertices[NUM_ENEMY_VERTICES];
525 struct Point position; 529 struct Point position;
530 bool exists;
526 int explode_countdown; 531 int explode_countdown;
527 long last_time_appeared; 532 long last_time_appeared;
528 short size_probability; 533 short size_probability;
529 short appear_probability; 534 short appear_probability;
530 short appear_timing; 535 short appear_timing;
531}; 536};
532 537
@@ -546,9 +551,7 @@ static int extra_life;
546static int show_level_timeout; 551static int show_level_timeout;
547static int current_level; 552static int current_level;
548static int current_score; 553static int current_score;
549static int space_check_size = 30*SCALE;
550 554
551static bool enemy_on_screen;
552static struct Ship ship; 555static struct Ship ship;
553static struct Point stars[NUM_STARS]; 556static struct Point stars[NUM_STARS];
554static struct Asteroid asteroids_array[MAX_NUM_ASTEROIDS]; 557static struct Asteroid asteroids_array[MAX_NUM_ASTEROIDS];
@@ -556,7 +559,7 @@ static struct Missile missiles_array[MAX_NUM_MISSILES];
556static struct Missile enemy_missile; 559static struct Missile enemy_missile;
557static struct Enemy enemy; 560static struct Enemy enemy;
558static struct Point lives_points[NUM_SHIP_VERTICES]; 561static struct Point lives_points[NUM_SHIP_VERTICES];
559static struct TrailPoint trailPoints[NUM_TRAIL_POINTS]; 562static struct TrailPoint trail_points[NUM_TRAIL_POINTS];
560 563
561void draw_and_move_asteroids(void); 564void draw_and_move_asteroids(void);
562void initialise_game(int nStartNum); 565void initialise_game(int nStartNum);
@@ -572,7 +575,7 @@ void create_stars(void);
572 575
573void initialise_ship(void); 576void initialise_ship(void);
574void draw_and_move_ship(void); 577void draw_and_move_ship(void);
575void rotate_ship(int s, int c); 578void rotate_ship(int c, int s);
576void thrust_ship(void); 579void thrust_ship(void);
577 580
578void initialise_missile(struct Missile* missile); 581void initialise_missile(struct Missile* missile);
@@ -599,6 +602,7 @@ void init(void)
599 enemy.size_probability = ENEMY_BIG_PROBABILITY_START; 602 enemy.size_probability = ENEMY_BIG_PROBABILITY_START;
600 current_level = START_LEVEL; 603 current_level = START_LEVEL;
601 num_lives = START_LIVES; 604 num_lives = START_LIVES;
605 extra_life = EXTRA_LIFE;
602 current_score = 0; 606 current_score = 0;
603 initialise_ship(); 607 initialise_ship();
604 initialise_game(current_level); 608 initialise_game(current_level);
@@ -608,10 +612,8 @@ void init(void)
608 612
609static bool spacerocks_help(void) 613static bool spacerocks_help(void)
610{ 614{
611 rb->lcd_setfont(FONT_UI);
612#define WORDS (sizeof help_text / sizeof (char*))
613 static char *help_text[] = { 615 static char *help_text[] = {
614 "Spacerocks", "", "Aim", "", "The", "goal", "of", "the", "game", "is", 616 "Spacerocks", "", "Aim", "", "The", "goal", "of", "the", "game", "is",
615 "to", "blow", "up", "the", "asteroids", "and", "avoid", "being", "hit", "by", 617 "to", "blow", "up", "the", "asteroids", "and", "avoid", "being", "hit", "by",
616 "them.", "Also", "you'd", "better", "watch", "out", "for", "the", "UFOs!" 618 "them.", "Also", "you'd", "better", "watch", "out", "for", "the", "UFOs!"
617 }; 619 };
@@ -620,18 +622,20 @@ static bool spacerocks_help(void)
620 { 2, C_RED }, 622 { 2, C_RED },
621 { -1, 0 } 623 { -1, 0 }
622 }; 624 };
625 int button;
626
627 rb->lcd_setfont(FONT_UI);
623#ifdef HAVE_LCD_COLOR 628#ifdef HAVE_LCD_COLOR
624 rb->lcd_set_background(LCD_BLACK); 629 rb->lcd_set_background(LCD_BLACK);
625 rb->lcd_set_foreground(LCD_WHITE); 630 rb->lcd_set_foreground(LCD_WHITE);
626#endif 631#endif
627 int button; 632 if (display_text(ARRAYLEN(help_text), help_text, formation, NULL)
628 if (display_text(WORDS, help_text, formation, NULL)==PLUGIN_USB_CONNECTED) 633 ==PLUGIN_USB_CONNECTED)
629 return true; 634 return true;
630 do { 635 do {
631 button = rb->button_get(true); 636 button = rb->button_get(true);
632 if (button == SYS_USB_CONNECTED) { 637 if (button == SYS_USB_CONNECTED)
633 return true; 638 return true;
634 }
635 } while( ( button == BUTTON_NONE ) 639 } while( ( button == BUTTON_NONE )
636 || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); 640 || ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
637 rb->lcd_setfont(FONT_SYSFIXED); 641 rb->lcd_setfont(FONT_SYSFIXED);
@@ -650,22 +654,20 @@ static int spacerocks_menu_cb(int action, const struct menu_item_ex *this_item)
650 654
651static int spacerocks_menu(bool ingame) 655static int spacerocks_menu(bool ingame)
652{ 656{
653 rb->button_clear_queue();
654 int choice = 0; 657 int choice = 0;
655 658
656 _ingame = ingame; 659 _ingame = ingame;
657 660
658 MENUITEM_STRINGLIST (main_menu, "Spacerocks Menu", spacerocks_menu_cb, 661 MENUITEM_STRINGLIST(main_menu, "Spacerocks Menu", spacerocks_menu_cb,
659 "Resume Game", 662 "Resume Game", "Start New Game",
660 "Start New Game", 663 "Help", "High Scores",
661 "Help", 664 "Playback Control", "Quit");
662 "High Scores", 665 rb->button_clear_queue();
663 "Playback Control", 666
664 "Quit"); 667 while (1)
665 668 {
666 while (1) { 669 switch (rb->do_menu(&main_menu, &choice, NULL, false))
667 choice = rb->do_menu(&main_menu, &choice, NULL, false); 670 {
668 switch (choice) {
669 case 0: 671 case 0:
670 return 0; 672 return 0;
671 case 1: 673 case 1:
@@ -676,7 +678,7 @@ static int spacerocks_menu(bool ingame)
676 return 1; 678 return 1;
677 break; 679 break;
678 case 3: 680 case 3:
679 highscore_show(NUM_SCORES, highest, NUM_SCORES, true); 681 highscore_show(NUM_SCORES, highscores, NUM_SCORES, true);
680 break; 682 break;
681 case 4: 683 case 4:
682 playback_control(NULL); 684 playback_control(NULL);
@@ -691,32 +693,27 @@ static int spacerocks_menu(bool ingame)
691 } 693 }
692} 694}
693 695
694bool point_in_poly(struct Point* _point, int num_vertices, int x, int y) 696bool point_in_poly(struct Point* point, int num_vertices, int x, int y)
695{ 697{
696 struct Point* pi; 698 struct Point* pi;
697 struct Point* pj; 699 struct Point* pj;
698 int n; 700 int n;
699 bool c = false; 701 bool c = false;
700 702
701 pi = _point; 703 pi = point;
702 pj = _point; 704 pj = point + num_vertices-1;
703 pj += num_vertices-1; 705
704
705 n = num_vertices; 706 n = num_vertices;
706 while(n--) 707 while(n--)
707 { 708 {
708 if((((pi->y <= y) && (y < pj->y)) || ((pj->y <= y) && (y < pi->y))) && 709 if((((pi->y <= y) && (y < pj->y)) || ((pj->y <= y) && (y < pi->y))) &&
709 (x < (pj->x - pi->x) * (y - pi->y) / (pj->y - pi->y) + pi->x)) 710 (x < (pj->x - pi->x) * (y - pi->y) / (pj->y - pi->y) + pi->x))
710 c = !c; 711 c = !c;
711 712
712 if(n == num_vertices - 1) 713 pj = pi;
713 pj = _point;
714 else
715 pj++;
716
717 pi++; 714 pi++;
718 } 715 }
719 716
720 return c; 717 return c;
721} 718}
722 719
@@ -724,143 +721,147 @@ void move_point(struct Point* point)
724{ 721{
725 point->x += point->dx; 722 point->x += point->dx;
726 point->y += point->dy; 723 point->y += point->dy;
727 724
728 /*check bounds on the x-axis:*/ 725 /*check bounds on the x-axis:*/
729 if(point->x >= SCALED_WIDTH) 726 point->x %= SCALED_WIDTH;
730 point->x = 0; 727 if(point->x < 0)
731 else if(point->x <= 0) 728 point->x += SCALED_WIDTH;
732 point->x = SCALED_WIDTH; 729
733
734 /*Check bounds on the y-axis:*/ 730 /*Check bounds on the y-axis:*/
735 if(point->y >= SCALED_HEIGHT) 731 point->y %= SCALED_HEIGHT;
736 point->y = 0; 732 if(point->y < 0)
737 else if(point->y <= 0) 733 point->y += SCALED_HEIGHT;
738 point->y = SCALED_HEIGHT;
739} 734}
740 735
741void create_trail(struct TrailPoint* tpoint) 736void create_ship_trail(struct TrailPoint* tpoint)
742{ 737{
743 tpoint->position.dx = -( ship.vertices[0].x - ship.vertices[2].x )/10; 738 tpoint->position.dx = -( ship.vertices[0].x - ship.vertices[2].x )/10;
744 tpoint->position.dy = -( ship.vertices[0].y - ship.vertices[2].y )/10; 739 tpoint->position.dy = -( ship.vertices[0].y - ship.vertices[2].y )/10;
745} 740}
746 741
747void create_explosion_trail(struct TrailPoint* tpoint) 742void create_explosion_trail(struct TrailPoint* tpoint)
748{ 743{
749 tpoint->position.dx = (rb->rand()%5050)-2500; 744 tpoint->position.dx = (rb->rand()%5001)-2500;
750 tpoint->position.dy = (rb->rand()%5050)-2500; 745 tpoint->position.dy = (rb->rand()%5001)-2500;
751} 746}
752 747
753void create_trail_blaze(int colour, struct Point* position) 748void create_trail_blaze(int colour, struct Point* position)
754{ 749{
755 int numtoadd; 750 int numtoadd;
756 struct TrailPoint* tpoint; 751 struct TrailPoint* tpoint;
757 int n; 752 int n;
758 int xadd,yadd; 753
759 if(colour != SHIP_EXPLOSION_COLOUR) 754 if(colour != SHIP_EXPLOSION_COLOUR)
760 { 755 {
761 numtoadd = NUM_TRAIL_POINTS/5; 756 numtoadd = NUM_TRAIL_POINTS/5;
762 xadd = position->x; 757 }
763 yadd = position->y; 758 else
764 }
765 else
766 {
767 numtoadd = NUM_TRAIL_POINTS/8;
768 xadd = ship.position.x;
769 yadd = ship.position.y;
770 }
771
772 /* give the point a random countdown timer, so they dissapears at different times */
773 tpoint = trailPoints;
774 n = NUM_TRAIL_POINTS;
775 while(--n)
776 {
777 if(tpoint->alive <= 0 && numtoadd)
778 { 759 {
779 numtoadd--; 760 numtoadd = NUM_TRAIL_POINTS/8;
780 /* take a random x point anywhere between bottom two points of ship. */ 761 }
781 /* ship.position.x; */ 762
782 tpoint->position.x = (ship.vertices[2].x + (rb->rand()%18000)-9000) + position->x; 763 /* give the point a random countdown timer, so they dissapears at different
783 tpoint->position.y = (ship.vertices[2].y + (rb->rand()%18000)-9000) + position->y; 764 times */
784 765 tpoint = trail_points;
785 switch(colour) 766 n = NUM_TRAIL_POINTS;
786 { 767 while(n-- && numtoadd)
787 case SHIP_EXPLOSION_COLOUR: 768 {
788 tpoint->r = 255; 769 /* find a space in the array of trail_points that is NULL or DEAD or
789 tpoint->g = 255; 770 whatever and place this one here. */
790 tpoint->b = 255; 771 if(tpoint->alive <= 0)
791 create_explosion_trail(tpoint); 772 {
792 tpoint->alive = 510; 773 numtoadd--;
793 tpoint->dec = 2; 774 /* take a random x point anywhere between bottom two points of ship. */
794 break; 775 /* ship.position.x; */
795 case ASTEROID_EXPLOSION_COLOUR: 776 tpoint->position.x = (ship.vertices[2].x + (rb->rand()%18000)-9000)
796 tpoint->r = ASTEROID_R; 777 + position->x;
797 tpoint->g = ASTEROID_G; 778 tpoint->position.y = (ship.vertices[2].y + (rb->rand()%18000)-9000)
798 tpoint->b = ASTEROID_B; 779 + position->y;
799 create_explosion_trail(tpoint); 780
800 tpoint->alive = 510; 781 switch(colour)
801 tpoint->dec = 2; 782 {
802 break; 783 case SHIP_EXPLOSION_COLOUR:
803 case ENEMY_EXPLOSION_COLOUR: 784 create_explosion_trail(tpoint);
804 tpoint->r = ENEMY_R; 785 tpoint->alive = 510;
805 tpoint->g = ENEMY_G; 786#ifdef HAVE_LCD_COLOR
806 tpoint->b = ENEMY_B; 787 tpoint->r = SHIP_R;
807 create_explosion_trail(tpoint); 788 tpoint->g = SHIP_G;
808 tpoint->alive = 510; 789 tpoint->b = SHIP_B;
809 tpoint->dec = 2; 790 tpoint->dec = 2;
810 break; 791#endif
811 case THRUST_COLOUR: 792 break;
812 tpoint->r = THRUST_R; 793 case ASTEROID_EXPLOSION_COLOUR:
813 tpoint->g = THRUST_G; 794 create_explosion_trail(tpoint);
814 tpoint->b = THRUST_B; 795 tpoint->alive = 510;
815 create_trail(tpoint); 796#ifdef HAVE_LCD_COLOR
816 tpoint->alive = 175; 797 tpoint->r = ASTEROID_R;
817 tpoint->dec = 4; 798 tpoint->g = ASTEROID_G;
818 break; 799 tpoint->b = ASTEROID_B;
819 } 800 tpoint->dec = 2;
820 /* add a proportional bit to the x and y based on dx and dy */ 801#endif
821 802 break;
822 /* give the points a speed based on direction of travel - i.e. opposite */ 803 case ENEMY_EXPLOSION_COLOUR:
823 tpoint->position.dx += position->dx; 804 create_explosion_trail(tpoint);
824 tpoint->position.dy += position->dy; 805 tpoint->alive = 510;
825 806#ifdef HAVE_LCD_COLOR
826 807 tpoint->r = ENEMY_R;
808 tpoint->g = ENEMY_G;
809 tpoint->b = ENEMY_B;
810 tpoint->dec = 2;
811#endif
812 break;
813 case THRUST_COLOUR:
814 create_ship_trail(tpoint);
815 tpoint->alive = 175;
816#ifdef HAVE_LCD_COLOR
817 tpoint->r = THRUST_R;
818 tpoint->g = THRUST_G;
819 tpoint->b = THRUST_B;
820 tpoint->dec = 4;
821#endif
822 break;
823 }
824
825 /* give the points a speed based on direction of travel
826 - i.e. opposite */
827 tpoint->position.dx += position->dx;
828 tpoint->position.dy += position->dy;
829 }
830 tpoint++;
827 } 831 }
828 tpoint++;
829 }
830 /* find a space in the array of trail_points that is NULL or DEAD or whatever.
831 and place this one here. */
832
833} 832}
834 833
835void draw_trail_blaze(void) 834void draw_trail_blaze(void)
836{ 835{
837 struct TrailPoint* tpoint; 836 struct TrailPoint* tpoint;
838 /* loop through, if alive then move and draw. 837 int n;
839 when drawn, countdown it's timer. 838
840 if zero kill it! */ 839 /* loop through, if alive then move and draw.
841 tpoint = trailPoints; 840 when drawn, countdown it's timer.
842 int n = NUM_TRAIL_POINTS; 841 if zero kill it! */
843 842
844 while(--n) 843 tpoint = trail_points;
845 { 844 n = NUM_TRAIL_POINTS;
846 if(tpoint->alive) 845 while(n--)
847 { 846 {
848 if(game_state != PAUSE_MODE) 847 if(tpoint->alive)
849 { 848 {
850 tpoint->alive-=10; 849 if(game_state != PAUSE_MODE)
851 move_point(&(tpoint->position)); 850 {
852 } 851 tpoint->alive -= 10;
853 #ifdef HAVE_LCD_COLOR 852 move_point(&(tpoint->position));
854 /* intensity = tpoint->alive/2; */ 853 }
855 if(tpoint->r>0)tpoint->r-=tpoint->dec; 854#ifdef HAVE_LCD_COLOR
856 if(tpoint->g>0)tpoint->g-=tpoint->dec; 855 /* intensity = tpoint->alive/2; */
857 if(tpoint->b>0)tpoint->b-=tpoint->dec; 856 if(tpoint->r >= tpoint->dec) tpoint->r -= tpoint->dec;
858 SET_FG(LCD_RGBPACK(tpoint->r, tpoint->g, tpoint->b)); 857 if(tpoint->g >= tpoint->dec) tpoint->g -= tpoint->dec;
859 #endif 858 if(tpoint->b >= tpoint->dec) tpoint->b -= tpoint->dec;
860 rb->lcd_drawpixel(tpoint->position.x/SCALE , tpoint->position.y/SCALE); 859 SET_FG(LCD_RGBPACK(tpoint->r, tpoint->g, tpoint->b));
860#endif
861 rb->lcd_drawpixel(tpoint->position.x/SCALE, tpoint->position.y/SCALE);
862 }
863 tpoint++;
861 } 864 }
862 tpoint++;
863 }
864} 865}
865 866
866/*Check if point is within a rectangle*/ 867/*Check if point is within a rectangle*/
@@ -889,28 +890,28 @@ void draw_polygon(struct Point* vertices, int px, int py, int num_vertices)
889 struct Point *p; 890 struct Point *p;
890 bool bDrawAll = px < WRAP_GAP || LCD_WIDTH - px < WRAP_GAP || 891 bool bDrawAll = px < WRAP_GAP || LCD_WIDTH - px < WRAP_GAP ||
891 py < WRAP_GAP || LCD_HEIGHT - py < WRAP_GAP; 892 py < WRAP_GAP || LCD_HEIGHT - py < WRAP_GAP;
892 893
893 p = vertices; 894 p = vertices + num_vertices - 1;
894 p += num_vertices-1;
895 oldX = p->x/SCALE + px; 895 oldX = p->x/SCALE + px;
896 oldY = p->y/SCALE + py; 896 oldY = p->y/SCALE + py;
897 p = vertices; 897 p = vertices;
898 for(n = num_vertices+1; --n;) 898 n = num_vertices;
899 while(n--)
899 { 900 {
900 t1 = p->x/SCALE + px; 901 t1 = p->x/SCALE + px;
901 t2 = p->y/SCALE + py; 902 t2 = p->y/SCALE + py;
902 903
903 rb->lcd_drawline(oldX, oldY, t1, t2); 904 rb->lcd_drawline(oldX, oldY, t1, t2);
904 905
905 if(bDrawAll) 906 if(bDrawAll)
906 { 907 {
907 rb->lcd_drawline(oldX - LCD_WIDTH, oldY, t1 - LCD_WIDTH, t2); 908 rb->lcd_drawline(oldX - LCD_WIDTH, oldY, t1 - LCD_WIDTH, t2);
908 rb->lcd_drawline(oldX + LCD_WIDTH, oldY, t1 + LCD_WIDTH, t2); 909 rb->lcd_drawline(oldX + LCD_WIDTH, oldY, t1 + LCD_WIDTH, t2);
909 rb->lcd_drawline(oldX - LCD_WIDTH, oldY + LCD_HEIGHT, 910 rb->lcd_drawline(oldX - LCD_WIDTH, oldY + LCD_HEIGHT,
910 t1 - LCD_WIDTH, t2 + LCD_HEIGHT); 911 t1 - LCD_WIDTH, t2 + LCD_HEIGHT);
911 rb->lcd_drawline(oldX + LCD_WIDTH, oldY + LCD_HEIGHT, 912 rb->lcd_drawline(oldX + LCD_WIDTH, oldY + LCD_HEIGHT,
912 t1 + LCD_WIDTH, t2 + LCD_HEIGHT); 913 t1 + LCD_WIDTH, t2 + LCD_HEIGHT);
913 914
914 rb->lcd_drawline(oldX, oldY - LCD_HEIGHT, t1, t2 - LCD_HEIGHT); 915 rb->lcd_drawline(oldX, oldY - LCD_HEIGHT, t1, t2 - LCD_HEIGHT);
915 rb->lcd_drawline(oldX, oldY + LCD_HEIGHT, t1, t2 + LCD_HEIGHT); 916 rb->lcd_drawline(oldX, oldY + LCD_HEIGHT, t1, t2 + LCD_HEIGHT);
916 rb->lcd_drawline(oldX - LCD_WIDTH, oldY - LCD_HEIGHT, 917 rb->lcd_drawline(oldX - LCD_WIDTH, oldY - LCD_HEIGHT,
@@ -927,18 +928,18 @@ void draw_polygon(struct Point* vertices, int px, int py, int num_vertices)
927void animate_and_draw_explosion(struct Point* point, int num_points, 928void animate_and_draw_explosion(struct Point* point, int num_points,
928 int xoffset, int yoffset) 929 int xoffset, int yoffset)
929{ 930{
930 int n; 931 int n = num_points;
931 for(n = num_points; --n;) 932 while(n--)
932 { 933 {
933 if(game_state != PAUSE_MODE) 934 if(game_state != PAUSE_MODE)
934 { 935 {
935 point->x += point->dx; 936 point->x += point->dx;
936 point->y += point->dy; 937 point->y += point->dy;
937 } 938 }
938 rb->lcd_fillrect( point->x/SCALE + xoffset, point->y/SCALE + yoffset, 939 rb->lcd_fillrect( point->x/SCALE + xoffset, point->y/SCALE + yoffset,
939 POINT_SIZE, POINT_SIZE); 940 POINT_SIZE, POINT_SIZE );
940 point++; 941 point++;
941 } 942 }
942} 943}
943 944
944/*stop movement of ship, 'cos that's what happens when you go into hyperspace.*/ 945/*stop movement of ship, 'cos that's what happens when you go into hyperspace.*/
@@ -957,24 +958,25 @@ void initialise_enemy(void)
957 958
958 if(rb->rand()%100 > enemy.size_probability) 959 if(rb->rand()%100 > enemy.size_probability)
959 { 960 {
960 size = BIG_SHIP; 961 size = BIG_SHIP;
961 enemy.size_probability++; 962 enemy.size_probability++;
962 if(enemy.size_probability < 90) 963 if(enemy.size_probability > 90)
963 { 964 {
964 enemy.size_probability = ENEMY_BIG_PROBABILITY_START; 965 enemy.size_probability = ENEMY_BIG_PROBABILITY_START;
965 } 966 }
966 } 967 }
967 else 968 else
968 { 969 {
969 size = LITTLE_SHIP; 970 size = LITTLE_SHIP;
970 } 971 enemy.size_probability = ENEMY_BIG_PROBABILITY_START;
971 972 }
973
972 enemy_missile.survived = 0; 974 enemy_missile.survived = 0;
973 enemy_on_screen = true; 975 enemy.exists = true;
974 enemy.explode_countdown = 0; 976 enemy.explode_countdown = 0;
975 enemy.last_time_appeared = *rb->current_tick; 977 enemy.last_time_appeared = *rb->current_tick;
976 point = enemy.vertices; 978 point = enemy.vertices;
977 for(n = 0; n < NUM_ENEMY_VERTICES+NUM_ENEMY_VERTICES; n+=2) 979 for(n = 0; n < NUM_ENEMY_VERTICES*2; n += 2)
978 { 980 {
979 point->x = enemy_vertices[n]; 981 point->x = enemy_vertices[n];
980 point->y = enemy_vertices[n+1]; 982 point->y = enemy_vertices[n+1];
@@ -982,7 +984,7 @@ void initialise_enemy(void)
982 point->y *= SCALE/size; 984 point->y *= SCALE/size;
983 point++; 985 point++;
984 } 986 }
985 987
986 if(ship.position.x >= SCALED_WIDTH/2) 988 if(ship.position.x >= SCALED_WIDTH/2)
987 { 989 {
988 enemy.position.dx = ENEMY_SPEED; 990 enemy.position.dx = ENEMY_SPEED;
@@ -993,7 +995,7 @@ void initialise_enemy(void)
993 enemy.position.dx = -ENEMY_SPEED; 995 enemy.position.dx = -ENEMY_SPEED;
994 enemy.position.x = SCALED_WIDTH; 996 enemy.position.x = SCALED_WIDTH;
995 } 997 }
996 998
997 if(ship.position.y >= SCALED_HEIGHT/2) 999 if(ship.position.y >= SCALED_HEIGHT/2)
998 { 1000 {
999 enemy.position.dy = ENEMY_SPEED; 1001 enemy.position.dy = ENEMY_SPEED;
@@ -1004,7 +1006,7 @@ void initialise_enemy(void)
1004 enemy.position.dy = -ENEMY_SPEED; 1006 enemy.position.dy = -ENEMY_SPEED;
1005 enemy.position.y = SCALED_HEIGHT; 1007 enemy.position.y = SCALED_HEIGHT;
1006 } 1008 }
1007 1009
1008 enemy.position.dx *= SCALE/10; 1010 enemy.position.dx *= SCALE/10;
1009 enemy.position.dy *= SCALE/10; 1011 enemy.position.dy *= SCALE/10;
1010} 1012}
@@ -1012,20 +1014,18 @@ void initialise_enemy(void)
1012void draw_and_move_enemy(void) 1014void draw_and_move_enemy(void)
1013{ 1015{
1014 int enemy_x, enemy_y; 1016 int enemy_x, enemy_y;
1015 struct Point *point;
1016 1017
1017 SET_FG(COL_ENEMY); 1018 SET_FG(COL_ENEMY);
1018 1019
1019 if(enemy_on_screen) 1020 if(enemy.exists)
1020 { 1021 {
1021 enemy_x = enemy.position.x/SCALE; 1022 enemy_x = enemy.position.x/SCALE;
1022 enemy_y = enemy.position.y/SCALE; 1023 enemy_y = enemy.position.y/SCALE;
1023 if(!enemy.explode_countdown) 1024 if(!enemy.explode_countdown)
1024 { 1025 {
1025 point = enemy.vertices;
1026 draw_polygon(enemy.vertices, enemy_x, enemy_y, NUM_ENEMY_VERTICES); 1026 draw_polygon(enemy.vertices, enemy_x, enemy_y, NUM_ENEMY_VERTICES);
1027 rb->lcd_drawline(enemy.vertices[0].x/SCALE + enemy_x, 1027 rb->lcd_drawline(enemy.vertices[0].x/SCALE + enemy_x,
1028 enemy.vertices[0].y/SCALE + enemy_y, 1028 enemy.vertices[0].y/SCALE + enemy_y,
1029 enemy.vertices[3].x/SCALE + enemy_x, 1029 enemy.vertices[3].x/SCALE + enemy_x,
1030 enemy.vertices[3].y/SCALE + enemy_y); 1030 enemy.vertices[3].y/SCALE + enemy_y);
1031 1031
@@ -1033,85 +1033,83 @@ void draw_and_move_enemy(void)
1033 { 1033 {
1034 enemy.position.x += enemy.position.dx; 1034 enemy.position.x += enemy.position.dx;
1035 enemy.position.y += enemy.position.dy; 1035 enemy.position.y += enemy.position.dy;
1036
1037 if(enemy.position.x > SCALED_WIDTH || enemy.position.x < 0)
1038 enemy.exists = false;
1039
1040 if(enemy.position.y > SCALED_HEIGHT)
1041 enemy.position.y = 0;
1042 else if(enemy.position.y < 0)
1043 enemy.position.y = SCALED_HEIGHT;
1044
1045 if((rb->rand()%1000) < 10)
1046 enemy.position.dy = -enemy.position.dy;
1036 } 1047 }
1037
1038 if(enemy.position.x > SCALED_WIDTH || enemy.position.x < 0)
1039 enemy_on_screen = false;
1040
1041 if(enemy.position.y > SCALED_HEIGHT)
1042 enemy.position.y = 0;
1043 else if(enemy.position.y < 0)
1044 enemy.position.y = SCALED_HEIGHT;
1045
1046 if( (rb->rand()%1000) < 10)
1047 enemy.position.dy = -enemy.position.dy;
1048 } 1048 }
1049 else 1049 else
1050 { 1050 {
1051
1052 /* animate_and_draw_explosion(enemy.vertices, NUM_ENEMY_VERTICES, 1051 /* animate_and_draw_explosion(enemy.vertices, NUM_ENEMY_VERTICES,
1053 enemy_x, enemy.position.y/SCALE); */ 1052 enemy_x, enemy.position.y/SCALE); */
1054 if(game_state != PAUSE_MODE) 1053 if(game_state != PAUSE_MODE)
1055 { 1054 {
1056 enemy.explode_countdown--; 1055 enemy.explode_countdown--;
1057 if(!enemy.explode_countdown) 1056 if(!enemy.explode_countdown)
1058 enemy_on_screen = false; 1057 enemy.exists = false;
1059 } 1058 }
1060 } 1059 }
1061 } 1060 }
1062 else 1061 else
1063 { 1062 {
1064 if( (*rb->current_tick - enemy.last_time_appeared) > enemy.appear_timing) 1063 if (TIME_AFTER(*rb->current_tick,
1065 if(rb->rand()%100 > enemy.appear_probability) initialise_enemy(); 1064 enemy.last_time_appeared+enemy.appear_timing))
1065 {
1066 if(rb->rand()%100 >= enemy.appear_probability)
1067 initialise_enemy();
1068 }
1066 } 1069 }
1067 1070
1068 if(!enemy_missile.survived && game_state != GAME_OVER) 1071 if(!enemy_missile.survived)
1069 { 1072 {
1070 /*if no missile and the enemy is here and not exploding..then shoot baby!*/ 1073 /*if no missile and the enemy is here and not exploding..then shoot baby!*/
1071 if( !enemy.explode_countdown && enemy_on_screen && 1074 if( !enemy.explode_countdown && enemy.exists &&
1072 !ship.waiting_for_space && (rb->rand()%10) > 5 ) 1075 !ship.waiting_for_space && game_state == PLAY_MODE &&
1076 (rb->rand()%10) >= 5 )
1073 { 1077 {
1074 enemy_missile.position.x = enemy.position.x; 1078 enemy_missile.position.x = enemy.position.x;
1075 enemy_missile.position.y = enemy.position.y; 1079 enemy_missile.position.y = enemy.position.y;
1076 1080
1077 /*lame, needs to be sorted - it's trying to shoot at the ship*/ 1081 /*lame, needs to be sorted - it's trying to shoot at the ship*/
1078 if(ABS(enemy.position.y - ship.position.y) <= 5*SCALE) 1082 if(ABS(enemy.position.y - ship.position.y) <= 5*SCALE)
1079 {
1080 enemy_missile.position.dy = 0; 1083 enemy_missile.position.dy = 0;
1081 } 1084 else if( enemy.position.y < ship.position.y)
1085 enemy_missile.position.dy = 1;
1082 else 1086 else
1083 { 1087 enemy_missile.position.dy = -1;
1084 if( enemy.position.y < ship.position.y) 1088
1085 enemy_missile.position.dy = 1;
1086 else
1087 enemy_missile.position.dy = -1;
1088 }
1089
1090 if(ABS(enemy.position.x - ship.position.x) <= 5*SCALE) 1089 if(ABS(enemy.position.x - ship.position.x) <= 5*SCALE)
1091 enemy_missile.position.dx = 0; 1090 enemy_missile.position.dx = 0;
1091 else if( enemy.position.x < ship.position.x)
1092 enemy_missile.position.dx = 1;
1092 else 1093 else
1093 { 1094 enemy_missile.position.dx = -1;
1094 if( enemy.position.x < ship.position.x) 1095
1095 enemy_missile.position.dx = 1; 1096 while(enemy_missile.position.dx == 0 &&
1096 else 1097 enemy_missile.position.dy == 0)
1097 enemy_missile.position.dx = -1; 1098 {
1099 enemy_missile.position.dx = rb->rand()%2-1;
1100 enemy_missile.position.dy = rb->rand()%2-1;
1098 } 1101 }
1099 1102
1100 if(enemy_missile.position.dx == 0 &&
1101 enemy_missile.position.dy == 0)
1102 enemy_missile.position.dx = enemy_missile.position.dy = -1;
1103
1104 enemy_missile.position.dx *= SCALE; 1103 enemy_missile.position.dx *= SCALE;
1105 enemy_missile.position.dy *= SCALE; 1104 enemy_missile.position.dy *= SCALE;
1106 enemy_missile.survived = ENEMY_MISSILE_SURVIVAL_LENGTH; 1105 enemy_missile.survived = ENEMY_MISSILE_SURVIVAL_LENGTH;
1107
1108 } 1106 }
1109 } 1107 }
1110 else 1108 else
1111 { 1109 {
1112 rb->lcd_fillrect( enemy_missile.position.x/SCALE, 1110 rb->lcd_fillrect( enemy_missile.position.x/SCALE,
1113 enemy_missile.position.y/SCALE, 1111 enemy_missile.position.y/SCALE,
1114 POINT_SIZE, POINT_SIZE); 1112 POINT_SIZE, POINT_SIZE );
1115 if(game_state != PAUSE_MODE) 1113 if(game_state != PAUSE_MODE)
1116 { 1114 {
1117 move_point(&enemy_missile.position); 1115 move_point(&enemy_missile.position);
@@ -1120,49 +1118,51 @@ void draw_and_move_enemy(void)
1120 } 1118 }
1121} 1119}
1122 1120
1123/****************** 1121void add_score(int val)
1124* Lame method of collision 1122{
1125* detection. It's checking for collision 1123 current_score += val;
1126* between point and a big rectangle around the asteroid... 1124 if(current_score >= extra_life)
1127*******************/ 1125 {
1126 num_lives++;
1127 extra_life += EXTRA_LIFE;
1128 }
1129}
1130
1128bool is_point_within_asteroid(struct Asteroid* asteroid, struct Point* point) 1131bool is_point_within_asteroid(struct Asteroid* asteroid, struct Point* point)
1129{ 1132{
1130 if( !is_point_within_rectangle(&asteroid->position, point, 1133 if(!is_point_within_rectangle(&asteroid->position, point, asteroid->radius))
1131 asteroid->radius+4*SCALE) )
1132 return false; 1134 return false;
1133 1135
1134 if(point_in_poly(asteroid->vertices, NUM_ASTEROID_VERTICES, 1136 if(point_in_poly(asteroid->vertices, NUM_ASTEROID_VERTICES,
1135 point->x - asteroid->position.x, 1137 point->x - asteroid->position.x,
1136 point->y - asteroid->position.y)) 1138 point->y - asteroid->position.y))
1137 { 1139 {
1140 struct Point p;
1141 p.dx = asteroid->position.dx;
1142 p.dy = asteroid->position.dy;
1143 p.x = asteroid->position.x;
1144 p.y = asteroid->position.y;
1145
1146 asteroid_count--;
1147 asteroid->exists = false;
1148
1138 switch(asteroid->type) 1149 switch(asteroid->type)
1139 {
1140 case(SMALL):
1141 asteroid->explode_countdown = EXPLOSION_LENGTH;
1142 create_trail_blaze(ASTEROID_EXPLOSION_COLOUR, &asteroid->position);
1143 break;
1144
1145 case(LARGE):
1146 create_asteroid(MEDIUM, asteroid->position.x,
1147 asteroid->position.y);
1148 create_asteroid(MEDIUM, asteroid->position.x,
1149 asteroid->position.y);
1150 break;
1151
1152 case(MEDIUM):
1153 create_asteroid(SMALL, asteroid->position.x, asteroid->position.y);
1154 create_asteroid(SMALL, asteroid->position.x, asteroid->position.y);
1155 break;
1156 }
1157
1158 current_score++;
1159 if(current_score > extra_life)
1160 { 1150 {
1161 num_lives++; 1151 case SMALL:
1162 extra_life = current_score+EXTRA_LIFE; 1152 asteroid->explode_countdown = EXPLOSION_LENGTH;
1153 create_trail_blaze(ASTEROID_EXPLOSION_COLOUR, &p);
1154 break;
1155
1156 case MEDIUM:
1157 create_asteroid(SMALL, p.x, p.y);
1158 create_asteroid(SMALL, p.x, p.y);
1159 break;
1160
1161 case LARGE:
1162 create_asteroid(MEDIUM, p.x, p.y);
1163 create_asteroid(MEDIUM, p.x, p.y);
1164 break;
1163 } 1165 }
1164 asteroid_count--;
1165 asteroid->exists = false;
1166 return true; 1166 return true;
1167 } 1167 }
1168 else 1168 else
@@ -1173,8 +1173,8 @@ bool is_point_within_enemy(struct Point* point)
1173{ 1173{
1174 if( is_point_within_rectangle(&enemy.position, point, 7*SCALE) ) 1174 if( is_point_within_rectangle(&enemy.position, point, 7*SCALE) )
1175 { 1175 {
1176 current_score += 5; 1176 add_score(5);
1177 /*enemy_missile.survived = 0;*/ 1177 /* enemy_missile.survived = 0; */
1178 enemy.explode_countdown = EXPLOSION_LENGTH; 1178 enemy.explode_countdown = EXPLOSION_LENGTH;
1179 /* initialise_explosion(enemy.vertices, NUM_ENEMY_VERTICES); */ 1179 /* initialise_explosion(enemy.vertices, NUM_ENEMY_VERTICES); */
1180 create_trail_blaze(ENEMY_EXPLOSION_COLOUR, &enemy.position); 1180 create_trail_blaze(ENEMY_EXPLOSION_COLOUR, &enemy.position);
@@ -1186,178 +1186,180 @@ bool is_point_within_enemy(struct Point* point)
1186 1186
1187bool is_ship_within_asteroid(struct Asteroid* asteroid) 1187bool is_ship_within_asteroid(struct Asteroid* asteroid)
1188{ 1188{
1189 bool hit = false;
1190 struct Point p; 1189 struct Point p;
1191 1190
1192 p.x = ship.position.x + ship.vertices[0].x; 1191 p.x = ship.position.x + ship.vertices[0].x;
1193 p.y = ship.position.y + ship.vertices[0].y; 1192 p.y = ship.position.y + ship.vertices[0].y;
1194 hit |= is_point_within_asteroid(asteroid, &p); 1193 if(is_point_within_asteroid(asteroid, &p))
1195 1194 return true;
1196 if(!hit) 1195
1197 { 1196 p.x = ship.position.x + ship.vertices[1].x;
1198 p.x = ship.position.x + ship.vertices[1].x; 1197 p.y = ship.position.y + ship.vertices[1].y;
1199 p.y = ship.position.y + ship.vertices[1].y; 1198 if(is_point_within_asteroid(asteroid, &p))
1200 hit |= is_point_within_asteroid(asteroid, &p); 1199 return true;
1201 if(!hit) 1200
1202 { 1201 p.x = ship.position.x + ship.vertices[3].x;
1203 p.x = ship.position.x + ship.vertices[3].x; 1202 p.y = ship.position.y + ship.vertices[3].y;
1204 p.y = ship.position.y + ship.vertices[3].y; 1203 if(is_point_within_asteroid(asteroid, &p))
1205 hit |= is_point_within_asteroid(asteroid, &p); 1204 return true;
1206 } 1205
1207 } 1206 return false;
1208
1209 return hit;
1210} 1207}
1211 1208
1212void initialise_explosion(struct Point* point, int num_points) 1209void initialise_explosion(struct Point* point, int num_points)
1213{ 1210{
1214 int n; 1211 int n;
1215 1212
1216 point->x += point->dx; 1213 point->x += point->dx;
1217 point->y += point->dy; 1214 point->y += point->dy;
1218 for(n = num_points; --n;) 1215 n = num_points;
1216 while(n--)
1219 { 1217 {
1220 point->dx = point->x; 1218 point->dx = point->x;
1221 point->dy = point->y; 1219 point->dy = point->y;
1222 point++; 1220 point++;
1223 } 1221 }
1224
1225} 1222}
1226 1223
1227/* Check for collsions between the missiles and the asteroids and the ship */ 1224/* Check for collsions between the missiles and the asteroids and the ship */
1228void check_collisions(void) 1225void check_collisions(void)
1229{ 1226{
1230 int m, n;
1231 bool asteroids_onscreen = false;
1232 struct Missile* missile; 1227 struct Missile* missile;
1233 struct Asteroid* asteroid; 1228 struct Asteroid* asteroid;
1234 bool ship_cant_be_placed = false; 1229 int m, n;
1235 1230 bool asteroids_onscreen = false;
1231 bool ship_cant_be_placed = false;
1232
1236 asteroid = asteroids_array; 1233 asteroid = asteroids_array;
1237 m = MAX_NUM_ASTEROIDS; 1234 m = MAX_NUM_ASTEROIDS;
1238 while(--m) 1235 while(m--)
1239 { 1236 {
1240 /*if the asteroids exists then test missile collision:*/ 1237 /*if the asteroids exists then test missile collision:*/
1241 if(asteroid->exists) 1238 if (asteroid->exists)
1242 { 1239 {
1243 missile = missiles_array; 1240 missile = missiles_array;
1244 n = MAX_NUM_MISSILES; 1241 n = MAX_NUM_MISSILES;
1245 while(--n) 1242 while(n--)
1246 { 1243 {
1247 /*if the missiles exists:*/ 1244 /*if the missiles exists:*/
1248 if(missile->survived > 0) 1245 if(missile->survived > 0)
1249 { 1246 {
1250 /*has the missile hit the asteroid?*/ 1247 /*has the missile hit the asteroid?*/
1251 if(is_point_within_asteroid(asteroid, &missile->position) 1248 if(is_point_within_asteroid(asteroid, &missile->position) ||
1252 || is_point_within_asteroid(asteroid, 1249 is_point_within_asteroid(asteroid, &missile->oldpoint))
1253 &missile->oldpoint))
1254 { 1250 {
1251 add_score(1);
1255 missile->survived = 0; 1252 missile->survived = 0;
1256 break; 1253 break;
1257 } 1254 }
1258 } 1255 }
1259 missile++; 1256 missile++;
1260 } 1257 }
1261 1258
1262 /*now check collision with ship:*/ 1259 /*now check collision with ship:*/
1263 if(asteroid->exists && !ship.waiting_for_space && !ship.explode_countdown) 1260 if (asteroid->exists && !ship.waiting_for_space && !ship.explode_countdown)
1264 { 1261 {
1265 if(is_ship_within_asteroid(asteroid)) 1262 if (is_ship_within_asteroid(asteroid))
1266 { 1263 {
1267 if (!ship.invulnerable) 1264 add_score(1);
1268 { 1265 if (!ship.invulnerable)
1266 {
1269 /*if not invulnerable, blow up ship*/ 1267 /*if not invulnerable, blow up ship*/
1270 ship.explode_countdown = EXPLOSION_LENGTH; 1268 ship.explode_countdown = EXPLOSION_LENGTH;
1271 /* initialise_explosion(ship.vertices, NUM_SHIP_VERTICES); */ 1269 /* initialise_explosion(ship.vertices, NUM_SHIP_VERTICES); */
1272 create_trail_blaze(SHIP_EXPLOSION_COLOUR, &ship.position); 1270 create_trail_blaze(SHIP_EXPLOSION_COLOUR, &ship.position);
1273 } 1271 }
1274 } 1272 }
1275 1273
1276 /*has the enemy missile blown something up?*/ 1274 /*has the enemy missile blown something up?*/
1277 if(asteroid->exists && enemy_missile.survived) 1275 if (asteroid->exists && enemy_missile.survived)
1278 { 1276 {
1279 if(is_point_within_asteroid(asteroid, &enemy_missile.position)) 1277 if(is_point_within_asteroid(asteroid, &enemy_missile.position))
1280 { 1278 {
1281 /*take that score back then:*/ 1279 enemy_missile.survived = 0;
1282 if(current_score > 0) current_score--; 1280 }
1283 enemy_missile.survived = 0; 1281
1284 } 1282 /*if it still exists, check if ship is waiting for space:*/
1285 1283 if (asteroid->exists && ship.waiting_for_space)
1286 /*if it still exists, check if ship is waiting for space:*/ 1284 {
1287 if(asteroid->exists && ship.waiting_for_space) 1285 ship_cant_be_placed |=
1288 ship_cant_be_placed |= 1286 is_point_within_rectangle(&ship.position,
1289 is_point_within_rectangle(&ship.position, 1287 &asteroid->position,
1290 &asteroid->position, 1288 SPACE_CHECK_SIZE);
1291 space_check_size); 1289 }
1292 } 1290 }
1293 } 1291 }
1294 } 1292 }
1293
1295 /*is an asteroid still exploding?*/ 1294 /*is an asteroid still exploding?*/
1296 if(asteroid->explode_countdown) 1295 if (asteroid->explode_countdown)
1297 asteroids_onscreen = true; 1296 asteroids_onscreen = true;
1298 1297
1299 asteroid++; 1298 asteroid++;
1300 } 1299 }
1301 1300
1302 /*now check collision between ship and enemy*/ 1301 /*now check collision between ship and enemy*/
1303 if(enemy_on_screen && !ship.waiting_for_space && 1302 if(enemy.exists && !enemy.explode_countdown &&
1304 !ship.explode_countdown && !enemy.explode_countdown) 1303 !ship.waiting_for_space && !ship.explode_countdown)
1305 { 1304 {
1306 /*has the enemy collided with the ship?*/ 1305 /*has the enemy collided with the ship?*/
1307 if(is_point_within_enemy(&ship.position)) 1306 if(is_point_within_enemy(&ship.position))
1308 { 1307 {
1309 if (!ship.invulnerable) 1308 if (!ship.invulnerable)
1310 { 1309 {
1311 ship.explode_countdown = EXPLOSION_LENGTH; 1310 ship.explode_countdown = EXPLOSION_LENGTH;
1312 /* initialise_explosion(ship.vertices, NUM_SHIP_VERTICES); */ 1311 /* initialise_explosion(ship.vertices, NUM_SHIP_VERTICES); */
1313 create_trail_blaze(SHIP_EXPLOSION_COLOUR, &ship.position); 1312 create_trail_blaze(SHIP_EXPLOSION_COLOUR, &ship.position);
1314 } 1313 }
1315 create_trail_blaze(ENEMY_EXPLOSION_COLOUR, &enemy.position); 1314 create_trail_blaze(ENEMY_EXPLOSION_COLOUR, &enemy.position);
1316 } 1315 }
1317 1316
1318 /*Now see if the enemy has been shot at by the ships missiles:*/ 1317 if (enemy.exists && !enemy.explode_countdown)
1319 missile = missiles_array;
1320 n = MAX_NUM_MISSILES;
1321 while(--n)
1322 { 1318 {
1323 if(missile->survived > 0 && 1319 /*Now see if the enemy has been shot at by the ships missiles:*/
1324 is_point_within_enemy(&missile->position)) 1320 missile = missiles_array;
1321 n = MAX_NUM_MISSILES;
1322 while(n--)
1325 { 1323 {
1326 missile->survived = 0; 1324 if (missile->survived > 0 &&
1327 break; 1325 is_point_within_enemy(&missile->position))
1326 {
1327 missile->survived = 0;
1328 break;
1329 }
1330 missile++;
1328 } 1331 }
1329 missile++;
1330 } 1332 }
1331 } 1333 }
1332 1334
1333 /*test collision with enemy missile and ship:*/ 1335 /*test collision with enemy missile and ship:*/
1334 if(!ship_cant_be_placed && enemy_missile.survived > 0 && 1336 if (!ship_cant_be_placed && enemy_missile.survived > 0 &&
1335 point_in_poly(ship.vertices, NUM_SHIP_VERTICES, 1337 point_in_poly(ship.vertices, NUM_SHIP_VERTICES,
1336 enemy_missile.position.x - ship.position.x, 1338 enemy_missile.position.x - ship.position.x,
1337 enemy_missile.position.y - ship.position.y)) 1339 enemy_missile.position.y - ship.position.y))
1338 { 1340 {
1339 if (!ship.invulnerable) 1341 if (!ship.invulnerable)
1340 { 1342 {
1341 ship.explode_countdown = EXPLOSION_LENGTH; 1343 ship.explode_countdown = EXPLOSION_LENGTH;
1342 /* initialise_explosion(ship.vertices, NUM_SHIP_VERTICES); */ 1344 /* initialise_explosion(ship.vertices, NUM_SHIP_VERTICES); */
1343 create_trail_blaze(SHIP_EXPLOSION_COLOUR, &ship.position); 1345 create_trail_blaze(SHIP_EXPLOSION_COLOUR, &ship.position);
1344 } 1346 }
1345 enemy_missile.survived = 0; 1347 enemy_missile.survived = 0;
1346 enemy_missile.position.x = enemy_missile.position.y = 0; 1348 enemy_missile.position.x = enemy_missile.position.y = 0;
1347 } 1349 }
1348 1350
1349 if(!ship_cant_be_placed) 1351 if(!ship_cant_be_placed)
1350 ship.waiting_for_space = false; 1352 ship.waiting_for_space = false;
1351 1353
1352 /*if all asteroids cleared then start again:*/ 1354 /*if all asteroids cleared then start again:*/
1353 if(asteroid_count == 0 && !enemy_on_screen && !asteroids_onscreen) 1355 if(asteroid_count == 0 && !enemy.exists && !asteroids_onscreen)
1354 { 1356 {
1355 current_level++; 1357 current_level++;
1356 game_state = SHOW_LEVEL; 1358 game_state = SHOW_LEVEL;
1357 enemy.appear_probability += 5; 1359 enemy.appear_probability += 5;
1358 enemy.appear_timing -= 200; 1360 enemy.appear_timing -= 200;
1359 if( enemy.appear_probability > 100) 1361 if (enemy.appear_probability >= 100)
1360 enemy.appear_probability = ENEMY_APPEAR_PROBABILITY_START; 1362 enemy.appear_probability = ENEMY_APPEAR_PROBABILITY_START;
1361 show_level_timeout = SHOW_LEVEL_TIME; 1363 show_level_timeout = SHOW_LEVEL_TIME;
1362 } 1364 }
1363} 1365}
@@ -1370,10 +1372,10 @@ void create_asteroid(enum asteroid_type type, int x, int y)
1370{ 1372{
1371 struct Asteroid* asteroid; 1373 struct Asteroid* asteroid;
1372 int n; 1374 int n;
1373 1375
1374 asteroid = asteroids_array; 1376 asteroid = asteroids_array;
1375 n = MAX_NUM_ASTEROIDS; 1377 n = MAX_NUM_ASTEROIDS;
1376 while(--n) 1378 while(n--)
1377 { 1379 {
1378 if(!asteroid->exists && !asteroid->explode_countdown) 1380 if(!asteroid->exists && !asteroid->explode_countdown)
1379 { 1381 {
@@ -1382,7 +1384,7 @@ void create_asteroid(enum asteroid_type type, int x, int y)
1382 asteroid->position.y = y; 1384 asteroid->position.y = y;
1383 break; 1385 break;
1384 } 1386 }
1385 asteroid++; 1387 asteroid++;
1386 } 1388 }
1387} 1389}
1388 1390
@@ -1394,83 +1396,32 @@ void initialise_missile(struct Missile* missile)
1394 missile->position.dx = (ship.vertices[0].x - ship.vertices[2].x)/2; 1396 missile->position.dx = (ship.vertices[0].x - ship.vertices[2].x)/2;
1395 missile->position.dy = (ship.vertices[0].y - ship.vertices[2].y)/2; 1397 missile->position.dy = (ship.vertices[0].y - ship.vertices[2].y)/2;
1396 missile->survived = MISSILE_SURVIVAL_LENGTH; 1398 missile->survived = MISSILE_SURVIVAL_LENGTH;
1397 missile->oldpoint.x = missile->position.x; 1399 missile->oldpoint.x = missile->position.x;
1398 missile->oldpoint.y = missile->position.y; 1400 missile->oldpoint.y = missile->position.y;
1399} 1401}
1400 1402
1401/* Draw and Move all the missiles */ 1403/* Draw and Move all the missiles */
1402void draw_and_move_missiles(void) 1404void draw_and_move_missiles(void)
1403{ 1405{
1404 int n;
1405 int p1x, p1y;
1406 int p2x, p2y;
1407
1408 struct Missile* missile; 1406 struct Missile* missile;
1409 missile = missiles_array; 1407 struct Point vertices[2];
1408 int n;
1410 1409
1411 SET_FG(COL_MISSILE); 1410 SET_FG(COL_MISSILE);
1412 1411
1412 missile = missiles_array;
1413 n = MAX_NUM_MISSILES; 1413 n = MAX_NUM_MISSILES;
1414 while(--n) 1414 while(n--)
1415 { 1415 {
1416 if(missile->survived) 1416 if(missile->survived)
1417 { 1417 {
1418 if(missile->position.dx > 0) 1418 vertices[0].x = 0;
1419 { 1419 vertices[0].y = 0;
1420 if(missile->position.x >= missile->oldpoint.x) 1420 vertices[1].x = -missile->position.dx;
1421 { 1421 vertices[1].y = -missile->position.dy;
1422 p1x = missile->oldpoint.x; 1422 draw_polygon(vertices, missile->position.x/SCALE,
1423 p2x = missile->position.x; 1423 missile->position.y/SCALE, 2);
1424 } 1424
1425 else
1426 {
1427 p1x = 0;
1428 p2x = missile->position.x;
1429 }
1430 }
1431 else
1432 {
1433 if(missile->oldpoint.x >= missile->position.x)
1434 {
1435 p1x = missile->oldpoint.x;
1436 p2x = missile->position.x;
1437 }
1438 else
1439 {
1440 p1x = missile->oldpoint.x;
1441 p2x = LCD_WIDTH;
1442 }
1443 }
1444
1445 if(missile->position.dy > 0)
1446 {
1447 if(missile->position.y >= missile->oldpoint.y)
1448 {
1449 p1y = missile->oldpoint.y;
1450 p2y = missile->position.y;
1451 }
1452 else
1453 {
1454 p1y = 0;
1455 p2y = missile->position.y;
1456 }
1457 }
1458 else
1459 {
1460 if(missile->oldpoint.y >= missile->position.y)
1461 {
1462 p1y = missile->oldpoint.y;
1463 p2y = missile->position.y;
1464 }
1465 else
1466 {
1467 p1y = missile->oldpoint.y;
1468 p2y = LCD_HEIGHT;
1469 }
1470 }
1471
1472 rb->lcd_drawline( p1x/SCALE, p1y/SCALE, p2x/SCALE, p2y/SCALE);
1473
1474 if(game_state != PAUSE_MODE) 1425 if(game_state != PAUSE_MODE)
1475 { 1426 {
1476 missile->oldpoint.x = missile->position.x; 1427 missile->oldpoint.x = missile->position.x;
@@ -1486,42 +1437,43 @@ void draw_and_move_missiles(void)
1486void draw_lives(void) 1437void draw_lives(void)
1487{ 1438{
1488 int n; 1439 int n;
1489 int px = (LCD_WIDTH - num_lives*4 - 1); 1440#if (LARGE_LCD)
1490 #if(LARGE_LCD) 1441 int px = (LCD_WIDTH-1 - 4);
1491 int py = (LCD_HEIGHT-6); 1442 int py = (LCD_HEIGHT-1 - 6);
1492 #else 1443#else
1493 int py = (LCD_HEIGHT-4); 1444 int px = (LCD_WIDTH-1 - 3);
1494 #endif 1445 int py = (LCD_HEIGHT-1 - 4);
1495 1446#endif
1447
1496 SET_FG(COL_PLAYER); 1448 SET_FG(COL_PLAYER);
1497 1449
1498 n = num_lives; 1450 n = num_lives-1;
1499 while(--n) 1451 while(n--)
1500 { 1452 {
1501 draw_polygon(lives_points, px, py, NUM_SHIP_VERTICES); 1453 draw_polygon(lives_points, px, py, NUM_SHIP_VERTICES);
1502 #if(LARGE_LCD) 1454#if (LARGE_LCD)
1503 px += 8; 1455 px -= 8;
1504 #else 1456#else
1505 px += 6; 1457 px -= 6;
1506 #endif 1458#endif
1507 } 1459 }
1508} 1460}
1509 1461
1510/*Fire the next missile*/ 1462/*Fire the next missile*/
1511void fire_missile(void) 1463void fire_missile(void)
1512{ 1464{
1513 int n;
1514 struct Missile* missile; 1465 struct Missile* missile;
1515 1466 int n;
1516 if(!ship.explode_countdown && !ship.waiting_for_space) 1467
1468 if (!ship.explode_countdown && !ship.waiting_for_space)
1517 { 1469 {
1518 missile = missiles_array; 1470 missile = missiles_array;
1519 n = MAX_NUM_MISSILES; 1471 n = MAX_NUM_MISSILES;
1520 while(--n) 1472 while(n--)
1521 { 1473 {
1522 if(!missile->survived) 1474 if(!missile->survived)
1523 { 1475 {
1524 initialise_missile(missile); 1476 initialise_missile(missile);
1525 break; 1477 break;
1526 } 1478 }
1527 missile++; 1479 missile++;
@@ -1532,28 +1484,30 @@ void fire_missile(void)
1532/* Initialise the passed Asteroid */ 1484/* Initialise the passed Asteroid */
1533void initialise_asteroid(struct Asteroid* asteroid, enum asteroid_type type) 1485void initialise_asteroid(struct Asteroid* asteroid, enum asteroid_type type)
1534{ 1486{
1535 int n; 1487 const short *asteroid_vertices;
1536 bool b,b2;
1537 struct Point* point; 1488 struct Point* point;
1489 int n;
1490
1538 asteroid->exists = true; 1491 asteroid->exists = true;
1539 asteroid->type = type; 1492 asteroid->type = type;
1540 asteroid->explode_countdown = 0; 1493 asteroid->explode_countdown = 0;
1541 1494
1542 /*Set the radius of the asteroid:*/ 1495 /*Set the radius of the asteroid:*/
1543 asteroid->radius = (int)type*SCALE; 1496 asteroid->radius = (int)type*SCALE*3;
1544 1497
1545 /*shall we move Clockwise and Fast*/ 1498 /*shall we move Clockwise and Fast*/
1546 if((rb->rand()%100)>75) 1499 n = rb->rand()%100;
1500 if(n < 25)
1547 { 1501 {
1548 asteroid->speed_cos = FAST_ROT_CW_COS; 1502 asteroid->speed_cos = FAST_ROT_CW_COS;
1549 asteroid->speed_sin = FAST_ROT_CW_SIN; 1503 asteroid->speed_sin = FAST_ROT_CW_SIN;
1550 } 1504 }
1551 else if((rb->rand()%100)>75) 1505 else if(n < 50)
1552 { 1506 {
1553 asteroid->speed_cos = FAST_ROT_ACW_COS; 1507 asteroid->speed_cos = FAST_ROT_ACW_COS;
1554 asteroid->speed_sin = FAST_ROT_ACW_SIN; 1508 asteroid->speed_sin = FAST_ROT_ACW_SIN;
1555 } 1509 }
1556 else if((rb->rand()%100)>75) 1510 else if(n < 75)
1557 { 1511 {
1558 asteroid->speed_cos = SLOW_ROT_ACW_COS; 1512 asteroid->speed_cos = SLOW_ROT_ACW_COS;
1559 asteroid->speed_sin = SLOW_ROT_ACW_SIN; 1513 asteroid->speed_sin = SLOW_ROT_ACW_SIN;
@@ -1563,65 +1517,48 @@ void initialise_asteroid(struct Asteroid* asteroid, enum asteroid_type type)
1563 asteroid->speed_cos = SLOW_ROT_CW_COS; 1517 asteroid->speed_cos = SLOW_ROT_CW_COS;
1564 asteroid->speed_sin = SLOW_ROT_CW_SIN; 1518 asteroid->speed_sin = SLOW_ROT_CW_SIN;
1565 } 1519 }
1566 1520
1567 b = (rb->rand()%100)>66; 1521 n = rb->rand()%99;
1568 b2 = (rb->rand()%100)>66; 1522 if (n < 33)
1523 asteroid_vertices = asteroid_one;
1524 else if (n < 66)
1525 asteroid_vertices = asteroid_two;
1526 else
1527 asteroid_vertices = asteroid_three;
1528
1569 point = asteroid->vertices; 1529 point = asteroid->vertices;
1570 for(n = 0; n < NUM_ASTEROID_VERTICES*2; n+=2) 1530 for(n = 0; n < NUM_ASTEROID_VERTICES*2; n += 2)
1571 { 1531 {
1572 if(b) 1532 point->x = asteroid_vertices[n];
1573 { 1533 point->y = asteroid_vertices[n+1];
1574 point->x = asteroid_one[n]; 1534 point->x *= asteroid->radius/20;
1575 point->y = asteroid_one[n+1]; 1535 point->y *= asteroid->radius/20;
1576 }
1577 else if( b2 )
1578 {
1579 point->x = asteroid_two[n];
1580 point->y = asteroid_two[n+1];
1581 }
1582 else
1583 {
1584 point->x = asteroid_three[n];
1585 point->y = asteroid_three[n+1];
1586 }
1587
1588 point->x *= asteroid->radius/6;
1589 point->y *= asteroid->radius/6;
1590 point++; 1536 point++;
1591 } 1537 }
1592 1538
1593 1539 do
1594 asteroid->radius += 6*SCALE;
1595 if(asteroid->type == SMALL)
1596 asteroid->radius /= 3;/*2*/
1597 else if(asteroid->type == LARGE)
1598 asteroid->radius += 3*SCALE;/*2*/
1599 b = true;
1600 while(b)
1601 { 1540 {
1602 /*Set the position randomly:*/ 1541 /*Set the position randomly:*/
1603 asteroid->position.x = (rb->rand()%SCALED_WIDTH); 1542 asteroid->position.x = (rb->rand()%SCALED_WIDTH);
1604 asteroid->position.y = (rb->rand()%SCALED_HEIGHT); 1543 asteroid->position.y = (rb->rand()%SCALED_HEIGHT);
1605 1544 } while (is_point_within_rectangle(&ship.position, &asteroid->position,
1606 asteroid->position.dx = 0; 1545 SPACE_CHECK_SIZE));
1607 while(asteroid->position.dx == 0) 1546
1608 asteroid->position.dx = (rb->rand()%ASTEROID_SPEED)-ASTEROID_SPEED/2; 1547 do {
1609 1548 asteroid->position.dx = (rb->rand()%ASTEROID_SPEED)-ASTEROID_SPEED/2;
1610 asteroid->position.dy = 0; 1549 } while (asteroid->position.dx == 0);
1611 while(asteroid->position.dy == 0) 1550
1612 asteroid->position.dy = (rb->rand()%ASTEROID_SPEED)-ASTEROID_SPEED/2; 1551 do {
1613 1552 asteroid->position.dy = (rb->rand()%ASTEROID_SPEED)-ASTEROID_SPEED/2;
1614 asteroid->position.dx *= SCALE/10; 1553 } while (asteroid->position.dy == 0);
1615 asteroid->position.dy *= SCALE/10; 1554
1616 1555 asteroid->position.dx *= SCALE/10;
1617 b = is_point_within_rectangle(&ship.position, &asteroid->position, 1556 asteroid->position.dy *= SCALE/10;
1618 space_check_size); 1557
1619 }
1620
1621 /*Now rotate the asteroid a bit, so they all look a bit different*/ 1558 /*Now rotate the asteroid a bit, so they all look a bit different*/
1622 for(n=(rb->rand()%30) + 2;--n;) 1559 for(n = (rb->rand()%30)+2; n--; )
1623 rotate_asteroid(asteroid); 1560 rotate_asteroid(asteroid);
1624 1561
1625 /*great, we've created an asteroid, don't forget to increment the total:*/ 1562 /*great, we've created an asteroid, don't forget to increment the total:*/
1626 asteroid_count++; 1563 asteroid_count++;
1627} 1564}
@@ -1632,40 +1569,29 @@ void initialise_ship(void)
1632 struct Point* point; 1569 struct Point* point;
1633 struct Point* lives_point; 1570 struct Point* lives_point;
1634 int n; 1571 int n;
1635 1572
1636 ship.position.x = CENTER_LCD_X; 1573 ship.position.x = CENTER_LCD_X * SCALE;
1637 ship.position.y = CENTER_LCD_Y; 1574 ship.position.y = CENTER_LCD_Y * SCALE;
1638 ship.position.x *= SCALE; 1575 ship.position.dx = 0;
1639 ship.position.y *= SCALE; 1576 ship.position.dy = 0;
1640 ship.position.dx = ship.position.dy = 0; 1577 ship.explode_countdown = 0;
1641 ship.spawn_time = SPAWN_TIME; 1578 ship.spawn_time = SPAWN_TIME;
1642 ship.invulnerable = 1; 1579 ship.invulnerable = 1;
1643 1580
1644 point = ship.vertices; 1581 point = ship.vertices;
1645 lives_point = lives_points; 1582 lives_point = lives_points;
1646 for(n = 0; n < NUM_SHIP_VERTICES*2; n+=2) 1583 for(n = 0; n < NUM_SHIP_VERTICES*2; n += 2)
1647 { 1584 {
1648 point->x = ship_vertices[n]; 1585 point->x = ship_vertices[n];
1649 point->y = ship_vertices[n+1]; 1586 point->y = ship_vertices[n+1];
1650 point->x *= SCALE; 1587 point->x *= SCALE;
1651 point->y *= SCALE; 1588 point->y *= SCALE;
1652 point++; 1589 /*grab a copy of the ships points for the lives display:*/
1653 lives_point++; 1590 lives_point->x = point->x;
1654 }
1655
1656 ship.position.dx = 0;
1657 ship.position.dy = 0;
1658 ship.explode_countdown = 0;
1659
1660 /*grab a copy of the ships points for the lives display:*/
1661 point = ship.vertices;
1662 lives_point = lives_points;
1663 for(n = 0; n < NUM_SHIP_VERTICES*2; n+=2)
1664 {
1665 lives_point->x = point->x;
1666 lives_point->y = point->y; 1591 lives_point->y = point->y;
1667 lives_point++; 1592
1668 point++; 1593 point++;
1594 lives_point++;
1669 } 1595 }
1670} 1596}
1671 1597
@@ -1688,46 +1614,47 @@ void rotate_asteroid(struct Asteroid* asteroid)
1688} 1614}
1689 1615
1690/************************************************* 1616/*************************************************
1691** Draws the ship, moves the ship and creates a new 1617** Draws the ship, moves the ship and creates a new
1692** one if it's finished exploding. 1618** one if it's finished exploding.
1693**************************************************/ 1619**************************************************/
1694void draw_and_move_ship(void) 1620void draw_and_move_ship(void)
1695{ 1621{
1696 int nxoffset = ship.position.x/SCALE; 1622 if (ship.invulnerable &&
1697 int nyoffset = ship.position.y/SCALE; 1623 (ship.spawn_time > BLINK_TIME || ship.spawn_time % 2 == 0))
1698 if (ship.invulnerable && (ship.spawn_time > BLINK_TIME || ship.spawn_time % 2 == 0))
1699 { 1624 {
1700 SET_FG(COL_INVULN); 1625 SET_FG(COL_INVULN);
1701 } 1626 }
1702 else 1627 else
1703 { 1628 {
1704 SET_FG(COL_PLAYER); 1629 SET_FG(COL_PLAYER);
1705 } 1630 }
1631
1706 if(!ship.explode_countdown) 1632 if(!ship.explode_countdown)
1707 { 1633 {
1708 /* make sure ship is invulnerable until spawn time over */ 1634 /* make sure ship is invulnerable until spawn time over */
1709 if (ship.spawn_time) 1635 if (ship.spawn_time)
1710 { 1636 {
1711 ship.spawn_time--; 1637 ship.spawn_time--;
1712 if (ship.spawn_time <= 0) 1638 if (ship.spawn_time <= 0)
1713 { 1639 {
1714 ship.invulnerable = 0; 1640 ship.invulnerable = 0;
1715 } 1641 }
1716 } 1642 }
1717 if(!ship.waiting_for_space) 1643 if(!ship.waiting_for_space)
1718 { 1644 {
1719 draw_polygon(ship.vertices, nxoffset, nyoffset, NUM_SHIP_VERTICES); 1645 draw_polygon(ship.vertices, ship.position.x/SCALE,
1720 if(game_state != PAUSE_MODE && game_state != GAME_OVER) 1646 ship.position.y/SCALE, NUM_SHIP_VERTICES);
1721 { 1647 if(game_state != PAUSE_MODE && game_state != GAME_OVER)
1722 move_point(&ship.position); 1648 {
1723 } 1649 move_point(&ship.position);
1650 }
1724 } 1651 }
1725 } 1652 }
1726 else 1653 else
1727 { 1654 {
1728 /* animate_and_draw_explosion(ship.vertices, NUM_SHIP_VERTICES, 1655 /* animate_and_draw_explosion(ship.vertices, NUM_SHIP_VERTICES,
1729 ship.position.x/SCALE, 1656 ship.position.x/SCALE,
1730 ship.position.y/SCALE); */ 1657 ship.position.y/SCALE); */
1731 if(game_state != PAUSE_MODE) 1658 if(game_state != PAUSE_MODE)
1732 { 1659 {
1733 ship.explode_countdown--; 1660 ship.explode_countdown--;
@@ -1754,11 +1681,12 @@ void thrust_ship(void)
1754 { 1681 {
1755 ship.position.dx += ( ship.vertices[0].x - ship.vertices[2].x )/20; 1682 ship.position.dx += ( ship.vertices[0].x - ship.vertices[2].x )/20;
1756 ship.position.dy += ( ship.vertices[0].y - ship.vertices[2].y )/20; 1683 ship.position.dy += ( ship.vertices[0].y - ship.vertices[2].y )/20;
1684
1757 /*if dx and dy are below a certain threshold, then set 'em to 0 1685 /*if dx and dy are below a certain threshold, then set 'em to 0
1758 but to do this we need to ascertain if the spacehip as moved on screen 1686 but to do this we need to ascertain if the spacehip as moved on screen
1759 for more than a certain amount. */ 1687 for more than a certain amount. */
1760 1688
1761 create_trail_blaze(THRUST_COLOUR, &ship.position); 1689 create_trail_blaze(THRUST_COLOUR, &ship.position);
1762 } 1690 }
1763} 1691}
1764 1692
@@ -1769,7 +1697,7 @@ void rotate_ship(int c, int s)
1769{ 1697{
1770 struct Point* point; 1698 struct Point* point;
1771 int n; 1699 int n;
1772 double xtemp; 1700 long xtemp;
1773 1701
1774 if(!ship.waiting_for_space && !ship.explode_countdown) 1702 if(!ship.waiting_for_space && !ship.explode_countdown)
1775 { 1703 {
@@ -1787,12 +1715,13 @@ void rotate_ship(int c, int s)
1787void drawstars() 1715void drawstars()
1788{ 1716{
1789 struct Point* p; 1717 struct Point* p;
1790 int n = NUM_STARS; 1718 int n;
1791 1719
1792 p = stars;
1793 SET_FG(COL_STARS); 1720 SET_FG(COL_STARS);
1794 1721
1795 while(--n) 1722 p = stars;
1723 n = NUM_STARS;
1724 while(n--)
1796 { 1725 {
1797 rb->lcd_drawpixel(p->x , p->y); 1726 rb->lcd_drawpixel(p->x , p->y);
1798 p++; 1727 p++;
@@ -1804,14 +1733,14 @@ void drawstars()
1804*************************************************/ 1733*************************************************/
1805void draw_and_move_asteroids(void) 1734void draw_and_move_asteroids(void)
1806{ 1735{
1807 int n;
1808 struct Asteroid* asteroid; 1736 struct Asteroid* asteroid;
1809 1737 int n;
1810 asteroid = asteroids_array; 1738
1811 SET_FG(COL_ASTEROID); 1739 SET_FG(COL_ASTEROID);
1812 1740
1741 asteroid = asteroids_array;
1813 n = MAX_NUM_ASTEROIDS; 1742 n = MAX_NUM_ASTEROIDS;
1814 while(--n) 1743 while(n--)
1815 { 1744 {
1816 if(game_state != PAUSE_MODE) 1745 if(game_state != PAUSE_MODE)
1817 { 1746 {
@@ -1820,92 +1749,85 @@ void draw_and_move_asteroids(void)
1820 move_point(&asteroid->position); 1749 move_point(&asteroid->position);
1821 rotate_asteroid(asteroid); 1750 rotate_asteroid(asteroid);
1822 draw_polygon(asteroid->vertices, asteroid->position.x/SCALE, 1751 draw_polygon(asteroid->vertices, asteroid->position.x/SCALE,
1823 asteroid->position.y/SCALE, 1752 asteroid->position.y/SCALE, NUM_ASTEROID_VERTICES);
1824 NUM_ASTEROID_VERTICES);
1825 } 1753 }
1826 else if(asteroid->explode_countdown) 1754 else if(asteroid->explode_countdown)
1827 { 1755 {
1828 /* animate_and_draw_explosion(asteroid->vertices, 1756 /* animate_and_draw_explosion(asteroid->vertices,
1829 NUM_ASTEROID_VERTICES, 1757 NUM_ASTEROID_VERTICES,
1830 asteroid->position.x/SCALE, 1758 asteroid->position.x/SCALE,
1831 asteroid->position.y/SCALE); */ 1759 asteroid->position.y/SCALE); */
1832 asteroid->explode_countdown--; 1760 asteroid->explode_countdown--;
1833 } 1761 }
1834 } 1762 }
1835 else 1763 else
1836 { 1764 {
1837 if(asteroid->exists) 1765 if(asteroid->exists)
1838 draw_polygon(asteroid->vertices, 1766 draw_polygon(asteroid->vertices, asteroid->position.x/SCALE,
1839 asteroid->position.x/SCALE, 1767 asteroid->position.y/SCALE, NUM_ASTEROID_VERTICES);
1840 asteroid->position.y/SCALE,
1841 NUM_ASTEROID_VERTICES);
1842 } 1768 }
1843 asteroid++; 1769 asteroid++;
1844 } 1770 }
1845} 1771}
1846 1772
1847void create_stars(void) 1773void create_stars(void)
1848{ 1774{
1849 struct TrailPoint* tpoint; 1775 struct TrailPoint* tpoint;
1850 struct Point* p; 1776 struct Point* p;
1851 int n; 1777 int n;
1852 1778
1853 p = stars; 1779 p = stars;
1854 n = NUM_STARS; 1780 n = NUM_STARS;
1855 while(--n) 1781 while(n--)
1856 { 1782 {
1857 p->x = (rb->rand()%LCD_WIDTH); 1783 p->x = (rb->rand()%LCD_WIDTH);
1858 p->y = (rb->rand()%LCD_HEIGHT); 1784 p->y = (rb->rand()%LCD_HEIGHT);
1859 p++; 1785 p++;
1860 } 1786 }
1861 1787
1862 1788 tpoint = trail_points;
1863 /* give the point a random countdown timer, so they dissapears at different 1789 n = NUM_TRAIL_POINTS;
1864 times */ 1790 while(--n)
1865 tpoint = trailPoints; 1791 {
1866 n = NUM_TRAIL_POINTS; 1792 tpoint->alive = 0;
1867 while(--n) 1793 tpoint++;
1868 { 1794 }
1869 tpoint->alive = 0;
1870 tpoint++;
1871 }
1872} 1795}
1873 1796
1874/************************************************* 1797/*************************************************
1875** Creates start_num number of new asteroids of 1798** Creates start_num number of new asteroids of
1876** full size. 1799** full size.
1877**************************************************/ 1800**************************************************/
1878void initialise_game(int start_num) 1801void initialise_game(int start_num)
1879{ 1802{
1803 struct Asteroid* asteroid;
1804 struct Missile* missile;
1880 int n; 1805 int n;
1881 asteroid_count = next_missile_count = next_thrust_count = 0; 1806 asteroid_count = next_missile_count = next_thrust_count = 0;
1882 struct Asteroid* asteroid;
1883 struct Missile* missile;
1884 extra_life = EXTRA_LIFE;
1885 1807
1886 /*no enemy*/ 1808 /*no enemy*/
1887 enemy_on_screen = 0; 1809 enemy.exists = 0;
1888 enemy_missile.survived = 0; 1810 enemy_missile.survived = 0;
1889 1811
1890 /*clear asteroids*/ 1812 /*clear asteroids*/
1891 asteroid = asteroids_array; 1813 asteroid = asteroids_array;
1892 n = MAX_NUM_ASTEROIDS; 1814 n = MAX_NUM_ASTEROIDS;
1893 while(--n) 1815 while(n--)
1894 { 1816 {
1895 asteroid->exists = false; 1817 asteroid->exists = false;
1896 asteroid++; 1818 asteroid++;
1897 } 1819 }
1898 1820
1899 /*make some LARGE asteroids*/ 1821 /*make some LARGE asteroids*/
1900 for(n = 0; n < start_num; n++) 1822 for(n = 0; n < start_num; n++)
1901 initialise_asteroid(&asteroids_array[n], LARGE); 1823 initialise_asteroid(&asteroids_array[n], LARGE);
1902 1824
1903 /*ensure all missiles are out of action: */ 1825 /*ensure all missiles are out of action: */
1904 missile = missiles_array; 1826 missile = missiles_array;
1905 n = MAX_NUM_MISSILES; 1827 n = MAX_NUM_MISSILES;
1906 while(--n) 1828 while(--n)
1907 { 1829 {
1908 missile->survived=0; 1830 missile->survived = 0;
1909 missile++; 1831 missile++;
1910 } 1832 }
1911} 1833}
@@ -1920,7 +1842,7 @@ static int spacerocks_game_loop(void)
1920 1842
1921 /*create stars once, and once only:*/ 1843 /*create stars once, and once only:*/
1922 create_stars(); 1844 create_stars();
1923 1845
1924 if (spacerocks_menu(false)!=0) 1846 if (spacerocks_menu(false)!=0)
1925 return 0; 1847 return 0;
1926 1848
@@ -1931,131 +1853,138 @@ static int spacerocks_game_loop(void)
1931 end = *rb->current_tick + (CYCLETIME * HZ) / 1000; 1853 end = *rb->current_tick + (CYCLETIME * HZ) / 1000;
1932 rb->lcd_clear_display(); 1854 rb->lcd_clear_display();
1933 SET_FG(COL_TEXT); 1855 SET_FG(COL_TEXT);
1934 switch(game_state) { 1856 switch(game_state)
1935 case(GAME_OVER): 1857 {
1936 rb->splash (HZ * 2, "Game Over"); 1858 case GAME_OVER:
1937 rb->lcd_clear_display(); 1859 rb->splash (HZ * 2, "Game Over");
1938 position=highscore_update(current_score, current_level, "", 1860 rb->lcd_clear_display();
1939 highest,NUM_SCORES); 1861 position = highscore_update(current_score, current_level, "",
1940 if (position == 0) 1862 highscores, NUM_SCORES);
1941 rb->splash(HZ*2, "New High Score"); 1863 if (position != -1)
1942 if (position != -1) 1864 {
1943 highscore_show(position, highest, NUM_SCORES, true); 1865 if (position == 0)
1944 if (spacerocks_menu(false)!=0) 1866 rb->splash(HZ*2, "New High Score");
1945 return 0; 1867 highscore_show(position, highscores, NUM_SCORES, true);
1946 break; 1868 }
1947 1869 if (spacerocks_menu(false)!=0)
1948 case(PAUSE_MODE): 1870 return 0;
1949 rb->snprintf(s, sizeof(s), "score %d ", current_score); 1871 break;
1950 rb->lcd_putsxy(1,LCD_HEIGHT-8, s);
1951 rb->lcd_putsxy(CENTER_LCD_X - 15,
1952 CENTER_LCD_Y + CENTER_LCD_Y/2 - 4, "pause");
1953 draw_and_move_missiles();
1954 draw_lives();
1955 draw_and_move_ship();
1956 break;
1957
1958 case(PLAY_MODE):
1959 rb->snprintf(s, sizeof(s), "score %d ", current_score);
1960 rb->lcd_putsxy(1,LCD_HEIGHT-8, s);
1961 draw_and_move_missiles();
1962 draw_lives();
1963 check_collisions();
1964 draw_and_move_ship();
1965 break;
1966 1872
1967 case(SHOW_LEVEL): 1873 case PAUSE_MODE:
1968 show_level_timeout--; 1874 rb->snprintf(s, sizeof(s), "score %d ", current_score);
1969 rb->snprintf(s, sizeof(s), "score %d ", current_score); 1875 rb->lcd_putsxy(1,LCD_HEIGHT-8, s);
1970 rb->lcd_putsxy(1,LCD_HEIGHT-8, s); 1876 rb->lcd_putsxy(CENTER_LCD_X - 15,
1971 rb->snprintf(level, sizeof(level), "stage %d ", current_level); 1877 CENTER_LCD_Y + CENTER_LCD_Y/2 - 4, "pause");
1972 rb->lcd_putsxy(CENTER_LCD_X - 20, 1878 draw_and_move_missiles();
1973 CENTER_LCD_Y + CENTER_LCD_Y/2 - 4, level);
1974 draw_and_move_ship();
1975 draw_lives();
1976 if(!show_level_timeout) {
1977 initialise_game(current_level);
1978 game_state = PLAY_MODE;
1979 draw_lives(); 1879 draw_lives();
1980 } 1880 draw_and_move_ship();
1981 break; 1881 break;
1882
1883 case PLAY_MODE:
1884 rb->snprintf(s, sizeof(s), "score %d ", current_score);
1885 rb->lcd_putsxy(1,LCD_HEIGHT-8, s);
1886 draw_and_move_missiles();
1887 draw_lives();
1888 check_collisions();
1889 draw_and_move_ship();
1890 break;
1891
1892 case SHOW_LEVEL:
1893 rb->snprintf(s, sizeof(s), "score %d ", current_score);
1894 rb->lcd_putsxy(1,LCD_HEIGHT-8, s);
1895 rb->snprintf(level, sizeof(level), "stage %d ", current_level);
1896 rb->lcd_putsxy(CENTER_LCD_X - 20,
1897 CENTER_LCD_Y + CENTER_LCD_Y/2 - 4, level);
1898 draw_and_move_ship();
1899 draw_lives();
1900 show_level_timeout--;
1901 if(!show_level_timeout)
1902 {
1903 initialise_game(current_level);
1904 game_state = PLAY_MODE;
1905 draw_lives();
1906 }
1907 break;
1982 } 1908 }
1983 draw_trail_blaze(); 1909 draw_trail_blaze();
1984 drawstars(); 1910 drawstars();
1985 draw_and_move_asteroids(); 1911 draw_and_move_asteroids();
1986 draw_and_move_enemy(); 1912 draw_and_move_enemy();
1987 1913
1988 rb->lcd_update(); 1914 rb->lcd_update();
1989
1990#ifdef HAS_BUTTON_HOLD
1991 if (rb->button_hold())
1992 game_state = PAUSE_MODE;
1993 1915
1916#ifdef HAS_BUTTON_HOLD
1917 if (rb->button_hold() && game_state == PLAY_MODE)
1918 game_state = PAUSE_MODE;
1994#endif 1919#endif
1995 button = rb->button_get(false); 1920 button = rb->button_get(false);
1996 switch(button) { 1921 switch(button)
1922 {
1997 case(AST_QUIT): 1923 case(AST_QUIT):
1998 if (spacerocks_menu(true)!=0) 1924 if (spacerocks_menu(true)!=0)
1999 return 0; 1925 return 0;
2000 break; 1926 break;
2001#ifdef AST_PAUSE 1927#ifdef AST_PAUSE
2002 case(AST_PAUSE): 1928 case(AST_PAUSE):
2003 if (game_state == PAUSE_MODE) { 1929 if (game_state == PAUSE_MODE)
2004 game_state = PLAY_MODE; 1930 game_state = PLAY_MODE;
2005 break; 1931 else if (game_state == PLAY_MODE)
2006 } 1932 game_state = PAUSE_MODE;
2007 else if (game_state != PLAY_MODE) 1933 break;
2008 break; 1934#endif
2009#endif
2010 case (AST_LEFT): 1935 case (AST_LEFT):
2011 case (AST_LEFT | BUTTON_REPEAT): 1936 case (AST_LEFT | BUTTON_REPEAT):
2012 if(game_state == PLAY_MODE || game_state == SHOW_LEVEL) 1937 if(game_state == PLAY_MODE || game_state == SHOW_LEVEL)
2013 rotate_ship(SHIP_ROT_ACW_COS, SHIP_ROT_ACW_SIN); 1938 rotate_ship(SHIP_ROT_ACW_COS, SHIP_ROT_ACW_SIN);
2014 break; 1939 break;
2015 1940
2016 case (AST_RIGHT): 1941 case (AST_RIGHT):
2017 case (AST_RIGHT | BUTTON_REPEAT): 1942 case (AST_RIGHT | BUTTON_REPEAT):
2018 if(game_state == PLAY_MODE || game_state == SHOW_LEVEL) 1943 if(game_state == PLAY_MODE || game_state == SHOW_LEVEL)
2019 rotate_ship(SHIP_ROT_CW_COS, SHIP_ROT_CW_SIN); 1944 rotate_ship(SHIP_ROT_CW_COS, SHIP_ROT_CW_SIN);
2020 break; 1945 break;
2021 1946
2022 case (AST_THRUST): 1947 case (AST_THRUST):
2023 case (AST_THRUST | BUTTON_REPEAT): 1948 case (AST_THRUST | BUTTON_REPEAT):
2024 if((game_state == PLAY_MODE || game_state == SHOW_LEVEL) && 1949 if(game_state == PLAY_MODE || game_state == SHOW_LEVEL)
2025 !next_thrust_count) { 1950 {
2026 thrust_ship(); 1951 if (!next_thrust_count)
2027 next_thrust_count = 5; 1952 {
1953 next_thrust_count = 5;
1954 thrust_ship();
1955 }
2028 } 1956 }
2029 break; 1957 break;
2030 1958
2031 case (AST_HYPERSPACE): 1959 case (AST_HYPERSPACE):
2032 if(game_state == PLAY_MODE) 1960 if(game_state == PLAY_MODE)
2033 hyperspace(); 1961 hyperspace();
2034 /*maybe shield if it gets too hard */ 1962 /*maybe shield if it gets too hard */
2035 break; 1963 break;
2036 1964
2037 case (AST_FIRE): 1965 case (AST_FIRE):
2038 case (AST_FIRE | BUTTON_REPEAT): 1966 case (AST_FIRE | BUTTON_REPEAT):
2039 if(game_state == PLAY_MODE) { 1967 if(game_state == PLAY_MODE)
2040 if(!next_missile_count) { 1968 {
1969 if(!next_missile_count)
1970 {
2041 fire_missile(); 1971 fire_missile();
2042 next_missile_count = 10; 1972 next_missile_count = 10;
2043 } 1973 }
2044 } 1974 }
2045 else if(game_state == PAUSE_MODE) { 1975 else if(game_state == PAUSE_MODE)
2046 game_state = PLAY_MODE; 1976 game_state = PLAY_MODE;
2047 }
2048 break; 1977 break;
2049 1978
2050 default: 1979 default:
2051 if (rb->default_event_handler(button)==SYS_USB_CONNECTED) 1980 if (rb->default_event_handler(button)==SYS_USB_CONNECTED)
2052 return PLUGIN_USB_CONNECTED; 1981 return PLUGIN_USB_CONNECTED;
2053 break; 1982 break;
2054 } 1983 }
2055 1984
2056 if(next_missile_count) 1985 if(next_missile_count)
2057 next_missile_count--; 1986 next_missile_count--;
2058 1987
2059 if(next_thrust_count) 1988 if(next_thrust_count)
2060 next_thrust_count--; 1989 next_thrust_count--;
2061 1990
@@ -2069,7 +1998,7 @@ static int spacerocks_game_loop(void)
2069enum plugin_status plugin_start(const void* parameter) 1998enum plugin_status plugin_start(const void* parameter)
2070{ 1999{
2071 (void)parameter; 2000 (void)parameter;
2072 2001
2073#if LCD_DEPTH > 1 2002#if LCD_DEPTH > 1
2074 rb->lcd_set_backdrop(NULL); 2003 rb->lcd_set_backdrop(NULL);
2075#endif 2004#endif
@@ -2077,10 +2006,12 @@ enum plugin_status plugin_start(const void* parameter)
2077 rb->lcd_setfont(FONT_SYSFIXED); 2006 rb->lcd_setfont(FONT_SYSFIXED);
2078 /* Turn off backlight timeout */ 2007 /* Turn off backlight timeout */
2079 backlight_force_on(); /* backlight control in lib/helper.c */ 2008 backlight_force_on(); /* backlight control in lib/helper.c */
2080 highscore_load(HIGH_SCORE,highest,NUM_SCORES); 2009 highscore_load(HIGH_SCORE, highscores, NUM_SCORES);
2010
2081 spacerocks_game_loop(); 2011 spacerocks_game_loop();
2012
2082 rb->lcd_setfont(FONT_UI); 2013 rb->lcd_setfont(FONT_UI);
2083 highscore_save(HIGH_SCORE,highest,NUM_SCORES); 2014 highscore_save(HIGH_SCORE, highscores, NUM_SCORES);
2084 /* Turn on backlight timeout (revert to settings) */ 2015 /* Turn on backlight timeout (revert to settings) */
2085 backlight_use_settings(); /* backlight control in lib/helper.c */ 2016 backlight_use_settings(); /* backlight control in lib/helper.c */
2086 2017