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.
gameovermanager.h
00001 #ifndef GAMEOVERMANAGER_H 00002 #define GAMEOVERMANAGER_H 00003 00004 /** 00005 * GameOverManager Class 00006 * @brief A class for updating and drawing GameOver state. 00007 * @author Dmitrijs Griskovs 00008 * @date 30/04/2019 00009 */ 00010 class GameOverManager { 00011 public: 00012 /** 00013 * Constructor. 00014 * @brief It init the GameOver with reseting 00015 * the statrting sequence of the gameOver state. 00016 */ 00017 GameOverManager() { reset(); } 00018 00019 /** 00020 * @brief Resets the gameOver to the animiation to appear again 00021 * @returns bool started, when GameOver begins. 00022 */ 00023 void reset() { started = false; } 00024 /** 00025 * @brief Updates and draws the game over animation. 00026 * @details It draws "GameOver" sprite from the leftside of the screen to the center 00027 * and "youDied" sprite from the right side to the center. 00028 */ 00029 void updateAndDraw() { 00030 if (!started) { startAnimation();} 00031 if (animation_counter < animation_length) { 00032 if (gamepad.check_event(gamepad.START_PRESSED)) { 00033 gameOverLogo.pos.x = game_area_x - 29 + 42; 00034 youDied.pos.x = game_area_width - 42; 00035 animation_counter = animation_length; 00036 } else { 00037 animation_counter++; 00038 gameOverLogo.pos.x += 1; 00039 youDied.pos.x -= 1; 00040 } 00041 } 00042 drawSprite(gameOverLogo.pos, game_over_sprite); 00043 drawSprite(youDied.pos, you_died_sprite); 00044 gameOverPostAnimation(); 00045 musicGameOver(); 00046 ledsGameOver(); 00047 } 00048 00049 /** 00050 * @brief Checks for whether the animation of GameOver has stoped drawing or not 00051 * @details It check the value of the counter against the total length of the 00052 * animation play. When the counter equals to the total length, it indicates that 00053 * the animation has stopped 00054 */ 00055 bool isPlayingAnimation() { 00056 return animation_counter < animation_length; 00057 }; 00058 00059 private: 00060 void startAnimation() { 00061 started = true; 00062 gameOverLogo.pos.x = game_area_x - 29; // 0 - the sprite length 00063 gameOverLogo.pos.y = game_area_y; 00064 youDied.pos.x = game_area_width; 00065 youDied.pos.y = game_area_y; 00066 animation_counter = 0; 00067 led_state = false; 00068 low_frequency_music_counter = 0; 00069 high_frequency_music_counter = 0; 00070 } 00071 00072 void ledsGameOver(){ 00073 gamepad.led(1,(float)led_state); 00074 gamepad.led(2,(float)!led_state); 00075 gamepad.led(3,(float)led_state); 00076 gamepad.led(4,(float)!led_state); 00077 gamepad.led(5,(float)led_state); 00078 gamepad.led(6,(float)!led_state); 00079 led_state = !led_state; 00080 } 00081 00082 void musicGameOver(){ 00083 lowFrequencyPartMusic(); 00084 highFrequencyPartMusic(); 00085 high_frequency_music_counter++; 00086 low_frequency_music_counter++;//comment out this for epic game over beat. 00087 #ifdef DEBUGel17dg 00088 printf("Low frequency counter value:: %i\n", low_frequency_music_counter); 00089 printf("high frequency counter value:: %i\n", high_frequency_music_counter); 00090 #endif 00091 } 00092 00093 void lowFrequencyPartMusic(){ 00094 // Low frequency 00095 if (low_frequency_music_counter == 0){ gamepad.tone(60,3);} 00096 else if (low_frequency_music_counter == 3){gamepad.tone(90,3);} 00097 else if (low_frequency_music_counter == 6){gamepad.tone(60,3);} 00098 else if (low_frequency_music_counter == 9){gamepad.tone(80,3);} 00099 else if (low_frequency_music_counter == 12){gamepad.tone(70,2);} 00100 else if (low_frequency_music_counter == 14){gamepad.tone(60,2);} 00101 else if (low_frequency_music_counter == 16){gamepad.tone(70,3);} 00102 else if (low_frequency_music_counter == 19){gamepad.tone(50,1);} 00103 else if (low_frequency_music_counter == 20){gamepad.tone(40,3);} 00104 else if (low_frequency_music_counter== 23){ 00105 gamepad.tone(60,2); 00106 low_frequency_music_counter = 0; 00107 } 00108 } 00109 00110 void highFrequencyPartMusic(){ 00111 // High frequency 00112 if ( high_frequency_music_counter == 0){ gamepad.tone(300,0.1);} 00113 else if (high_frequency_music_counter == 3){gamepad.tone(250,0.1);} 00114 else if (high_frequency_music_counter == 6){gamepad.tone(230,0.2);} 00115 else if (high_frequency_music_counter == 9){gamepad.tone(250,0.1);} 00116 else if ( high_frequency_music_counter == 12){gamepad.tone(250,0.2);} 00117 else if ( high_frequency_music_counter == 14){gamepad.tone(220,0.1);} 00118 else if ( high_frequency_music_counter == 16){gamepad.tone(210,0.3);} 00119 else if ( high_frequency_music_counter == 19){gamepad.tone(200,1);} 00120 else if ( high_frequency_music_counter == 21){gamepad.tone(250,1);} 00121 else if ( high_frequency_music_counter == 22){ 00122 gamepad.tone(200,1); 00123 high_frequency_music_counter = 0; 00124 } 00125 } 00126 void updateHighScore(){ 00127 if (GameGlobals::high_score < GameGlobals::game_score){ 00128 GameGlobals::high_score = GameGlobals::game_score; 00129 } 00130 } 00131 00132 void gameOverPostAnimation(){ 00133 char buffer[32]; 00134 sprintf(buffer,"Score: %i", GameGlobals::game_score); 00135 updateHighScore(); 00136 lcd.printString(buffer,0,3); 00137 lcd.printString("Press Y",0,4); 00138 lcd.printString("to restart",0,5); 00139 } 00140 00141 bool started; 00142 static const int animation_length = 42; 00143 int animation_counter; 00144 GameObject gameOverLogo; 00145 GameObject youDied; 00146 bool led_state; 00147 int low_frequency_music_counter; 00148 int high_frequency_music_counter; 00149 }; 00150 00151 #endif
Generated on Wed Dec 20 2023 20:30:17 by
