Arturs Kozlovskis / Mbed 2 deprecated ELEC2645_Project_el18ak

Dependencies:   mbed

main.cpp

Committer:
thestudent
Date:
2020-05-07
Revision:
16:e2aaef863d7c
Parent:
15:3f558f8b54ea
Child:
17:cb208b15be5c

File content as of revision 16:e2aaef863d7c:

/*
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"


// objects
Gamepad pad;
N5110 lcd;



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

//variables
bool game_check = false;
bool game_playing = false;


int main()
{
    initialise();
    while(1) {
        //create the game
        game();
    }
}

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

}

void game()
{
    
    Objects objects;
    Functions functions;
    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);//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.15);

        lcd.clear();
        //added this so the cannon moves faster than the balls
        objects.cannon_position(pad);//eveluates the cannon position
        objects.draw_cannon(lcd);//draws the cannon
        lcd.refresh();
        wait(0.005);
    }
    //prints the the score and game over and the continue option
    lcd.printString("Game over!", 15,2);
    char buf_score[4];
    sprintf(buf_score,"%d",functions.get_score());
    lcd.printString("Score:",0,0);
    lcd.printString(buf_score,36,0);
    lcd.refresh();
    wait(2);
    game_check = false;
}