From 7f7c5c56dce30d47c32fb57fad6d839d0990b054 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Wed, 8 Jan 2025 10:08:03 +0100 Subject: enemy spawn working + enemy shooting --- game/enemy/EnemyBulletScript.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 game/enemy/EnemyBulletScript.cpp (limited to 'game/enemy/EnemyBulletScript.cpp') diff --git a/game/enemy/EnemyBulletScript.cpp b/game/enemy/EnemyBulletScript.cpp new file mode 100644 index 0000000..561d086 --- /dev/null +++ b/game/enemy/EnemyBulletScript.cpp @@ -0,0 +1,36 @@ +#include +#include "EnemyBulletScript.h" +#include +#include +#include +using namespace crepe; +using namespace std; +void EnemyBulletScript::init(){ + this->subscribe([this](const CollisionEvent& e) -> bool { + return this->on_collide(e); + }); +} +void EnemyBulletScript::fixed_update(crepe::duration_t dt){ + Transform& transform = this->get_component(); + Camera& camera = this->get_components_by_name("camera").front(); + Transform& cam_transform = this->get_components_by_name("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 EnemyBulletScript::despawn_bullet(){ + Transform& transform = this->get_component(); + Rigidbody& bullet_body = this->get_component(); + bullet_body.active = false; + transform.position = {0,-750}; +} + +bool EnemyBulletScript::on_collide(const CollisionEvent& e){ + cout << "collision happened with " << e.info.other.metadata.tag << endl; + //this->despawn_bullet(); + return false; +} -- cgit v1.2.3