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@9:62d6559f0d50, 2020-05-09 (annotated)
- Committer:
- el19zf
- Date:
- Sat May 09 08:27:07 2020 +0000
- Revision:
- 9:62d6559f0d50
- Parent:
- 8:8287d2ef965d
- Child:
- 11:494cc44777fe
update mechanism of game, make harder
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 | 9:62d6559f0d50 | 20 | //check every sprite set points |
el19zf | 9:62d6559f0d50 | 21 | if(lcd.getPixel(_people_pos.x+1,_people_pos.y)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 22 | if(lcd.getPixel(_people_pos.x+2,_people_pos.y)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 23 | if(lcd.getPixel(_people_pos.x,_people_pos.y+1)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 24 | if(lcd.getPixel(_people_pos.x+1,_people_pos.y+1)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 25 | if(lcd.getPixel(_people_pos.x+2,_people_pos.y+1)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 26 | if(lcd.getPixel(_people_pos.x+3,_people_pos.y+1)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 27 | if(lcd.getPixel(_people_pos.x+1,_people_pos.y+2)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 28 | if(lcd.getPixel(_people_pos.x+2,_people_pos.y+2)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 29 | if(lcd.getPixel(_people_pos.x+1,_people_pos.y+3)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 30 | if(lcd.getPixel(_people_pos.x+2,_people_pos.y+3)) { _check_index = 1; } |
el19zf | 8:8287d2ef965d | 31 | //printf("index = %d\n",_check_index); |
el19zf | 8:8287d2ef965d | 32 | //printf("people_pos = %f,%f\n",_people_pos.x+2,_people_pos.y+3); |
el19zf | 8:8287d2ef965d | 33 | if((_check_index == 1)&&(_health > 0)) { |
el19zf | 8:8287d2ef965d | 34 | //_check_index = 0; |
el19zf | 8:8287d2ef965d | 35 | _health = _health - 1; |
el19zf | 8:8287d2ef965d | 36 | } |
el19zf | 8:8287d2ef965d | 37 | return _check_index; |
el19zf | 8:8287d2ef965d | 38 | //printf("health is %d\n",_health); |
el19zf | 8:8287d2ef965d | 39 | |
el19zf | 8:8287d2ef965d | 40 | } |
el19zf | 8:8287d2ef965d | 41 | |
el19zf | 8:8287d2ef965d | 42 | void Collision::draw(N5110 &lcd) { |
el19zf | 8:8287d2ef965d | 43 | if(_health > 0) |
el19zf | 8:8287d2ef965d | 44 | lcd.drawRect(1,1,_health,2,FILL_TRANSPARENT); |
el19zf | 8:8287d2ef965d | 45 | } |
el19zf | 8:8287d2ef965d | 46 | |
el19zf | 8:8287d2ef965d | 47 | int Collision::get_health() { |
el19zf | 8:8287d2ef965d | 48 | return _health; |
el19zf | 8:8287d2ef965d | 49 | } |
el19zf | 8:8287d2ef965d | 50 | |
el19zf | 8:8287d2ef965d | 51 | void Collision::set_pos(Vector2D pos) { |
el19zf | 8:8287d2ef965d | 52 | _people_pos = pos; |
el19zf | 8:8287d2ef965d | 53 | } |
el19zf | 8:8287d2ef965d | 54 | |
el19zf | 8:8287d2ef965d | 55 | |
el19zf | 8:8287d2ef965d | 56 |