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@29:15e9640646b7, 2019-05-08 (annotated)
- Committer:
- el17m2h
- Date:
- Wed May 08 21:11:35 2019 +0000
- Revision:
- 29:15e9640646b7
- Parent:
- 24:67dc71a8f009
- Child:
- 31:5c4acae51026
Changed the enemy file so that it has functions to make it update its position or make it disappear from the screen. The floors h file includes the enemy, and depending on its position it updates it or not.
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| el17m2h | 16:e0542761fc8c | 1 | #include "Bullet.h" | 
| el17m2h | 29:15e9640646b7 | 2 | Bullet::Bullet() | 
| el17m2h | 29:15e9640646b7 | 3 | { | 
| el17m2h | 16:e0542761fc8c | 4 | } | 
| el17m2h | 29:15e9640646b7 | 5 | Bullet::~Bullet() | 
| el17m2h | 29:15e9640646b7 | 6 | { | 
| el17m2h | 16:e0542761fc8c | 7 | } | 
| el17m2h | 16:e0542761fc8c | 8 | |
| el17m2h | 29:15e9640646b7 | 9 | void Bullet::init(float dood_pos_x, float dood_pos_y) | 
| el17m2h | 29:15e9640646b7 | 10 | { | 
| el17m2h | 16:e0542761fc8c | 11 | _radius = 1; | 
| el17m2h | 29:15e9640646b7 | 12 | _position_x = dood_pos_x + 12; | 
| el17m2h | 23:9be87557b89a | 13 | _position_y = dood_pos_y + 4; | 
| el17m2h | 16:e0542761fc8c | 14 | } | 
| el17m2h | 16:e0542761fc8c | 15 | |
| el17m2h | 29:15e9640646b7 | 16 | void Bullet::draw(N5110 &lcd) | 
| el17m2h | 29:15e9640646b7 | 17 | { | 
| el17m2h | 16:e0542761fc8c | 18 | lcd.drawCircle(_position_x, _position_y, _radius, FILL_BLACK); | 
| el17m2h | 16:e0542761fc8c | 19 | } | 
| el17m2h | 16:e0542761fc8c | 20 | |
| el17m2h | 29:15e9640646b7 | 21 | void Bullet::update(float dood_pos_x, float dood_pos_y) | 
| el17m2h | 29:15e9640646b7 | 22 | { | 
| el17m2h | 19:5a7b0cdf013b | 23 | _position_y -= 3; | 
| el17m2h | 29:15e9640646b7 | 24 | if (_position_y < 9) { // reached end of screen | 
| el17m2h | 24:67dc71a8f009 | 25 | _position_x = dood_pos_x + 12; | 
| el17m2h | 23:9be87557b89a | 26 | _position_y = dood_pos_y + 4; | 
| el17m2h | 16:e0542761fc8c | 27 | } | 
| el17m2h | 16:e0542761fc8c | 28 | } | 
| el17m2h | 16:e0542761fc8c | 29 | |
| el17m2h | 29:15e9640646b7 | 30 | float Bullet::get_position_x() | 
| el17m2h | 29:15e9640646b7 | 31 | { | 
| el17m2h | 29:15e9640646b7 | 32 | float p_x = _position_x; | 
| el17m2h | 16:e0542761fc8c | 33 | return p_x; | 
| el17m2h | 16:e0542761fc8c | 34 | } | 
| el17m2h | 16:e0542761fc8c | 35 | |
| el17m2h | 29:15e9640646b7 | 36 | float Bullet::get_position_y() | 
| el17m2h | 29:15e9640646b7 | 37 | { | 
| el17m2h | 16:e0542761fc8c | 38 | float p_y = _position_y; | 
| el17m2h | 16:e0542761fc8c | 39 | return p_y; | 
| el17m2h | 16:e0542761fc8c | 40 | } | 
| el17m2h | 16:e0542761fc8c | 41 | |
| el17m2h | 29:15e9640646b7 | 42 | void Bullet::set_position(float pos_x, float pos_y) | 
| el17m2h | 29:15e9640646b7 | 43 | { | 
| el17m2h | 29:15e9640646b7 | 44 | _position_x = pos_x; | 
| el17m2h | 16:e0542761fc8c | 45 | _position_y = pos_y; | 
| el17m2h | 16:e0542761fc8c | 46 | } | 
| el17m2h | 16:e0542761fc8c | 47 |