Ellis Blackford Stroud 201155309

Dependencies:   mbed FATFileSystem

main.cpp

Committer:
ellisbhastroud
Date:
2019-03-29
Revision:
3:a8960004d261
Parent:
2:81cfa8310f55
Child:
4:035448357749

File content as of revision 3:a8960004d261:

/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Ellis Blackford Stroud
Username: el17ebs
Student ID Number: 201155309
Date: 09/05/19
*/
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "Menu.h"
#include "Ball.h"


// objects 
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
Menu menu;
Ball ball;
void init();

int main()
{
    init();
    lcd.clear();
    menu.print_welcome(lcd);
    menu.print_menu(lcd);
    bool start_game = false; 
    
    //menu loop navigates menu until game started
    while(start_game == false) {
        menu.menu_select(pad, lcd); //main menu cursor code loops until start pressed
        start_game = menu.menu_change(lcd, pad); //changes menu screen to choice returns true if game started
        //check if game has been started
        if(start_game == false) {
            menu.menu_return(lcd, pad); //if game not started wait until back pressed
        }
    }  
    //code to run game 
    
    int x_pos = 24;
    int y_pos = 24;
    float x_vel = 0.0f;
    float y_vel = 0.0f;
    ball.init(x_pos, y_pos);
    ball.set_vel(x_vel, y_vel);
    
    while(1){ 
    
        lcd.clear();
        ball.move_ball();
        ball.draw_ball(lcd);
        ball.read_joy(pad);
        ball.draw_aim(lcd);
        ball.draw_screen(lcd);
        ball.shoot_ball(pad);
        lcd.refresh();

        wait(0.1);
    }
    
}

void init()
{
    lcd.init();
    lcd.setContrast(0.5);
    pad.init();
}