Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Rework spacerocks: * Use consistent name for variables/field names. * Consistent use of field of structures. * Simplify draw_polygon(). * Add some helper functions.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23916 a1c6a512-1295-4272-9138-f99709370657

+171 -189
+171 -189
apps/plugins/spacerocks.c
··· 277 277 278 278 #define SHOW_COL 0 279 279 #define SCALE 5000 280 - #define WRAP_GAP 12*SCALE 280 + #define WRAP_GAP (LARGE*SCALE*3) 281 281 #define POINT_SIZE 2 282 282 #define START_LEVEL 1 283 283 #define SHOW_LEVEL_TIME 50 ··· 293 293 #define NUM_SHIP_VERTICES 4 294 294 #define NUM_ENEMY_VERTICES 8 295 295 296 - #define SPAWN_TIME 30 296 + #define INVULNERABLE_TIME 30 297 297 #define BLINK_TIME 10 298 298 #define EXTRA_LIFE 250 299 299 #define START_LIVES 3 300 - #define MISSILE_SURVIVAL_LENGTH 40 300 + #define MISSILE_LIFE_LENGTH 40 301 301 302 302 #define ASTEROID_SPEED (RES/20) 303 303 #define SPACE_CHECK_SIZE 30*SCALE 304 304 305 + #if (LARGE_LCD) 306 + #define SIZE_SHIP_COLLISION 8*SCALE 307 + #else 308 + #define SIZE_SHIP_COLLISION 6*SCALE 309 + #endif 310 + 305 311 #define LITTLE_SHIP 1 306 312 #define BIG_SHIP 2 307 313 #define ENEMY_BIG_PROBABILITY_START 10 308 314 #define ENEMY_APPEAR_PROBABILITY_START 35 309 315 #define ENEMY_APPEAR_TIMING_START 600 310 316 #define ENEMY_SPEED 4 311 - #define ENEMY_MISSILE_SURVIVAL_LENGTH (RES/2) 317 + #define ENEMY_MISSILE_LIFE_LENGTH (RES/2) 312 318 #if (LARGE_LCD) 313 319 #define SIZE_ENEMY_COLLISION 7*SCALE 314 320 #else ··· 507 513 508 514 struct TrailPoint 509 515 { 510 - int alive; 511 516 struct Point position; 517 + int alive; 512 518 #ifdef HAVE_LCD_COLOR 513 519 short r; 514 520 short g; ··· 532 538 533 539 struct Ship 534 540 { 535 - struct Point vertices[NUM_SHIP_VERTICES]; 536 541 struct Point position; 537 - bool waiting_for_space; 542 + struct Point vertices[NUM_SHIP_VERTICES]; 543 + bool exists; 538 544 int explode_countdown; 539 - bool invulnerable; 540 - int spawn_time; 545 + int invulnerable_time; 541 546 }; 542 547 543 548 struct Enemy 544 549 { 545 - struct Point vertices[NUM_ENEMY_VERTICES]; 546 550 struct Point position; 551 + struct Point vertices[NUM_ENEMY_VERTICES]; 547 552 bool exists; 548 553 int explode_countdown; 549 554 int appear_countdown; ··· 556 561 { 557 562 struct Point position; 558 563 struct Point oldpoint; 559 - int survived; 564 + int alive; 560 565 }; 561 566 562 567 static enum game_state game_state; ··· 621 626 int dy = p->y - rect->y; 622 627 #if SHOW_COL 623 628 rb->lcd_drawrect((rect->x - size)/SCALE, (rect->y - size)/SCALE, 624 - size*2/SCALE, size*2/SCALE); 629 + (size*2+1)/SCALE, (size*2+1)/SCALE); 625 630 #endif 626 631 if (dx < -SCALED_WIDTH/2) dx += SCALED_WIDTH; 627 632 else if (dx > SCALED_WIDTH/2) dx -= SCALED_WIDTH; ··· 656 661 { 657 662 int n, new_x, new_y, old_x, old_y; 658 663 struct Point *p; 659 - bool bDrawAll = (px < WRAP_GAP || SCALED_WIDTH - px < WRAP_GAP || 660 - py < WRAP_GAP || SCALED_HEIGHT - py < WRAP_GAP); 664 + bool draw_wrap; 665 + 666 + if (px > SCALED_WIDTH - WRAP_GAP) 667 + px -= SCALED_WIDTH; 668 + if (py > SCALED_HEIGHT - WRAP_GAP) 669 + py -= SCALED_HEIGHT; 670 + 671 + draw_wrap = (px < WRAP_GAP || py < WRAP_GAP); 661 672 662 673 p = vertices + num_vertices - 1; 663 674 old_x = (p->x + px)/SCALE; 664 675 old_y = (p->y + py)/SCALE; 665 676 p = vertices; 666 677 n = num_vertices; 667 - while(n--) 678 + while (n--) 668 679 { 669 680 new_x = (p->x + px)/SCALE; 670 681 new_y = (p->y + py)/SCALE; 671 682 672 683 rb->lcd_drawline(old_x, old_y, new_x, new_y); 673 - 674 - if(bDrawAll) 684 + if (draw_wrap) 675 685 { 676 - rb->lcd_drawline(old_x - LCD_WIDTH, old_y, new_x - LCD_WIDTH, new_y); 677 686 rb->lcd_drawline(old_x + LCD_WIDTH, old_y, new_x + LCD_WIDTH, new_y); 678 - rb->lcd_drawline(old_x - LCD_WIDTH, old_y + LCD_HEIGHT, 679 - new_x - LCD_WIDTH, new_y + LCD_HEIGHT); 687 + rb->lcd_drawline(old_x, old_y + LCD_HEIGHT, new_x, new_y + LCD_HEIGHT); 680 688 rb->lcd_drawline(old_x + LCD_WIDTH, old_y + LCD_HEIGHT, 681 689 new_x + LCD_WIDTH, new_y + LCD_HEIGHT); 682 - 683 - rb->lcd_drawline(old_x, old_y - LCD_HEIGHT, new_x, new_y - LCD_HEIGHT); 684 - rb->lcd_drawline(old_x, old_y + LCD_HEIGHT, new_x, new_y + LCD_HEIGHT); 685 - rb->lcd_drawline(old_x - LCD_WIDTH, old_y - LCD_HEIGHT, 686 - new_x - LCD_WIDTH, new_y - LCD_HEIGHT); 687 - rb->lcd_drawline(old_x + LCD_WIDTH, old_y - LCD_HEIGHT, 688 - new_x + LCD_WIDTH, new_y - LCD_HEIGHT); 689 690 } 690 691 old_x = new_x; 691 692 old_y = new_y; ··· 748 749 { 749 750 /* find a space in the array of trail_points that is NULL or DEAD or 750 751 whatever and place this one here. */ 751 - if (!tpoint->alive) 752 + if (tpoint->alive <= 0) 752 753 { 753 754 numtoadd--; 754 755 /* take a random point near the position. */ ··· 821 822 n = NUM_TRAIL_POINTS; 822 823 while (n--) 823 824 { 824 - if (tpoint->alive) 825 + if (tpoint->alive > 0) 825 826 { 826 827 if (game_state != PAUSE_MODE) 827 828 { ··· 863 864 int n; 864 865 865 866 asteroid->exists = true; 866 - asteroid->type = type; 867 867 asteroid->explode_countdown = 0; 868 + asteroid->type = type; 868 869 869 870 /* Set the radius of the asteroid: */ 870 871 asteroid->radius = (int)type*SCALE*3; ··· 956 957 n = MAX_NUM_ASTEROIDS; 957 958 while (n--) 958 959 { 959 - if (!asteroid->exists && !asteroid->explode_countdown) 960 + if (!asteroid->exists && asteroid->explode_countdown <= 0) 960 961 { 961 962 initialise_asteroid(asteroid, type, position); 962 963 break; ··· 977 978 n = MAX_NUM_ASTEROIDS; 978 979 while (n--) 979 980 { 981 + if (asteroid->exists) 982 + { 983 + draw_polygon(asteroid->vertices, NUM_ASTEROID_VERTICES, 984 + asteroid->position.x, asteroid->position.y); 985 + } 980 986 if (game_state != PAUSE_MODE) 981 987 { 982 988 if (asteroid->exists) ··· 984 990 move_point(&asteroid->position); 985 991 rotate_asteroid(asteroid); 986 992 } 987 - else if (asteroid->explode_countdown) 993 + else if (asteroid->explode_countdown > 0) 988 994 { 989 995 asteroid->explode_countdown--; 990 996 } 991 997 } 992 - if (asteroid->exists) 993 - { 994 - draw_polygon(asteroid->vertices, NUM_ASTEROID_VERTICES, 995 - asteroid->position.x, asteroid->position.y); 996 - } 997 998 asteroid++; 998 999 } 999 1000 } 1000 1001 1002 + static void explode_asteroid(struct Asteroid* asteroid) 1003 + { 1004 + struct Point p; 1005 + p.dx = asteroid->position.dx; 1006 + p.dy = asteroid->position.dy; 1007 + p.x = asteroid->position.x; 1008 + p.y = asteroid->position.y; 1009 + 1010 + asteroid_count--; 1011 + asteroid->exists = false; 1012 + 1013 + switch(asteroid->type) 1014 + { 1015 + case SMALL: 1016 + asteroid->explode_countdown = EXPLOSION_LENGTH; 1017 + create_trail_blaze(EXPLOSION_ASTEROID, &p); 1018 + break; 1019 + 1020 + case MEDIUM: 1021 + create_asteroid(SMALL, &p); 1022 + create_asteroid(SMALL, &p); 1023 + break; 1024 + 1025 + case LARGE: 1026 + create_asteroid(MEDIUM, &p); 1027 + create_asteroid(MEDIUM, &p); 1028 + break; 1029 + } 1030 + } 1031 + 1001 1032 /************************************************* 1002 1033 ** Handle ship. 1003 1034 *************************************************/ ··· 1013 1044 ship.position.y = CENTER_LCD_Y * SCALE; 1014 1045 ship.position.dx = 0; 1015 1046 ship.position.dy = 0; 1016 - ship.explode_countdown = 0; 1017 - ship.spawn_time = SPAWN_TIME; 1018 - ship.invulnerable = 1; 1047 + ship.exists = true; 1048 + ship.explode_countdown = 0; 1049 + ship.invulnerable_time = INVULNERABLE_TIME; 1019 1050 1020 1051 point = ship.vertices; 1021 1052 lives_point = lives_points; ··· 1040 1071 */ 1041 1072 static void draw_and_move_ship(void) 1042 1073 { 1043 - if (ship.invulnerable && 1044 - (ship.spawn_time > BLINK_TIME || ship.spawn_time % 2 == 0)) 1074 + if (ship.invulnerable_time > BLINK_TIME || ship.invulnerable_time % 2 != 0) 1045 1075 { 1046 1076 SET_FG(COL_INVULN); 1047 1077 } ··· 1050 1080 SET_FG(COL_PLAYER); 1051 1081 } 1052 1082 1053 - if (!ship.explode_countdown) 1083 + if (ship.exists) 1054 1084 { 1055 - /* make sure ship is invulnerable until spawn time over */ 1056 - if (game_state != PAUSE_MODE) 1057 - { 1058 - if (ship.spawn_time) 1059 - { 1060 - ship.spawn_time--; 1061 - if (ship.spawn_time <= 0) 1062 - { 1063 - ship.invulnerable = 0; 1064 - } 1065 - } 1066 - } 1067 - if (!ship.waiting_for_space) 1068 - { 1069 - draw_polygon(ship.vertices, NUM_SHIP_VERTICES, 1070 - ship.position.x, ship.position.y); 1071 - if (game_state != PAUSE_MODE && game_state != GAME_OVER) 1072 - { 1073 - move_point(&ship.position); 1074 - } 1075 - } 1085 + draw_polygon(ship.vertices, NUM_SHIP_VERTICES, 1086 + ship.position.x, ship.position.y); 1076 1087 } 1077 - else 1088 + 1089 + if (game_state != PAUSE_MODE) 1078 1090 { 1079 - if (game_state != PAUSE_MODE) 1091 + if (ship.exists) 1092 + { 1093 + if (ship.invulnerable_time > 0) 1094 + ship.invulnerable_time--; 1095 + move_point(&ship.position); 1096 + } 1097 + else if (ship.explode_countdown > 0) 1080 1098 { 1081 1099 ship.explode_countdown--; 1082 - if (!ship.explode_countdown) 1100 + if (ship.explode_countdown <= 0) 1083 1101 { 1084 1102 num_lives--; 1085 1103 if (!num_lives) ··· 1089 1107 else 1090 1108 { 1091 1109 initialise_ship(); 1092 - ship.waiting_for_space = true; 1093 1110 } 1094 1111 } 1095 1112 } 1096 1113 } 1097 1114 } 1098 1115 1116 + static void explode_ship(void) 1117 + { 1118 + if (!ship.invulnerable_time) 1119 + { 1120 + /* if not invulnerable, blow up ship */ 1121 + ship.explode_countdown = EXPLOSION_LENGTH; 1122 + ship.exists = false; 1123 + create_trail_blaze(EXPLOSION_SHIP, &ship.position); 1124 + } 1125 + } 1126 + 1099 1127 /* Rotate the ship using the passed sin & cos values */ 1100 1128 static void rotate_ship(int cos, int sin) 1101 1129 { 1102 - if (!ship.waiting_for_space && !ship.explode_countdown) 1130 + if (ship.exists) 1103 1131 { 1104 1132 rotate_polygon(ship.vertices, NUM_SHIP_VERTICES, cos, sin); 1105 1133 } ··· 1107 1135 1108 1136 static void thrust_ship(void) 1109 1137 { 1110 - if (!ship.waiting_for_space && !ship.explode_countdown) 1138 + if (ship.exists) 1111 1139 { 1112 1140 ship.position.dx += ( ship.vertices[0].x - ship.vertices[2].x )/20; 1113 1141 ship.position.dy += ( ship.vertices[0].y - ship.vertices[2].y )/20; ··· 1123 1151 /* stop movement of ship, 'cos that's what happens when you go into hyperspace. */ 1124 1152 static void hyperspace(void) 1125 1153 { 1126 - if (!ship.waiting_for_space && !ship.explode_countdown) 1154 + if (ship.exists) 1127 1155 { 1128 1156 ship.position.dx = ship.position.dy = 0; 1129 1157 ship.position.x = (rb->rand()%SCALED_WIDTH); ··· 1167 1195 missile->position.y = ship.position.y + ship.vertices[0].y; 1168 1196 missile->position.dx = (ship.vertices[0].x - ship.vertices[2].x)/2; 1169 1197 missile->position.dy = (ship.vertices[0].y - ship.vertices[2].y)/2; 1170 - missile->survived = MISSILE_SURVIVAL_LENGTH; 1198 + missile->alive = MISSILE_LIFE_LENGTH; 1171 1199 missile->oldpoint.x = missile->position.x; 1172 1200 missile->oldpoint.y = missile->position.y; 1173 1201 } ··· 1178 1206 struct Missile* missile; 1179 1207 int n; 1180 1208 1181 - if (!ship.explode_countdown && !ship.waiting_for_space) 1209 + if (ship.exists) 1182 1210 { 1183 1211 missile = missiles_array; 1184 1212 n = MAX_NUM_MISSILES; 1185 1213 while (n--) 1186 1214 { 1187 - if (!missile->survived) 1215 + if (missile->alive <= 0) 1188 1216 { 1189 1217 initialise_missile(missile); 1190 1218 break; ··· 1207 1235 n = MAX_NUM_MISSILES; 1208 1236 while (n--) 1209 1237 { 1210 - if (missile->survived) 1238 + if (missile->alive > 0) 1211 1239 { 1212 1240 vertices[0].x = 0; 1213 1241 vertices[0].y = 0; ··· 1220 1248 missile->oldpoint.x = missile->position.x; 1221 1249 missile->oldpoint.y = missile->position.y; 1222 1250 move_point(&missile->position); 1223 - missile->survived--; 1251 + missile->alive--; 1224 1252 } 1225 1253 } 1226 1254 missile++; ··· 1298 1326 1299 1327 if (enemy.exists) 1300 1328 { 1301 - if (!enemy.explode_countdown) 1329 + draw_polygon(enemy.vertices, NUM_ENEMY_VERTICES, 1330 + enemy.position.x, enemy.position.y); 1331 + } 1332 + 1333 + if (game_state != PAUSE_MODE) 1334 + { 1335 + if (enemy.exists) 1302 1336 { 1303 - draw_polygon(enemy.vertices, NUM_ENEMY_VERTICES, 1304 - enemy.position.x, enemy.position.y); 1337 + enemy.position.x += enemy.position.dx; 1338 + enemy.position.y += enemy.position.dy; 1305 1339 1306 - if (game_state != PAUSE_MODE) 1307 - { 1308 - enemy.position.x += enemy.position.dx; 1309 - enemy.position.y += enemy.position.dy; 1340 + if (enemy.position.x > SCALED_WIDTH || enemy.position.x < 0) 1341 + enemy.exists = false; 1310 1342 1311 - if (enemy.position.x > SCALED_WIDTH || enemy.position.x < 0) 1312 - enemy.exists = false; 1343 + enemy.position.y %= SCALED_HEIGHT; 1344 + if (enemy.position.y < 0) 1345 + enemy.position.y += SCALED_HEIGHT; 1313 1346 1314 - enemy.position.y %= SCALED_HEIGHT; 1315 - if (enemy.position.y < 0) 1316 - enemy.position.y += SCALED_HEIGHT; 1317 - 1318 - if ((rb->rand()%1000) < 10) 1319 - enemy.position.dy = -enemy.position.dy; 1320 - } 1347 + if ((rb->rand()%1000) < 10) 1348 + enemy.position.dy = -enemy.position.dy; 1321 1349 } 1322 - else 1350 + else if (enemy.explode_countdown > 0) 1323 1351 { 1324 - if (game_state != PAUSE_MODE) 1325 - { 1326 - enemy.explode_countdown--; 1327 - if (!enemy.explode_countdown) 1328 - { 1329 - enemy.exists = false; 1330 - } 1331 - } 1352 + enemy.explode_countdown--; 1332 1353 } 1333 - } 1334 - else 1335 - { 1336 - if (game_state != PAUSE_MODE) 1354 + else 1337 1355 { 1338 - if (enemy.appear_countdown) 1356 + if (enemy.appear_countdown > 0) 1339 1357 enemy.appear_countdown--; 1340 1358 else if (rb->rand()%100 >= enemy.appear_probability) 1341 1359 initialise_enemy(); 1342 1360 } 1343 1361 } 1344 1362 1345 - if (!enemy_missile.survived) 1363 + if (enemy_missile.alive <= 0) 1346 1364 { 1347 1365 /* if no missile and the enemy is here and not exploding.. 1348 1366 then shoot baby! */ 1349 - if (!enemy.explode_countdown && enemy.exists && 1350 - !ship.waiting_for_space && game_state == PLAY_MODE && 1351 - (rb->rand()%10) >= 5 ) 1367 + if (enemy.exists && ship.exists && 1368 + game_state == PLAY_MODE && (rb->rand()%10) >= 5 ) 1352 1369 { 1353 1370 int dx = ship.position.x - enemy.position.x; 1354 1371 int dy = ship.position.y - enemy.position.y; ··· 1385 1402 1386 1403 enemy_missile.position.dx *= SCALE; 1387 1404 enemy_missile.position.dy *= SCALE; 1388 - enemy_missile.survived = ENEMY_MISSILE_SURVIVAL_LENGTH; 1405 + enemy_missile.alive = ENEMY_MISSILE_LIFE_LENGTH; 1389 1406 } 1390 1407 } 1391 1408 else ··· 1396 1413 if (game_state != PAUSE_MODE) 1397 1414 { 1398 1415 move_point(&enemy_missile.position); 1399 - enemy_missile.survived--; 1416 + enemy_missile.alive--; 1400 1417 } 1401 1418 } 1402 1419 } ··· 1424 1441 point->x - asteroid->position.x, 1425 1442 point->y - asteroid->position.y)) 1426 1443 { 1427 - struct Point p; 1428 - p.dx = asteroid->position.dx; 1429 - p.dy = asteroid->position.dy; 1430 - p.x = asteroid->position.x; 1431 - p.y = asteroid->position.y; 1444 + explode_asteroid(asteroid); 1445 + return true; 1446 + } 1447 + else 1448 + return false; 1449 + } 1432 1450 1433 - asteroid_count--; 1434 - asteroid->exists = false; 1435 - 1436 - switch(asteroid->type) 1437 - { 1438 - case SMALL: 1439 - asteroid->explode_countdown = EXPLOSION_LENGTH; 1440 - create_trail_blaze(EXPLOSION_ASTEROID, &p); 1441 - break; 1442 - 1443 - case MEDIUM: 1444 - create_asteroid(SMALL, &p); 1445 - create_asteroid(SMALL, &p); 1446 - break; 1447 - 1448 - case LARGE: 1449 - create_asteroid(MEDIUM, &p); 1450 - create_asteroid(MEDIUM, &p); 1451 - break; 1452 - } 1451 + static bool is_point_within_ship(struct Point* point) 1452 + { 1453 + if (is_point_within_rectangle(&ship.position, point, SIZE_SHIP_COLLISION) 1454 + && is_point_in_polygon(ship.vertices, NUM_SHIP_VERTICES, 1455 + point->x - ship.position.x, 1456 + point->y - ship.position.y)) 1457 + { 1453 1458 return true; 1454 1459 } 1455 1460 else ··· 1462 1467 { 1463 1468 add_score(5); 1464 1469 enemy.explode_countdown = EXPLOSION_LENGTH; 1470 + enemy.exists = false; 1465 1471 create_trail_blaze(EXPLOSION_ENEMY, &enemy.position); 1466 1472 return true; 1467 1473 } ··· 1473 1479 { 1474 1480 struct Point p; 1475 1481 1482 + if (!is_point_within_rectangle(&asteroid->position, &ship.position, 1483 + asteroid->radius+SIZE_SHIP_COLLISION)) 1484 + return false; 1485 + 1476 1486 p.x = ship.position.x + ship.vertices[0].x; 1477 1487 p.y = ship.position.y + ship.vertices[0].y; 1478 1488 if (is_point_within_asteroid(asteroid, &p)) ··· 1498 1508 struct Asteroid* asteroid; 1499 1509 int m, n; 1500 1510 bool asteroids_onscreen = false; 1501 - bool ship_cant_be_placed = false; 1502 1511 1503 1512 asteroid = asteroids_array; 1504 1513 m = MAX_NUM_ASTEROIDS; ··· 1512 1521 while (n--) 1513 1522 { 1514 1523 /* if the missiles exists: */ 1515 - if (missile->survived > 0) 1524 + if (missile->alive > 0) 1516 1525 { 1517 1526 /* has the missile hit the asteroid? */ 1518 1527 if (is_point_within_asteroid(asteroid, &missile->position) || 1519 1528 is_point_within_asteroid(asteroid, &missile->oldpoint)) 1520 1529 { 1521 1530 add_score(1); 1522 - missile->survived = 0; 1531 + missile->alive = 0; 1523 1532 break; 1524 1533 } 1525 1534 } ··· 1527 1536 } 1528 1537 1529 1538 /* now check collision with ship: */ 1530 - if (asteroid->exists && !ship.waiting_for_space && !ship.explode_countdown) 1539 + if (asteroid->exists && ship.exists) 1531 1540 { 1532 1541 if (is_ship_within_asteroid(asteroid)) 1533 1542 { 1534 1543 add_score(1); 1535 - if (!ship.invulnerable) 1536 - { 1537 - /* if not invulnerable, blow up ship */ 1538 - ship.explode_countdown = EXPLOSION_LENGTH; 1539 - create_trail_blaze(EXPLOSION_SHIP, &ship.position); 1540 - } 1544 + explode_ship(); 1541 1545 } 1546 + } 1542 1547 1543 - /* has the enemy missile blown something up? */ 1544 - if (asteroid->exists && enemy_missile.survived) 1548 + /* has the enemy missile blown something up? */ 1549 + if (asteroid->exists && enemy_missile.alive > 0) 1550 + { 1551 + if (is_point_within_asteroid(asteroid, &enemy_missile.position)) 1545 1552 { 1546 - if (is_point_within_asteroid(asteroid, &enemy_missile.position)) 1547 - { 1548 - enemy_missile.survived = 0; 1549 - } 1550 - 1551 - /* if it still exists, check if ship is waiting for space: */ 1552 - if (asteroid->exists && ship.waiting_for_space) 1553 - { 1554 - ship_cant_be_placed |= 1555 - is_point_within_rectangle(&ship.position, 1556 - &asteroid->position, 1557 - SPACE_CHECK_SIZE); 1558 - } 1553 + enemy_missile.alive = 0; 1559 1554 } 1560 1555 } 1561 1556 } 1562 1557 1563 1558 /* is an asteroid still exploding? */ 1564 - if (asteroid->explode_countdown) 1559 + if (asteroid->explode_countdown > 0) 1565 1560 asteroids_onscreen = true; 1566 1561 1567 1562 asteroid++; 1568 1563 } 1569 1564 1570 1565 /* now check collision between ship and enemy */ 1571 - if (enemy.exists && !enemy.explode_countdown && 1572 - !ship.waiting_for_space && !ship.explode_countdown) 1566 + if (enemy.exists && ship.exists) 1573 1567 { 1574 1568 /* has the enemy collided with the ship? */ 1575 1569 if (is_point_within_enemy(&ship.position)) 1576 1570 { 1577 - if (!ship.invulnerable) 1578 - { 1579 - ship.explode_countdown = EXPLOSION_LENGTH; 1580 - create_trail_blaze(EXPLOSION_SHIP, &ship.position); 1581 - } 1571 + explode_ship(); 1582 1572 create_trail_blaze(EXPLOSION_ENEMY, &enemy.position); 1583 1573 } 1584 1574 1585 - if (enemy.exists && !enemy.explode_countdown) 1575 + if (enemy.exists) 1586 1576 { 1587 1577 /* Now see if the enemy has been shot at by the ships missiles: */ 1588 1578 missile = missiles_array; 1589 1579 n = MAX_NUM_MISSILES; 1590 1580 while (n--) 1591 1581 { 1592 - if (missile->survived > 0 && 1582 + if (missile->alive > 0 && 1593 1583 is_point_within_enemy(&missile->position)) 1594 1584 { 1595 - missile->survived = 0; 1585 + missile->alive = 0; 1596 1586 break; 1597 1587 } 1598 1588 missile++; ··· 1601 1591 } 1602 1592 1603 1593 /* test collision with enemy missile and ship: */ 1604 - if (!ship_cant_be_placed && enemy_missile.survived > 0 && 1605 - is_point_in_polygon(ship.vertices, NUM_SHIP_VERTICES, 1606 - enemy_missile.position.x - ship.position.x, 1607 - enemy_missile.position.y - ship.position.y)) 1594 + if (enemy_missile.alive > 0 && is_point_within_ship(&enemy_missile.position)) 1608 1595 { 1609 - if (!ship.invulnerable) 1610 - { 1611 - ship.explode_countdown = EXPLOSION_LENGTH; 1612 - create_trail_blaze(EXPLOSION_SHIP, &ship.position); 1613 - } 1614 - enemy_missile.survived = 0; 1596 + explode_ship(); 1597 + enemy_missile.alive = 0; 1615 1598 enemy_missile.position.x = enemy_missile.position.y = 0; 1616 1599 } 1617 1600 1618 - if (!ship_cant_be_placed) 1619 - ship.waiting_for_space = false; 1620 - 1621 1601 /* if all asteroids cleared then start again: */ 1622 - if (asteroid_count == 0 && !enemy.exists && !asteroids_onscreen) 1602 + if (asteroid_count == 0 && !asteroids_onscreen 1603 + && !enemy.exists && enemy.explode_countdown <= 0) 1623 1604 { 1624 1605 current_level++; 1625 1606 enemy.appear_probability += 5; ··· 1682 1663 1683 1664 /* no enemy */ 1684 1665 enemy.exists = 0; 1685 - enemy_missile.survived = 0; 1666 + enemy.explode_countdown = 0; 1667 + enemy_missile.alive = 0; 1686 1668 1687 1669 /* clear asteroids */ 1688 1670 asteroid = asteroids_array; ··· 1702 1684 n = MAX_NUM_MISSILES; 1703 1685 while (n--) 1704 1686 { 1705 - missile->survived = 0; 1687 + missile->alive = 0; 1706 1688 missile++; 1707 1689 } 1708 1690