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/Player/Bullets/Bullets.cpp@32:fe6359ef9916, 2019-05-06 (annotated)
- Committer:
- el17sm
- Date:
- Mon May 06 08:56:48 2019 +0000
- Revision:
- 32:fe6359ef9916
- Child:
- 33:4f3948dcd2f7
A bit of code cleanup;; Draw functions are now inside the classes;; Moved classes into it's folders;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el17sm | 32:fe6359ef9916 | 1 | #include "Bullets.h" |
| el17sm | 32:fe6359ef9916 | 2 | |
| el17sm | 32:fe6359ef9916 | 3 | Bullets::Bullets(float pos_x, float pos_y, int dir) |
| el17sm | 32:fe6359ef9916 | 4 | { |
| el17sm | 32:fe6359ef9916 | 5 | _damage_self_upon_collision = false; |
| el17sm | 32:fe6359ef9916 | 6 | moving = true; |
| el17sm | 32:fe6359ef9916 | 7 | face = 0; |
| el17sm | 32:fe6359ef9916 | 8 | hp = 1; |
| el17sm | 32:fe6359ef9916 | 9 | hitbox.width = 3; |
| el17sm | 32:fe6359ef9916 | 10 | hitbox.height = 3; |
| el17sm | 32:fe6359ef9916 | 11 | position.x = pos_x; |
| el17sm | 32:fe6359ef9916 | 12 | position.y = pos_y; |
| el17sm | 32:fe6359ef9916 | 13 | sprite_size.width = 3; |
| el17sm | 32:fe6359ef9916 | 14 | sprite_size.height = 3; |
| el17sm | 32:fe6359ef9916 | 15 | sprite_size.offset_x = 0; |
| el17sm | 32:fe6359ef9916 | 16 | sprite_size.offset_y = 1; |
| el17sm | 32:fe6359ef9916 | 17 | direction = dir; |
| el17sm | 32:fe6359ef9916 | 18 | } |
| el17sm | 32:fe6359ef9916 | 19 | |
| el17sm | 32:fe6359ef9916 | 20 | void Bullets::move(float speed, float unused, int * unused2, bool * unused3) |
| el17sm | 32:fe6359ef9916 | 21 | { |
| el17sm | 32:fe6359ef9916 | 22 | if (direction == 0) { |
| el17sm | 32:fe6359ef9916 | 23 | position.y -= speed; |
| el17sm | 32:fe6359ef9916 | 24 | } else if (direction == 1) { |
| el17sm | 32:fe6359ef9916 | 25 | position.x += speed; |
| el17sm | 32:fe6359ef9916 | 26 | } else if (direction == 2) { |
| el17sm | 32:fe6359ef9916 | 27 | position.y += speed; |
| el17sm | 32:fe6359ef9916 | 28 | } else if (direction == 3) { |
| el17sm | 32:fe6359ef9916 | 29 | position.x -= speed; |
| el17sm | 32:fe6359ef9916 | 30 | } |
| el17sm | 32:fe6359ef9916 | 31 | } |
| el17sm | 32:fe6359ef9916 | 32 | |
| el17sm | 32:fe6359ef9916 | 33 | void Bullets::draw(N5110 &lcd) |
| el17sm | 32:fe6359ef9916 | 34 | { |
| el17sm | 32:fe6359ef9916 | 35 | lcd.drawSpriteTransparent(position.x-sprite_size.offset_x, |
| el17sm | 32:fe6359ef9916 | 36 | position.y-sprite_size.offset_y, |
| el17sm | 32:fe6359ef9916 | 37 | sprite_size.height, |
| el17sm | 32:fe6359ef9916 | 38 | sprite_size.width, |
| el17sm | 32:fe6359ef9916 | 39 | get_frame()); |
| el17sm | 32:fe6359ef9916 | 40 | } |
| el17sm | 32:fe6359ef9916 | 41 | |
| el17sm | 32:fe6359ef9916 | 42 | void Bullets::take_damage(int damage) |
| el17sm | 32:fe6359ef9916 | 43 | { |
| el17sm | 32:fe6359ef9916 | 44 | hp -= damage; |
| el17sm | 32:fe6359ef9916 | 45 | } |
| el17sm | 32:fe6359ef9916 | 46 | |
| el17sm | 32:fe6359ef9916 | 47 | bool Bullets::out_of_bounds_check(int * map, bool * doorways) |
| el17sm | 32:fe6359ef9916 | 48 | { |
| el17sm | 32:fe6359ef9916 | 49 | if (entity_to_map_collision_test(position.x, position.y, map, doorways)) { |
| el17sm | 32:fe6359ef9916 | 50 | return true; |
| el17sm | 32:fe6359ef9916 | 51 | } |
| el17sm | 32:fe6359ef9916 | 52 | if ((0 > position.x) || (position.x > 84) || (0 > position.y) || (position.y > 48)) { |
| el17sm | 32:fe6359ef9916 | 53 | return true; |
| el17sm | 32:fe6359ef9916 | 54 | } |
| el17sm | 32:fe6359ef9916 | 55 | return false; |
| el17sm | 32:fe6359ef9916 | 56 | } |
| el17sm | 32:fe6359ef9916 | 57 | |
| el17sm | 32:fe6359ef9916 | 58 | int * Bullets::get_frame() |
| el17sm | 32:fe6359ef9916 | 59 | { |
| el17sm | 32:fe6359ef9916 | 60 | return (int *) bullets_sprite; |
| el17sm | 32:fe6359ef9916 | 61 | } |