ELEC2645 (2018/19) / Mbed 2 deprecated EL17MCD

Dependencies:   mbed

main.cpp

Committer:
el17mcd
Date:
2019-04-09
Revision:
7:a3ccabdebe2e
Parent:
6:5d57c758c31d
Child:
8:d4e419dad90f

File content as of revision 7:a3ccabdebe2e:

/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Maxim C. Delacoe
Username: EL 17 MCD
Student ID Number: 2011 58344
Date: 19/03/2019
*/
///////// pre-processor directives ////////
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "Bitmap.h"
#include "TankL.h"
#include "TanksEngine.h"
#include "Projectile.h"

#ifdef WITH_TESTING

#endif

/////////////// objects ///////////////
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
TankL tankl;
Projectile proj;
TanksEngine engine;

void welcome()
{
    lcd.clear();
    lcd.printString("  ELEC 2645",0,0);
    lcd.printString("  Game  ",0,1);
    lcd.printString("   Project",0,2);
    lcd.printString("Max C. Delacoe",0,4);
    lcd.printString(" 2011 58344",0,5);
    lcd.refresh();
    wait(0.2);
}

int main()
{
    lcd.init();
    tankl.set_health(1);
   // welcome();  // display welcome message 

    while(1) {  // infinite loop
        
        srand(time(NULL));  
        int t_pos_x = rand() % (84-1-10); // Tank position
        int t_pos_y = rand() % (48-1-6);
        tankl.set_position(t_pos_x, t_pos_y);
        
        int p_pos_x = rand() % (84-1-5);  // projectile position
        int p_pos_y = rand() % (48-1-5);
        proj.set_position(p_pos_x, p_pos_y);
        
        tankl.generate_hitbox();
        proj.generate_hitbox();
        bool hit = engine.collision_pl(tankl, proj);   
        
        lcd.clear();
        tankl.draw(lcd);
        proj.draw(lcd);
        lcd.refresh(); 
        if (hit == true) {
            wait(1.5);
            lcd.clear();
            tankl.lose_health();
            lcd.printString("HIT",0,1);
            lcd.refresh();
            wait(0.5);
        }
        else {wait_ms(50);}
    }

}