ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el19zf

Dependencies:   mbed

Revision:
8:8287d2ef965d
Parent:
6:dce38fe4e092
Child:
9:62d6559f0d50
--- a/Collision/Collision.cpp	Wed Apr 29 05:10:57 2020 +0000
+++ b/Collision/Collision.cpp	Wed Apr 29 15:20:34 2020 +0000
@@ -8,3 +8,48 @@
 
 }
 
+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;
+}
+    
+
+