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
Diff: main.cpp
- Revision:
- 7:e0cab3e73df9
- Parent:
- 6:e7ac87a41840
- Child:
- 8:3c15554e6723
diff -r e7ac87a41840 -r e0cab3e73df9 main.cpp
--- a/main.cpp Wed May 08 10:08:56 2019 +0000
+++ b/main.cpp Wed May 08 19:25:27 2019 +0000
@@ -4,7 +4,6 @@
#include "N5110.h"
#include "SpaceRebEngine.h"
-
#define SPACEINVADER_WIDTH 8
#define SPACEINVADER_HEIGHT 11
#define MISSILES_SIZE 2
@@ -25,26 +24,37 @@
void update_game(UserInput input);
void render();
void welcome();
-
+void Game1Over();
+///////////// gloabal variable ////////////////
+bool end = false;
+float counter = 1.0;
+int score = 0;
+int speed = MISSILES_SPEED;
///////////// functions ////////////////
int main()
{
+ start:
+ end = false;
int fps = 8; // frames per second
-
+
init(); // initialise and then display welcome screen...
welcome(); // waiting for the user to start
render(); // first draw the initial frame
wait(1.0f/fps); // and wait for one frame period
-
// game loop - read input, update the game state and render the display
- while (1) {
+ while (!end) {
spacerebellion.read_input(pad);
spacerebellion.update(pad);
render();
+ end = spacerebellion.game_end();
wait(1.0f/fps);
+ counter = counter + 1/8;
}
+ lcd.clear();
+ Game1Over();
+ goto start;
}
// initialies all classes and libraries
@@ -85,3 +95,20 @@
}
}
+
+void Game1Over() {
+ lcd.printString(" You died! ",0,1);
+ lcd.printString(" Score =",0,2);
+ spacerebellion.print_scores(lcd);
+ lcd.printString("Press BACK...",0,4);
+ lcd.refresh();
+ // wait flashing LEDs until start button is pressed
+ while ( pad.check_event(Gamepad::BACK_PRESSED) == false) {
+ pad.leds_on();
+ wait(0.1);
+ pad.leds_off();
+ wait(0.1);
+ }
+
+}
+