Balint Bogdan SnekGame

Dependencies:   FoodLibrary Gamepad N5110 SnekGame mbed

Committer:
Nefos
Date:
Fri May 05 15:22:29 2017 +0000
Revision:
2:94b01aafb32f
Parent:
1:a222ad7a05b9
Handed in final version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nefos 0:789c74742603 1 #include "mbed.h"
Nefos 0:789c74742603 2 #include "N5110.h"
Nefos 1:a222ad7a05b9 3 #include "Gamepad.h"
Nefos 1:a222ad7a05b9 4
Nefos 1:a222ad7a05b9 5 #include "Snake.h"
Nefos 1:a222ad7a05b9 6
Nefos 1:a222ad7a05b9 7 /************************Structs************************/
Nefos 1:a222ad7a05b9 8 struct UserInput {
Nefos 1:a222ad7a05b9 9 Direction d;
Nefos 1:a222ad7a05b9 10
Nefos 1:a222ad7a05b9 11 };
Nefos 0:789c74742603 12
Nefos 0:789c74742603 13
Nefos 1:a222ad7a05b9 14 /************************Objects************************/
Nefos 1:a222ad7a05b9 15 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);//set LCD pins
Nefos 1:a222ad7a05b9 16 Gamepad pad;
Nefos 1:a222ad7a05b9 17 Snake snake;
Nefos 1:a222ad7a05b9 18
Nefos 1:a222ad7a05b9 19 //Serial pc(USBTX , USBRX );//tx, rx
Nefos 1:a222ad7a05b9 20 //Engine bman;
Nefos 0:789c74742603 21
Nefos 1:a222ad7a05b9 22 /************************Prototypes************************/
Nefos 1:a222ad7a05b9 23 void start_screen();
Nefos 1:a222ad7a05b9 24
Nefos 0:789c74742603 25
Nefos 1:a222ad7a05b9 26 /************************Variables************************/
Nefos 1:a222ad7a05b9 27
Nefos 1:a222ad7a05b9 28 //int heroChar[4]=(1,1,0,1);
Nefos 1:a222ad7a05b9 29 //int bomb[4]=(0,1,0,1);
Nefos 1:a222ad7a05b9 30 //int boulderLocation[4][8]={}// set the coordinate for boulder, if 00, boulder does not exist
Nefos 1:a222ad7a05b9 31
Nefos 1:a222ad7a05b9 32 /************************Main code************************/
Nefos 0:789c74742603 33 int main()
Nefos 0:789c74742603 34 {
Nefos 0:789c74742603 35 lcd.init();//initializing display
Nefos 1:a222ad7a05b9 36 pad.init();
Nefos 1:a222ad7a05b9 37 //pc.printf("initalized");
Nefos 2:94b01aafb32f 38 snake.init(25,25,5,3);
Nefos 1:a222ad7a05b9 39 start_screen();
Nefos 0:789c74742603 40 while (true) {
Nefos 2:94b01aafb32f 41
Nefos 1:a222ad7a05b9 42 //printf("updated");
Nefos 1:a222ad7a05b9 43 snake.draw(lcd);
Nefos 1:a222ad7a05b9 44 snake.update(pad);
Nefos 2:94b01aafb32f 45
Nefos 0:789c74742603 46 }
Nefos 0:789c74742603 47 }
Nefos 1:a222ad7a05b9 48 /************************Functions************************/
Nefos 0:789c74742603 49
Nefos 1:a222ad7a05b9 50 void start_screen(){
Nefos 2:94b01aafb32f 51
Nefos 1:a222ad7a05b9 52 lcd.printString("Snek, the game",0,1);
Nefos 1:a222ad7a05b9 53 lcd.printString("Press Start",0,4);
Nefos 1:a222ad7a05b9 54 lcd.refresh();
Nefos 1:a222ad7a05b9 55 printf("waiting for input");
Nefos 2:94b01aafb32f 56 while ( pad.check_event(Gamepad::START_PRESSED) == false) {//This switch code was taken from Pong, as it is a very simple code I left it here
Nefos 2:94b01aafb32f 57
Nefos 2:94b01aafb32f 58 pad.leds_on();
Nefos 2:94b01aafb32f 59 wait(0.1);
Nefos 2:94b01aafb32f 60 pad.leds_off();
Nefos 2:94b01aafb32f 61 wait(0.1);
Nefos 2:94b01aafb32f 62 printf("still...");
Nefos 2:94b01aafb32f 63
Nefos 0:789c74742603 64 }
Nefos 1:a222ad7a05b9 65 printf("done");
Nefos 2:94b01aafb32f 66 }
Nefos 2:94b01aafb32f 67