diff options
author | Ben Basha <benbasha@rockbox.org> | 2006-03-17 13:38:45 +0000 |
---|---|---|
committer | Ben Basha <benbasha@rockbox.org> | 2006-03-17 13:38:45 +0000 |
commit | cee9568611c0744e5ac4754f6f6d73fd0b53b3a2 (patch) | |
tree | ac8df2303c6e0663421c778762021a022e5567a6 /apps | |
parent | 4092029b3b616b09e483db1d1eb5e3566b518d9d (diff) | |
download | rockbox-cee9568611c0744e5ac4754f6f6d73fd0b53b3a2.tar.gz rockbox-cee9568611c0744e5ac4754f6f6d73fd0b53b3a2.zip |
*patch by Mikael Magnusson, do not reinitialize the board when hit by a qix. *some code cleanup by me
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9076 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/xobox.c | 89 |
1 files changed, 46 insertions, 43 deletions
diff --git a/apps/plugins/xobox.c b/apps/plugins/xobox.c index 2093ab1eab..2b1321631f 100644 --- a/apps/plugins/xobox.c +++ b/apps/plugins/xobox.c | |||
@@ -165,11 +165,7 @@ static struct pos | |||
165 | } stack[STACK_SIZE]; | 165 | } stack[STACK_SIZE]; |
166 | static int stackPointer; | 166 | static int stackPointer; |
167 | 167 | ||
168 | /* div function (divide two numbers and truncate the answer) */ | 168 | #define div(a,b) (((a)/(b))) |
169 | static inline int div (int a, int b) | ||
170 | { | ||
171 | return (a/b); | ||
172 | } | ||
173 | 169 | ||
174 | static bool pop (struct pos *p) | 170 | static bool pop (struct pos *p) |
175 | { | 171 | { |
@@ -353,7 +349,7 @@ static inline int infested_area (int i, int j) | |||
353 | init_testboard (); | 349 | init_testboard (); |
354 | if (!push (&p)) | 350 | if (!push (&p)) |
355 | return -1; | 351 | return -1; |
356 | while ((pop (&p)) && (!hit)) { | 352 | while (pop (&p)) { |
357 | hit = (boardcopy[p.y][p.x] == QIX); | 353 | hit = (boardcopy[p.y][p.x] == QIX); |
358 | testboard[p.y][p.x] = CHECKED; | 354 | testboard[p.y][p.x] = CHECKED; |
359 | if (hit) | 355 | if (hit) |
@@ -436,34 +432,39 @@ static inline int fill_area (int i, int j) | |||
436 | 432 | ||
437 | 433 | ||
438 | /* take care of stuff after xonix has landed on a filled spot */ | 434 | /* take care of stuff after xonix has landed on a filled spot */ |
439 | static void complete_trail (void) | 435 | static void complete_trail (int fill) |
440 | { | 436 | { |
441 | int i, j, ret; | 437 | int i, j, ret; |
442 | for (j = 0; j < BOARD_H; j++) | 438 | for (j = 0; j < BOARD_H; j++) |
443 | for (i = 0; i < BOARD_W; i++) | 439 | for (i = 0; i < BOARD_W; i++) { |
444 | if (board[j][i] == TRAIL) | 440 | if (board[j][i] == TRAIL) { |
445 | board[j][i] = FILLED; | 441 | if (fill) |
446 | 442 | board[j][i] = FILLED; | |
447 | for (j = 0; j < BOARD_H; j++) | 443 | else |
448 | for (i = 0; i < BOARD_W; i++) | 444 | board[j][i] = EMPTIED; |
445 | } | ||
449 | boardcopy[j][i] = board[j][i]; | 446 | boardcopy[j][i] = board[j][i]; |
450 | for (i = 0; i < player.level + STARTING_QIXES; i++) /* add qixes to board */ | 447 | } |
451 | boardcopy[div (qixes[i].y - BOARD_Y, CUBE_SIZE)][div | 448 | |
452 | (qixes[i].x - BOARD_X, | 449 | if (fill) { |
453 | CUBE_SIZE)] = QIX; | 450 | for (i = 0; i < player.level + STARTING_QIXES; i++) /* add qixes to board */ |
454 | 451 | boardcopy[div (qixes[i].y - BOARD_Y, CUBE_SIZE)][div | |
455 | for (j = 1; j < BOARD_H - 1; j++) | 452 | (qixes[i].x - BOARD_X, |
456 | for (i = 0; i < BOARD_W - 0; i++) | 453 | CUBE_SIZE)] = QIX; |
457 | if (board[j][i] != FILLED) { | 454 | |
458 | ret = infested_area (i, j); | 455 | for (j = 1; j < BOARD_H - 1; j++) |
459 | if (ret < 0) | 456 | for (i = 0; i < BOARD_W - 0; i++) |
460 | quit = true; | 457 | if (board[j][i] != FILLED) { |
461 | else if (ret == 0) { | 458 | ret = infested_area (i, j); |
462 | ret = fill_area (i, j); | ||
463 | if (ret < 0) | 459 | if (ret < 0) |
464 | quit = true; | 460 | quit = true; |
461 | else if (ret == 0) { | ||
462 | ret = fill_area (i, j); | ||
463 | if (ret < 0) | ||
464 | quit = true; | ||
465 | } | ||
465 | } | 466 | } |
466 | } | 467 | } |
467 | } | 468 | } |
468 | 469 | ||
469 | /* returns the color the real pixel(x,y) on the lcd is pointing at */ | 470 | /* returns the color the real pixel(x,y) on the lcd is pointing at */ |
@@ -525,6 +526,22 @@ static bool line_check (int newx, int newy, int side) | |||
525 | return filled; | 526 | return filled; |
526 | } | 527 | } |
527 | 528 | ||
529 | static void die (void) | ||
530 | { | ||
531 | player.lives--; | ||
532 | if (player.lives == 0) | ||
533 | player.gameover = true; | ||
534 | else { | ||
535 | refresh_board (); | ||
536 | rb->splash (HZ, true, "Crash!"); | ||
537 | complete_trail (false); | ||
538 | player.move = MOVE_NO; | ||
539 | player.drawing = false; | ||
540 | player.i = BOARD_W / 2; | ||
541 | player.j = 1; | ||
542 | } | ||
543 | } | ||
544 | |||
528 | static void move_qix (struct qix *q) | 545 | static void move_qix (struct qix *q) |
529 | { | 546 | { |
530 | int newx, newy, dir; | 547 | int newx, newy, dir; |
@@ -585,18 +602,8 @@ static void move_qix (struct qix *q) | |||
585 | } | 602 | } |
586 | q->x = newx; | 603 | q->x = newx; |
587 | q->y = newy; | 604 | q->y = newy; |
588 | refresh_board (); | ||
589 | newx = get_newx (newx, q->velocity, q->angle); | ||
590 | newy = get_newy (newy, q->velocity, q->angle); | ||
591 | q->x = newx; | ||
592 | q->y = newy; | ||
593 | } else if (nexthit == TRAIL) { | 605 | } else if (nexthit == TRAIL) { |
594 | player.lives--; | 606 | die(); |
595 | if (player.lives == 0) | ||
596 | player.gameover = true; | ||
597 | refresh_board (); | ||
598 | rb->splash (HZ, true, "Crash!"); | ||
599 | init_board (); | ||
600 | } | 607 | } |
601 | } | 608 | } |
602 | 609 | ||
@@ -637,7 +644,7 @@ static inline void move_board (void) | |||
637 | else if ((player.drawing) && (board[newj][newi] == FILLED)) { /* finish drawing */ | 644 | else if ((player.drawing) && (board[newj][newi] == FILLED)) { /* finish drawing */ |
638 | player.move = MOVE_NO; /* stop moving */ | 645 | player.move = MOVE_NO; /* stop moving */ |
639 | player.drawing = false; | 646 | player.drawing = false; |
640 | complete_trail (); | 647 | complete_trail (true); |
641 | } else if ((board[player.j][player.i] == FILLED) | 648 | } else if ((board[player.j][player.i] == FILLED) |
642 | && (board[newj][newi] == EMPTIED)) { | 649 | && (board[newj][newi] == EMPTIED)) { |
643 | /* start drawing */ | 650 | /* start drawing */ |
@@ -656,8 +663,6 @@ static inline void move_board (void) | |||
656 | init_board (); | 663 | init_board (); |
657 | refresh_board (); | 664 | refresh_board (); |
658 | rb->splash (HZ * 2, true, "READY?"); | 665 | rb->splash (HZ * 2, true, "READY?"); |
659 | rb->lcd_update (); | ||
660 | refresh_board (); | ||
661 | } | 666 | } |
662 | } | 667 | } |
663 | 668 | ||
@@ -719,8 +724,6 @@ static void init_game (void) | |||
719 | init_board (); | 724 | init_board (); |
720 | refresh_board (); | 725 | refresh_board (); |
721 | rb->splash (HZ * 2, true, "READY?"); | 726 | rb->splash (HZ * 2, true, "READY?"); |
722 | rb->lcd_update (); | ||
723 | refresh_board (); | ||
724 | } | 727 | } |
725 | 728 | ||
726 | /* general keypad handler loop */ | 729 | /* general keypad handler loop */ |