ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18jgb

Dependencies:   mbed

Eng.cpp

Committer:
el18jgb
Date:
2020-05-17
Revision:
6:d560ecc21ae6
Parent:
5:c37f4ed2cad3
Child:
7:04a7826ff7e4

File content as of revision 6:d560ecc21ae6:


#include "Eng.h"
Eng::Eng()
{

}

Eng::~Eng()
{

}
// objects
//Gamepad pad;
//N5110 lcd;
Aim aim;
Heston heston;


void Eng::init()
{
    
    aim.init();
    heston.init();


}

//void Eng::read_input(Gamepad &pad);
void Eng::update(Gamepad &pad, bool fire, N5110 &lcd)
{
        if (fire == 1){
            aim.draw(lcd, fire);
            lcd.refresh();
            wait(0.1);
            check_hit(pad);
        }
        heston.update(pad);
        aim.update(pad);


}

void Eng::draw(N5110 &lcd)
{
    heston.draw(lcd);
    aim.draw(lcd, 0);
}

void Eng::check_hit(Gamepad &pad)
{
    Vector2D aim_pos = aim.get_pos();
    Vector2D h1_pos = heston.get_pos();
    
    if (
        (aim_pos.y >= h1_pos.y) && //top
        (aim_pos.y <= h1_pos.y + 12) && //bottom
        (aim_pos.x >= h1_pos.x) && //left
        (aim_pos.x <= h1_pos.x + 11)  //right
    ) {
        heston.hit(pad);
}

}