Balint Bogdan SnekGame

Dependencies:   FoodLibrary Gamepad N5110 SnekGame mbed

Committer:
Nefos
Date:
Fri May 05 11:56:20 2017 +0000
Revision:
1:a222ad7a05b9
Parent:
0:789c74742603
Child:
2:94b01aafb32f
Food+snake made, ready to make food work;

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 void init();
Nefos 1:a222ad7a05b9 25 void display();
Nefos 1:a222ad7a05b9 26 void update_game(UserInput input);
Nefos 1:a222ad7a05b9 27
Nefos 0:789c74742603 28
Nefos 1:a222ad7a05b9 29 /************************Variables************************/
Nefos 1:a222ad7a05b9 30
Nefos 1:a222ad7a05b9 31 //int heroChar[4]=(1,1,0,1);
Nefos 1:a222ad7a05b9 32 //int bomb[4]=(0,1,0,1);
Nefos 1:a222ad7a05b9 33 //int boulderLocation[4][8]={}// set the coordinate for boulder, if 00, boulder does not exist
Nefos 1:a222ad7a05b9 34
Nefos 1:a222ad7a05b9 35 /************************Main code************************/
Nefos 0:789c74742603 36 int main()
Nefos 0:789c74742603 37 {
Nefos 0:789c74742603 38 lcd.init();//initializing display
Nefos 1:a222ad7a05b9 39 pad.init();
Nefos 1:a222ad7a05b9 40 //pc.printf("initalized");
Nefos 1:a222ad7a05b9 41 snake.init(25,25,6);
Nefos 1:a222ad7a05b9 42 start_screen();
Nefos 0:789c74742603 43 while (true) {
Nefos 1:a222ad7a05b9 44 //run game engine
Nefos 1:a222ad7a05b9 45 //implement safety features
Nefos 1:a222ad7a05b9 46 //start stop buttons here for menu
Nefos 1:a222ad7a05b9 47
Nefos 1:a222ad7a05b9 48 pad.leds_on();
Nefos 1:a222ad7a05b9 49 wait(0.05f);
Nefos 1:a222ad7a05b9 50 pad.leds_off();
Nefos 1:a222ad7a05b9 51 wait(0.1f);
Nefos 1:a222ad7a05b9 52 //engine.getInput(pad);
Nefos 1:a222ad7a05b9 53 //snake.update(pad);
Nefos 1:a222ad7a05b9 54 //printf("updated");
Nefos 1:a222ad7a05b9 55 snake.draw(lcd);
Nefos 1:a222ad7a05b9 56 snake.update(pad);
Nefos 1:a222ad7a05b9 57 //wait(0.2f);
Nefos 0:789c74742603 58 }
Nefos 0:789c74742603 59 }
Nefos 1:a222ad7a05b9 60 /************************Functions************************/
Nefos 0:789c74742603 61
Nefos 1:a222ad7a05b9 62 void start_screen(){
Nefos 1:a222ad7a05b9 63 lcd.printString("Snek, the game",0,1);
Nefos 1:a222ad7a05b9 64 lcd.printString("Press Start",0,4);
Nefos 1:a222ad7a05b9 65 lcd.refresh();
Nefos 1:a222ad7a05b9 66 printf("waiting for input");
Nefos 1:a222ad7a05b9 67 while ( pad.check_event(Gamepad::START_PRESSED) == false) {//this is a placeholder code from pong, change it please
Nefos 1:a222ad7a05b9 68 pad.leds_on();
Nefos 1:a222ad7a05b9 69 wait(0.1);
Nefos 1:a222ad7a05b9 70 pad.leds_off();
Nefos 1:a222ad7a05b9 71 wait(0.1);
Nefos 1:a222ad7a05b9 72 printf("still...");
Nefos 0:789c74742603 73 }
Nefos 1:a222ad7a05b9 74 printf("done");
Nefos 1:a222ad7a05b9 75 }
Nefos 1:a222ad7a05b9 76
Nefos 1:a222ad7a05b9 77 void init(){
Nefos 0:789c74742603 78
Nefos 1:a222ad7a05b9 79 lcd.init();//initalizing display
Nefos 1:a222ad7a05b9 80 pad.init();//inita;izing pad
Nefos 1:a222ad7a05b9 81
Nefos 1:a222ad7a05b9 82 //bman.init();//initalizing game
Nefos 0:789c74742603 83 }
Nefos 0:789c74742603 84
Nefos 1:a222ad7a05b9 85 void display() {
Nefos 0:789c74742603 86
Nefos 1:a222ad7a05b9 87 lcd.clear();
Nefos 1:a222ad7a05b9 88 //bman.display(lcd);
Nefos 1:a222ad7a05b9 89 lcd.refresh();
Nefos 1:a222ad7a05b9 90 }