Aiming Wu / Mbed 2 deprecated Game

Dependencies:   mbed N5110

Committer:
Wuuu
Date:
Fri May 03 13:03:59 2019 +0000
Revision:
0:7173d91b03e1
Copter, which with header programme.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wuuu 0:7173d91b03e1 1 #include "mbed.h"
Wuuu 0:7173d91b03e1 2 #include "N5110.h"
Wuuu 0:7173d91b03e1 3 #include "Gamepad.h"
Wuuu 0:7173d91b03e1 4 #include "Game1.h"
Wuuu 0:7173d91b03e1 5
Wuuu 0:7173d91b03e1 6 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Wuuu 0:7173d91b03e1 7 Gamepad pad;
Wuuu 0:7173d91b03e1 8 Game1 gam;
Wuuu 0:7173d91b03e1 9
Wuuu 0:7173d91b03e1 10 void init();
Wuuu 0:7173d91b03e1 11 void welcome();
Wuuu 0:7173d91b03e1 12 void loading();
Wuuu 0:7173d91b03e1 13 void game();
Wuuu 0:7173d91b03e1 14
Wuuu 0:7173d91b03e1 15 int main() {
Wuuu 0:7173d91b03e1 16 while(1){
Wuuu 0:7173d91b03e1 17 init();
Wuuu 0:7173d91b03e1 18 welcome();
Wuuu 0:7173d91b03e1 19 loading();
Wuuu 0:7173d91b03e1 20 while(pad.check_event(Gamepad::BACK_PRESSED) == false) {
Wuuu 0:7173d91b03e1 21 game();
Wuuu 0:7173d91b03e1 22 }
Wuuu 0:7173d91b03e1 23 }
Wuuu 0:7173d91b03e1 24 }
Wuuu 0:7173d91b03e1 25
Wuuu 0:7173d91b03e1 26 void init() {
Wuuu 0:7173d91b03e1 27 lcd.init();
Wuuu 0:7173d91b03e1 28 pad.init();
Wuuu 0:7173d91b03e1 29 gam.init();
Wuuu 0:7173d91b03e1 30 }
Wuuu 0:7173d91b03e1 31
Wuuu 0:7173d91b03e1 32 void welcome() {
Wuuu 0:7173d91b03e1 33 lcd.clear();
Wuuu 0:7173d91b03e1 34 lcd.printString(" Copter! ",0,1);
Wuuu 0:7173d91b03e1 35 lcd.printString(" Press Start ",0,4);
Wuuu 0:7173d91b03e1 36 lcd.refresh();
Wuuu 0:7173d91b03e1 37
Wuuu 0:7173d91b03e1 38 // wait flashing LEDs until start button is pressed
Wuuu 0:7173d91b03e1 39 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
Wuuu 0:7173d91b03e1 40 pad.leds_on();
Wuuu 0:7173d91b03e1 41 wait(0.1);
Wuuu 0:7173d91b03e1 42 pad.leds_off();
Wuuu 0:7173d91b03e1 43 wait(0.1);
Wuuu 0:7173d91b03e1 44 }
Wuuu 0:7173d91b03e1 45
Wuuu 0:7173d91b03e1 46 }
Wuuu 0:7173d91b03e1 47
Wuuu 0:7173d91b03e1 48 void loading(){
Wuuu 0:7173d91b03e1 49 lcd.clear();
Wuuu 0:7173d91b03e1 50 lcd.printString(" READY!!! ",0,3);
Wuuu 0:7173d91b03e1 51 lcd.refresh();
Wuuu 0:7173d91b03e1 52 wait_ms(500);
Wuuu 0:7173d91b03e1 53 lcd.clear();
Wuuu 0:7173d91b03e1 54 lcd.printString(" 3 ",0,3);
Wuuu 0:7173d91b03e1 55 lcd.refresh();
Wuuu 0:7173d91b03e1 56 wait_ms(500);
Wuuu 0:7173d91b03e1 57 lcd.clear();
Wuuu 0:7173d91b03e1 58 lcd.printString(" 2 ",0,3);
Wuuu 0:7173d91b03e1 59 lcd.refresh();
Wuuu 0:7173d91b03e1 60 wait_ms(500);
Wuuu 0:7173d91b03e1 61 lcd.clear();
Wuuu 0:7173d91b03e1 62 lcd.printString(" 1 ",0,3);
Wuuu 0:7173d91b03e1 63 lcd.refresh();
Wuuu 0:7173d91b03e1 64 wait_ms(500);
Wuuu 0:7173d91b03e1 65 lcd.clear();
Wuuu 0:7173d91b03e1 66 lcd.printString(" GO!!! ",0,3);
Wuuu 0:7173d91b03e1 67 lcd.refresh();
Wuuu 0:7173d91b03e1 68 wait_ms(500);
Wuuu 0:7173d91b03e1 69 }
Wuuu 0:7173d91b03e1 70
Wuuu 0:7173d91b03e1 71 void game()
Wuuu 0:7173d91b03e1 72 {
Wuuu 0:7173d91b03e1 73 lcd.clear();
Wuuu 0:7173d91b03e1 74 int d = gam.draw(lcd, pad);
Wuuu 0:7173d91b03e1 75 if(d == 1) {
Wuuu 0:7173d91b03e1 76 while(1) {
Wuuu 0:7173d91b03e1 77 init();
Wuuu 0:7173d91b03e1 78 welcome();
Wuuu 0:7173d91b03e1 79 loading();
Wuuu 0:7173d91b03e1 80 while(pad.check_event(Gamepad::BACK_PRESSED) == false) {
Wuuu 0:7173d91b03e1 81 game();
Wuuu 0:7173d91b03e1 82 }
Wuuu 0:7173d91b03e1 83 }
Wuuu 0:7173d91b03e1 84 }
Wuuu 0:7173d91b03e1 85 lcd.refresh();
Wuuu 0:7173d91b03e1 86 wait(0.8);
Wuuu 0:7173d91b03e1 87 }