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@19:5a7b0cdf013b, 2019-04-25 (annotated)
- Committer:
- el17m2h
- Date:
- Thu Apr 25 08:43:46 2019 +0000
- Revision:
- 19:5a7b0cdf013b
- Parent:
- 18:9f40a2f8c2c5
- Child:
- 23:9be87557b89a
Added a game over function to the main file so that once the doodler hits the floor the game is finalized.
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 | 18:9f40a2f8c2c5 | 17 | void Bullet::update(float position_x, float position_y, float dood_pos_x, float dood_pos_y){ |
| el17m2h | 18:9f40a2f8c2c5 | 18 | _position_x = position_x; |
| el17m2h | 19:5a7b0cdf013b | 19 | _position_y -= 3; |
| el17m2h | 18:9f40a2f8c2c5 | 20 | if (_position_y < 0){ // reached end of screen |
| el17m2h | 18:9f40a2f8c2c5 | 21 | _position_x = dood_pos_x; |
| el17m2h | 18:9f40a2f8c2c5 | 22 | _position_y = dood_pos_y; |
| el17m2h | 16:e0542761fc8c | 23 | } |
| el17m2h | 16:e0542761fc8c | 24 | } |
| el17m2h | 16:e0542761fc8c | 25 | |
| el17m2h | 16:e0542761fc8c | 26 | float Bullet::get_position_x(){ |
| el17m2h | 16:e0542761fc8c | 27 | float p_x = _position_x; |
| el17m2h | 16:e0542761fc8c | 28 | return p_x; |
| el17m2h | 16:e0542761fc8c | 29 | } |
| el17m2h | 16:e0542761fc8c | 30 | |
| el17m2h | 16:e0542761fc8c | 31 | float Bullet::get_position_y(){ |
| el17m2h | 16:e0542761fc8c | 32 | float p_y = _position_y; |
| el17m2h | 16:e0542761fc8c | 33 | return p_y; |
| el17m2h | 16:e0542761fc8c | 34 | } |
| el17m2h | 16:e0542761fc8c | 35 | |
| el17m2h | 16:e0542761fc8c | 36 | void Bullet::set_position(float pos_x, float pos_y){ |
| el17m2h | 16:e0542761fc8c | 37 | _position_x = pos_x; |
| el17m2h | 16:e0542761fc8c | 38 | _position_y = pos_y; |
| el17m2h | 16:e0542761fc8c | 39 | } |
| el17m2h | 16:e0542761fc8c | 40 |