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:
- 3:3d35ab70b565
- Parent:
- 2:ee9b361ba6df
- Child:
- 4:3446009e2f38
--- a/main.cpp Sun May 05 21:54:07 2019 +0000
+++ b/main.cpp Mon May 06 19:50:27 2019 +0000
@@ -6,24 +6,23 @@
Engine engine;
int main() {
-
+
init();
welcome();
string option = menu();
begin(option);
-
+
lcd.printString(" END",0,3);
}
void init() {
-
-
+
// initialise display and peripherals
lcd.init();
pad.init();
-
+
// initialise any in game functions (e.g: sprites)
- engine.init(MAP_WIDTH,MAP_HEIGHT);
+ engine.init(MAP_WIDTH,MAP_HEIGHT,SCREEN_WIDTH,SCREEN_HEIGHT);
}
void welcome() {
@@ -40,7 +39,7 @@
lcd.printString("Foster",0,3);
lcd.refresh();
wait(2.0);
-
+
while (pad.check_event(Gamepad::START_PRESSED) == false) {
lcd.printString("Press start ",0,5);
lcd.refresh();
@@ -57,18 +56,18 @@
}
string menu() {
-
+
string option = "0";
lcd.init();
-
+
while(option == "0") {
-
+
lcd.printString("A - Play Now",0,1);
lcd.printString("B - Tutorial",0,2);
lcd.printString("X - Highscores",0,3);
lcd.printString("Y - Credits",0,4);
lcd.refresh();
-
+
if (pad.check_event(Gamepad::A_PRESSED) == true) {
option = "A";
} else if (pad.check_event(Gamepad::B_PRESSED) == true) {
@@ -78,7 +77,7 @@
} else if (pad.check_event(Gamepad::Y_PRESSED) == true) {
option = "Y";
}
-
+
wait(0.2);
}
if (option == "A") {
@@ -94,14 +93,14 @@
}
void ask(string option) {
-
+
int start = -1;
lcd.printString("Are you sure?",0,3);
lcd.printString("Back? Start?",0,5);
lcd.refresh();
-
+
while (start == -1) {
-
+
if (pad.check_event(Gamepad::START_PRESSED) == true) {
start = 1;
} else if(pad.check_event(Gamepad::BACK_PRESSED) == true) {
@@ -109,14 +108,14 @@
}
wait(0.2);
}
-
+
if (start == 0) {
menu();
}
}
void begin(string option) {
-
+
init();
if (option == "A") {
play();
@@ -131,9 +130,11 @@
void play() {
+ lcd.refresh();
wait(0.2);
-
- while (pad.check_event(Gamepad::START_PRESSED) == false) {
+
+ while ( pad.check_event(Gamepad::START_PRESSED) == false) {
+ lcd.refresh();
engine.read(pad);
engine.write(MAX_SPEED);
engine.render(lcd);
@@ -142,19 +143,19 @@
}
void tutorial() {
-
+
lcd.printString(" Tutorial!! ",0,0);
lcd.refresh();
}
void highscores() {
-
+
lcd.printString(" Highscores!! ",0,0);
lcd.refresh();
}
void credits() {
-
+
lcd.printString(" Credits!! ",0,0);
lcd.refresh();
}
\ No newline at end of file