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:
- 37:6a2bf4488022
- Parent:
- 36:207ec7db8648
- Child:
- 38:ef3968546d36
diff -r 207ec7db8648 -r 6a2bf4488022 game/game.cpp
--- a/game/game.cpp	Thu May 02 13:35:22 2019 +0000
+++ b/game/game.cpp	Mon May 06 22:35:51 2019 +0000
@@ -32,7 +32,6 @@
 Player player;
 GameOverManager gameOverManager;
 
-CircleBounds circleBounds;
 Hud hud;
 
 
@@ -59,6 +58,7 @@
 
 void Game::updateAndDrawGameover() {
     gameOverManager.updateAndDraw();
+    lcd.normalMode();
     if (gamepad.check_event(gamepad.Y_PRESSED) && !gameOverManager.isPlayingAnimation()) {
         gameOverManager.reset();
         game_state = GameState_newgame;
@@ -102,9 +102,7 @@
   */
 bool Game::updateAndDraw() {
     if (game_state == GameState_newgame) {
-        #ifdef DEBUGel17dg
-        printf("start game \n");
-        #endif
+        DG_PRINTF("start game \n");
         startNewGame();
     }
     if (game_state == GameState_gameplay) { updateAndDrawGameplay(); }
@@ -136,15 +134,13 @@
             Enemy& enemy = enemies.enemies[i];
             GameObject& blast = player.blasts[j];
             if (enemy.active && !enemy.dead && blast.active) {
-                bool collision = circleBounds.circleCollideTwoObjects(
+                bool collision = circleCollideTwoObjects(
                     enemy.pos, enemies.enemy_bounds, 
                     blast.pos, player.blast_bounds
                 );
                 if (collision) {
                     enemy.die();
-                    #ifdef DEBUGel17dg
-                    printf("enemy got hit and dies");
-                    #endif
+                    DG_PRINTF("enemy got hit and dies \n");
                     GameGlobals::game_score += 30;
                     GameGlobals::score_count_for_difficulty +=30;
                     GameGlobals::score_count_for_boss_mode += 30;
@@ -166,7 +162,7 @@
     for (int i = 0; i < enemies.max_enemies; ++i) {
         GameObject& blast = enemies.enemy_blasts[i];
         if (blast.active) {
-            bool collision = circleBounds.circleCollideTwoObjects(
+            bool collision = circleCollideTwoObjects(
                 player.pos, player.player_bounds,
                 blast.pos, enemies.enemy_blast_bounds
             );
@@ -174,9 +170,7 @@
                 if (!GameGlobals::is_shield_on){
                     gamepad.tone(423,0.4); 
                     GameGlobals::player_lifes -= 1;
-                    #ifdef DEBUGel17dg
-                    printf("lost a life from blast. left: %i \n", GameGlobals::player_lifes);
-                    #endif
+                    DG_PRINTF("lost a life from blast. left: %i \n", GameGlobals::player_lifes);
                     blast.active = false;
                 }else{
                     blast.active = false;
@@ -195,7 +189,7 @@
     for (int i = 0; i < enemies.max_enemies; ++i) {
         Enemy& enemy = enemies.enemies[i];
         if (enemy.active && !enemy.dead) {
-            bool collision = circleBounds.circleCollideTwoObjects(
+            bool collision = circleCollideTwoObjects(
                 player.pos, player.player_bounds,
                 enemy.pos, enemies.enemy_bounds
             );
@@ -203,10 +197,8 @@
                 GameGlobals::player_lifes -= 1;
                
                 enemy.die();
-                #ifdef DEBUGel17dg
-                printf("enemy got hit from collsion and dies");
-                printf("lost a life from enemy col. left: %i \n", GameGlobals::player_lifes);
-                #endif
+                DG_PRINTF("enemy got hit from collsion and dies");
+                DG_PRINTF("lost a life from enemy col. left: %i \n", GameGlobals::player_lifes);
             }
         }
     } 
@@ -216,7 +208,7 @@
     for (int i = 0; i < player.max_player_blasts; ++i) {
         GameObject& blast = player.blasts[i];
         if (blast.active) {
-            bool collision = circleBounds.circleCollideTwoObjects(
+            bool collision = circleCollideTwoObjects(
                 boss.pos, boss.boss_bounds,
                 blast.pos, player.blast_bounds
             );
@@ -224,9 +216,7 @@
                 boss.boss_lives -= 1;
                 gamepad.tone(123,0.4);
                 blast.active = false;
-                #ifdef DEBUGel17dg
-                printf("boss has. left: %i \n", boss.boss_lives);
-                #endif 
+                DG_PRINTF("boss has. left: %i \n", boss.boss_lives);
             }
         }
     } 
@@ -236,24 +226,20 @@
     for (int i = 0; i < boss.max_boss_blasts; ++i) {
         GameObject& blast = boss.boss_blasts[i];
         if (blast.active) {
-            bool collision = circleBounds.circleCollideTwoObjects(
+            bool collision = circleCollideTwoObjects(
                 player.pos, player.player_bounds,
                 blast.pos, boss.boss_blast_bounds
             );
-            #ifdef DEBUGel17dg
-            printf("player pos:%i,%i; offset:%i,%i; radius:%f.3; \n", player.pos.x, player.pos.y, player.player_bounds.center.x, player.player_bounds.center.y, player.player_bounds.radius);
-            printf("blas pos:%i,%i; offset:%i,%i; radius:%f.3; \n", blast.pos.x, blast.pos.y, boss.boss_blast_bounds.center.x, boss.boss_blast_bounds.center.y, boss.boss_blast_bounds.radius);
-            #endif 
+            DG_PRINTF("player pos:%i,%i; offset:%i,%i; radius:%f.3; \n", player.pos.x, player.pos.y, player.player_bounds.center.x, player.player_bounds.center.y, player.player_bounds.radius);
+            DG_PRINTF("blas pos:%i,%i; offset:%i,%i; radius:%f.3; \n", blast.pos.x, blast.pos.y, boss.boss_blast_bounds.center.x, boss.boss_blast_bounds.center.y, boss.boss_blast_bounds.radius);
             if (collision) {
                 if (!GameGlobals::is_shield_on){
                     
                     gamepad.tone(423,0.4); 
                     GameGlobals::player_lifes -= 1;
                     blast.active = false;
-                    #ifdef DEBUGel17dg
-                    printf("collision happened;\n");
-                    printf("lost a life from blast. left: %i \n", GameGlobals::player_lifes);
-                    #endif
+                    DG_PRINTF("collision happened;\n");
+                    DG_PRINTF("lost a life from blast. left: %i \n", GameGlobals::player_lifes);
                 }else{
                     blast.active = false;
                     gamepad.tone(700,0.6);
@@ -270,7 +256,8 @@
     */
 void Game::startNewGame() {
     is_boss_active = false;
-    game_state = GameState_gameplay;
+    //game_state = GameState_gameplay;
+    game_state = GameState_boss_cutscene;
     player.pos.x = 0; //player was defined in player.h
     player.pos.y = 24;
     stars.stars_delay = 0;
@@ -284,10 +271,7 @@
     hud.resetRedLed();
     enemies.enemy_blast_speed = 3;
     enemy.enemy_speed = 1;
-    #ifdef DEBUGel17dg
-    printf("startNewGame\n");
-     
-    #endif 
+    
     for (int i = 0; i < enemies.max_enemies; ++i) {
         enemies.enemies[i].active = false;
     }
@@ -354,9 +338,7 @@
     bool want_to_pause = false;
 
     if (gamepad.check_event(gamepad.START_PRESSED)){
-        #ifdef DEBUGel17dg
-        printf("game paused\n");
-        #endif
+        DG_PRINTF("game paused\n");
         gamepad.check_event(gamepad.START_PRESSED);
         want_to_pause = true;
     }
    