Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of el17dg by
Diff: game/stars.h
- Revision:
- 29:579e00b7f118
- Parent:
- 28:35af3843de8f
- Child:
- 31:becb8f6bf7b7
diff -r 35af3843de8f -r 579e00b7f118 game/stars.h
--- a/game/stars.h Wed Apr 10 15:42:10 2019 +0000
+++ b/game/stars.h Mon Apr 15 12:59:51 2019 +0000
@@ -8,15 +8,21 @@
const int stars_delay_max = 5;
int stars_delay;
+/**Stars Class
+ * @brief A library for describing the background stars.
+ * @author Dmitrijs Griskovs
+ * @date 15/04/2019
+ */
class Stars {
public:
GameObject small_stars[max_small_stars];
GameObject medium_stars[max_medium_stars];
- /** Searches through the small stars array and if a star is not active,
- * it becomes active and is given the position of x (which is 0) and.
- * and random position of y.
- */
+/** @brief Makes a small star active and gives it the start positions.
+ * @details Searches through the small stars array and if a star is not active,
+ * it becomes active and is given the position of x (which is 0) and.
+ * and random position of y.
+ */
void newSmallStarFlies() {
// Search the array of stars if inactive we can use it. - the same as with blasts
int found = -1;
@@ -33,26 +39,27 @@
small_stars[found].pos.y = rand() % screen_height + game_area_y;
}
}
-/** when a small star is active, this function updates the position and draws it
- * on the screen.
- */
+/** @brief draws small stars on the screen.
+ * @details when a small star is active, this function updates the position and
+ * draws it on the screen. Also, When the star leaves the screen limits it
+ * deactivates the star for a new star to fly.
+ */
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;
- }
-
+ }
drawSprite(small_stars[i].pos, small_star_sprite);
}
- }
-
+ }
}
-/** Searches through the medium stars array and if a star is not active,
- * it becomes active and is given the position of x (which is 0) and.
- * and random position of y.
- */
+/** @brief Makes a medium star active and gives it the start positions.
+ * @details Searches through the medium stars array and if a star is not active,
+ * it becomes active and is given the position of x (which is 0) and.
+ * and random position of y.
+ */
void newMediumStarFlies() {
// Search the array of stars if inactive we can use it. - the same as with blasts
int found = -1;
@@ -62,16 +69,17 @@
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;
}
}
-/** when a medium star is active, this function updates the position and draws it
- * on the screen.
- */
+/** @brief draws medium stars on the screen.
+ * @details when a medium star is active, this function updates the position and
+ * draws it on the screen. Also, When the star leaves the screen limits it
+ * deactivates the star for a new star to fly.
+ */
void updateAndDrawMediumStars(){
for (int i = 0; i < max_medium_stars; ++i) {
if (medium_stars[i].active) {
@@ -84,7 +92,7 @@
}
}
- /** A separate function for delaying the stars spawn time.*/
+/** @brief A separate function for delaying the stars spawn time.*/
void starsSpawnDelay(){
if (stars_delay == stars_delay_max){
//This is dealy between stars generation.
