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:
- 9:192ad897ec95
- Parent:
- 6:0bc6813fe434
- Child:
- 11:ba1906f151fd
--- a/main.cpp Mon Apr 22 03:37:34 2019 +0000
+++ b/main.cpp Sun Apr 28 21:32:06 2019 +0000
@@ -12,11 +12,20 @@
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
-//#include "CopterEngine.h"
+#include "CopterEngine.h"
+#ifdef WITH_TESTING
+# include "tests.h"
+#endif
+
+
+#define WALL_SIZE 3
+#define BIRD_WIDTH 15
+#define BIRD_HEIGHT 10
+#define BIRD_SPEED 1
/////////////// structs /////////////////
struct UserInput {
Direction d;
@@ -25,7 +34,13 @@
/////////////// objects ///////////////
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
-//CopterEngine copter;
+CopterEngine copter;
+extern N5110 lcd;
+
+
+
+
+
@@ -35,7 +50,7 @@
void render();
void welcome();
-////////////// functions ////////////////
+///////////// functions ////////////////
int main()
@@ -43,59 +58,60 @@
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
+ 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) {
-
- lcd.clear();
-
- int a = copter.GameOver();
- if(a == 1) {
- a=0;
- lcd.clear();
- lcd.printString("GAME OVER", 10,1);
- lcd.refresh();
- int h=0;
- for(h=1; h<=500; h++) {
- pad.tone(h,0.5);
- }
-
- wait(1.0);
- lcd.printString("PRESS BACK",13,3);
- lcd.printString("RESTART",20,4);
- lcd.refresh();
- while (pad.check_event(Gamepad::BACK_PRESSED)== false) {
-
- pad.leds_on();
- wait(0.1);
- }
-
- init();
- welcome();
-
- render();
- wait(1.0f/fps);
- }
-
+
+ lcd.clear();
+
+ int a = copter.GameOver();
+ if(a == 1)
+ { a=0;
+ lcd.clear();
+ lcd.printString("GAME OVER", 10,1);
+ lcd.refresh();
+ int h=0;
+ for(h=1; h<=500; h++){
+ pad.tone(h,0.5);
+ }
+
+ wait(1.0);
+ lcd.printString("PRESS BACK" ,13,3);
+ lcd.printString("RESTART",20,4);
+ lcd.refresh();
+ while (pad.check_event(Gamepad::BACK_PRESSED)== false)
+ {
+
+ pad.leds_on();
+ wait(0.1);
+ }
+
+ init();
+ welcome();
+
+ render();
+ wait(1.0f/fps);
+ }
+
copter.read_input(pad);
copter.update(pad);
-
+
render();
wait(1.0f/fps);
-
+
}
-}
+}
// initialies all classes and libraries
void init()
{
- // need to initialise LCD and Gamepad
+ // need to initialise LCD and Gamepad
lcd.init();
pad.init();
-
- copter.init(COPTER_WIDTH,COPTER_HEIGHT,WALL_SIZE,COPTER_SPEED,WALL1_SIZE,WALL2_SIZE);
+
+ copter.init(BIRD_WIDTH,BIRD_HEIGHT,WALL_SIZE,BIRD_SPEED);
}
@@ -103,25 +119,26 @@
void render()
{
// clear screen, re-draw and refresh
- lcd.clear();
+ lcd.clear();
copter.draw(lcd);
lcd.refresh();
}
-void welcome()
-{
+// simple splash screen displayed on start-up
+void welcome() {
pad.leds_on();
lcd.printString("COPTER", 25,1);
lcd.printString("Press START ",10,3);
lcd.printString("to Start ",20,5);
lcd.refresh();
-
+
//print the symbal on the screen
+ // wait flashing LEDs until start button is pressed
while ( pad.check_event(Gamepad::START_PRESSED) == false) {
pad.leds_on();
wait(0.2);
- pad.tone(50,0.1);
+ /* pad.tone(50,0.1);
wait(0.2);
pad.tone(100,0.1);
wait(0.2);
@@ -146,7 +163,7 @@
pad.tone(100,0.1);
wait(0.2);
pad.tone(50,0.1);
-
+ */
}
-
+
}
\ No newline at end of file