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 MotionSensor
Entity/Bullets/Bullets.cpp@26:abbc19edc5c1, 2019-04-29 (annotated)
- Committer:
- el17sm
- Date:
- Mon Apr 29 02:45:17 2019 +0000
- Revision:
- 26:abbc19edc5c1
- Parent:
- 23:5a8f75e93508
- Child:
- 27:a1b41626f57c
RoomEngine done, no test yet, Room h partial done;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el17sm | 13:d04a6caba40d | 1 | #include "Bullets.h" |
| el17sm | 13:d04a6caba40d | 2 | |
| el17sm | 22:7abf4581bc9b | 3 | Bullets::Bullets(float pos_x, float pos_y, int dir) |
| el17sm | 22:7abf4581bc9b | 4 | { |
| el17sm | 13:d04a6caba40d | 5 | moving = true; |
| el17sm | 13:d04a6caba40d | 6 | face = 0; |
| el17sm | 13:d04a6caba40d | 7 | hp = 1; |
| el17sm | 26:abbc19edc5c1 | 8 | hitbox.width = 3; |
| el17sm | 26:abbc19edc5c1 | 9 | hitbox.height = 3; |
| el17sm | 13:d04a6caba40d | 10 | position.x = pos_x; |
| el17sm | 13:d04a6caba40d | 11 | position.y = pos_y; |
| el17sm | 26:abbc19edc5c1 | 12 | sprite_size.width = 3; |
| el17sm | 26:abbc19edc5c1 | 13 | sprite_size.height = 3; |
| el17sm | 13:d04a6caba40d | 14 | sprite_size.offset_x = 0; |
| el17sm | 15:44d5cc33d389 | 15 | sprite_size.offset_y = 1; |
| el17sm | 13:d04a6caba40d | 16 | direction = dir; |
| el17sm | 13:d04a6caba40d | 17 | } |
| el17sm | 13:d04a6caba40d | 18 | |
| el17sm | 22:7abf4581bc9b | 19 | void Bullets::move(float speed, float unused) |
| el17sm | 22:7abf4581bc9b | 20 | { |
| el17sm | 22:7abf4581bc9b | 21 | if (direction == 0) { |
| el17sm | 14:3361879490b2 | 22 | position.y -= speed; |
| el17sm | 22:7abf4581bc9b | 23 | } else if (direction == 1) { |
| el17sm | 14:3361879490b2 | 24 | position.x += speed; |
| el17sm | 22:7abf4581bc9b | 25 | } else if (direction == 2) { |
| el17sm | 14:3361879490b2 | 26 | position.y += speed; |
| el17sm | 22:7abf4581bc9b | 27 | } else if (direction == 3) { |
| el17sm | 14:3361879490b2 | 28 | position.x -= speed; |
| el17sm | 14:3361879490b2 | 29 | } |
| el17sm | 13:d04a6caba40d | 30 | } |
| el17sm | 13:d04a6caba40d | 31 | |
| el17sm | 23:5a8f75e93508 | 32 | void Bullets::take_damage(int damage) |
| el17sm | 23:5a8f75e93508 | 33 | { |
| el17sm | 23:5a8f75e93508 | 34 | hp -= damage; |
| el17sm | 23:5a8f75e93508 | 35 | } |
| el17sm | 23:5a8f75e93508 | 36 | |
| el17sm | 22:7abf4581bc9b | 37 | int * Bullets::get_frame() |
| el17sm | 22:7abf4581bc9b | 38 | { |
| el17sm | 13:d04a6caba40d | 39 | return (int *) bullets_sprite; |
| el17sm | 14:3361879490b2 | 40 | } |
| el17sm | 14:3361879490b2 | 41 | |
| el17sm | 22:7abf4581bc9b | 42 | bool Bullets::out_of_bounds_check() |
| el17sm | 22:7abf4581bc9b | 43 | { |
| el17sm | 22:7abf4581bc9b | 44 | if (matrix_collision_test(position.x, position.y, 0)) { |
| el17sm | 14:3361879490b2 | 45 | return true; |
| el17sm | 14:3361879490b2 | 46 | } |
| el17sm | 22:7abf4581bc9b | 47 | if ((0 > position.x) || (position.x > 84) || (0 > position.y) || (position.y > 48)) { |
| el17sm | 14:3361879490b2 | 48 | return true; |
| el17sm | 14:3361879490b2 | 49 | } |
| el17sm | 14:3361879490b2 | 50 | return false; |
| el17sm | 13:d04a6caba40d | 51 | } |