Final Commit

Dependencies:   mbed

main.cpp

Committer:
JRM1986
Date:
2018-04-06
Revision:
11:e260c17a0489
Parent:
10:62d8cb7742c3
Child:
12:9f2f64016f56

File content as of revision 11:e260c17a0489:

#include "mbed.h"
#include "FXOS8700CQ.h"
#include "Gamepad.h"
#include "N5110.h"
#include "Testing.h"
#include "SnakeEngine.h"

#define FOOD_X 20
#define FOOD_Y 20

struct UserInput 
{
    
    Direction d;
    
};

/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Joshua Robert Marshall
Username: ll13jrm
Student ID Number: 200764543
Date: 28/02/2018
*/

// ----- Objects -----

SnakeEngine snake_engine;
Gamepad pad;
Snake snake;
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Testing test1;

// ----- Prototypes -----

void init();
void update_game(UserInput input);
void render();
void start_menu();

int main() {
        
        init();
        //render();
        wait(1.0);
        
        while(1) {
        
         snake_engine.get_input(pad, snake);
         snake_engine.update(pad);
         render();
         wait(1.0); 
         
               
  

    /*    
    if(test1.update_snake_test(W, E)) {
        
        printf("Passed direction test1 \n");
            
            }
    else {
            
        printf("Failed direction test \n");
            
          }*/
          
    if(test1.position_test(W, E)) {
        
        printf("Passed position test1 \n");
            
            }
    else {
            
        printf("Failed position test \n");
            
          }    
        
        }
    }
    
// initialies all classes and libraries
void init()
{
    // need to initialise LCD and Gamepad 
    lcd.init();
    pad.init();
     
    // initialise the game with food, snake...
    snake_engine.init();

}

// this function draws each frame on the LCD
void render()
{
    // clear screen, re-draw and refresh
    lcd.clear();
    snake_engine.draw(lcd);
    lcd.refresh();
    
}

void start_menu() {
    
    // brings up start menu, levels, scores
    
}