Initial publish

Dependencies:   mbed

Fork of el17dg by Dmitrijs Griskovs

Revision:
23:240bc00ef25b
Parent:
21:0eb394495b8a
Child:
26:676874c42883
--- a/game/stars.h	Wed Mar 27 16:35:52 2019 +0000
+++ b/game/stars.h	Sun Mar 31 01:04:59 2019 +0000
@@ -1,64 +1,81 @@
 #ifndef STARS_H
 #define STARS_H
 
-void newSmallStarFlies() {
-    // Search the array of stars if inactive we can use it. - the same as with blasts
-    int found = -1;
-    for (int i = 0; i < MAX_SMALL_STARS; ++i) {
-        if (!small_stars[i].active) {
-            found = i;
-            break;
+const int max_small_stars = 5;
+const int max_medium_stars = 5;
+const int small_star_speed = 5;
+const int medium_star_speed = 5;
+
+
+
+class Stars : public GameObject {
+public:
+    GameObject small_stars[max_small_stars];
+    GameObject medium_stars[max_medium_stars];
+    
+     /**@brief
+    * This is the main function of game.cpp, where the actual gameplay happens.
+    * Here all other functions are activeated, and when the player dies, it
+    * returns back to main menu "main.cpp". 
+    */
+    void newSmallStarFlies() {
+        // Search the array of stars if inactive we can use it. - the same as with blasts
+        int found = -1;
+        for (int i = 0; i < max_small_stars; ++i) {
+            if (!small_stars[i].active) {
+                found = i;
+                break;
+            }
+        }
+        
+        if (found != -1) {
+            small_stars[found].active = true;
+            small_stars[found].pos.x = screen_width;
+            small_stars[found].pos.y = rand() % screen_height + game_area_y;
         }
     }
     
-    if (found != -1) {
-        small_stars[found].active = true;
-        small_stars[found].pos.x = screen_width;
-        small_stars[found].pos.y = rand() % screen_height + game_area_y;
-    }
-}
-
-void updateAndDrawSmallStars(){
-    const int small_star_speed = 5;
-    for (int i = 0; i < MAX_SMALL_STARS; ++i) {
-        if (small_stars[i].active) {
-            small_stars[i].pos.x -= small_star_speed;
-            if (small_stars[i].pos.x <= 0){
-                small_stars[i].active = false;   
+    void updateAndDrawSmallStars(){
+        for (int i = 0; i < max_small_stars; ++i) {
+            if (small_stars[i].active) {
+                small_stars[i].pos.x -= small_star_speed;
+                if (small_stars[i].pos.x <= 0){
+                    small_stars[i].active = false;   
+                }
+                //awSprite(pos, small_star_sprite);
+                lcd.drawSprite(small_stars[i].pos.x, small_stars[i].pos.y, 3, 3, (int*)starSmall);
             }
-            lcd.drawSprite(small_stars[i].pos.x, small_stars[i].pos.y, 3, 3, (int*)starSmall);
-        }
-    }
-}
-
-void newMediumStarFlies() {
-    // Search the array of stars if inactive we can use it. - the same as with blasts
-    int found = -1;
-    for (int i = 0; i < MAX_MEDIUM_STARS; ++i) {
-        if (!medium_stars[i].active) {
-            found = i;
-            break;
         }
     }
     
-    if (found != -1) {
-        medium_stars[found].active = true;
-        medium_stars[found].pos.x = screen_width;
-        medium_stars[found].pos.y =rand() % screen_height + game_area_y;
-    }
-}
-
-void updateAndDrawMediumStars(){
-    const int medium_star_speed = 5;
-    for (int i = 0; i < MAX_MEDIUM_STARS; ++i) {
-        if (medium_stars[i].active) {
-            medium_stars[i].pos.x -= medium_star_speed;
-            if (medium_stars[i].pos.x <= -2){
-                medium_stars[i].active = false;   
+    void newMediumStarFlies() {
+        // Search the array of stars if inactive we can use it. - the same as with blasts
+        int found = -1;
+        for (int i = 0; i < max_medium_stars; ++i) {
+            if (!medium_stars[i].active) {
+                found = i;
+                break;
             }
-            lcd.drawSprite(medium_stars[i].pos.x, medium_stars[i].pos.y, 5, 5, (int*)starMedium);
+        }
+        
+        if (found != -1) {
+            medium_stars[found].active = true;
+            medium_stars[found].pos.x = screen_width;
+            medium_stars[found].pos.y = rand() % screen_height + game_area_y;
         }
     }
-}
-
+    
+    void updateAndDrawMediumStars(){
+        for (int i = 0; i < max_medium_stars; ++i) {
+            if (medium_stars[i].active) {
+                medium_stars[i].pos.x -= medium_star_speed;
+                if (medium_stars[i].pos.x <= -2){
+                    medium_stars[i].active = false;   
+                }
+                lcd.drawSprite(medium_stars[i].pos.x, medium_stars[i].pos.y, 5, 5, (int*)starMedium);
+                //awSprite(pos, medium_star_sprite);
+            }
+        }
+    }
+};
 #endif
\ No newline at end of file