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
Diff: Entity/Player/Bullets/Bullets.cpp
- Revision:
- 53:93338b52489d
- Parent:
- 51:4d0cd75e7ed3
- Child:
- 57:1c12361b6e3d
--- a/Entity/Player/Bullets/Bullets.cpp Thu May 09 07:47:58 2019 +0000
+++ b/Entity/Player/Bullets/Bullets.cpp Thu May 09 08:02:07 2019 +0000
@@ -1,29 +1,33 @@
#include "Bullets.h"
+// Constructor
Bullets::Bullets(float pos_x, float pos_y, int dir)
{
- face = 0;
+ face = dir;
hp = 1;
+
hitbox.width = 3;
hitbox.height = 3;
+
position.x = pos_x;
position.y = pos_y;
+
sprite_size.width = 3;
sprite_size.height = 3;
sprite_size.offset_x = -1;
sprite_size.offset_y = -4;
- direction = dir;
}
-void Bullets::move(float speed, float unused, char * unused2, bool * unused3)
+// Functions
+void Bullets::move(float speed, float unused, char * unused2, bool * unused3) // Moves regarding face(constant after constructed)
{
- if (direction == 0) {
+ if (face == 0) {
position.y -= speed;
- } else if (direction == 1) {
+ } else if (face == 1) {
position.x += speed;
- } else if (direction == 2) {
+ } else if (face == 2) {
position.y += speed;
- } else if (direction == 3) {
+ } else if (face == 3) {
position.x -= speed;
}
}
@@ -34,15 +38,15 @@
position.y+sprite_size.offset_y,
sprite_size.height,
sprite_size.width,
- get_frame());
+ (char *) bullets_sprite);
}
-void Bullets::take_damage(int damage)
+void Bullets::take_damage(int damage) // Taking damage, currently not used(has to be inherited, as well as useful for possible future use)
{
hp -= damage;
}
-bool Bullets::out_of_bounds_check(char * map, bool * doorways)
+bool Bullets::out_of_bounds_check(char * map, bool * doorways) // Returns true when bullets exit map or collide with walls
{
if (entity_to_map_collision_test(position.x, position.y, map, doorways)) {
return true;
@@ -51,9 +55,4 @@
return true;
}
return false;
-}
-
-char * Bullets::get_frame()
-{
- return (char *) bullets_sprite;
}
\ No newline at end of file