diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2025-01-10 16:26:05 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2025-01-10 16:26:05 +0100 |
commit | a981a42a7378ed51155590215557e52553031272 (patch) | |
tree | 7ca1b0cb7f72d6e8d50df09470a177a09ee12e51 /game/missile | |
parent | 0f8bf257d86b5532f3d6f559e5368668c255af7c (diff) |
missile solution, cannot find @max issue
Diffstat (limited to 'game/missile')
-rw-r--r-- | game/missile/AlertScript.cpp | 2 | ||||
-rw-r--r-- | game/missile/MissileScript.cpp | 9 | ||||
-rw-r--r-- | game/missile/SpawnEvent.cpp | 10 | ||||
-rw-r--r-- | game/missile/SpawnEvent.h | 2 |
4 files changed, 9 insertions, 14 deletions
diff --git a/game/missile/AlertScript.cpp b/game/missile/AlertScript.cpp index 24b4af9..0e6f5c5 100644 --- a/game/missile/AlertScript.cpp +++ b/game/missile/AlertScript.cpp @@ -18,7 +18,7 @@ void AlertScript::fixed_update(crepe::duration_t dt) { auto alert_transforms = this->get_components_by_name<Transform>("missile_alert"); int idx = 0; - for (int i = 0; i < missile_transforms.size(); i++) { + for (int i = 0; i < missile_transforms.size(); ++i) { const auto & missile_transform = missile_transforms[i].get(); if (this_transform.game_object_id == missile_transform.game_object_id) { idx = i; diff --git a/game/missile/MissileScript.cpp b/game/missile/MissileScript.cpp index bcc4f5b..f87dd20 100644 --- a/game/missile/MissileScript.cpp +++ b/game/missile/MissileScript.cpp @@ -27,7 +27,6 @@ void MissileScript::kill_missile() { auto animations = this->get_components<Animator>(); auto sprites = this->get_components<Sprite>(); auto collider = this->get_component<CircleCollider>(); - auto & fly_sound = this->get_components<AudioSource>().front().get(); auto & this_script = this->get_components<BehaviorScript>().front().get(); animations[0].get().active = false; @@ -36,11 +35,10 @@ void MissileScript::kill_missile() { sprites[0].get().active = false; sprites[1].get().active = false; sprites[2].get().active = true; + collider.active = false; this_script.active = false; this->seeking_disabled = false; - - fly_sound.stop(); } void MissileScript::activate() { auto anim = this->get_components<Animator>(); @@ -49,14 +47,10 @@ void MissileScript::activate() { anim[0].get().active = true; anim[1].get().active = true; anim[2].get().stop(); - //anim[3].get().active = true; - sprites[0].get().active = true; sprites[1].get().active = true; sprites[2].get().active = false; - //sprites[3].get().active = true; } - bool MissileScript::on_collision(const CollisionEvent & ev) { auto & explosion_sound = this->get_components<AudioSource>().back().get(); @@ -79,6 +73,7 @@ void MissileScript::fixed_update(crepe::duration_t dt) { const auto & cam = this->get_components_by_name<Transform>("camera").front().get(); const auto & velocity = this->get_component<Rigidbody>().data.linear_velocity; + if (missile.position.x < (cam.position.x - VIEWPORT_X / 1.8)) { this->kill_missile(); return; diff --git a/game/missile/SpawnEvent.cpp b/game/missile/SpawnEvent.cpp index c7209b7..6109686 100644 --- a/game/missile/SpawnEvent.cpp +++ b/game/missile/SpawnEvent.cpp @@ -20,16 +20,17 @@ void MissileSpawnEventHandler::init() { } bool MissileSpawnEventHandler::on_event(const MissileSpawnEvent & event) { - auto missile_transforms = this->get_components_by_name<Transform>("missile"); auto alert_sprites = this->get_components_by_name<Sprite>("missile_alert"); - auto alert_transforms = this->get_components_by_name<Transform>("missile_alert"); + + auto missile_transforms = this->get_components_by_name<Transform>("missile"); auto colliders = this->get_components_by_name<CircleCollider>("missile"); auto missile_behaviorscripts = this->get_components_by_name<BehaviorScript>("missile"); auto missile_audiosources = this->get_components_by_name<AudioSource>("missile"); + auto & camera_transform = this->get_components_by_name<Transform>("camera").front().get(); - for (size_t i = 0; i < missile_behaviorscripts.size(); ++i) { - auto & script = missile_behaviorscripts[i * 2].get(); + for (size_t i = 0; i < missile_transforms.size(); ++i) { + BehaviorScript & script = missile_behaviorscripts[i * 2].get(); if (script.active) continue; script.active = true; colliders[i].get().active = true; @@ -39,7 +40,6 @@ bool MissileSpawnEventHandler::on_event(const MissileSpawnEvent & event) { transform.position.x = camera_transform.position.x + this->MISSILE_OFFSET; transform.position.y = Random::i(this->MAX_RANGE, this->MIN_RANGE); - auto & alert_transform = alert_transforms[i].get(); auto & alert_sprite = alert_sprites[i].get(); alert_sprite.active = true; break; diff --git a/game/missile/SpawnEvent.h b/game/missile/SpawnEvent.h index 58293d7..3b9638c 100644 --- a/game/missile/SpawnEvent.h +++ b/game/missile/SpawnEvent.h @@ -10,7 +10,7 @@ struct MissileSpawnEvent : public crepe::Event {}; class MissileSpawnEventHandler : public crepe::Script { private: static constexpr int MISSILE_OFFSET = VIEWPORT_X; - static constexpr int RANGE = GAME_HEIGHT / 4; + static constexpr int RANGE = GAME_HEIGHT / 4.5; static constexpr int MIN_RANGE = -RANGE; static constexpr int MAX_RANGE = RANGE; |