200943373MAZE

Dependencies:   Gamepad N5110 mbed

Committer:
hongyunAHN
Date:
Thu May 04 11:25:43 2017 +0000
Revision:
0:df4347043adf
200943373 hongyun AHN

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hongyunAHN 0:df4347043adf 1
hongyunAHN 0:df4347043adf 2 #include "mbed.h"
hongyunAHN 0:df4347043adf 3 #include "Gamepad.h"
hongyunAHN 0:df4347043adf 4 #include "N5110.h"
hongyunAHN 0:df4347043adf 5 #include "Background.h"
hongyunAHN 0:df4347043adf 6
hongyunAHN 0:df4347043adf 7
hongyunAHN 0:df4347043adf 8
hongyunAHN 0:df4347043adf 9 struct UserInput {
hongyunAHN 0:df4347043adf 10 Direction d;
hongyunAHN 0:df4347043adf 11 float mag;
hongyunAHN 0:df4347043adf 12 };
hongyunAHN 0:df4347043adf 13
hongyunAHN 0:df4347043adf 14 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
hongyunAHN 0:df4347043adf 15 Gamepad pad;
hongyunAHN 0:df4347043adf 16 Background back;
hongyunAHN 0:df4347043adf 17
hongyunAHN 0:df4347043adf 18 void init();
hongyunAHN 0:df4347043adf 19 void update_game(UserInput input);
hongyunAHN 0:df4347043adf 20 void render();
hongyunAHN 0:df4347043adf 21 void welcome();
hongyunAHN 0:df4347043adf 22
hongyunAHN 0:df4347043adf 23 int main()
hongyunAHN 0:df4347043adf 24 {
hongyunAHN 0:df4347043adf 25 int fps = 8;
hongyunAHN 0:df4347043adf 26
hongyunAHN 0:df4347043adf 27 init();
hongyunAHN 0:df4347043adf 28 welcome();
hongyunAHN 0:df4347043adf 29
hongyunAHN 0:df4347043adf 30 render();
hongyunAHN 0:df4347043adf 31 wait(1.0f/fps);
hongyunAHN 0:df4347043adf 32
hongyunAHN 0:df4347043adf 33
hongyunAHN 0:df4347043adf 34 while (1) {
hongyunAHN 0:df4347043adf 35 back.read_input(pad);
hongyunAHN 0:df4347043adf 36 back.update(pad,lcd);
hongyunAHN 0:df4347043adf 37 render();
hongyunAHN 0:df4347043adf 38 wait(1.0f/fps);
hongyunAHN 0:df4347043adf 39 }
hongyunAHN 0:df4347043adf 40 }
hongyunAHN 0:df4347043adf 41
hongyunAHN 0:df4347043adf 42 void init()
hongyunAHN 0:df4347043adf 43 {
hongyunAHN 0:df4347043adf 44 lcd.init();
hongyunAHN 0:df4347043adf 45 pad.init();
hongyunAHN 0:df4347043adf 46
hongyunAHN 0:df4347043adf 47 back.init();
hongyunAHN 0:df4347043adf 48
hongyunAHN 0:df4347043adf 49 }
hongyunAHN 0:df4347043adf 50
hongyunAHN 0:df4347043adf 51 void render()
hongyunAHN 0:df4347043adf 52 {
hongyunAHN 0:df4347043adf 53
hongyunAHN 0:df4347043adf 54 lcd.clear();
hongyunAHN 0:df4347043adf 55 back.draw(lcd);
hongyunAHN 0:df4347043adf 56 lcd.refresh();
hongyunAHN 0:df4347043adf 57 }
hongyunAHN 0:df4347043adf 58
hongyunAHN 0:df4347043adf 59 void welcome() {
hongyunAHN 0:df4347043adf 60
hongyunAHN 0:df4347043adf 61 lcd.printString(" MAZE ",0,2);
hongyunAHN 0:df4347043adf 62 lcd.printString(" Press Start ",0,5);
hongyunAHN 0:df4347043adf 63 lcd.refresh();
hongyunAHN 0:df4347043adf 64
hongyunAHN 0:df4347043adf 65
hongyunAHN 0:df4347043adf 66 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
hongyunAHN 0:df4347043adf 67 pad.leds_on();
hongyunAHN 0:df4347043adf 68 wait(0.3);
hongyunAHN 0:df4347043adf 69 pad.leds_off();
hongyunAHN 0:df4347043adf 70 wait(0.2);
hongyunAHN 0:df4347043adf 71 }
hongyunAHN 0:df4347043adf 72
hongyunAHN 0:df4347043adf 73 }