ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el19zf

Dependencies:   mbed

Collision/Collision.cpp

Committer:
el19zf
Date:
2020-04-29
Revision:
8:8287d2ef965d
Parent:
6:dce38fe4e092
Child:
9:62d6559f0d50

File content as of revision 8:8287d2ef965d:

#include "Collision.h"

Collision::Collision() {
    
}

Collision::~Collision() {

}

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

bool Collision::check(N5110 &lcd) {
    
    _check_index = 0;
    if(lcd.getPixel(_people_pos.x+1,_people_pos.y)) {  _check_index = 1; }//check every sprite set points
    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);
    
}

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

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

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