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@8:8287d2ef965d, 2020-04-29 (annotated)
- Committer:
- el19zf
- Date:
- Wed Apr 29 15:20:34 2020 +0000
- Revision:
- 8:8287d2ef965d
- Parent:
- 6:dce38fe4e092
- Child:
- 9:62d6559f0d50
update class collision and game mechanics
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el19zf | 6:dce38fe4e092 | 1 | #include "Collision.h" |
el19zf | 6:dce38fe4e092 | 2 | |
el19zf | 6:dce38fe4e092 | 3 | Collision::Collision() { |
el19zf | 6:dce38fe4e092 | 4 | |
el19zf | 6:dce38fe4e092 | 5 | } |
el19zf | 6:dce38fe4e092 | 6 | |
el19zf | 6:dce38fe4e092 | 7 | Collision::~Collision() { |
el19zf | 6:dce38fe4e092 | 8 | |
el19zf | 6:dce38fe4e092 | 9 | } |
el19zf | 6:dce38fe4e092 | 10 | |
el19zf | 8:8287d2ef965d | 11 | void Collision::init() { |
el19zf | 8:8287d2ef965d | 12 | _health = 3; |
el19zf | 8:8287d2ef965d | 13 | _check_index = 0; |
el19zf | 8:8287d2ef965d | 14 | |
el19zf | 8:8287d2ef965d | 15 | } |
el19zf | 8:8287d2ef965d | 16 | |
el19zf | 8:8287d2ef965d | 17 | bool Collision::check(N5110 &lcd) { |
el19zf | 8:8287d2ef965d | 18 | |
el19zf | 8:8287d2ef965d | 19 | _check_index = 0; |
el19zf | 8:8287d2ef965d | 20 | if(lcd.getPixel(_people_pos.x+1,_people_pos.y)) { _check_index = 1; }//check every sprite set points |
el19zf | 8:8287d2ef965d | 21 | if(lcd.getPixel(_people_pos.x+2,_people_pos.y)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 22 | if(lcd.getPixel(_people_pos.x,_people_pos.y+1)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 23 | if(lcd.getPixel(_people_pos.x+1,_people_pos.y+1)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 24 | if(lcd.getPixel(_people_pos.x+2,_people_pos.y+1)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 25 | if(lcd.getPixel(_people_pos.x+3,_people_pos.y+1)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 26 | if(lcd.getPixel(_people_pos.x+1,_people_pos.y+2)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 27 | if(lcd.getPixel(_people_pos.x+2,_people_pos.y+2)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 28 | if(lcd.getPixel(_people_pos.x+1,_people_pos.y+3)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 29 | if(lcd.getPixel(_people_pos.x+2,_people_pos.y+3)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 30 | //printf("index = %d\n",_check_index); |
el19zf | 8:8287d2ef965d | 31 | //printf("people_pos = %f,%f\n",_people_pos.x+2,_people_pos.y+3); |
el19zf | 8:8287d2ef965d | 32 | if((_check_index == 1)&&(_health > 0)) { |
el19zf | 8:8287d2ef965d | 33 | //_check_index = 0; |
el19zf | 8:8287d2ef965d | 34 | _health = _health - 1; |
el19zf | 8:8287d2ef965d | 35 | } |
el19zf | 8:8287d2ef965d | 36 | return _check_index; |
el19zf | 8:8287d2ef965d | 37 | //printf("health is %d\n",_health); |
el19zf | 8:8287d2ef965d | 38 | |
el19zf | 8:8287d2ef965d | 39 | } |
el19zf | 8:8287d2ef965d | 40 | |
el19zf | 8:8287d2ef965d | 41 | void Collision::draw(N5110 &lcd) { |
el19zf | 8:8287d2ef965d | 42 | if(_health > 0) |
el19zf | 8:8287d2ef965d | 43 | lcd.drawRect(1,1,_health,2,FILL_TRANSPARENT); |
el19zf | 8:8287d2ef965d | 44 | } |
el19zf | 8:8287d2ef965d | 45 | |
el19zf | 8:8287d2ef965d | 46 | int Collision::get_health() { |
el19zf | 8:8287d2ef965d | 47 | return _health; |
el19zf | 8:8287d2ef965d | 48 | } |
el19zf | 8:8287d2ef965d | 49 | |
el19zf | 8:8287d2ef965d | 50 | void Collision::set_pos(Vector2D pos) { |
el19zf | 8:8287d2ef965d | 51 | _people_pos = pos; |
el19zf | 8:8287d2ef965d | 52 | } |
el19zf | 8:8287d2ef965d | 53 | |
el19zf | 8:8287d2ef965d | 54 | |
el19zf | 8:8287d2ef965d | 55 |