Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Collision/Collision.cpp
- Committer:
- el19zf
- Date:
- 2020-05-11
- Revision:
- 11:494cc44777fe
- Parent:
- 9:62d6559f0d50
- Child:
- 12:009895f6b6e4
File content as of revision 11:494cc44777fe:
#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,FILL_TRANSPARENT);
}
int Collision::get_health()
{
return _health;
}
int Collision::get_des()
{
return _check_des_index;
}
void Collision::set_pos(Vector2D pos)
{
_people_pos = pos;
}