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
Enemy/Enemy.cpp@20:a359092079b0, 2019-04-25 (annotated)
- Committer:
- el17m2h
- Date:
- Thu Apr 25 11:34:01 2019 +0000
- Revision:
- 20:a359092079b0
- Child:
- 23:9be87557b89a
I added a rectangle for the screen, updated the screen range and removed a floor. Added a tone for when the bullet is shot. Also added an enemy file that in contact with doodler the game ends. It also disappears if shot by bullet.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17m2h | 20:a359092079b0 | 1 | #include "Enemy.h" |
el17m2h | 20:a359092079b0 | 2 | Enemy::Enemy(){ |
el17m2h | 20:a359092079b0 | 3 | } |
el17m2h | 20:a359092079b0 | 4 | Enemy::~Enemy(){ |
el17m2h | 20:a359092079b0 | 5 | } |
el17m2h | 20:a359092079b0 | 6 | |
el17m2h | 20:a359092079b0 | 7 | void Enemy::init(float floor_pos_x, float floor_pos_y){ // sets its position |
el17m2h | 20:a359092079b0 | 8 | _radius = 3; |
el17m2h | 20:a359092079b0 | 9 | _position.x = floor_pos_x + 4; |
el17m2h | 20:a359092079b0 | 10 | _position.y = floor_pos_y + 4; |
el17m2h | 20:a359092079b0 | 11 | } |
el17m2h | 20:a359092079b0 | 12 | |
el17m2h | 20:a359092079b0 | 13 | void Enemy::draw(N5110 &lcd){ |
el17m2h | 20:a359092079b0 | 14 | lcd.drawCircle(_position.x, _position.y, _radius, FILL_TRANSPARENT); |
el17m2h | 20:a359092079b0 | 15 | } |
el17m2h | 20:a359092079b0 | 16 | |
el17m2h | 20:a359092079b0 | 17 | void Enemy::update(float floor_pos_x, float floor_pos_y){ // decides if it gets erased |
el17m2h | 20:a359092079b0 | 18 | bullet_pos_y = b.get_position_y(); |
el17m2h | 20:a359092079b0 | 19 | _position.x = floor_pos_x + 4; |
el17m2h | 20:a359092079b0 | 20 | _position.y = floor_pos_y + 4; |
el17m2h | 20:a359092079b0 | 21 | if (_position.y + 3 > bullet_pos_y){ |
el17m2h | 20:a359092079b0 | 22 | _position.x = 90; // out of the screen and if pos x = 90 then lower point |
el17m2h | 20:a359092079b0 | 23 | } |
el17m2h | 20:a359092079b0 | 24 | } |
el17m2h | 20:a359092079b0 | 25 | |
el17m2h | 20:a359092079b0 | 26 | Vector2D Enemy::get_position(){ |
el17m2h | 20:a359092079b0 | 27 | Vector2D p = {_position.x,_position.y}; |
el17m2h | 20:a359092079b0 | 28 | return p; |
el17m2h | 20:a359092079b0 | 29 | } |
el17m2h | 20:a359092079b0 | 30 | |
el17m2h | 20:a359092079b0 | 31 | void Enemy::set_position(Vector2D pos){ |
el17m2h | 20:a359092079b0 | 32 | _position.x = pos.x; |
el17m2h | 20:a359092079b0 | 33 | _position.y = pos.y; |
el17m2h | 20:a359092079b0 | 34 | } |