Arturs Kozlovskis / Mbed 2 deprecated ELEC2645_Project_el18ak

Dependencies:   mbed

main.cpp

Committer:
thestudent
Date:
2020-05-21
Revision:
27:da17a102c8d0
Parent:
24:74a53dd49806
Child:
28:b6f048f46ffb

File content as of revision 27:da17a102c8d0:

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

Name:Arturs Kolovskis
Username:el18ak
Student ID Number: 201253737
Date:08.03.2020
*/

// includes
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "Objects.h"
#include "Functions.h"
#include "Menu.h"


// objects
Gamepad pad;
N5110 lcd;
Menu menu(lcd,pad);

//functions
void initialise();
void game();

//variables
bool game_check = false;
int pause_return_value = 0;
int game_return_value = 2;
string game_speed;
float extra_speed = 0.05;

int main()
{
    initialise();
    //creates the inital screen
    menu.first_screen();
    //infinite game and menu loop 
    while(1) {
        //menu
        menu.menu_screen();
        //checks the game speed setting
        game_speed = menu.get_game_speed();
        if (game_speed == "fast"){
            extra_speed = 0.0f;
        }else{
            //decreasesn the speed
            extra_speed = 0.05f;
        }
        //create the game
        game();
    }
}

void initialise()
{
    pad.init();//initialises the gamepad
    lcd.init();//initialises the N5110 screen
    lcd.clear();
}

void game()
{
    //creates class objects
    Objects objects;
    Functions functions;
    
    //runs the game engine
    while(game_check == false) {

        lcd.clear();
        objects.draw_shots(lcd,pad, true);// draws the shot
        
        //creates the balls and clears the shots
        functions.ball_creater_linear(lcd, objects, pad);
        functions.ball_creater_parabolic(lcd,objects,pad);
        
        objects.draw_shots(lcd,pad, true);//again draws the shots so they would be visible on the screen
        functions.collision_checker(lcd,objects,pad);//cheks for the collisions
        objects.draw_base(lcd);//draws the base of the game
        objects.cannon_position(pad);//changes the cannon postion
        objects.draw_cannon(lcd);//draws the cannon
        game_check = functions.cannon_smash(lcd, objects); //checks if the cannon has been hit by a ball
        lcd.refresh();
        wait(0.1f + extra_speed);

        //added this so the cannon moves faster than the balls
        lcd.clear();
        objects.cannon_position(pad);//eveluates the cannon position
        objects.draw_cannon(lcd);//draws the cannon
        lcd.refresh();
        wait(0.005);
        
        //if a pressed display pause screen
        pause_return_value = menu.pause_screen(functions.get_score());
        if(pause_return_value == 1) {
            break;
        }
    }
    
    if(pause_return_value == 0) {
        //prints the the score and game over
        game_return_value = menu.game_over_screen(functions.get_score());
        if (game_return_value == 2) {
            game_check = false;
        }
    }  
}