From 15a958a7f327bb2e81e7d445f1499ec78c7f5839 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Fri, 10 Jan 2025 12:05:16 +0100 Subject: alers scripts and quitscript with ESC key --- game/missile/AlertScript.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 game/missile/AlertScript.cpp (limited to 'game/missile/AlertScript.cpp') diff --git a/game/missile/AlertScript.cpp b/game/missile/AlertScript.cpp new file mode 100644 index 0000000..c1124ac --- /dev/null +++ b/game/missile/AlertScript.cpp @@ -0,0 +1,38 @@ +#include "AlertScript.h" +#include "../Config.h" +#include "api/CircleCollider.h" +#include "api/Sprite.h" + +#include + +using namespace crepe; + +void AlertScript::fixed_update(crepe::duration_t dt) { + const auto & cam = this->get_components_by_name("camera").front().get(); + //missile transform + const auto & this_transform = this->get_component(); + auto missile_transforms = this->get_components_by_name("missile"); + const auto & this_collider = this->get_component(); + + auto alert_sprites = this->get_components_by_name("missile_alert"); + auto alert_transforms = this->get_components_by_name("missile_alert"); + + int idx = 0; + 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; + break; + } + } + + auto & alert_transform = alert_transforms[idx].get(); + alert_transform.position.x = cam.position.x + (VIEWPORT_X / 2 - 100); + alert_transform.position.y = this_transform.position.y; + + // check if transform is in camera view + if (this_transform.position.x > cam.position.x - (VIEWPORT_X / 2) + && this_transform.position.x < cam.position.x + (VIEWPORT_X / 2)) { + alert_sprites[idx].get().active = false; + } +} -- cgit v1.2.3 From 938b6a7bb62459e8308320280d15ccaf1b8af0ac Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Fri, 10 Jan 2025 14:43:07 +0100 Subject: adjsuted includes so that it has <> and not --- game/CMakeLists.txt | 2 +- game/QuitScript.cpp | 5 +++-- game/QuitScript.h | 3 ++- game/hud/HudScript.cpp | 3 ++- game/missile/AlertScript.cpp | 4 ++-- game/missile/AlertScript.h | 3 ++- game/missile/AlertSubScene.cpp | 11 ++++------- game/missile/AlertSubScene.h | 3 ++- game/missile/MissileScript.cpp | 10 ++++------ game/missile/SpawnEvent.cpp | 4 ++-- 10 files changed, 24 insertions(+), 24 deletions(-) (limited to 'game/missile/AlertScript.cpp') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index b39416b..a94beca 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.28) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 20) set(CMAKE_EXPORT_COMPILE_COMMANDS 1) -set(CMAKE_BUILD_TYPE Debug) +set(CMAKE_BUILD_TYPE Release) project(game C CXX) add_subdirectory(../src crepe) diff --git a/game/QuitScript.cpp b/game/QuitScript.cpp index e48863f..fc33dcf 100644 --- a/game/QuitScript.cpp +++ b/game/QuitScript.cpp @@ -1,8 +1,9 @@ #include "QuitScript.h" -#include "api/Event.h" -#include "api/KeyCodes.h" + +#include +#include using namespace crepe; diff --git a/game/QuitScript.h b/game/QuitScript.h index c295183..af78ccf 100644 --- a/game/QuitScript.h +++ b/game/QuitScript.h @@ -1,7 +1,8 @@ #pragma once -#include "api/Script.h" +#include + class QuitScript : public crepe::Script { private: bool on_event(const crepe::KeyPressEvent & ev); diff --git a/game/hud/HudScript.cpp b/game/hud/HudScript.cpp index 3fb7a77..e4aeae7 100644 --- a/game/hud/HudScript.cpp +++ b/game/hud/HudScript.cpp @@ -3,6 +3,7 @@ #include "../Config.h" #include "../Events.h" +#include "api/KeyCodes.h" #include "menus/endgame/EndGameSubScript.h" #include @@ -37,7 +38,7 @@ void HudScript::init() { } bool HudScript::toggle_fps(crepe::KeyPressEvent ev) { - if (ev.key != Keycode::END) return false; + if (ev.key != Keycode::D1) return false; Text & txt_fps = this->get_components_by_name(HUD_FPS).front(); this->show_fps = !this->show_fps; if (this->show_fps) { diff --git a/game/missile/AlertScript.cpp b/game/missile/AlertScript.cpp index c1124ac..24b4af9 100644 --- a/game/missile/AlertScript.cpp +++ b/game/missile/AlertScript.cpp @@ -1,8 +1,8 @@ #include "AlertScript.h" #include "../Config.h" -#include "api/CircleCollider.h" -#include "api/Sprite.h" +#include +#include #include using namespace crepe; diff --git a/game/missile/AlertScript.h b/game/missile/AlertScript.h index ab29863..5b0b3a1 100644 --- a/game/missile/AlertScript.h +++ b/game/missile/AlertScript.h @@ -1,6 +1,7 @@ #pragma once -#include "api/Script.h" +#include + class AlertScript : public crepe::Script { private: bool has_alert = false; diff --git a/game/missile/AlertSubScene.cpp b/game/missile/AlertSubScene.cpp index c3379e8..8d59f97 100644 --- a/game/missile/AlertSubScene.cpp +++ b/game/missile/AlertSubScene.cpp @@ -1,10 +1,9 @@ #include "AlertSubScene.h" #include "../Config.h" -#include "api/Animator.h" -#include "api/BehaviorScript.h" -#include "api/Scene.h" -#include "api/Sprite.h" -#include "missile/AlertScript.h" + +#include +#include +#include using namespace crepe; @@ -13,8 +12,6 @@ MissileAlert::MissileAlert(Scene& scn){ Asset missile_alert_ss {"asset/obstacles/missile/missileAlert.png"}; - //alert.add_component().set_script(); - auto & missile_alert_sprite = alert.add_component( missile_alert_ss, Sprite::Data { diff --git a/game/missile/AlertSubScene.h b/game/missile/AlertSubScene.h index 661b3f1..8ea288f 100644 --- a/game/missile/AlertSubScene.h +++ b/game/missile/AlertSubScene.h @@ -1,6 +1,7 @@ #pragma once -#include "api/Scene.h" +#include + class MissileAlert { public: MissileAlert(crepe::Scene & scn); diff --git a/game/missile/MissileScript.cpp b/game/missile/MissileScript.cpp index 2d1052e..797e1ac 100644 --- a/game/missile/MissileScript.cpp +++ b/game/missile/MissileScript.cpp @@ -1,17 +1,15 @@ #include "MissileScript.h" #include "../Config.h" -#include "Collider.h" -#include "api/BehaviorScript.h" -#include "api/CircleCollider.h" -#include "api/Rigidbody.h" +#include +#include +#include +#include #include #include #include #include #include - -#include #include #include #include diff --git a/game/missile/SpawnEvent.cpp b/game/missile/SpawnEvent.cpp index c407832..a54d0a5 100644 --- a/game/missile/SpawnEvent.cpp +++ b/game/missile/SpawnEvent.cpp @@ -1,8 +1,8 @@ #include "SpawnEvent.h" -#include "Config.h" #include "Random.h" -#include "api/CircleCollider.h" + +#include #include #include #include -- cgit v1.2.3