From abbfe5d06697b93de485dcfe975812befc018a00 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 16:31:58 +0100 Subject: Moved EndGameScript to Player --- game/CMakeLists.txt | 2 +- game/EndGameScript.cpp | 60 ----------------------------------------- game/EndGameScript.h | 12 --------- game/GameScene.cpp | 3 --- game/player/PlayerEndScript.cpp | 60 +++++++++++++++++++++++++++++++++++++++++ game/player/PlayerEndScript.h | 12 +++++++++ game/player/PlayerScript.cpp | 3 +-- game/player/PlayerSubScene.cpp | 2 ++ 8 files changed, 76 insertions(+), 78 deletions(-) delete mode 100644 game/EndGameScript.cpp delete mode 100644 game/EndGameScript.h create mode 100644 game/player/PlayerEndScript.cpp create mode 100644 game/player/PlayerEndScript.h (limited to 'game') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 33ceaf4..8e3692b 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -19,7 +19,7 @@ add_executable(main player/PlayerScript.cpp player/PlayerSubScene.cpp StartGameScript.cpp - EndGameScript.cpp + player/PlayerEndScript.cpp background/StartSubScene.cpp main.cpp ) diff --git a/game/EndGameScript.cpp b/game/EndGameScript.cpp deleted file mode 100644 index a18f18c..0000000 --- a/game/EndGameScript.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "EndGameScript.h" - -#include -#include -#include -#include -#include - -using namespace crepe; -using namespace std; - -void EndGameScript::init() { - BoxCollider jetpack_coll = this->get_components_by_name("player").back(); - CircleCollider head_coll = this->get_components_by_name("player").back(); - jetpack_coll.active = false; - head_coll.active = false; -} - -void EndGameScript::fixed_update(crepe::duration_t dt) { - Transform & transform_player = this->get_components_by_name("player").front(); - RefVector anim_player = this->get_components_by_name("player"); - Rigidbody & rb_player = this->get_components_by_name("player").front(); - Rigidbody & rb_camera = this->get_components_by_name("camera").front(); - - if (transform_player.position.y >= 194) { - if (jump == 0 || jump == 1) { - int random_number = rand() % 4; - for (Animator & anim : anim_player) { - anim.active = false; - anim.set_anim(6); - for (int i = 0; i < random_number; i++) { - anim.next_anim(); - } - } - } else if (jump == 2) { - for (Animator & anim : anim_player) { - anim.active = false; - anim.set_anim(7); - } - rb_player.data.angular_velocity = 0; - transform_player.rotation = 90; - } - if (jump == 0) { - rb_player.data.linear_velocity = vec2(100, -150); - rb_player.data.angular_velocity = 320; - rb_player.data.angular_velocity_coefficient = 0.8; - jump++; - } else if (jump == 1) { - rb_player.data.linear_velocity = vec2(100, -125); - rb_player.data.angular_velocity = 300; - rb_player.data.angular_velocity_coefficient = 0.8; - jump++; - } else if (jump == 2) { - rb_player.data.linear_velocity = vec2(100, 0); - rb_player.data.linear_velocity_coefficient = vec2(0.5, 0.5); - rb_camera.data.linear_velocity_coefficient = vec2(0.5, 0.5); - jump++; - } - } -} diff --git a/game/EndGameScript.h b/game/EndGameScript.h deleted file mode 100644 index 980dff5..0000000 --- a/game/EndGameScript.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -class EndGameScript : public crepe::Script { -public: - void init(); - void fixed_update(crepe::duration_t dt); - -private: - int jump = 0; -}; diff --git a/game/GameScene.cpp b/game/GameScene.cpp index b471484..821191d 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -1,6 +1,5 @@ #include "GameScene.h" #include "Config.h" -#include "EndGameScript.h" #include "MoveCameraManualyScript.h" #include "StartGameScript.h" @@ -67,8 +66,6 @@ void GameScene::load_scene() { GameObject start_game_script = new_object("start_game_script", "script", vec2(0, 0)); start_game_script.add_component().set_script(); - GameObject end_game_script = new_object("end_game_script", "script", vec2(0, 0)); - end_game_script.add_component().set_script().active = false; // zapper, laser and missile (below) for testing purpose only!!! GameObject zapper = new_object("zapper", "zapper", vec2(1000, 0)); diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp new file mode 100644 index 0000000..c0b4e74 --- /dev/null +++ b/game/player/PlayerEndScript.cpp @@ -0,0 +1,60 @@ +#include "PlayerEndScript.h" + +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +void PlayerEndScript::init() { + BoxCollider jetpack_coll = this->get_components_by_name("player").back(); + CircleCollider head_coll = this->get_components_by_name("player").back(); + jetpack_coll.active = false; + head_coll.active = false; +} + +void PlayerEndScript::fixed_update(crepe::duration_t dt) { + Transform & transform_player = this->get_components_by_name("player").front(); + RefVector anim_player = this->get_components_by_name("player"); + Rigidbody & rb_player = this->get_components_by_name("player").front(); + Rigidbody & rb_camera = this->get_components_by_name("camera").front(); + + if (transform_player.position.y >= 194) { + if (jump == 0 || jump == 1) { + int random_number = rand() % 4; + for (Animator & anim : anim_player) { + anim.active = false; + anim.set_anim(6); + for (int i = 0; i < random_number; i++) { + anim.next_anim(); + } + } + } else if (jump == 2) { + for (Animator & anim : anim_player) { + anim.active = false; + anim.set_anim(7); + } + rb_player.data.angular_velocity = 0; + transform_player.rotation = 90; + } + if (jump == 0) { + rb_player.data.linear_velocity = vec2(100, -150); + rb_player.data.angular_velocity = 320; + rb_player.data.angular_velocity_coefficient = 0.8; + jump++; + } else if (jump == 1) { + rb_player.data.linear_velocity = vec2(100, -125); + rb_player.data.angular_velocity = 300; + rb_player.data.angular_velocity_coefficient = 0.8; + jump++; + } else if (jump == 2) { + rb_player.data.linear_velocity = vec2(100, 0); + rb_player.data.linear_velocity_coefficient = vec2(0.5, 0.5); + rb_camera.data.linear_velocity_coefficient = vec2(0.5, 0.5); + jump++; + } + } +} diff --git a/game/player/PlayerEndScript.h b/game/player/PlayerEndScript.h new file mode 100644 index 0000000..240ab7c --- /dev/null +++ b/game/player/PlayerEndScript.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +class PlayerEndScript : public crepe::Script { +public: + void init(); + void fixed_update(crepe::duration_t dt); + +private: + int jump = 0; +}; diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index de53fc7..7f5d0c4 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -18,8 +18,7 @@ void PlayerScript::init() { bool PlayerScript::on_collision(const CollisionEvent & ev) { BehaviorScript & play_scr = this->get_components_by_name("player").front(); - BehaviorScript & end_scr - = this->get_components_by_name("end_game_script").front(); + BehaviorScript & end_scr = this->get_components_by_name("player").back(); RefVector animators = this->get_components_by_name("player"); RefVector emitters = this->get_components_by_name("player"); diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index 812d99a..91ae882 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -1,4 +1,5 @@ #include "PlayerSubScene.h" +#include "PlayerEndScript.h" #include "PlayerScript.h" #include "../Config.h" @@ -148,4 +149,5 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .collision_layer = COLL_LAY_PLAYER, }); player.add_component().set_script().active = false; + player.add_component().set_script().active = false; } -- cgit v1.2.3