Dependencies: mbed
Diff: main.cpp
- Revision:
- 4:c5addc5475d3
- Parent:
- 3:36f9e3a75905
- Child:
- 5:256e5e0b6cd7
--- a/main.cpp Wed May 06 11:35:18 2020 +0000 +++ b/main.cpp Fri May 08 08:40:29 2020 +0000 @@ -17,6 +17,7 @@ #include "Snake.h" + // objects Gamepad pad; N5110 lcd; @@ -30,14 +31,47 @@ { lcd.init(); - welcome(); //display welcome age on start up + welcome(); + pad.init(); //display welcome age on start up input.mode(PullUp); while(1) { + /*Direction _d = pad.get_direction(); + if (_d == N) { + printf("North\n"); + } else if (_d == NE) { + printf("North East\n"); + } else if (_d == E) { + printf("East\n"); + } else if (_d == SE) { + printf("South East\n"); + } else if (_d == S) { + printf("South\n"); + } else if (_d == SW) { + printf("South West\n"); + } else if (_d == W) { + printf("West\n"); + } else if (_d == NW) { + printf("North West\n"); + } else { + printf("Centre\n"); + };*/ int state = input; //creates an integer number from button input - //printf("state: %d\n", state); + printf("state: %d\n", state); //switch state based on button presses switch(state) { case 3: + + snake.init(1,3); + + while(1) { + lcd.clear(); + snake.draw(lcd); + Direction _d = pad.get_direction(); + //printf("Stick direction: %s", d); + snake.change_direction(_d); + snake.update(); + lcd.refresh(); + wait(0.5); } break; case 5: @@ -55,6 +89,8 @@ } + + void welcome() { lcd.printString("SNAKE", 28, 0); lcd.printString("A.Play Game", 0, 1);