Yufan Zhong / Mbed 2 deprecated GOLD_MINER

Dependencies:   mbed

main.cpp

Committer:
ZhongYufan
Date:
2020-04-22
Revision:
1:9c7bb3db32bc
Parent:
0:edf120185e12
Child:
7:5bb5cde8951a

File content as of revision 1:9c7bb3db32bc:

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

Name: Yufan Zhong
Username: el17yz
Student ID Number: 201199708
Date: May,2020

*/ 
 

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

#ifdef WITH_TESTING
# include "tests.h"
#endif

#define WINCH_WIDTH 12
#define WINCH_HEIGHT 6
#define CLAW_SPEED 3
#define MONSTER_SIZE 3

/////////////// structs /////////////////
struct UserInput {
    Direction d;
    float mag;
};
/////////////// objects ///////////////
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
MinerEngine Miner;

///////////// prototypes ///////////////
void init();
void update_game(UserInput input);
void render();
void welcome();

///////////// functions ////////////////
int main()
{
     
#ifdef WITH_TESTING
    int number_of_failures = run_all_tests();

    if(number_of_failures > 0) return number_of_failures;
#endif

    int fps = 8;  // frames per second

    init();     // initialise and then display welcome screen...
    welcome();  // waiting for the user to start
    
    render();  // first draw the initial frame 
    wait(1.0f/fps);  // and wait for one frame period


    // game loop - read input, update the game state and render the display
    while (1) {
        miner.read_input(pad);
        miner.update(pad);
        render();
        wait(1.0f/fps);
    }
}

// initialies all classes and libraries
void init()
{
    // need to initialise LCD and Gamepad 
    lcd.init();
    pad.init();
     
    // initialise the game with correct claw and winch sizes
    miner.init(WINCH_WIDTH,WINCH_HEIGHT,MONSTER_SIZE,CLAW_SPEED);

}

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

// simple splash screen displayed on start-up
void welcome() {
    
    miner.welcome(pad,lcd);
    miner.menu(pad,lcd);
    
}