Jelajahi Sumber

Keep power up on game play area

SimplyMinimal 2 tahun lalu
induk
melakukan
343e87d2b2
1 mengubah file dengan 5 tambahan dan 3 penghapusan
  1. 5 3
      app.c

+ 5 - 3
app.c

@@ -732,10 +732,12 @@ PowerUp* add_powerUp(AsteroidsApp* app) {
     float min_distance = 20;
     float x, y;
     do {
-        //size*2 to make sure power up is not spawned on the edge of the screen
-        //It also keeps it away from the lives and score at the top of screen
+        //Make sure power up is not spawned on the edge of the screen
         x = rand() % (SCREEN_XRES - (int)size);
-        y = rand() % (SCREEN_YRES - (int)size + 20);
+        y = rand() % (SCREEN_YRES - (int)size);
+
+        //Also keep it away from the lives and score at the top of screen
+        if(y < size) y = size;
     } while(
         ((distance(app->ship.x, app->ship.y, x, y) < min_distance + size) ||
          isPowerUpCollidingWithEachOther(app, x, y, size)));