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/gameovermanager.h
- Revision:
- 33:c623c6d5ed16
- Child:
- 34:754915ce9de5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/game/gameovermanager.h Mon Apr 29 08:10:52 2019 +0000 @@ -0,0 +1,120 @@ +#ifndef GAMEOVERMANAGER_H +#define GAMEOVERMANAGER_H + +#include "main.h" + +class GameOverManager { +public: + GameOverManager() { reset(); } + + void reset() { started = false; } + + void updateAndDraw() { + if (!started) { + startAnimation(); + } + + if (animation_counter < animation_length) { + if (gamepad.check_event(gamepad.START_PRESSED)) { + gameOverLogo.pos.x = game_area_x - 29 + 42; + youDied.pos.x = game_area_width - 42; + } else { + animation_counter++; + gameOverLogo.pos.x += 1; + youDied.pos.x -= 1; + } + } + drawSprite(gameOverLogo.pos, game_over_sprite); + drawSprite(youDied.pos, you_died_sprite); + + char buffer[32]; + sprintf(buffer,"Your Score %i", GameGlobals::game_score); + lcd.printString(buffer,0,3); + lcd.printString("Press Y",0,4); + lcd.printString("to restart",0,5); + + musicGameOver(); + ledsGameOver(); + } + + bool isPlayingAnimation() { + return animation_counter < animation_length; + }; + +private: + void startAnimation() { + started = true; + gameOverLogo.pos.x = game_area_x - 29; // 0 - the sprite length + gameOverLogo.pos.y = game_area_y; + youDied.pos.x = game_area_width; + youDied.pos.y = game_area_y; + animation_counter = 0; + led_state = false; + low_frequency_music_counter = 0; + high_frequency_music_counter = 0; + } + + void ledsGameOver(){ + gamepad.led(1,(float)led_state); + gamepad.led(2,(float)!led_state); + gamepad.led(3,(float)led_state); + gamepad.led(4,(float)!led_state); + gamepad.led(5,(float)led_state); + gamepad.led(6,(float)!led_state); + led_state = !led_state; + } + + void musicGameOver(){ + lowFrequencyPartMusic(); + highFrequencyPartMusic(); + high_frequency_music_counter++; + low_frequency_music_counter++;//comment out this for epic game over beat. + //printf("Low frequency counter value:: %i\n", low_frequency_music_counter); + //printf("high frequency counter value:: %i\n", high_frequency_music_counter); + } + + void lowFrequencyPartMusic(){ + // Low frequency + if (low_frequency_music_counter == 0){ gamepad.tone(60,3);} + else if (low_frequency_music_counter == 3){gamepad.tone(90,3);} + else if (low_frequency_music_counter == 6){gamepad.tone(60,3);} + else if (low_frequency_music_counter == 9){gamepad.tone(80,3);} + else if (low_frequency_music_counter == 12){gamepad.tone(70,2);} + else if (low_frequency_music_counter == 14){gamepad.tone(60,2);} + else if (low_frequency_music_counter == 16){gamepad.tone(70,3);} + else if (low_frequency_music_counter == 19){gamepad.tone(50,1);} + else if (low_frequency_music_counter == 20){gamepad.tone(40,3);} + else if (low_frequency_music_counter== 23){ + gamepad.tone(60,2); + low_frequency_music_counter = 0; + } +} + + void highFrequencyPartMusic(){ + // High frequency + if ( high_frequency_music_counter == 0){ gamepad.tone(300,0.1);} + else if (high_frequency_music_counter == 3){gamepad.tone(250,0.1);} + else if (high_frequency_music_counter == 6){gamepad.tone(230,0.2);} + else if (high_frequency_music_counter == 9){gamepad.tone(250,0.1);} + else if ( high_frequency_music_counter == 12){gamepad.tone(250,0.2);} + else if ( high_frequency_music_counter == 14){gamepad.tone(220,0.1);} + else if ( high_frequency_music_counter == 16){gamepad.tone(210,0.3);} + else if ( high_frequency_music_counter == 19){gamepad.tone(200,1);} + else if ( high_frequency_music_counter == 21){gamepad.tone(250,1);} + else if ( high_frequency_music_counter == 22){ + gamepad.tone(200,1); + high_frequency_music_counter = 0; + } + } + + bool started; + static const int animation_length = 42; + int animation_counter; + GameObject gameOverLogo; + GameObject youDied; + bool led_state; + int low_frequency_music_counter; + int high_frequency_music_counter; +}; + +#endif \ No newline at end of file