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/game.cpp
- Revision:
- 27:f05f4e738ba9
- Parent:
- 26:676874c42883
- Child:
- 28:35af3843de8f
--- a/game/game.cpp Sat Apr 06 20:13:33 2019 +0000
+++ b/game/game.cpp Mon Apr 08 14:41:57 2019 +0000
@@ -18,7 +18,7 @@
int stars_delay;
int game_score;
int score_count_for_difficulty;
-int player_lifes;
+int player_lifes = 3;
bool red_led_state;
int red_led_flashing;
int enemy_ship_delay_counter;
@@ -51,9 +51,6 @@
blast.pos, blast_bounds
);
if (collision) {
- gamepad.tone(87,0.1);
- gamepad.tone(187,0.2);
- gamepad.tone(123,0.3);
enemy.die();
game_score += 30;
score_count_for_difficulty +=30;
@@ -83,6 +80,7 @@
gamepad.tone(87,0.3);
gamepad.tone(287,0.2);
gamepad.tone(423,0.4);
+ printf("lost a life. left: %i \n", player_lifes);
player_lifes -= 1;
blast.active = false;
}
@@ -95,7 +93,7 @@
* of enemy ship and the player's ship
*/
void Game::collideEnemiesAndPlayer() {
- for (int i = 0; i < max_enemy_blasts; ++i) {
+ for (int i = 0; i < max_enemies; ++i) {
Enemy& enemy = enemies.enemies[i];
if (enemy.active && !enemy.dead) {
bool collision = circleCollideTwoObjects(
@@ -103,7 +101,7 @@
enemy.pos, enemies.enemy_bounds
);
if (collision) {
- player_lifes = 0;
+ player_lifes -= 1;
enemy.die();
}
}
@@ -142,6 +140,9 @@
for (int i = 0; i < max_enemy_blasts; ++i) {
enemies.enemy_blasts[i].active = false;
}
+ //Reset start button event
+ gamepad.check_event(gamepad.START_PRESSED);
+
}
/**@brief
@@ -179,10 +180,10 @@
/**@brief
* A separate function for delaying the stars spawn.
*/
-void Game::starsSpawnDelay(){
+void Game::starsSpawnDelay(){ // TODO Move to stars.h
if (stars_delay == stars_delay_max){
//This is dealy between stars generation.
- //stars.newSmallStarFlies();
+ stars.newSmallStarFlies();
stars.newMediumStarFlies();
stars_delay = 0;
}
@@ -217,7 +218,9 @@
* returns back to main menu "main.cpp".
*/
bool Game::updateAndDraw() {
+ //printf("update \n");
if (game_over) {
+ printf("start game \n");
startNewGame();
}
@@ -240,7 +243,7 @@
collideEnemiesBlastsAndPlayer();
collideEnemiesAndPlayer();
enemies.updateAndDrawEnemyBlasts();
- hud.drawHighScore();
+ hud.drawScore();
/**@brief
* This small statment checks whether the pause button was pressed or not.
@@ -248,12 +251,22 @@
* the current status of the object until the game is continued.
*/
bool want_to_pause = false;
+ game_over = checkForGameOver();
if (game_over){
+ printf("game over happened\n");
gameOver();
want_to_pause = true;
}
if (gamepad.check_event(gamepad.START_PRESSED)){
+ printf("pausing the game\n");
want_to_pause = true;
}
return want_to_pause;
+}
+/**@brief
+ * This is a single line function to set the player lifes to 0 when the.
+ * game is over.
+ */
+bool Game::checkForGameOver() {
+ return player_lifes == 0;
}
\ No newline at end of file
