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@59:fd4669864b67, 2019-05-09 (annotated)
- Committer:
- el17sm
- Date:
- Thu May 09 14:49:27 2019 +0000
- Revision:
- 59:fd4669864b67
- Parent:
- 57:1c12361b6e3d
wtf y no work
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 | 53:93338b52489d | 3 | // Constructor |
| el17sm | 32:fe6359ef9916 | 4 | Bullets::Bullets(float pos_x, float pos_y, int dir) |
| el17sm | 32:fe6359ef9916 | 5 | { |
| el17sm | 57:1c12361b6e3d | 6 | _face = dir; |
| el17sm | 57:1c12361b6e3d | 7 | _hp = 1; |
| el17sm | 53:93338b52489d | 8 | |
| el17sm | 57:1c12361b6e3d | 9 | _hitbox.width = 3; |
| el17sm | 57:1c12361b6e3d | 10 | _hitbox.height = 3; |
| el17sm | 53:93338b52489d | 11 | |
| el17sm | 57:1c12361b6e3d | 12 | _position.x = pos_x; |
| el17sm | 57:1c12361b6e3d | 13 | _position.y = pos_y; |
| el17sm | 53:93338b52489d | 14 | |
| el17sm | 57:1c12361b6e3d | 15 | _sprite_size.width = 3; |
| el17sm | 57:1c12361b6e3d | 16 | _sprite_size.height = 3; |
| el17sm | 57:1c12361b6e3d | 17 | _sprite_size.offset_x = -1; |
| el17sm | 57:1c12361b6e3d | 18 | _sprite_size.offset_y = -4; |
| el17sm | 32:fe6359ef9916 | 19 | } |
| el17sm | 32:fe6359ef9916 | 20 | |
| el17sm | 53:93338b52489d | 21 | // Functions |
| el17sm | 53:93338b52489d | 22 | void Bullets::move(float speed, float unused, char * unused2, bool * unused3) // Moves regarding face(constant after constructed) |
| el17sm | 32:fe6359ef9916 | 23 | { |
| el17sm | 57:1c12361b6e3d | 24 | if (_face == 0) { |
| el17sm | 57:1c12361b6e3d | 25 | _position.y -= speed; |
| el17sm | 57:1c12361b6e3d | 26 | } else if (_face == 1) { |
| el17sm | 57:1c12361b6e3d | 27 | _position.x += speed; |
| el17sm | 57:1c12361b6e3d | 28 | } else if (_face == 2) { |
| el17sm | 57:1c12361b6e3d | 29 | _position.y += speed; |
| el17sm | 57:1c12361b6e3d | 30 | } else if (_face == 3) { |
| el17sm | 57:1c12361b6e3d | 31 | _position.x -= speed; |
| el17sm | 32:fe6359ef9916 | 32 | } |
| el17sm | 32:fe6359ef9916 | 33 | } |
| el17sm | 32:fe6359ef9916 | 34 | |
| el17sm | 32:fe6359ef9916 | 35 | void Bullets::draw(N5110 &lcd) |
| el17sm | 32:fe6359ef9916 | 36 | { |
| el17sm | 57:1c12361b6e3d | 37 | lcd.drawSpriteTransparent(_position.x+_sprite_size.offset_x, |
| el17sm | 57:1c12361b6e3d | 38 | _position.y+_sprite_size.offset_y, |
| el17sm | 57:1c12361b6e3d | 39 | _sprite_size.height, |
| el17sm | 57:1c12361b6e3d | 40 | _sprite_size.width, |
| el17sm | 53:93338b52489d | 41 | (char *) bullets_sprite); |
| el17sm | 32:fe6359ef9916 | 42 | } |
| el17sm | 32:fe6359ef9916 | 43 | |
| el17sm | 53:93338b52489d | 44 | void Bullets::take_damage(int damage) // Taking damage, currently not used(has to be inherited, as well as useful for possible future use) |
| el17sm | 32:fe6359ef9916 | 45 | { |
| el17sm | 57:1c12361b6e3d | 46 | _hp -= damage; |
| el17sm | 32:fe6359ef9916 | 47 | } |
| el17sm | 32:fe6359ef9916 | 48 | |
| el17sm | 53:93338b52489d | 49 | bool Bullets::out_of_bounds_check(char * map, bool * doorways) // Returns true when bullets exit map or collide with walls |
| el17sm | 32:fe6359ef9916 | 50 | { |
| el17sm | 57:1c12361b6e3d | 51 | if (entity_to_map_collision_test(_position.x, _position.y, map, doorways)) { |
| el17sm | 32:fe6359ef9916 | 52 | return true; |
| el17sm | 32:fe6359ef9916 | 53 | } |
| el17sm | 57:1c12361b6e3d | 54 | if ((0 > _position.x) || (_position.x > 84) || (0 > _position.y) || (_position.y > 48)) { |
| el17sm | 32:fe6359ef9916 | 55 | return true; |
| el17sm | 32:fe6359ef9916 | 56 | } |
| el17sm | 32:fe6359ef9916 | 57 | return false; |
| el17sm | 32:fe6359ef9916 | 58 | } |