diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2025-01-08 10:08:03 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2025-01-08 10:08:03 +0100 |
commit | 7f7c5c56dce30d47c32fb57fad6d839d0990b054 (patch) | |
tree | eebc8d3f4c332d969f4a66a566edd844bd43387c /game/player/PlayerBulletScript.cpp | |
parent | ceb41b7ae7e2734af954364b319fc0b6f2a86c2f (diff) |
enemy spawn working + enemy shooting
Diffstat (limited to 'game/player/PlayerBulletScript.cpp')
-rw-r--r-- | game/player/PlayerBulletScript.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/game/player/PlayerBulletScript.cpp b/game/player/PlayerBulletScript.cpp new file mode 100644 index 0000000..e1637c2 --- /dev/null +++ b/game/player/PlayerBulletScript.cpp @@ -0,0 +1,39 @@ +#include <iostream> + +#include <crepe/api/Camera.h> +#include <crepe/api/Rigidbody.h> +#include <crepe/api/Metadata.h> + +#include "PlayerBulletScript.h" + +using namespace crepe; +using namespace std; +void PlayerBulletScript::init(){ + this->subscribe<CollisionEvent>([this](const CollisionEvent& e) -> bool { + return this->on_collide(e); + }); +} +void PlayerBulletScript::fixed_update(crepe::duration_t dt){ + Transform& transform = this->get_component<Transform>(); + Camera& camera = this->get_components_by_name<Camera>("camera").front(); + Transform& cam_transform = this->get_components_by_name<Transform>("camera").front(); + + vec2 half_screen = camera.viewport_size / 2; + float despawn_location = cam_transform.position.x + half_screen.x + 50; + if(transform.position.x < despawn_location){ + this->despawn_bullet(); + } +} + +void PlayerBulletScript::despawn_bullet(){ + Transform& transform = this->get_component<Transform>(); + Rigidbody& bullet_body = this->get_component<Rigidbody>(); + bullet_body.active = false; + transform.position = {0,-850}; +} + +bool PlayerBulletScript::on_collide(const CollisionEvent& e){ + cout << "collision happened with " << e.info.other.metadata.tag << endl; + //this->despawn_bullet(); + return false; +} |