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.
Diff: main.cpp
- Revision:
- 9:fe86ddbf7799
- Parent:
- 8:9d01fd4a63ad
- Child:
- 10:279d3775d52c
--- a/main.cpp Sun May 06 20:17:50 2018 +0000
+++ b/main.cpp Sun May 06 20:49:48 2018 +0000
@@ -12,6 +12,7 @@
#include "Gamepad.h"
#include "N5110.h"
#include "Engine.h"
+#include "Menu.h"
/////////////// structs /////////////////
struct UserInput {
@@ -22,31 +23,35 @@
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
Engine gameEngine;
+Menu mainMenu;
///////////// prototypes ///////////////
void init();
void update_game(UserInput input);
-void render();
+void renderGame();
+void renderMenu();
void welcome();
-void menu();
///////////// functions ////////////////
int main()
-{
- int fps = 8; // frames per second
-
+{
init();
welcome();
- wait(1.0f/fps); // and wait for one frame period
+ wait(1.0f/8); // and wait for one frame period
// game loop - read input, update the game state and render the display
while (1) {
- gameEngine.read_input(pad);
- gameEngine.update(pad);
- render();
- wait(1.0f/fps);
+ if (mainMenu.started()) {
+ gameEngine.read_input(pad);
+ gameEngine.update(pad);
+ renderGame();
+ } else {
+ mainMenu.read_input(pad);
+ mainMenu.update(); //draws the main menu before the game fully starts
+ renderMenu();
+ }
}
}
@@ -63,8 +68,7 @@
pad.leds_off();
wait(0.1);
}
-
- menu();
+
}
void init()
@@ -73,14 +77,28 @@
gameEngine.init();
lcd.init();
pad.init();
+ mainMenu.init();
}
-void render()
+void renderGame()
{
+
+ int fps = 8; // frames per second
+
// clear screen, re-draw and refresh
lcd.clear();
gameEngine.draw(lcd);
lcd.refresh();
+ wait(1.0f/fps);
}
+void renderMenu()
+{
+ // clear screen, re-draw and refresh
+ lcd.clear();
+ mainMenu.draw(lcd);
+ lcd.refresh();
+ wait(1.0f/8);
+}
+