فهرست منبع

Bugfix: Powerup spawn anti-collide, code reorganiz

SimplyMinimal 2 سال پیش
والد
کامیت
35a2c6fdcf
1فایلهای تغییر یافته به همراه27 افزوده شده و 26 حذف شده
  1. 27 26
      app.c

+ 27 - 26
app.c

@@ -686,7 +686,7 @@ void asteroid_was_hit(AsteroidsApp* app, int id) {
 bool isPowerUpCollidingWithEachOther(AsteroidsApp* app, float x, float y, float size) {
     for(int i = 0; i < app->powerUps_num; i++) {
         PowerUp* p2 = &app->powerUps[i];
-        if(objects_are_colliding(x, y, size, p2->x, p2->y, p2->size, 1.0)) return true;
+        if(objects_are_colliding(x, y, size, p2->x, p2->y, p2->size, 1)) return true;
     }
     return false;
 }
@@ -714,8 +714,9 @@ PowerUp* add_powerUp(AsteroidsApp* app) {
         //It also keeps it away from the lives and score at the top of screen
         x = rand() % (SCREEN_XRES - (int)size);
         y = rand() % (SCREEN_YRES - (int)size);
-    } while((distance(app->ship.x, app->ship.y, x, y) < min_distance + size) &&
-            (!isPowerUpCollidingWithEachOther(app, x, y, size)));
+    } while(
+        ((distance(app->ship.x, app->ship.y, x, y) < min_distance + size) ||
+         isPowerUpCollidingWithEachOther(app, x, y, size)));
 
     PowerUp* p = &app->powerUps[app->powerUps_num++];
     p->x = x;
@@ -737,6 +738,24 @@ PowerUp* add_powerUp(AsteroidsApp* app) {
     return p;
 }
 
+bool isPowerUpActive(AsteroidsApp* const app, PowerUpType const powerUpType) {
+    for(int i = 0; i < app->powerUps_num; i++) {
+        // PowerUp* p = &app->powerUps[i];
+        // if(p->powerUpType == powerUpType && p->ttl > 0 && p->display_ttl == 0) return true;
+        if(app->powerUps[i].isPowerUpActive && app->powerUps[i].powerUpType == powerUpType) {
+            return true;
+        }
+    }
+    return false;
+}
+
+bool isPowerUpAlreadyExists(AsteroidsApp* const app, PowerUpType const powerUpType) {
+    for(int i = 0; i < app->powerUps_num; i++) {
+        if(app->powerUps[i].powerUpType == powerUpType) return true;
+    }
+    return false;
+}
+
 //@todo remove_powerUp
 void remove_powerUp(AsteroidsApp* app, int id) {
     // Invalid ID, ignore
@@ -787,24 +806,6 @@ void powerUp_was_hit(AsteroidsApp* app, int id) {
     p->isPowerUpActive = true;
 }
 
-bool isPowerUpActive(AsteroidsApp* const app, PowerUpType const powerUpType) {
-    for(int i = 0; i < app->powerUps_num; i++) {
-        // PowerUp* p = &app->powerUps[i];
-        // if(p->powerUpType == powerUpType && p->ttl > 0 && p->display_ttl == 0) return true;
-        if(app->powerUps[i].isPowerUpActive && app->powerUps[i].powerUpType == powerUpType) {
-            return true;
-        }
-    }
-    return false;
-}
-
-bool isPowerUpAlreadyExists(AsteroidsApp* const app, PowerUpType const powerUpType) {
-    for(int i = 0; i < app->powerUps_num; i++) {
-        if(app->powerUps[i].powerUpType == powerUpType) return true;
-    }
-    return false;
-}
-
 /* ================================ Game States ================================ */
 /* Set gameover state. When in game-over mode, the game displays a gameover
  * text with a background of many asteroids floating around. */
@@ -1184,11 +1185,11 @@ int32_t asteroids_app_entry(void* p) {
         } else {
             /* Useful to understand if the app is still alive when it
              * does not respond because of bugs. */
-            if(DEBUG_MSG) {
-                static int c = 0;
-                c++;
-                if(!(c % 20)) FURI_LOG_E(TAG, "Loop timeout");
-            }
+            // if(DEBUG_MSG) {
+            //     static int c = 0;
+            //     c++;
+            //     if(!(c % 20)) FURI_LOG_E(TAG, "Loop timeout");
+            // }
         }
     }