diff options
Diffstat (limited to 'src/example/GameScene.cpp')
-rw-r--r-- | src/example/GameScene.cpp | 86 |
1 files changed, 2 insertions, 84 deletions
diff --git a/src/example/GameScene.cpp b/src/example/GameScene.cpp index 50b61d8..c280474 100644 --- a/src/example/GameScene.cpp +++ b/src/example/GameScene.cpp @@ -1,6 +1,8 @@ #include "GameScene.h" #include "BackgroundSubScene.h" +#include "MoveCameraManualyScript.h" #include "PlayerSubScene.h" +#include "StartGameScript.h" #include <cmath> #include <crepe/api/Animator.h> @@ -22,90 +24,6 @@ using namespace crepe; using namespace std; -class MoveCameraManualyScript : public Script { -public: - void init() { - subscribe<KeyPressEvent>( - [this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); }); - } - -private: - bool keypressed(const KeyPressEvent & event) { - if (event.key == Keycode::RIGHT) { - Transform & cam = this->get_components_by_name<Transform>("camera").front(); - cam.position.x += 100; - return true; - } else if (event.key == Keycode::LEFT) { - Transform & cam = this->get_components_by_name<Transform>("camera").front(); - cam.position.x -= 100; - return true; - } - return false; - } -}; - -class StartGameScript : public Script { -public: - void update() { - Transform & player_transform - = this->get_components_by_name<Transform>("player").front(); - - // Create hole in wall and activate panic lamp - if (player_transform.position.x > 75 && !this->created_hole) { - Sprite & lamp_sprite = this->get_components_by_name<Sprite>("start_end").back(); - lamp_sprite.active = true; - Sprite & hole_sprite = this->get_components_by_name<Sprite>("start_hole").front(); - hole_sprite.active = true; - - RefVector<Rigidbody> frags_rg - = this->get_components_by_tag<Rigidbody>("wall_fragment"); - RefVector<Sprite> frags_sprite - = this->get_components_by_tag<Sprite>("wall_fragment"); - for (Rigidbody & frag_rg : frags_rg) { - frag_rg.active = true; - } - for (Sprite & frag_sprite : frags_sprite) { - frag_sprite.active = true; - } - - RefVector<ParticleEmitter> smoke_emitters - = this->get_components_by_name<ParticleEmitter>("smoke_particles"); - for (ParticleEmitter & emitter : smoke_emitters) { - emitter.active = true; - } - - this->created_hole = true; - } - - // Take jetpack from jetpack stand - if (player_transform.position.x > 275 && !this->took_jetpack) { - Animator & jetpack_stand_anim - = this->get_components_by_name<Animator>("start_begin").back(); - jetpack_stand_anim.next_anim(); - Sprite & jetpack_sprite = this->get_components_by_name<Sprite>("player").back(); - jetpack_sprite.active = true; - - this->took_jetpack = true; - } - - // Start camera movement, enable player jumping and disable this script - if (player_transform.position.x > 500) { - Rigidbody & rb = this->get_components_by_name<Rigidbody>("camera").front(); - rb.data.linear_velocity = vec2(100, 0); - BehaviorScript & player_script - = this->get_components_by_name<BehaviorScript>("player").front(); - player_script.active = true; - BehaviorScript & this_script - = this->get_components_by_name<BehaviorScript>("start_game_script").front(); - this_script.active = false; - } - } - -private: - bool created_hole = false; - bool took_jetpack = false; -}; - void GameScene::load_scene() { BackgroundSubScene background(*this); |