diff options
-rw-r--r-- | game/CMakeLists.txt | 5 | ||||
-rw-r--r-- | game/Config.h | 2 | ||||
-rw-r--r-- | game/Random.cpp | 5 | ||||
-rw-r--r-- | game/Random.h | 1 | ||||
-rw-r--r-- | game/menus/mainmenu/ITransitionScript.cpp | 2 | ||||
-rw-r--r-- | game/prefab/ZapperObject.cpp | 4 | ||||
-rw-r--r-- | game/prefab/ZapperPoolScript.cpp | 27 | ||||
-rw-r--r-- | game/prefab/ZapperPoolScript.h | 4 | ||||
-rw-r--r-- | game/prefab/ZapperPoolSubScene.cpp | 5 | ||||
-rw-r--r-- | game/prefab/ZapperPoolSubScene.h | 4 | ||||
-rw-r--r-- | src/crepe/api/Vector2.hpp | 4 |
11 files changed, 29 insertions, 34 deletions
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 2ed2fee..e1168eb 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -7,7 +7,10 @@ set(CMAKE_BUILD_TYPE Debug) project(game C CXX) add_subdirectory(../src crepe) -add_executable(main + +add_executable(main) + +target_sources(main PUBLIC # enemy enemy/BattleScript.cpp enemy/EnemyPool.cpp diff --git a/game/Config.h b/game/Config.h index e4f617a..8fa41ba 100644 --- a/game/Config.h +++ b/game/Config.h @@ -61,6 +61,6 @@ static constexpr const char * PLAYER_NAME = "player"; static constexpr int PLAYER_SPEED = 7500; // In game units static constexpr int PLAYER_GRAVITY_SCALE = 60; // In game units +static constexpr const char * CAMERA_NAME = "camera"; // Jetpack particles static constexpr const char * JETPACK_PARTICLES = "jetpack_particles"; -static constexpr const char * CAMERA_NAME = "camera"; diff --git a/game/Random.cpp b/game/Random.cpp index 821ddc8..64cf1f3 100644 --- a/game/Random.cpp +++ b/game/Random.cpp @@ -26,7 +26,4 @@ unsigned Random::u(unsigned upper, unsigned lower) { return x + lower; } -bool Random::b() { - return rand() % 2; -} - +bool Random::b() { return rand() % 2; } diff --git a/game/Random.h b/game/Random.h index 0f0f79b..94f98d2 100644 --- a/game/Random.h +++ b/game/Random.h @@ -7,5 +7,4 @@ public: static int i(int upper, int lower = 0); static unsigned u(unsigned upper, unsigned lower = 0); static bool b(); - }; diff --git a/game/menus/mainmenu/ITransitionScript.cpp b/game/menus/mainmenu/ITransitionScript.cpp index 3e51a90..54b0875 100644 --- a/game/menus/mainmenu/ITransitionScript.cpp +++ b/game/menus/mainmenu/ITransitionScript.cpp @@ -1,8 +1,8 @@ #include "ITransitionScript.h" #include "MainMenuConfig.h" -#include "../MenusConfig.h" #include "../../Config.h" +#include "../MenusConfig.h" #include <crepe/api/Camera.h> #include <crepe/api/Transform.h> diff --git a/game/prefab/ZapperObject.cpp b/game/prefab/ZapperObject.cpp index 0a290e0..24bbbd2 100644 --- a/game/prefab/ZapperObject.cpp +++ b/game/prefab/ZapperObject.cpp @@ -81,12 +81,9 @@ ZapperObject::ZapperObject(crepe::GameObject && base) })}, collider {add_component<BoxCollider>(vec2(0, 0))} { this->set_active(false); - Log::logf(Log::DEBUG, "Creating zapper"); } void ZapperObject::place(const crepe::vec2 & position, float rotation, float length) { - Log::logf(Log::DEBUG, "Placing zapper [position = {}, rotation = {}, length = {}]", position, rotation, length); - this->transform.position = position; this->transform.rotation = rotation; @@ -119,4 +116,3 @@ void ZapperObject::set_active(bool active) { this->active = active; } - diff --git a/game/prefab/ZapperPoolScript.cpp b/game/prefab/ZapperPoolScript.cpp index b9b2a76..b832ddd 100644 --- a/game/prefab/ZapperPoolScript.cpp +++ b/game/prefab/ZapperPoolScript.cpp @@ -23,36 +23,38 @@ void ZapperPoolScript::init() { } void ZapperPoolScript::fixed_update(crepe::duration_t) { - float threshold = camera_transform->position.x - camera_camera->viewport_size.x / 2 - OFFSCREEN_MARGIN; + float threshold + = camera_transform->position.x - camera_camera->viewport_size.x / 2 - OFFSCREEN_MARGIN; for (ZapperObject & zapper : this->pool) { if (!zapper.active) continue; - if (zapper.transform.position.x < threshold) - zapper.set_active(false); + if (zapper.transform.position.x < threshold) zapper.set_active(false); } } void ZapperPoolScript::spawn_random() { OptionalRef<ZapperObject> zapper = this->get_next_zapper(); if (!zapper) return; // pool exhausted - - vec2 pos = { - .x = camera_transform->position.x + camera_camera->viewport_size.x / 2 + OFFSCREEN_MARGIN, - .y = Random::f(0.5, -0.5) * HALLWAY_HEIGHT, - }; bool horizontal = Random::b(); + vec2 pos; float rotation, length; + pos.x + = camera_transform->position.x + camera_camera->viewport_size.x / 2 + OFFSCREEN_MARGIN; if (horizontal) { rotation = 90; length = Random::f(400, 200); + pos.y = Random::f(0.5, -0.5) * HALLWAY_HEIGHT; + // align zapper to right edge of camera + pos.x -= MAX_LENGTH - (length / 2); } else { rotation = 0; - length = Random::f(200, 50); - if (abs(pos.y) + length / 2 > HALLWAY_HEIGHT / 2) { - // TODO: fix offset - } + length = Random::f(200, 75); + // ensure zapper doesn't crash into ceiling or floor + pos.y = Random::f(0.5, -0.5) * (HALLWAY_HEIGHT - length); + // align zapper to right edge of camera + pos.x -= MAX_LENGTH; } zapper->place(pos, rotation, length); @@ -66,4 +68,3 @@ OptionalRef<ZapperObject> ZapperPoolScript::get_next_zapper() { } return {}; } - diff --git a/game/prefab/ZapperPoolScript.h b/game/prefab/ZapperPoolScript.h index 6aee8b2..2208c80 100644 --- a/game/prefab/ZapperPoolScript.h +++ b/game/prefab/ZapperPoolScript.h @@ -28,6 +28,6 @@ private: void spawn_random(); private: - static constexpr float OFFSCREEN_MARGIN = 40; + static constexpr float MAX_LENGTH = 400; + static constexpr float OFFSCREEN_MARGIN = 50 + MAX_LENGTH; }; - diff --git a/game/prefab/ZapperPoolSubScene.cpp b/game/prefab/ZapperPoolSubScene.cpp index e341090..8422b8c 100644 --- a/game/prefab/ZapperPoolSubScene.cpp +++ b/game/prefab/ZapperPoolSubScene.cpp @@ -1,13 +1,13 @@ #include <crepe/api/BehaviorScript.h> -#include "ZapperPoolSubScene.h" #include "ZapperPoolScript.h" +#include "ZapperPoolSubScene.h" using namespace crepe; using namespace std; ZapperPoolSubScene::ZapperPoolSubScene(Scene & scene) - : controller { scene.new_object("controller") } { + : controller {scene.new_object("controller")} { Log::logf(Log::DEBUG, "Building zapper pool..."); vector<ZapperObject> pool; @@ -16,4 +16,3 @@ ZapperPoolSubScene::ZapperPoolSubScene(Scene & scene) BehaviorScript & behavior = this->controller.add_component<BehaviorScript>(); behavior.set_script<ZapperPoolScript>(std::move(pool)); } - diff --git a/game/prefab/ZapperPoolSubScene.h b/game/prefab/ZapperPoolSubScene.h index f930e22..6f6e297 100644 --- a/game/prefab/ZapperPoolSubScene.h +++ b/game/prefab/ZapperPoolSubScene.h @@ -1,8 +1,8 @@ #pragma once -#include <crepe/api/Scene.h> -#include <crepe/api/GameObject.h> #include <crepe/api/Event.h> +#include <crepe/api/GameObject.h> +#include <crepe/api/Scene.h> #include <crepe/util/OptionalRef.h> class CreateZapperEvent : public crepe::Event {}; diff --git a/src/crepe/api/Vector2.hpp b/src/crepe/api/Vector2.hpp index e2f96ed..30441d2 100644 --- a/src/crepe/api/Vector2.hpp +++ b/src/crepe/api/Vector2.hpp @@ -180,7 +180,7 @@ Vector2<T> Vector2<T>::rotate(float deg) const { } // namespace crepe template <typename T> -std::format_context::iterator std::formatter<crepe::Vector2<T>>::format(crepe::Vector2<T> vec, format_context & ctx) const { +std::format_context::iterator +std::formatter<crepe::Vector2<T>>::format(crepe::Vector2<T> vec, format_context & ctx) const { return formatter<string>::format(std::format("{{{}, {}}}", vec.x, vec.y), ctx); } - |