ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el19zf

Dependencies:   mbed

Collision/Collision.cpp

Committer:
el19zf
Date:
2020-05-11
Revision:
12:009895f6b6e4
Parent:
11:494cc44777fe
Child:
13:eb60628db8bf

File content as of revision 12:009895f6b6e4:

#include "Collision.h"

Collision::Collision() 
{
    
}

Collision::~Collision() 
{

}

void Collision::init() 
{
    _health = 3;
    _check_index = 0;
    _check_des_index = 0;
}

bool Collision::check(N5110 &lcd) 
{
    _check_index = 0;
    //check every sprite set points
    if(lcd.getPixel(_people_pos.x+1,_people_pos.y)) {  _check_index = 1; }
    if(lcd.getPixel(_people_pos.x+2,_people_pos.y)) {  _check_index = 1; }
    if(lcd.getPixel(_people_pos.x,_people_pos.y+1)) {  _check_index = 1; }
    if(lcd.getPixel(_people_pos.x+1,_people_pos.y+1)) {  _check_index = 1; }
    if(lcd.getPixel(_people_pos.x+2,_people_pos.y+1)) {  _check_index = 1; }
    if(lcd.getPixel(_people_pos.x+3,_people_pos.y+1)) {  _check_index = 1; }
    if(lcd.getPixel(_people_pos.x+1,_people_pos.y+2)) {  _check_index = 1; }
    if(lcd.getPixel(_people_pos.x+2,_people_pos.y+2)) {  _check_index = 1; }
    if(lcd.getPixel(_people_pos.x+1,_people_pos.y+3)) {  _check_index = 1; }
    if(lcd.getPixel(_people_pos.x+2,_people_pos.y+3)) {  _check_index = 1; }
    //printf("index = %d\n",_check_index);
    //printf("people_pos = %f,%f\n",_people_pos.x+2,_people_pos.y+3);
    if((_check_index == 1)&&(_health > 0)) { 
        //_check_index = 0;
        _health = _health - 1;
    }
    return _check_index;
    //printf("health is %d\n",_health);
}

bool Collision::check_des(N5110 &lcd)
{
    _check_des_index = 0;
    if(lcd.getPixel(82,24)||lcd.getPixel(82,25)||lcd.getPixel(82,26)||
    lcd.getPixel(82,27)||lcd.getPixel(82,23)||lcd.getPixel(82,22)||
    lcd.getPixel(82,21)||lcd.getPixel(82,20)||lcd.getPixel(82,28))
    {
        _check_des_index = 1;
        //printf("reach des\n");
    }
    return _check_des_index;
}

void Collision::draw(N5110 &lcd) 
{
    if(_health > 0)
        lcd.drawRect(1,1,_health*2,3,FILL_BLACK);
}

int Collision::get_health() 
{
    return _health;
}

int Collision::get_des()
{
    return _check_des_index;
}

void Collision::set_pos(Vector2D pos) 
{
    _people_pos = pos;
}