ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18jgb

Dependencies:   mbed

Eng.cpp

Committer:
el18jgb
Date:
2020-05-17
Revision:
5:c37f4ed2cad3
Parent:
4:6f898b000797
Child:
6:d560ecc21ae6

File content as of revision 5:c37f4ed2cad3:


#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)
{
        check_hit(pad);
        
        heston.update(pad);
        aim.update(pad);


}

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

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);
}

}