Zeyu Feng 201377605
Dependencies: mbed
On Minerva
Diff: Collision/Collision.cpp
- Revision:
- 20:a36ab1560e73
- Parent:
- 17:ba4d9cd1e347
- Child:
- 22:cded0cd8e1c9
--- a/Collision/Collision.cpp Thu May 21 17:07:46 2020 +0000 +++ b/Collision/Collision.cpp Fri May 22 03:54:22 2020 +0000 @@ -23,35 +23,41 @@ void Collision::init() { _health = 3; - _check_index = 0; + _check_col_index = 0; _check_des_index = 0; } +void Collision::reset_check_col() +{ + _check_col_index = 0; +} + bool Collision::check(N5110 &lcd) { - _check_index = 0; + _check_col_index = 0; //check main part of people expect hands and foots(x,y+3)(x+4,y+3)(x,y+7)(x+4,y+7) - if(lcd.getPixel(_people_pos.x+1,_people_pos.y)) { _check_index = 1; } - if(lcd.getPixel(_people_pos.x+3,_people_pos.y)) { _check_index = 1; } - if(lcd.getPixel(_people_pos.x+1,_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+1)) { _check_index = 1; } - if(lcd.getPixel(_people_pos.x+3,_people_pos.y+3)) { _check_index = 1; } - if(lcd.getPixel(_people_pos.x+1,_people_pos.y+5)) { _check_index = 1; } - if(lcd.getPixel(_people_pos.x+3,_people_pos.y+5)) { _check_index = 1; } - if(lcd.getPixel(_people_pos.x,_people_pos.y+6)) { _check_index = 1; } - if(lcd.getPixel(_people_pos.x+4,_people_pos.y+6)) { _check_index = 1; } - if(lcd.getPixel(_people_pos.x+2,_people_pos.y+3)) { _check_index = 1; } - //printf("index = %d\n",_check_index); + if(lcd.getPixel(_people_pos.x+1,_people_pos.y)) { _check_col_index = 1; } + if(lcd.getPixel(_people_pos.x+3,_people_pos.y)) { _check_col_index = 1; } + if(lcd.getPixel(_people_pos.x+1,_people_pos.y+1)) { _check_col_index = 1; } + if(lcd.getPixel(_people_pos.x+3,_people_pos.y+1)) { _check_col_index = 1; } + if(lcd.getPixel(_people_pos.x+1,_people_pos.y+1)) { _check_col_index = 1; } + if(lcd.getPixel(_people_pos.x+3,_people_pos.y+3)) { _check_col_index = 1; } + if(lcd.getPixel(_people_pos.x+1,_people_pos.y+5)) { _check_col_index = 1; } + if(lcd.getPixel(_people_pos.x+3,_people_pos.y+5)) { _check_col_index = 1; } + if(lcd.getPixel(_people_pos.x,_people_pos.y+6)) { _check_col_index = 1; } + if(lcd.getPixel(_people_pos.x+4,_people_pos.y+6)) { _check_col_index = 1; } + if(lcd.getPixel(_people_pos.x+2,_people_pos.y+3)) { _check_col_index = 1; } + //printf("index = %d\n",_check_col_index); //printf("people_pos = %f,%f\n",_people_pos.x+2,_people_pos.y+3); - if((_check_index == 1)&&(_health > 0)) { - //_check_index = 0; + if((_check_col_index == 1)&&(_health > 0)) { + //_check_col_index = 0; _health = _health - 1; } - return _check_index; + return _check_col_index; //printf("health is %d\n",_health); } +//use a getPixel function to check whether 'People' reaches the destination bool Collision::check_des(N5110 &lcd) { _check_des_index = 0; @@ -65,6 +71,7 @@ return _check_des_index; } +//draw the health indicator at the top left corner void Collision::draw(N5110 &lcd) { if(_health > 0) @@ -79,6 +86,8 @@ lcd.drawRect(1,1,3,HEIGHT-2,FILL_BLACK); lcd.drawRect(80,1,3,HEIGHT-2,FILL_BLACK); } + +//draw a 1 second collision interface to clearly show the health decreases void Collision::draw_collision(N5110 &lcd) { lcd.clear(); @@ -110,15 +119,10 @@ bool Collision::get_check_col() { - return _check_index; + return _check_col_index; } void Collision::set_pos(Vector2D pos) { _people_pos = pos; } - -void Collision::set_check_col() -{ - _check_index = 0; -} \ No newline at end of file