submit

Dependencies:   mbed Gamepad N5110

main.cpp

Committer:
694617778
Date:
2019-04-14
Revision:
3:1358cbb05ad3
Parent:
2:934daa65f73d
Child:
4:323f42022d87

File content as of revision 3:1358cbb05ad3:

///////// pre-processor directives ////////
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "snake.h"
#include "Engine.h"

/////////////// objects ///////////////
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
snake snake;
Engine engine;

///////////// prototypes ///////////////
void init();
void run();

///////////// functions ////////////////
int main()
{
    int fps = 8;  // frames per second
    
    init(); 
    engine.welcome(pad,lcd);  // show welcome display, waiting for the user to start
    
     // game loop - read input, update the game state and render the display
    while (snake.over == 0) {
    run();
    wait(1.0f/fps);  // and wait for one frame period
    }
    engine.gameover(pad,lcd);

 
}



// this function draws each frame on the LCD
void run()
{
    // clear screen, re-draw and refresh
    lcd.clear();
    int length = snake.get_length();
    snake.check_eat(pad);
    snake.draw(lcd,length);
    int direction = engine.get_direction(pad);
    snake.update(direction,length);
    snake.check_over(lcd);
    lcd.refresh();
}

// initialies all classes and libraries
void init()
{
    // need to initialise LCD and Gamepad 
    lcd.init();
    pad.init();    
    snake.init(2,3);
     
}