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@17:74de8c17ddac, 2019-04-24 (annotated)
- Committer:
- el17m2h
- Date:
- Wed Apr 24 10:37:47 2019 +0000
- Revision:
- 17:74de8c17ddac
- Parent:
- 16:e0542761fc8c
- Child:
- 18:9f40a2f8c2c5
Corrected the errors in the engine h file and the doodler's update function.
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 | 16:e0542761fc8c | 7 | void Bullet::init(float dood_position_x, float dood_position_y){ |
| el17m2h | 16:e0542761fc8c | 8 | _radius = 1; |
| el17m2h | 16:e0542761fc8c | 9 | _position_x = dood_position_x; // initially in same position as doodler |
| el17m2h | 16:e0542761fc8c | 10 | _position_y = dood_position_y; |
| 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 | 16:e0542761fc8c | 17 | void Bullet::update(float dood_position_x, float dood_position_y, bool button_Y){ |
| el17m2h | 16:e0542761fc8c | 18 | _position_x = get_position_x(); |
| el17m2h | 16:e0542761fc8c | 19 | _position_y = get_position_y(); |
| el17m2h | 16:e0542761fc8c | 20 | if (button_Y == true){ |
| el17m2h | 16:e0542761fc8c | 21 | _position_y -= 2; // moves upwards |
| el17m2h | 16:e0542761fc8c | 22 | } |
| el17m2h | 16:e0542761fc8c | 23 | if (_position_y < 0){ // checking it leaves screen |
| el17m2h | 16:e0542761fc8c | 24 | _position_x =dood_position_x; |
| el17m2h | 16:e0542761fc8c | 25 | _position_y =dood_position_y; |
| el17m2h | 16:e0542761fc8c | 26 | } |
| el17m2h | 16:e0542761fc8c | 27 | } |
| el17m2h | 16:e0542761fc8c | 28 | |
| el17m2h | 16:e0542761fc8c | 29 | float Bullet::get_position_x(){ |
| el17m2h | 16:e0542761fc8c | 30 | float p_x = _position_x; |
| el17m2h | 16:e0542761fc8c | 31 | return p_x; |
| el17m2h | 16:e0542761fc8c | 32 | } |
| el17m2h | 16:e0542761fc8c | 33 | |
| el17m2h | 16:e0542761fc8c | 34 | float Bullet::get_position_y(){ |
| el17m2h | 16:e0542761fc8c | 35 | float p_y = _position_y; |
| el17m2h | 16:e0542761fc8c | 36 | return p_y; |
| el17m2h | 16:e0542761fc8c | 37 | } |
| el17m2h | 16:e0542761fc8c | 38 | |
| el17m2h | 16:e0542761fc8c | 39 | void Bullet::set_position(float pos_x, float pos_y){ |
| el17m2h | 16:e0542761fc8c | 40 | _position_x = pos_x; |
| el17m2h | 16:e0542761fc8c | 41 | _position_y = pos_y; |
| el17m2h | 16:e0542761fc8c | 42 | } |
| el17m2h | 16:e0542761fc8c | 43 |