test 1 doc

Dependencies:   mbed Gamepad2

main.cpp

Committer:
joebarhouch
Date:
2020-05-27
Revision:
11:b3024ab59fa5
Parent:
7:530ca713d2b2
Child:
12:eb8d30593e95

File content as of revision 11:b3024ab59fa5:

/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
2019/20

Name: Joe Barhouch
Username: el18jb
Student ID Number: 201291584
*/

// includes
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "Bitmap.h"
#include "Player.h"
#include "Engine.h"

// objects
Gamepad pad;
N5110 lcd;
Player player;
Engine engine;

// input
struct UserInput {
    Direction d;
    float mag;
};

// function prototypes
void init();
void display();

// variables
bool gameState = 0;

int main()
{


    init();

    int fps = 10;  // frames per second
    display();  // first draw the initial frame
    wait(1.0f/fps);  // and wait for one frame period
    // game loop
    while (gameState == 0) {
        lcd.setContrast( pad.read_pot1()); //contrast set by pot1
        engine.read_input(pad);            //reads input from pad
        engine.update(pad);                //update physics and calculations
        display();                         //display on screen
        wait(1.0f/fps);                    //wait for fps
        gameState = engine.enemyCollide();
    }
    engine.gameOver(lcd);
    lcd.refresh();
}

//initialisation
void init()
{
    lcd.init();
    pad.init();
    engine.init();
}

//display function by clearing, updating and refreshing
void display()
{
    lcd.clear();
    engine.draw(lcd);
    lcd.refresh();
}