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
Bullet/Bullet.cpp@23:9be87557b89a, 2019-05-08 (annotated)
- Committer:
- el17m2h
- Date:
- Wed May 08 08:46:11 2019 +0000
- Revision:
- 23:9be87557b89a
- Parent:
- 19:5a7b0cdf013b
- Child:
- 24:67dc71a8f009
Added a sprite for the doodler and the enemy.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el17m2h | 16:e0542761fc8c | 1 | #include "Bullet.h" |
| el17m2h | 16:e0542761fc8c | 2 | Bullet::Bullet(){ |
| el17m2h | 16:e0542761fc8c | 3 | } |
| el17m2h | 16:e0542761fc8c | 4 | Bullet::~Bullet(){ |
| el17m2h | 16:e0542761fc8c | 5 | } |
| el17m2h | 16:e0542761fc8c | 6 | |
| el17m2h | 23:9be87557b89a | 7 | void Bullet::init(float dood_pos_x, float dood_pos_y){ |
| el17m2h | 16:e0542761fc8c | 8 | _radius = 1; |
| el17m2h | 23:9be87557b89a | 9 | _position_x = dood_pos_x + 15; // initially in same position as doodler's trunk |
| el17m2h | 23:9be87557b89a | 10 | _position_y = dood_pos_y + 4; |
| el17m2h | 16:e0542761fc8c | 11 | } |
| el17m2h | 16:e0542761fc8c | 12 | |
| el17m2h | 16:e0542761fc8c | 13 | void Bullet::draw(N5110 &lcd){ |
| el17m2h | 16:e0542761fc8c | 14 | lcd.drawCircle(_position_x, _position_y, _radius, FILL_BLACK); |
| el17m2h | 16:e0542761fc8c | 15 | } |
| el17m2h | 16:e0542761fc8c | 16 | |
| el17m2h | 23:9be87557b89a | 17 | void Bullet::update(float dood_pos_x, float dood_pos_y){ |
| el17m2h | 19:5a7b0cdf013b | 18 | _position_y -= 3; |
| el17m2h | 23:9be87557b89a | 19 | if (_position_y < 9){ // reached end of screen |
| el17m2h | 23:9be87557b89a | 20 | _position_x = dood_pos_x + 15; |
| el17m2h | 23:9be87557b89a | 21 | _position_y = dood_pos_y + 4; |
| el17m2h | 16:e0542761fc8c | 22 | } |
| el17m2h | 16:e0542761fc8c | 23 | } |
| el17m2h | 16:e0542761fc8c | 24 | |
| el17m2h | 16:e0542761fc8c | 25 | float Bullet::get_position_x(){ |
| el17m2h | 16:e0542761fc8c | 26 | float p_x = _position_x; |
| el17m2h | 16:e0542761fc8c | 27 | return p_x; |
| el17m2h | 16:e0542761fc8c | 28 | } |
| el17m2h | 16:e0542761fc8c | 29 | |
| el17m2h | 16:e0542761fc8c | 30 | float Bullet::get_position_y(){ |
| el17m2h | 16:e0542761fc8c | 31 | float p_y = _position_y; |
| el17m2h | 16:e0542761fc8c | 32 | return p_y; |
| el17m2h | 16:e0542761fc8c | 33 | } |
| el17m2h | 16:e0542761fc8c | 34 | |
| el17m2h | 16:e0542761fc8c | 35 | void Bullet::set_position(float pos_x, float pos_y){ |
| el17m2h | 16:e0542761fc8c | 36 | _position_x = pos_x; |
| el17m2h | 16:e0542761fc8c | 37 | _position_y = pos_y; |
| el17m2h | 16:e0542761fc8c | 38 | } |
| el17m2h | 16:e0542761fc8c | 39 |