diff options
Diffstat (limited to 'game/missile/MissileScript.cpp')
-rw-r--r-- | game/missile/MissileScript.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/game/missile/MissileScript.cpp b/game/missile/MissileScript.cpp index 6d0e40e..3aa4eb6 100644 --- a/game/missile/MissileScript.cpp +++ b/game/missile/MissileScript.cpp @@ -1,18 +1,19 @@ #include "MissileScript.h" #include "../Config.h" -#include "api/BehaviorScript.h" +#include <cmath> +#include <crepe/api/AI.h> #include <crepe/api/Animator.h> #include <crepe/api/AudioSource.h> +#include <crepe/api/BehaviorScript.h> +#include <crepe/api/CircleCollider.h> +#include <crepe/api/KeyCodes.h> +#include <crepe/api/Rigidbody.h> +#include <crepe/api/Sprite.h> #include <crepe/api/Transform.h> #include <crepe/system/CollisionSystem.h> #include <crepe/types.h> -#include <cmath> -#include <crepe/api/AI.h> -#include <crepe/api/KeyCodes.h> -#include <crepe/api/Sprite.h> - using namespace std; using namespace crepe; @@ -25,8 +26,8 @@ void MissileScript::init() { void MissileScript::kill_missile() { auto animations = this->get_components<Animator>(); auto sprites = this->get_components<Sprite>(); - auto & fly_sound = this->get_components<AudioSource>().front().get(); - auto & this_script = this->get_components<BehaviorScript>().back().get(); + auto collider = this->get_component<CircleCollider>(); + auto & this_script = this->get_components<BehaviorScript>().front().get(); animations[0].get().active = false; animations[1].get().active = false; @@ -35,23 +36,22 @@ void MissileScript::kill_missile() { 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>(); auto sprites = this->get_components<Sprite>(); - anim[0].get().active = true; - anim[1].get().active = true; - anim[2].get().stop(); sprites[0].get().active = true; sprites[1].get().active = true; sprites[2].get().active = false; -} + anim[0].get().active = true; + anim[1].get().active = true; + anim[2].get().stop(); +} bool MissileScript::on_collision(const CollisionEvent & ev) { auto & explosion_sound = this->get_components<AudioSource>().back().get(); @@ -74,15 +74,16 @@ 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; - } - // check if animation is at the end if (explosion_anim.data.row == 7) { this->activate(); this->seeking_disabled = false; + return; + } + + if (missile.position.x < (cam.position.x - VIEWPORT_X / 1.8)) { + this->kill_missile(); + return; } if (this->seeking_disabled) { |