diff options
author | Teruaki Kawashima <teru@rockbox.org> | 2009-12-12 14:05:03 +0000 |
---|---|---|
committer | Teruaki Kawashima <teru@rockbox.org> | 2009-12-12 14:05:03 +0000 |
commit | cfc50ec747b7c7cde60be4c03fdc824043208e26 (patch) | |
tree | 223efec6660db3465b718c88e86a58cf05d5c8bd | |
parent | ca6dfdc3fe49e0718e5380920e6696fc98ba2760 (diff) | |
download | rockbox-cfc50ec747b7c7cde60be4c03fdc824043208e26.tar.gz rockbox-cfc50ec747b7c7cde60be4c03fdc824043208e26.zip |
spacerocks: Fix FS#9380: spacerocks shows funny rocks.
Initialize seed for rand() at the beginning of plugin.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23944 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/plugins/spacerocks.c | 98 |
1 files changed, 59 insertions, 39 deletions
diff --git a/apps/plugins/spacerocks.c b/apps/plugins/spacerocks.c index bbba9bfd48..636aeddde7 100644 --- a/apps/plugins/spacerocks.c +++ b/apps/plugins/spacerocks.c | |||
@@ -207,22 +207,18 @@ PLUGIN_HEADER | |||
207 | #define AST_FIRE BUTTON_LEFT | 207 | #define AST_FIRE BUTTON_LEFT |
208 | 208 | ||
209 | #elif (CONFIG_KEYPAD == ONDAVX747_PAD) || \ | 209 | #elif (CONFIG_KEYPAD == ONDAVX747_PAD) || \ |
210 | (CONFIG_KEYPAD == ONDAVX777_PAD) || \ | 210 | (CONFIG_KEYPAD == ONDAVX777_PAD) || \ |
211 | CONFIG_KEYPAD == MROBE500_PAD | 211 | (CONFIG_KEYPAD == MROBE500_PAD) |
212 | #define AST_QUIT BUTTON_POWER | 212 | #define AST_QUIT BUTTON_POWER |
213 | 213 | ||
214 | #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD) | 214 | #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD) |
215 | #define AST_PAUSE BUTTON_FFWD | 215 | #define AST_PAUSE BUTTON_FFWD |
216 | #define AST_QUIT BUTTON_REC | 216 | #define AST_QUIT BUTTON_REC |
217 | #define AST_THRUST_REP (BUTTON_UP | BUTTON_REW) | ||
218 | #define AST_THRUST BUTTON_UP | 217 | #define AST_THRUST BUTTON_UP |
219 | #define AST_HYPERSPACE BUTTON_DOWN | 218 | #define AST_HYPERSPACE BUTTON_DOWN |
220 | #define AST_LEFT BUTTON_LEFT | 219 | #define AST_LEFT BUTTON_LEFT |
221 | #define AST_LEFT_REP (BUTTON_LEFT | BUTTON_REW) | ||
222 | #define AST_RIGHT BUTTON_RIGHT | 220 | #define AST_RIGHT BUTTON_RIGHT |
223 | #define AST_RIGHT_REP (BUTTON_RIGHT | BUTTON_REW) | ||
224 | #define AST_FIRE BUTTON_PLAY | 221 | #define AST_FIRE BUTTON_PLAY |
225 | #define AST_FIRE_REP (BUTTON_PLAY | BUTTON_REW) | ||
226 | 222 | ||
227 | #else | 223 | #else |
228 | #error No keymap defined! | 224 | #error No keymap defined! |
@@ -235,9 +231,6 @@ CONFIG_KEYPAD == MROBE500_PAD | |||
235 | #ifndef AST_QUIT | 231 | #ifndef AST_QUIT |
236 | #define AST_QUIT BUTTON_TOPLEFT | 232 | #define AST_QUIT BUTTON_TOPLEFT |
237 | #endif | 233 | #endif |
238 | #ifndef AST_THRUST_REP | ||
239 | #define AST_THRUST_REP (BUTTON_TOPMIDDLE | BUTTON_REPEAT) | ||
240 | #endif | ||
241 | #ifndef AST_THRUST | 234 | #ifndef AST_THRUST |
242 | #define AST_THRUST BUTTON_TOPMIDDLE | 235 | #define AST_THRUST BUTTON_TOPMIDDLE |
243 | #endif | 236 | #endif |
@@ -247,27 +240,12 @@ CONFIG_KEYPAD == MROBE500_PAD | |||
247 | #ifndef AST_LEFT | 240 | #ifndef AST_LEFT |
248 | #define AST_LEFT BUTTON_MIDLEFT | 241 | #define AST_LEFT BUTTON_MIDLEFT |
249 | #endif | 242 | #endif |
250 | #ifndef AST_LEFT_REP | ||
251 | #define AST_LEFT_REP (BUTTON_MIDLEFT | BUTTON_REPEAT) | ||
252 | #endif | ||
253 | #ifndef AST_RIGHT | 243 | #ifndef AST_RIGHT |
254 | #define AST_RIGHT BUTTON_MIDRIGHT | 244 | #define AST_RIGHT BUTTON_MIDRIGHT |
255 | #endif | 245 | #endif |
256 | #ifndef AST_RIGHT_REP | ||
257 | #define AST_RIGHT_REP (BUTTON_MIDRIGHT | BUTTON_REPEAT) | ||
258 | #endif | ||
259 | #ifndef AST_FIRE | 246 | #ifndef AST_FIRE |
260 | #define AST_FIRE BUTTON_BOTTOMMIDDLE | 247 | #define AST_FIRE BUTTON_BOTTOMMIDDLE |
261 | #endif | 248 | #endif |
262 | #ifndef AST_FIRE_REP | ||
263 | |||
264 | #ifdef BUTTON_MENU | ||
265 | #define AST_FIRE_REP (BUTTON_BOTTOMMIDDLE | BUTTON_MENU) | ||
266 | #else | ||
267 | #define AST_FIRE_REP BUTTON_BOTTOMMIDDLE | BUTTON_REPEAT | ||
268 | #endif | ||
269 | |||
270 | #endif | ||
271 | #endif | 249 | #endif |
272 | 250 | ||
273 | #define RES MAX(LCD_WIDTH, LCD_HEIGHT) | 251 | #define RES MAX(LCD_WIDTH, LCD_HEIGHT) |
@@ -527,6 +505,7 @@ struct TrailPoint | |||
527 | struct Asteroid | 505 | struct Asteroid |
528 | { | 506 | { |
529 | struct Point position; | 507 | struct Point position; |
508 | struct Point rotation; | ||
530 | struct Point vertices[NUM_ASTEROID_VERTICES]; | 509 | struct Point vertices[NUM_ASTEROID_VERTICES]; |
531 | bool exists; | 510 | bool exists; |
532 | int explode_countdown; | 511 | int explode_countdown; |
@@ -539,6 +518,7 @@ struct Asteroid | |||
539 | struct Ship | 518 | struct Ship |
540 | { | 519 | { |
541 | struct Point position; | 520 | struct Point position; |
521 | struct Point rotation; | ||
542 | struct Point vertices[NUM_SHIP_VERTICES]; | 522 | struct Point vertices[NUM_SHIP_VERTICES]; |
543 | bool exists; | 523 | bool exists; |
544 | int explode_countdown; | 524 | int explode_countdown; |
@@ -637,20 +617,39 @@ static bool is_point_within_rectangle(struct Point* rect, struct Point* p, | |||
637 | 617 | ||
638 | /* Rotate polygon */ | 618 | /* Rotate polygon */ |
639 | static void rotate_polygon(struct Point* vertices, int num_vertices, | 619 | static void rotate_polygon(struct Point* vertices, int num_vertices, |
640 | int cos, int sin) | 620 | struct Point* rotation, int cos, int sin) |
641 | { | 621 | { |
642 | struct Point* point; | 622 | struct Point* point; |
643 | int n; | 623 | int n; |
644 | long temp_x, temp_y; | 624 | long temp_x, temp_y; |
645 | 625 | ||
626 | temp_x = rotation->x; | ||
627 | temp_y = rotation->y; | ||
628 | rotation->x = (temp_x*cos - temp_y*sin)/SIN_COS_SCALE; | ||
629 | rotation->y = (temp_y*cos + temp_x*sin)/SIN_COS_SCALE; | ||
630 | #define MIN_SCALE (SIN_COS_SCALE-10) | ||
631 | #define MAX_SCALE (SIN_COS_SCALE+10) | ||
632 | /* normalize vector. this is not accurate but would be enough. */ | ||
633 | temp_x = rotation->x*rotation->x + rotation->y*rotation->y; | ||
634 | if (temp_x <= MIN_SCALE*MIN_SCALE) | ||
635 | { | ||
636 | rotation->x = rotation->x*SIN_COS_SCALE/MIN_SCALE; | ||
637 | rotation->y = rotation->y*SIN_COS_SCALE/MIN_SCALE; | ||
638 | } | ||
639 | else if (temp_x >= MAX_SCALE*MAX_SCALE) | ||
640 | { | ||
641 | rotation->x = rotation->x*SIN_COS_SCALE/MAX_SCALE; | ||
642 | rotation->y = rotation->y*SIN_COS_SCALE/MAX_SCALE; | ||
643 | } | ||
644 | #undef MIN_SCALE | ||
645 | #undef MAX_SCALE | ||
646 | |||
646 | point = vertices; | 647 | point = vertices; |
647 | n = num_vertices; | 648 | n = num_vertices; |
648 | while (n--) | 649 | while (n--) |
649 | { | 650 | { |
650 | temp_x = point->x; | 651 | point->x = (point->dx*rotation->x - point->dy*rotation->y)/SIN_COS_SCALE; |
651 | temp_y = point->y; | 652 | point->y = (point->dy*rotation->x + point->dx*rotation->y)/SIN_COS_SCALE; |
652 | point->x = temp_x*cos/SIN_COS_SCALE - temp_y*sin/SIN_COS_SCALE; | ||
653 | point->y = temp_y*cos/SIN_COS_SCALE + temp_x*sin/SIN_COS_SCALE; | ||
654 | point++; | 653 | point++; |
655 | } | 654 | } |
656 | } | 655 | } |
@@ -716,6 +715,8 @@ static void move_point(struct Point* point) | |||
716 | 715 | ||
717 | static void create_ship_trail(struct TrailPoint* tpoint) | 716 | static void create_ship_trail(struct TrailPoint* tpoint) |
718 | { | 717 | { |
718 | tpoint->position.x += ship.vertices[2].x; | ||
719 | tpoint->position.y += ship.vertices[2].y; | ||
719 | tpoint->position.dx = -( ship.vertices[0].x - ship.vertices[2].x )/10; | 720 | tpoint->position.dx = -( ship.vertices[0].x - ship.vertices[2].x )/10; |
720 | tpoint->position.dy = -( ship.vertices[0].y - ship.vertices[2].y )/10; | 721 | tpoint->position.dy = -( ship.vertices[0].y - ship.vertices[2].y )/10; |
721 | } | 722 | } |
@@ -745,13 +746,12 @@ static void create_trail_blaze(int colour, struct Point* position) | |||
745 | times */ | 746 | times */ |
746 | tpoint = trail_points; | 747 | tpoint = trail_points; |
747 | n = NUM_TRAIL_POINTS; | 748 | n = NUM_TRAIL_POINTS; |
748 | while (n-- && numtoadd) | 749 | while (n--) |
749 | { | 750 | { |
750 | /* find a space in the array of trail_points that is NULL or DEAD or | 751 | /* find a space in the array of trail_points that is NULL or DEAD or |
751 | whatever and place this one here. */ | 752 | whatever and place this one here. */ |
752 | if (tpoint->alive <= 0) | 753 | if (tpoint->alive <= 0) |
753 | { | 754 | { |
754 | numtoadd--; | ||
755 | /* take a random point near the position. */ | 755 | /* take a random point near the position. */ |
756 | tpoint->position.x = (rb->rand()%18000)-9000 + position->x; | 756 | tpoint->position.x = (rb->rand()%18000)-9000 + position->x; |
757 | tpoint->position.y = (rb->rand()%18000)-9000 + position->y; | 757 | tpoint->position.y = (rb->rand()%18000)-9000 + position->y; |
@@ -804,6 +804,10 @@ static void create_trail_blaze(int colour, struct Point* position) | |||
804 | - i.e. opposite */ | 804 | - i.e. opposite */ |
805 | tpoint->position.dx += position->dx; | 805 | tpoint->position.dx += position->dx; |
806 | tpoint->position.dy += position->dy; | 806 | tpoint->position.dy += position->dy; |
807 | |||
808 | numtoadd--; | ||
809 | if (numtoadd <= 0) | ||
810 | break; | ||
807 | } | 811 | } |
808 | tpoint++; | 812 | tpoint++; |
809 | } | 813 | } |
@@ -849,6 +853,7 @@ static void draw_and_move_trail_blaze(void) | |||
849 | static void rotate_asteroid(struct Asteroid* asteroid) | 853 | static void rotate_asteroid(struct Asteroid* asteroid) |
850 | { | 854 | { |
851 | rotate_polygon(asteroid->vertices, NUM_ASTEROID_VERTICES, | 855 | rotate_polygon(asteroid->vertices, NUM_ASTEROID_VERTICES, |
856 | &asteroid->rotation, | ||
852 | asteroid->speed_cos, asteroid->speed_sin); | 857 | asteroid->speed_cos, asteroid->speed_sin); |
853 | } | 858 | } |
854 | 859 | ||
@@ -908,6 +913,9 @@ static void initialise_asteroid(struct Asteroid* asteroid, | |||
908 | point->y = asteroid_vertices[n+1]; | 913 | point->y = asteroid_vertices[n+1]; |
909 | point->x *= asteroid->radius/20; | 914 | point->x *= asteroid->radius/20; |
910 | point->y *= asteroid->radius/20; | 915 | point->y *= asteroid->radius/20; |
916 | /* dx and dy are used when rotate polygon */ | ||
917 | point->dx = point->x; | ||
918 | point->dy = point->y; | ||
911 | point++; | 919 | point++; |
912 | } | 920 | } |
913 | 921 | ||
@@ -937,6 +945,9 @@ static void initialise_asteroid(struct Asteroid* asteroid, | |||
937 | asteroid->position.dx *= SCALE/10; | 945 | asteroid->position.dx *= SCALE/10; |
938 | asteroid->position.dy *= SCALE/10; | 946 | asteroid->position.dy *= SCALE/10; |
939 | 947 | ||
948 | asteroid->rotation.x = SIN_COS_SCALE; | ||
949 | asteroid->rotation.y = 0; | ||
950 | |||
940 | /* Now rotate the asteroid a bit, so they all look a bit different */ | 951 | /* Now rotate the asteroid a bit, so they all look a bit different */ |
941 | for(n = (rb->rand()%30)+2; n--; ) | 952 | for(n = (rb->rand()%30)+2; n--; ) |
942 | rotate_asteroid(asteroid); | 953 | rotate_asteroid(asteroid); |
@@ -1044,6 +1055,8 @@ static void initialise_ship(void) | |||
1044 | ship.position.y = CENTER_LCD_Y * SCALE; | 1055 | ship.position.y = CENTER_LCD_Y * SCALE; |
1045 | ship.position.dx = 0; | 1056 | ship.position.dx = 0; |
1046 | ship.position.dy = 0; | 1057 | ship.position.dy = 0; |
1058 | ship.rotation.x = SIN_COS_SCALE; | ||
1059 | ship.rotation.y = 0; | ||
1047 | ship.exists = true; | 1060 | ship.exists = true; |
1048 | ship.explode_countdown = 0; | 1061 | ship.explode_countdown = 0; |
1049 | ship.invulnerable_time = INVULNERABLE_TIME; | 1062 | ship.invulnerable_time = INVULNERABLE_TIME; |
@@ -1056,6 +1069,9 @@ static void initialise_ship(void) | |||
1056 | point->y = ship_vertices[n+1]; | 1069 | point->y = ship_vertices[n+1]; |
1057 | point->x *= SCALE; | 1070 | point->x *= SCALE; |
1058 | point->y *= SCALE; | 1071 | point->y *= SCALE; |
1072 | /* dx and dy are used when rotate polygon */ | ||
1073 | point->dx = point->x; | ||
1074 | point->dy = point->y; | ||
1059 | /* grab a copy of the ships points for the lives display: */ | 1075 | /* grab a copy of the ships points for the lives display: */ |
1060 | lives_point->x = point->x; | 1076 | lives_point->x = point->x; |
1061 | lives_point->y = point->y; | 1077 | lives_point->y = point->y; |
@@ -1100,7 +1116,7 @@ static void draw_and_move_ship(void) | |||
1100 | if (ship.explode_countdown <= 0) | 1116 | if (ship.explode_countdown <= 0) |
1101 | { | 1117 | { |
1102 | num_lives--; | 1118 | num_lives--; |
1103 | if (!num_lives) | 1119 | if (num_lives <= 0) |
1104 | { | 1120 | { |
1105 | game_state = GAME_OVER; | 1121 | game_state = GAME_OVER; |
1106 | } | 1122 | } |
@@ -1129,7 +1145,8 @@ static void rotate_ship(int cos, int sin) | |||
1129 | { | 1145 | { |
1130 | if (ship.exists) | 1146 | if (ship.exists) |
1131 | { | 1147 | { |
1132 | rotate_polygon(ship.vertices, NUM_SHIP_VERTICES, cos, sin); | 1148 | rotate_polygon(ship.vertices, NUM_SHIP_VERTICES, |
1149 | &ship.rotation, cos, sin); | ||
1133 | } | 1150 | } |
1134 | } | 1151 | } |
1135 | 1152 | ||
@@ -1603,6 +1620,8 @@ static void check_collisions(void) | |||
1603 | && !enemy.exists && enemy.explode_countdown <= 0) | 1620 | && !enemy.exists && enemy.explode_countdown <= 0) |
1604 | { | 1621 | { |
1605 | current_level++; | 1622 | current_level++; |
1623 | if (current_level > MAX_LEVEL) | ||
1624 | current_level = START_LEVEL; | ||
1606 | enemy.appear_probability += 5; | 1625 | enemy.appear_probability += 5; |
1607 | if (enemy.appear_probability >= 100) | 1626 | if (enemy.appear_probability >= 100) |
1608 | enemy.appear_probability = ENEMY_APPEAR_PROBABILITY_START; | 1627 | enemy.appear_probability = ENEMY_APPEAR_PROBABILITY_START; |
@@ -1859,7 +1878,7 @@ static int spacerocks_game_loop(void) | |||
1859 | draw_lives(); | 1878 | draw_lives(); |
1860 | draw_and_move_ship(); | 1879 | draw_and_move_ship(); |
1861 | show_level_timeout--; | 1880 | show_level_timeout--; |
1862 | if (!show_level_timeout) | 1881 | if (show_level_timeout <= 0) |
1863 | { | 1882 | { |
1864 | initialise_level(current_level); | 1883 | initialise_level(current_level); |
1865 | game_state = PLAY_MODE; | 1884 | game_state = PLAY_MODE; |
@@ -1907,7 +1926,7 @@ static int spacerocks_game_loop(void) | |||
1907 | case (AST_THRUST | BUTTON_REPEAT): | 1926 | case (AST_THRUST | BUTTON_REPEAT): |
1908 | if (game_state == PLAY_MODE || game_state == SHOW_LEVEL) | 1927 | if (game_state == PLAY_MODE || game_state == SHOW_LEVEL) |
1909 | { | 1928 | { |
1910 | if (!next_thrust_count) | 1929 | if (next_thrust_count <= 0) |
1911 | { | 1930 | { |
1912 | next_thrust_count = 5; | 1931 | next_thrust_count = 5; |
1913 | thrust_ship(); | 1932 | thrust_ship(); |
@@ -1923,9 +1942,9 @@ static int spacerocks_game_loop(void) | |||
1923 | 1942 | ||
1924 | case (AST_FIRE): | 1943 | case (AST_FIRE): |
1925 | case (AST_FIRE | BUTTON_REPEAT): | 1944 | case (AST_FIRE | BUTTON_REPEAT): |
1926 | if(game_state == PLAY_MODE) | 1945 | if (game_state == PLAY_MODE) |
1927 | { | 1946 | { |
1928 | if(!next_missile_count) | 1947 | if (next_missile_count <= 0) |
1929 | { | 1948 | { |
1930 | fire_missile(); | 1949 | fire_missile(); |
1931 | next_missile_count = 10; | 1950 | next_missile_count = 10; |
@@ -1941,10 +1960,10 @@ static int spacerocks_game_loop(void) | |||
1941 | break; | 1960 | break; |
1942 | } | 1961 | } |
1943 | 1962 | ||
1944 | if (next_missile_count) | 1963 | if (next_missile_count > 0) |
1945 | next_missile_count--; | 1964 | next_missile_count--; |
1946 | 1965 | ||
1947 | if (next_thrust_count) | 1966 | if (next_thrust_count > 0) |
1948 | next_thrust_count--; | 1967 | next_thrust_count--; |
1949 | 1968 | ||
1950 | if (TIME_BEFORE(*rb->current_tick, end)) | 1969 | if (TIME_BEFORE(*rb->current_tick, end)) |
@@ -1967,6 +1986,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
1967 | /* Turn off backlight timeout */ | 1986 | /* Turn off backlight timeout */ |
1968 | backlight_force_on(); /* backlight control in lib/helper.c */ | 1987 | backlight_force_on(); /* backlight control in lib/helper.c */ |
1969 | highscore_load(HIGH_SCORE, highscores, NUM_SCORES); | 1988 | highscore_load(HIGH_SCORE, highscores, NUM_SCORES); |
1989 | rb->srand(*rb->current_tick); | ||
1970 | 1990 | ||
1971 | /* create stars once, and once only: */ | 1991 | /* create stars once, and once only: */ |
1972 | create_stars(); | 1992 | create_stars(); |