From 999e1b928aa632e80521651f14013c267af604dc Mon Sep 17 00:00:00 2001 From: Max-001 Date: Sat, 21 Dec 2024 11:19:52 +0100 Subject: Moved file to sub directory --- game/AquariumSubScene.cpp | 135 ---------- game/AquariumSubScene.h | 13 - game/BackgroundSubScene.cpp | 37 --- game/BackgroundSubScene.h | 10 - game/CMakeLists.txt | 12 +- game/ForestParallaxScript.cpp | 28 -- game/ForestParallaxScript.h | 15 -- game/ForestSubScene.cpp | 131 --------- game/ForestSubScene.h | 15 -- game/GameScene.cpp | 3 +- game/HallwaySubScene.cpp | 128 --------- game/HallwaySubScene.h | 21 -- game/StartSubScene.cpp | 442 ------------------------------- game/StartSubScene.h | 20 -- game/background/AquariumSubScene.cpp | 129 +++++++++ game/background/AquariumSubScene.h | 13 + game/background/BackgroundSubScene.cpp | 37 +++ game/background/BackgroundSubScene.h | 10 + game/background/ForestParallaxScript.cpp | 28 ++ game/background/ForestParallaxScript.h | 15 ++ game/background/ForestSubScene.cpp | 131 +++++++++ game/background/ForestSubScene.h | 15 ++ game/background/HallwaySubScene.cpp | 128 +++++++++ game/background/HallwaySubScene.h | 21 ++ game/background/StartSubScene.cpp | 442 +++++++++++++++++++++++++++++++ game/background/StartSubScene.h | 20 ++ 26 files changed, 997 insertions(+), 1002 deletions(-) delete mode 100644 game/AquariumSubScene.cpp delete mode 100644 game/AquariumSubScene.h delete mode 100644 game/BackgroundSubScene.cpp delete mode 100644 game/BackgroundSubScene.h delete mode 100644 game/ForestParallaxScript.cpp delete mode 100644 game/ForestParallaxScript.h delete mode 100644 game/ForestSubScene.cpp delete mode 100644 game/ForestSubScene.h delete mode 100644 game/HallwaySubScene.cpp delete mode 100644 game/HallwaySubScene.h delete mode 100644 game/StartSubScene.cpp delete mode 100644 game/StartSubScene.h create mode 100644 game/background/AquariumSubScene.cpp create mode 100644 game/background/AquariumSubScene.h create mode 100644 game/background/BackgroundSubScene.cpp create mode 100644 game/background/BackgroundSubScene.h create mode 100644 game/background/ForestParallaxScript.cpp create mode 100644 game/background/ForestParallaxScript.h create mode 100644 game/background/ForestSubScene.cpp create mode 100644 game/background/ForestSubScene.h create mode 100644 game/background/HallwaySubScene.cpp create mode 100644 game/background/HallwaySubScene.h create mode 100644 game/background/StartSubScene.cpp create mode 100644 game/background/StartSubScene.h diff --git a/game/AquariumSubScene.cpp b/game/AquariumSubScene.cpp deleted file mode 100644 index f4b20f6..0000000 --- a/game/AquariumSubScene.cpp +++ /dev/null @@ -1,135 +0,0 @@ -#include "AquariumSubScene.h" - -#include -#include -#include -#include -#include - -using namespace crepe; -using namespace std; - -float AquariumSubScene::create(Scene & scn, float begin_x) { - this->add_background(scn, begin_x); - - GameObject aquarium_begin - = scn.new_object("aquarium_begin", "background", vec2(begin_x, 0)); - Asset aquarium_begin_asset{ - "asset/background/aquarium/glassTubeFG_1_TVOS.png"}; - aquarium_begin.add_component(aquarium_begin_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 0, - .size = vec2(0, 800), - }); - begin_x += 600; - - GameObject aquarium_middle_1 - = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); - Asset aquarium_middle_1_asset{ - "asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_1.add_component(aquarium_middle_1_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 2, - .size = vec2(0, 800), - }); - begin_x += 400; - - this->add_background(scn, begin_x - 200); - - GameObject aquarium_middle_2 - = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); - Asset aquarium_middle_2_asset{ - "asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_2.add_component(aquarium_middle_2_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 3, - .size = vec2(0, 800), - }); - begin_x += 400; - - GameObject aquarium_middle_3 - = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); - Asset aquarium_middle_3_asset{ - "asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_3.add_component(aquarium_middle_3_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 4, - .size = vec2(0, 800), - }); - begin_x += 400; - - this->add_background(scn, begin_x - 200); - - GameObject aquarium_middle_4 - = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); - Asset aquarium_middle_4_asset{ - "asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_4.add_component(aquarium_middle_4_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 5, - .size = vec2(0, 800), - }); - begin_x += 600; - - this->add_background(scn, begin_x); - - GameObject aquarium_end = scn.new_object("aquarium_end", "background", vec2(begin_x, 0)); - Asset aquarium_end_asset{ - "asset/background/aquarium/glassTubeFG_2_TVOS.png"}; - aquarium_end.add_component(aquarium_end_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 1, - .size = vec2(0, 800), - }); - begin_x += 600; - - return begin_x; -} - -void AquariumSubScene::add_background(Scene & scn, float begin_x) { - GameObject bg_1 = scn.new_object("aquarium_bg_1", "aquarium_background", vec2(begin_x, 0)); - Asset bg_1_1_asset{"asset/background/aquarium/AquariumBG1_1_TVOS.png"}; - bg_1.add_component(bg_1_1_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 2, - .size = vec2(0, 400), - .position_offset = vec2(-200, 100), - }); - Asset bg_1_2_asset{"asset/background/aquarium/AquariumBG1_2_TVOS.png"}; - bg_1.add_component(bg_1_2_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 2, - .size = vec2(0, 400), - .position_offset = vec2(200, 100), - }); - GameObject bg_2 = scn.new_object("aquarium_bg_2", "aquarium_background", vec2(begin_x, 0)); - Asset bg_2_1_asset{"asset/background/aquarium/AquariumBG2_1_TVOS.png"}; - bg_2.add_component(bg_2_1_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(200, -50), - }); - Asset bg_2_2_asset{"asset/background/aquarium/AquariumBG2_2_TVOS.png"}; - bg_2.add_component(bg_2_2_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(-200, -50), - }); - GameObject bg_3 = scn.new_object("aquarium_bg_3", "aquarium_background", vec2(begin_x, 0)); - Asset bg_3_1_asset{"asset/background/aquarium/AquariumBG3_1_TVOS.png"}; - bg_3.add_component(bg_3_1_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 0, - .size = vec2(0, 400), - .position_offset = vec2(200, -200), - }); - Asset bg_3_2_asset{"asset/background/aquarium/AquariumBG3_2_TVOS.png"}; - bg_3.add_component(bg_3_2_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 0, - .size = vec2(0, 400), - .position_offset = vec2(-200, -200), - }); -} diff --git a/game/AquariumSubScene.h b/game/AquariumSubScene.h deleted file mode 100644 index 2a188bc..0000000 --- a/game/AquariumSubScene.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -namespace crepe { -class Scene; -} - -class AquariumSubScene { -public: - float create(crepe::Scene & scn, float begin_x); - -private: - void add_background(crepe::Scene & scn, float begin_x); -}; diff --git a/game/BackgroundSubScene.cpp b/game/BackgroundSubScene.cpp deleted file mode 100644 index 6fdc598..0000000 --- a/game/BackgroundSubScene.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "BackgroundSubScene.h" -#include "AquariumSubScene.h" -#include "ForestSubScene.h" -#include "HallwaySubScene.h" -#include "StartSubScene.h" - -#include - -using namespace crepe; -using namespace std; - -BackgroundSubScene::BackgroundSubScene(Scene & scn) { - StartSubScene start; - HallwaySubScene hallway; - ForestSubScene forest; - AquariumSubScene aquarium; - - float begin_x = 400; - - begin_x = start.create(scn, begin_x); - - begin_x = hallway.create(scn, begin_x, 1, Color::YELLOW); - - begin_x = forest.create(scn, begin_x, "1"); - - begin_x = hallway.create(scn, begin_x, 2, Color::MAGENTA); - - begin_x = aquarium.create(scn, begin_x); - - begin_x = hallway.create(scn, begin_x, 3, Color::CYAN); - - begin_x = forest.create(scn, begin_x, "2"); - - begin_x = hallway.create(scn, begin_x, 4, Color::GREEN); - - begin_x = aquarium.create(scn, begin_x); -} diff --git a/game/BackgroundSubScene.h b/game/BackgroundSubScene.h deleted file mode 100644 index 06bdac4..0000000 --- a/game/BackgroundSubScene.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -namespace crepe { -class Scene; -} - -class BackgroundSubScene { -public: - BackgroundSubScene(crepe::Scene & scn); -}; diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index dc55523..937b5e6 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -9,17 +9,17 @@ project(game C CXX) add_subdirectory(../src crepe) add_executable(main - AquariumSubScene.cpp - BackgroundSubScene.cpp - ForestParallaxScript.cpp - ForestSubScene.cpp + background/AquariumSubScene.cpp + background/BackgroundSubScene.cpp + background/ForestParallaxScript.cpp + background/ForestSubScene.cpp GameScene.cpp - HallwaySubScene.cpp + background/HallwaySubScene.cpp MoveCameraManualyScript.cpp PlayerScript.cpp PlayerSubScene.cpp StartGameScript.cpp - StartSubScene.cpp + background/StartSubScene.cpp main.cpp ) diff --git a/game/ForestParallaxScript.cpp b/game/ForestParallaxScript.cpp deleted file mode 100644 index 27e30eb..0000000 --- a/game/ForestParallaxScript.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "ForestParallaxScript.h" - -using namespace crepe; -using namespace std; - -ForestParallaxScript::ForestParallaxScript(float begin_x, float end_x, - std::string unique_bg_name) - : begin_x(begin_x), - end_x(end_x), - name(unique_bg_name) {} - -void ForestParallaxScript::fixed_update(crepe::duration_t dt) { - RefVector vec_2 - = this->get_components_by_name("forest_bg_2_" + name); - RefVector vec_3 - = this->get_components_by_name("forest_bg_3_" + name); - - for (Transform & t : vec_2) { - if (t.position.x > end_x - 400) { - t.position.x = begin_x - 400; - } - } - for (Transform & t : vec_3) { - if (t.position.x > end_x - 400) { - t.position.x = begin_x - 400; - } - } -} diff --git a/game/ForestParallaxScript.h b/game/ForestParallaxScript.h deleted file mode 100644 index a65a684..0000000 --- a/game/ForestParallaxScript.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include - -class ForestParallaxScript : public crepe::Script { -public: - ForestParallaxScript(float begin_x, float end_x, std::string unique_bg_name); - - void fixed_update(crepe::duration_t dt); - -private: - const float begin_x; - const float end_x; - const std::string name; -}; diff --git a/game/ForestSubScene.cpp b/game/ForestSubScene.cpp deleted file mode 100644 index 810ef17..0000000 --- a/game/ForestSubScene.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#include "ForestSubScene.h" -#include "ForestParallaxScript.h" - -#include -#include -#include -#include -#include -#include -#include - -using namespace crepe; -using namespace std; - -float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_name) { - GameObject script = scn.new_object("forest_script", "background"); - script.add_component().set_script( - begin_x - 400, begin_x + 3000 + 400, unique_bg_name); - - this->add_background(scn, begin_x, unique_bg_name); - - GameObject begin = scn.new_object("forest_begin", "background", vec2(begin_x, 0)); - Asset begin_asset{"asset/background/forest/forestFG_1_TVOS.png"}; - begin.add_component(begin_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 0, - .size = vec2(0, 800), - }); - begin_x += 800; - - this->add_background(scn, begin_x, unique_bg_name); - - GameObject middle_1 = scn.new_object("forest_middle", "background", vec2(begin_x, 0)); - Asset middle_1_asset{"asset/background/forest/forestFG_3_TVOS.png"}; - middle_1.add_component(middle_1_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 2, - .size = vec2(0, 800), - }); - begin_x += 800; - - this->add_background(scn, begin_x, unique_bg_name); - - GameObject middle_2 = scn.new_object("forest_middle", "background", vec2(begin_x, 0)); - Asset middle_2_asset{"asset/background/forest/forestFG_3_TVOS.png"}; - middle_2.add_component(middle_2_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 3, - .size = vec2(0, 800), - }); - begin_x += 800; - - this->add_background(scn, begin_x, unique_bg_name); - - GameObject end = scn.new_object("forest_end", "background", vec2(begin_x, 0)); - Asset end_asset{"asset/background/forest/forestFG_2_TVOS.png"}; - end.add_component(end_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 1, - .size = vec2(0, 800), - }); - begin_x += 600; - - this->add_background(scn, begin_x + 200, unique_bg_name); - - return begin_x; -} - -void ForestSubScene::add_background(Scene & scn, float begin_x, std::string name) { - GameObject bg_1 - = scn.new_object("forest_bg_1_" + name, "forest_background", vec2(begin_x, 0)); - Asset bg_1_asset{"asset/background/forest/forestBG1_1_TVOS.png"}; - bg_1.add_component(bg_1_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 2, - .size = vec2(0, 800), - }); - GameObject bg_2 - = scn.new_object("forest_bg_2_" + name, "forest_background", vec2(begin_x, 0)); - Asset bg_2_1_asset{"asset/background/forest/forestBG2_1_TVOS.png"}; - bg_2.add_component(bg_2_1_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(200, 0), - }); - Asset bg_2_2_asset{"asset/background/forest/forestBG2_2_TVOS.png"}; - bg_2.add_component(bg_2_2_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(-200, 0), - }); - GameObject bg_3 - = scn.new_object("forest_bg_3_" + name, "forest_background", vec2(begin_x, 0)); - Asset bg_3_1_asset{"asset/background/forest/forestBG3_1_TVOS.png"}; - bg_3.add_component(bg_3_1_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(300, 0), - }); - Asset bg_3_2_asset{"asset/background/forest/forestBG3_2_TVOS.png"}; - bg_3.add_component(bg_3_2_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(100, 0), - }); - Asset bg_3_3_asset{"asset/background/forest/forestBG3_3_TVOS.png"}; - bg_3.add_component(bg_3_3_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(-100, 0), - }); - Asset bg_3_4_asset{"asset/background/forest/forestBG3_4_TVOS.png"}; - bg_3.add_component(bg_3_4_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(-300, 0), - }); - - bg_2.add_component(Rigidbody::Data{ - .linear_velocity = vec2(30, 0), - }); - bg_3.add_component(Rigidbody::Data{ - .linear_velocity = vec2(40, 0), - }); -} diff --git a/game/ForestSubScene.h b/game/ForestSubScene.h deleted file mode 100644 index 0a04001..0000000 --- a/game/ForestSubScene.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include - -namespace crepe { -class Scene; -} - -class ForestSubScene { -public: - float create(crepe::Scene & scn, float begin_x, std::string unique_bg_name); - -private: - void add_background(crepe::Scene & scn, float begin_x, std::string name); -}; diff --git a/game/GameScene.cpp b/game/GameScene.cpp index c280474..9606244 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -1,9 +1,10 @@ #include "GameScene.h" -#include "BackgroundSubScene.h" #include "MoveCameraManualyScript.h" #include "PlayerSubScene.h" #include "StartGameScript.h" +#include "background/BackgroundSubScene.h" + #include #include #include diff --git a/game/HallwaySubScene.cpp b/game/HallwaySubScene.cpp deleted file mode 100644 index 486b8c6..0000000 --- a/game/HallwaySubScene.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "HallwaySubScene.h" - -#include -#include -#include -#include -#include - -using namespace crepe; -using namespace std; - -float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_num, - Color sector_color) { - GameObject begin = scn.new_object("hallway_begin", "background", vec2(begin_x, 0)); - Asset begin_asset{"asset/background/hallway/hallway1FG_1_TVOS.png"}; - begin.add_component(begin_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 0, - .size = vec2(0, 800), - }); - begin_x += 600; - - this->add_sector_number(begin, vec2(-200, 0), sector_num, sector_color); - this->add_lamp(begin, vec2(330, -120), 11); - this->add_lamp(begin, vec2(430, -120), 9); - - GameObject middle_1 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); - Asset middle_asset{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_1.add_component(middle_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 2, - .size = vec2(0, 800), - }); - begin_x += 600; - - GameObject middle_2 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); - Asset middle_asset_2{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_2.add_component(middle_asset_2, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 3, - .size = vec2(0, 800), - }); - begin_x += 200; - - GameObject middle_3 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); - Asset middle_asset_3{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_3.add_component(middle_asset_3, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 4, - .size = vec2(0, 800), - }); - begin_x += 400; - - this->add_lamp(middle_3, vec2(0, -120)); - - GameObject middle_4 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); - Asset middle_asset_4{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_4.add_component(middle_asset_4, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 5, - .size = vec2(0, 800), - }); - begin_x += 600; - - GameObject end = scn.new_object("hallway_end", "background", vec2(begin_x, 0)); - Asset end_asset{"asset/background/hallway/hallway1FG_1_TVOS.png"}; - end.add_component(end_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 1, - .size = vec2(0, 800), - }); - begin_x += 600; - - return begin_x; -} - -void HallwaySubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) { - Asset lamp_asset{"asset/background/hallway/alarmLight_TVOS.png"}; - obj.add_component(lamp_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset, - }); - Asset lamp_glow_asset{"asset/background/hallway/alarmGlow_TVOS.png"}; - Sprite & lamp_glow_sprite = obj.add_component( - lamp_glow_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 1, - .size = vec2(0, 300), - .position_offset = offset - vec2(65, -30), - }); - obj.add_component(lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1), - Animator::Data{ - .fps = fps, - .looping = true, - }); -} - -void HallwaySubScene::add_sector_number(GameObject & obj, vec2 offset, unsigned int sector_num, - Color sector_color) { - Asset sector_text_asset{"asset/background/hallway/sectorText_TVOS.png"}; - obj.add_component(sector_text_asset, Sprite::Data{ - .color = sector_color, - .sorting_in_layer = 5, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset, - }); - Asset sector_num_asset{"asset/background/hallway/sectorNumbers_TVOS.png"}; - Sprite & sector_num_sprite = obj.add_component( - sector_num_asset, Sprite::Data{ - .color = sector_color, - .sorting_in_layer = 5, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset + vec2(200, 0), - }); - Animator & sector_num_anim = obj.add_component( - sector_num_sprite, ivec2(256, 128), uvec2(4, 4), Animator::Data{}); - int column = (sector_num - 1) / 4; - int row = (sector_num - 1) % 4; - sector_num_anim.set_anim(column); - for (int i = 0; i < row; i++) { - sector_num_anim.next_anim(); - } - sector_num_anim.pause(); -} diff --git a/game/HallwaySubScene.h b/game/HallwaySubScene.h deleted file mode 100644 index acc9329..0000000 --- a/game/HallwaySubScene.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include - -namespace crepe { -class Scene; -class GameObject; -class Color; -} // namespace crepe - -class HallwaySubScene { -public: - float create(crepe::Scene & scn, float begin_x, unsigned int sector_num, - crepe::Color sector_color); - -private: - void add_lamp(crepe::GameObject & obj, crepe::vec2 offset, unsigned int fps = 10); - - void add_sector_number(crepe::GameObject & obj, crepe::vec2 offset, - unsigned int sector_num, crepe::Color sector_color); -}; diff --git a/game/StartSubScene.cpp b/game/StartSubScene.cpp deleted file mode 100644 index 5d810c2..0000000 --- a/game/StartSubScene.cpp +++ /dev/null @@ -1,442 +0,0 @@ -#include "StartSubScene.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace crepe; -using namespace std; - -float StartSubScene::create(Scene & scn, float begin_x) { - this->create_wall_fragments(scn, begin_x - 300); - - GameObject begin = scn.new_object("start_begin", "background", vec2(begin_x, 0)); - Asset begin_asset{"asset/background/start/titleFG_1_TVOS.png"}; - begin.add_component(begin_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 0, - .size = vec2(0, 800), - }); - GameObject hole = scn.new_object("start_hole", "background", vec2(begin_x - 250, 140)); - Asset hole_asset{"asset/background/start/titleWallHole.png"}; - Sprite & hole_sprite = hole.add_component(hole_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 1, - .size = vec2(0, 200), - }); - hole_sprite.active = false; - begin_x += 700; - - this->add_table(begin, vec2(-150, 150)); - this->add_light(begin, vec2(-125, -150)); - this->add_jetpack_stand(begin, vec2(-125, 200)); - - GameObject end = scn.new_object("start_end", "background", vec2(begin_x, 0)); - Asset end_asset{"asset/background/start/titleFG_2_TVOS.png"}; - end.add_component(end_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 1, - .size = vec2(0, 800), - }); - begin_x += 100; - - this->add_lamp(end, vec2(-350, -95)); - - return begin_x; -} - -void StartSubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) { - Asset lamp_asset{"asset/background/start/alarmLight_TVOS.png"}; - obj.add_component(lamp_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset, - }); - Asset lamp_glow_asset{"asset/background/start/alarmGlow_TVOS.png"}; - Sprite & lamp_glow_sprite = obj.add_component( - lamp_glow_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 1, - .size = vec2(0, 300), - .position_offset = offset - vec2(65, -55), - }); - lamp_glow_sprite.active = false; - obj.add_component(lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1), - Animator::Data{ - .fps = fps, - .looping = true, - }); -} - -void StartSubScene::add_table(GameObject & obj, vec2 offset) { - Asset table_asset{"asset/background/start/table.png"}; - obj.add_component(table_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset, - }); - Asset gramophone_asset{"asset/background/start/gramophone_TVOS.png"}; - Sprite & gramophone_sprite = obj.add_component( - gramophone_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 1, - .size = vec2(0, 100), - .position_offset = offset + vec2(0, -50), - }); - obj.add_component(gramophone_sprite, ivec2(64, 128), uvec2(2, 1), - Animator::Data{ - .fps = 10, - .looping = true, - }); -} - -void StartSubScene::add_light(crepe::GameObject & obj, crepe::vec2 offset) { - Asset light_asset{"asset/background/start/title_light_TVOS.png"}; - obj.add_component(light_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = offset, - }); - Asset light_glow_asset{"asset/background/start/lightEffect2.png"}; - obj.add_component(light_glow_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 1, - .size = vec2(0, 100), - .position_offset = offset + vec2(0, 75), - }); - Asset light_effect_asset{"asset/background/start/lightEffect.png"}; - obj.add_component(light_effect_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset + vec2(0, 350), - }); -} - -void StartSubScene::add_jetpack_stand(crepe::GameObject & obj, crepe::vec2 offset) { - Asset jetpack_stand_asset{"asset/background/start/JetpackStand.png"}; - Sprite & jetpeck_stand_sprite - = obj.add_component(jetpack_stand_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 1, - .size = vec2(0, 70), - .position_offset = offset, - }); - obj.add_component(jetpeck_stand_sprite, ivec2(34, 46), uvec2(2, 1), - Animator::Data{ - .fps = 10, - .looping = true, - }) - .pause(); - Asset do_not_steal = {"asset/background/start/doNotTouchSign_TVOS.png"}; - obj.add_component(do_not_steal, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 1, - .size = vec2(0, 100), - .position_offset = offset + vec2(-75, -25), - }); -} - -void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { - GameObject frag_1 = scn.new_object("frag_1", "wall_fragment", vec2(begin_x, 200)); - Asset frag_1_asset{"asset/background/start/StartWall_frag1.png"}; - Sprite & frag_1_sprite - = frag_1.add_component(frag_1_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); - frag_1_sprite.active = false; - Rigidbody & frag_1_rb = frag_1.add_component(Rigidbody::Data{ - .gravity_scale = 10, - .linear_velocity = vec2(400, 400), - .linear_velocity_coefficient = vec2(0.5, 0.6), - .angular_velocity = 500, - .angular_velocity_coefficient = 0.55, - .elasticity_coefficient = 0.5, - .collision_layer = 5, - }); - frag_1_rb.active = false; - frag_1.add_component(25); - - GameObject frag_2 = scn.new_object("frag_2", "wall_fragment", vec2(begin_x, 180)); - Asset frag_2_asset{"asset/background/start/StartWall_frag2.png"}; - Sprite & frag_2_sprite - = frag_2.add_component(frag_2_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); - frag_2_sprite.active = false; - Rigidbody & frag_2_rb = frag_2.add_component(Rigidbody::Data{ - .gravity_scale = 20, - .linear_velocity = vec2(400, 400), - .linear_velocity_coefficient = vec2(0.35, 0.4), - .angular_velocity = 400, - .angular_velocity_coefficient = 0.55, - .elasticity_coefficient = 0.5, - .collision_layer = 5, - }); - frag_2_rb.active = false; - frag_2.add_component(55); - - GameObject frag_3 = scn.new_object("frag_3", "wall_fragment", vec2(begin_x, 170)); - Asset frag_3_asset{"asset/background/start/StartWall_frag3.png"}; - Sprite & frag_3_sprite - = frag_3.add_component(frag_3_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); - frag_3_sprite.active = false; - Rigidbody & frag_3_rb = frag_3.add_component(Rigidbody::Data{ - .gravity_scale = 30, - .linear_velocity = vec2(400, 400), - .linear_velocity_coefficient = vec2(0.3, 0.3), - .angular_velocity = 300, - .angular_velocity_coefficient = 0.55, - .elasticity_coefficient = 0.5, - .collision_layer = 5, - }); - frag_3_rb.active = false; - frag_3.add_component(35); - - GameObject frag_4 = scn.new_object("frag_4", "wall_fragment", vec2(begin_x, 160)); - Asset frag_4_asset{"asset/background/start/StartWall_frag4.png"}; - Sprite & frag_4_sprite - = frag_4.add_component(frag_4_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); - frag_4_sprite.active = false; - Rigidbody & frag_4_rb = frag_4.add_component(Rigidbody::Data{ - .gravity_scale = 40, - .linear_velocity = vec2(700, 400), - .linear_velocity_coefficient = vec2(0.2, 0.2), - .angular_velocity = 200, - .angular_velocity_coefficient = 0.55, - .elasticity_coefficient = 0.5, - .collision_layer = 5, - }); - frag_4_rb.active = false; - frag_4.add_component(60); - - GameObject frag_5 = scn.new_object("frag_5", "wall_fragment", vec2(begin_x, 150)); - Asset frag_5_asset{"asset/background/start/StartWall_frag5.png"}; - Sprite & frag_5_sprite - = frag_5.add_component(frag_5_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); - frag_5_sprite.active = false; - Rigidbody & frag_5_rb = frag_5.add_component(Rigidbody::Data{ - .gravity_scale = 50, - .linear_velocity = vec2(600, 800), - .linear_velocity_coefficient = vec2(0.25, 0.15), - .angular_velocity = 100, - .angular_velocity_coefficient = 0.55, - .elasticity_coefficient = 0.5, - .collision_layer = 5, - }); - frag_5_rb.active = false; - frag_5.add_component(5); - - GameObject frag_6 = scn.new_object("frag_6", "wall_fragment", vec2(begin_x, 140)); - Asset frag_6_asset{"asset/background/start/StartWall_frag6.png"}; - Sprite & frag_6_sprite - = frag_6.add_component(frag_6_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); - frag_6_sprite.active = false; - Rigidbody & frag_6_rb = frag_6.add_component(Rigidbody::Data{ - .gravity_scale = 30, - .linear_velocity = vec2(300, 800), - .linear_velocity_coefficient = vec2(0.35, 0.25), - .angular_velocity = 100, - .angular_velocity_coefficient = 0.55, - .elasticity_coefficient = 0.5, - .collision_layer = 5, - }); - frag_6_rb.active = false; - frag_6.add_component(30); - - GameObject frag_7 = scn.new_object("frag_7", "wall_fragment", vec2(begin_x, 130)); - Asset frag_7_asset{"asset/background/start/StartWall_frag7.png"}; - Sprite & frag_7_sprite - = frag_7.add_component(frag_7_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); - frag_7_sprite.active = false; - Rigidbody & frag_7_rb = frag_7.add_component(Rigidbody::Data{ - .gravity_scale = 20, - .linear_velocity = vec2(400, 500), - .linear_velocity_coefficient = vec2(0.45, 0.6), - .angular_velocity = 800, - .angular_velocity_coefficient = 0.55, - .elasticity_coefficient = 0.5, - .collision_layer = 5, - }); - frag_7_rb.active = false; - frag_7.add_component(45); - - GameObject frag_8 = scn.new_object("frag_8", "wall_fragment", vec2(begin_x, 120)); - Asset frag_8_asset{"asset/background/start/StartWall_frag8.png"}; - Sprite & frag_8_sprite - = frag_8.add_component(frag_8_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); - frag_8_sprite.active = false; - Rigidbody & frag_8_rb = frag_8.add_component(Rigidbody::Data{ - .gravity_scale = 30, - .linear_velocity = vec2(400, 400), - .linear_velocity_coefficient = vec2(0.5, 0.6), - .angular_velocity = 500, - .angular_velocity_coefficient = 0.55, - .elasticity_coefficient = 0.5, - .collision_layer = 5, - }); - frag_8_rb.active = false; - frag_8.add_component(25); - - GameObject frag_9 = scn.new_object("frag_9", "wall_fragment", vec2(begin_x, 110)); - Asset frag_9_asset{"asset/background/start/StartWall_frag9.png"}; - Sprite & frag_9_sprite - = frag_9.add_component(frag_9_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); - frag_9_sprite.active = false; - Rigidbody & frag_9_rb = frag_9.add_component(Rigidbody::Data{ - .gravity_scale = 40, - .linear_velocity = vec2(200, 400), - .linear_velocity_coefficient = vec2(0.5, 0.25), - .angular_velocity = 500, - .angular_velocity_coefficient = 0.55, - .elasticity_coefficient = 0.5, - .collision_layer = 5, - }); - frag_9_rb.active = false; - frag_9.add_component(15); - - GameObject frag_10 = scn.new_object("frag_10", "wall_fragment", vec2(begin_x, 100)); - Asset frag_10_asset{"asset/background/start/StartWall_frag10.png"}; - Sprite & frag_10_sprite - = frag_10.add_component(frag_10_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); - frag_10_sprite.active = false; - Rigidbody & frag_10_rb = frag_10.add_component(Rigidbody::Data{ - .gravity_scale = 50, - .linear_velocity = vec2(400, 900), - .linear_velocity_coefficient = vec2(0.35, 0.4), - .angular_velocity = 300, - .angular_velocity_coefficient = 0.55, - .elasticity_coefficient = 0.5, - .collision_layer = 5, - }); - frag_10_rb.active = false; - frag_10.add_component(60); - - GameObject frag_11 = scn.new_object("frag_11", "wall_fragment", vec2(begin_x, 90)); - Asset frag_11_asset{"asset/background/start/StartWall_frag11.png"}; - Sprite & frag_11_sprite - = frag_11.add_component(frag_11_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); - frag_11_sprite.active = false; - Rigidbody & frag_11_rb = frag_11.add_component(Rigidbody::Data{ - .gravity_scale = 60, - .linear_velocity = vec2(600, 800), - .linear_velocity_coefficient = vec2(0.3, 0.3), - .angular_velocity = 200, - .angular_velocity_coefficient = 0.55, - .elasticity_coefficient = 0.5, - .collision_layer = 5, - }); - frag_11_rb.active = false; - frag_11.add_component(5); - - GameObject frag_12 = scn.new_object("frag_12", "wall_fragment", vec2(begin_x, 80)); - Asset frag_12_asset{"asset/background/start/StartWall_frag12.png"}; - Sprite & frag_12_sprite - = frag_12.add_component(frag_12_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); - frag_12_sprite.active = false; - Rigidbody & frag_12_rb = frag_12.add_component(Rigidbody::Data{ - .gravity_scale = 70, - .linear_velocity = vec2(500, 800), - .linear_velocity_coefficient = vec2(0.25, 0.15), - .angular_velocity = 100, - .angular_velocity_coefficient = 0.55, - .elasticity_coefficient = 0.5, - .collision_layer = 5, - }); - frag_12_rb.active = false; - frag_12.add_component(50); - - GameObject smoke_particles_1 - = scn.new_object("smoke_particles", "particle_emitter", vec2(begin_x - 100, 200)); - Asset smoke_asset_1{"asset/particles/smoke.png"}; - Sprite & smoke_sprite_1 = smoke_particles_1.add_component( - smoke_asset_1, Sprite::Data{ - .color = Color(255, 255, 255, 50), - .sorting_in_layer = 15, - .order_in_layer = 0, - .size = vec2(0, 100), - }); - ParticleEmitter & emitter_1 = smoke_particles_1.add_component( - smoke_sprite_1, ParticleEmitter::Data{ - .emission_rate = 20, - .min_speed = 40, - .max_speed = 100, - .min_angle = -30, - .max_angle = 10, - .end_lifespan = 4, - }); - emitter_1.active = false; - - GameObject smoke_particles_2 - = scn.new_object("smoke_particles", "particle_emitter", vec2(begin_x - 100, 200)); - Asset smoke_asset_2{"asset/particles/smoke.png"}; - Sprite & smoke_sprite_2 = smoke_particles_2.add_component( - smoke_asset_2, Sprite::Data{ - .color = Color(255, 255, 255, 50), - .sorting_in_layer = 15, - .order_in_layer = 0, - .size = vec2(0, 70), - }); - ParticleEmitter & emitter_2 = smoke_particles_2.add_component( - smoke_sprite_2, ParticleEmitter::Data{ - .emission_rate = 30, - .min_speed = 40, - .max_speed = 100, - .min_angle = -45, - .max_angle = 5, - .end_lifespan = 3, - }); - emitter_2.active = false; -} diff --git a/game/StartSubScene.h b/game/StartSubScene.h deleted file mode 100644 index c83e3d5..0000000 --- a/game/StartSubScene.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include - -namespace crepe { -class Scene; -class GameObject; -} // namespace crepe - -class StartSubScene { -public: - float create(crepe::Scene & scn, float begin_x); - -private: - void add_lamp(crepe::GameObject & obj, crepe::vec2 offset, unsigned int fps = 10); - void add_table(crepe::GameObject & obj, crepe::vec2 offset); - void add_light(crepe::GameObject & obj, crepe::vec2 offset); - void add_jetpack_stand(crepe::GameObject & obj, crepe::vec2 offset); - void create_wall_fragments(crepe::Scene & scn, float begin_x); -}; diff --git a/game/background/AquariumSubScene.cpp b/game/background/AquariumSubScene.cpp new file mode 100644 index 0000000..40e22b7 --- /dev/null +++ b/game/background/AquariumSubScene.cpp @@ -0,0 +1,129 @@ +#include "AquariumSubScene.h" + +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +float AquariumSubScene::create(Scene & scn, float begin_x) { + this->add_background(scn, begin_x); + + GameObject aquarium_begin + = scn.new_object("aquarium_begin", "background", vec2(begin_x, 0)); + Asset aquarium_begin_asset{"asset/background/aquarium/glassTubeFG_1_TVOS.png"}; + aquarium_begin.add_component(aquarium_begin_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 0, + .size = vec2(0, 800), + }); + begin_x += 600; + + GameObject aquarium_middle_1 + = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); + Asset aquarium_middle_1_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; + aquarium_middle_1.add_component(aquarium_middle_1_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 2, + .size = vec2(0, 800), + }); + begin_x += 400; + + this->add_background(scn, begin_x - 200); + + GameObject aquarium_middle_2 + = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); + Asset aquarium_middle_2_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; + aquarium_middle_2.add_component(aquarium_middle_2_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 3, + .size = vec2(0, 800), + }); + begin_x += 400; + + GameObject aquarium_middle_3 + = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); + Asset aquarium_middle_3_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; + aquarium_middle_3.add_component(aquarium_middle_3_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 4, + .size = vec2(0, 800), + }); + begin_x += 400; + + this->add_background(scn, begin_x - 200); + + GameObject aquarium_middle_4 + = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); + Asset aquarium_middle_4_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; + aquarium_middle_4.add_component(aquarium_middle_4_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 5, + .size = vec2(0, 800), + }); + begin_x += 600; + + this->add_background(scn, begin_x); + + GameObject aquarium_end = scn.new_object("aquarium_end", "background", vec2(begin_x, 0)); + Asset aquarium_end_asset{"asset/background/aquarium/glassTubeFG_2_TVOS.png"}; + aquarium_end.add_component(aquarium_end_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 1, + .size = vec2(0, 800), + }); + begin_x += 600; + + return begin_x; +} + +void AquariumSubScene::add_background(Scene & scn, float begin_x) { + GameObject bg_1 = scn.new_object("aquarium_bg_1", "aquarium_background", vec2(begin_x, 0)); + Asset bg_1_1_asset{"asset/background/aquarium/AquariumBG1_1_TVOS.png"}; + bg_1.add_component(bg_1_1_asset, Sprite::Data{ + .sorting_in_layer = 3, + .order_in_layer = 2, + .size = vec2(0, 400), + .position_offset = vec2(-200, 100), + }); + Asset bg_1_2_asset{"asset/background/aquarium/AquariumBG1_2_TVOS.png"}; + bg_1.add_component(bg_1_2_asset, Sprite::Data{ + .sorting_in_layer = 3, + .order_in_layer = 2, + .size = vec2(0, 400), + .position_offset = vec2(200, 100), + }); + GameObject bg_2 = scn.new_object("aquarium_bg_2", "aquarium_background", vec2(begin_x, 0)); + Asset bg_2_1_asset{"asset/background/aquarium/AquariumBG2_1_TVOS.png"}; + bg_2.add_component(bg_2_1_asset, Sprite::Data{ + .sorting_in_layer = 3, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(200, -50), + }); + Asset bg_2_2_asset{"asset/background/aquarium/AquariumBG2_2_TVOS.png"}; + bg_2.add_component(bg_2_2_asset, Sprite::Data{ + .sorting_in_layer = 3, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(-200, -50), + }); + GameObject bg_3 = scn.new_object("aquarium_bg_3", "aquarium_background", vec2(begin_x, 0)); + Asset bg_3_1_asset{"asset/background/aquarium/AquariumBG3_1_TVOS.png"}; + bg_3.add_component(bg_3_1_asset, Sprite::Data{ + .sorting_in_layer = 3, + .order_in_layer = 0, + .size = vec2(0, 400), + .position_offset = vec2(200, -200), + }); + Asset bg_3_2_asset{"asset/background/aquarium/AquariumBG3_2_TVOS.png"}; + bg_3.add_component(bg_3_2_asset, Sprite::Data{ + .sorting_in_layer = 3, + .order_in_layer = 0, + .size = vec2(0, 400), + .position_offset = vec2(-200, -200), + }); +} diff --git a/game/background/AquariumSubScene.h b/game/background/AquariumSubScene.h new file mode 100644 index 0000000..2a188bc --- /dev/null +++ b/game/background/AquariumSubScene.h @@ -0,0 +1,13 @@ +#pragma once + +namespace crepe { +class Scene; +} + +class AquariumSubScene { +public: + float create(crepe::Scene & scn, float begin_x); + +private: + void add_background(crepe::Scene & scn, float begin_x); +}; diff --git a/game/background/BackgroundSubScene.cpp b/game/background/BackgroundSubScene.cpp new file mode 100644 index 0000000..6fdc598 --- /dev/null +++ b/game/background/BackgroundSubScene.cpp @@ -0,0 +1,37 @@ +#include "BackgroundSubScene.h" +#include "AquariumSubScene.h" +#include "ForestSubScene.h" +#include "HallwaySubScene.h" +#include "StartSubScene.h" + +#include + +using namespace crepe; +using namespace std; + +BackgroundSubScene::BackgroundSubScene(Scene & scn) { + StartSubScene start; + HallwaySubScene hallway; + ForestSubScene forest; + AquariumSubScene aquarium; + + float begin_x = 400; + + begin_x = start.create(scn, begin_x); + + begin_x = hallway.create(scn, begin_x, 1, Color::YELLOW); + + begin_x = forest.create(scn, begin_x, "1"); + + begin_x = hallway.create(scn, begin_x, 2, Color::MAGENTA); + + begin_x = aquarium.create(scn, begin_x); + + begin_x = hallway.create(scn, begin_x, 3, Color::CYAN); + + begin_x = forest.create(scn, begin_x, "2"); + + begin_x = hallway.create(scn, begin_x, 4, Color::GREEN); + + begin_x = aquarium.create(scn, begin_x); +} diff --git a/game/background/BackgroundSubScene.h b/game/background/BackgroundSubScene.h new file mode 100644 index 0000000..06bdac4 --- /dev/null +++ b/game/background/BackgroundSubScene.h @@ -0,0 +1,10 @@ +#pragma once + +namespace crepe { +class Scene; +} + +class BackgroundSubScene { +public: + BackgroundSubScene(crepe::Scene & scn); +}; diff --git a/game/background/ForestParallaxScript.cpp b/game/background/ForestParallaxScript.cpp new file mode 100644 index 0000000..27e30eb --- /dev/null +++ b/game/background/ForestParallaxScript.cpp @@ -0,0 +1,28 @@ +#include "ForestParallaxScript.h" + +using namespace crepe; +using namespace std; + +ForestParallaxScript::ForestParallaxScript(float begin_x, float end_x, + std::string unique_bg_name) + : begin_x(begin_x), + end_x(end_x), + name(unique_bg_name) {} + +void ForestParallaxScript::fixed_update(crepe::duration_t dt) { + RefVector vec_2 + = this->get_components_by_name("forest_bg_2_" + name); + RefVector vec_3 + = this->get_components_by_name("forest_bg_3_" + name); + + for (Transform & t : vec_2) { + if (t.position.x > end_x - 400) { + t.position.x = begin_x - 400; + } + } + for (Transform & t : vec_3) { + if (t.position.x > end_x - 400) { + t.position.x = begin_x - 400; + } + } +} diff --git a/game/background/ForestParallaxScript.h b/game/background/ForestParallaxScript.h new file mode 100644 index 0000000..a65a684 --- /dev/null +++ b/game/background/ForestParallaxScript.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +class ForestParallaxScript : public crepe::Script { +public: + ForestParallaxScript(float begin_x, float end_x, std::string unique_bg_name); + + void fixed_update(crepe::duration_t dt); + +private: + const float begin_x; + const float end_x; + const std::string name; +}; diff --git a/game/background/ForestSubScene.cpp b/game/background/ForestSubScene.cpp new file mode 100644 index 0000000..810ef17 --- /dev/null +++ b/game/background/ForestSubScene.cpp @@ -0,0 +1,131 @@ +#include "ForestSubScene.h" +#include "ForestParallaxScript.h" + +#include +#include +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_name) { + GameObject script = scn.new_object("forest_script", "background"); + script.add_component().set_script( + begin_x - 400, begin_x + 3000 + 400, unique_bg_name); + + this->add_background(scn, begin_x, unique_bg_name); + + GameObject begin = scn.new_object("forest_begin", "background", vec2(begin_x, 0)); + Asset begin_asset{"asset/background/forest/forestFG_1_TVOS.png"}; + begin.add_component(begin_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 0, + .size = vec2(0, 800), + }); + begin_x += 800; + + this->add_background(scn, begin_x, unique_bg_name); + + GameObject middle_1 = scn.new_object("forest_middle", "background", vec2(begin_x, 0)); + Asset middle_1_asset{"asset/background/forest/forestFG_3_TVOS.png"}; + middle_1.add_component(middle_1_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 2, + .size = vec2(0, 800), + }); + begin_x += 800; + + this->add_background(scn, begin_x, unique_bg_name); + + GameObject middle_2 = scn.new_object("forest_middle", "background", vec2(begin_x, 0)); + Asset middle_2_asset{"asset/background/forest/forestFG_3_TVOS.png"}; + middle_2.add_component(middle_2_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 3, + .size = vec2(0, 800), + }); + begin_x += 800; + + this->add_background(scn, begin_x, unique_bg_name); + + GameObject end = scn.new_object("forest_end", "background", vec2(begin_x, 0)); + Asset end_asset{"asset/background/forest/forestFG_2_TVOS.png"}; + end.add_component(end_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 1, + .size = vec2(0, 800), + }); + begin_x += 600; + + this->add_background(scn, begin_x + 200, unique_bg_name); + + return begin_x; +} + +void ForestSubScene::add_background(Scene & scn, float begin_x, std::string name) { + GameObject bg_1 + = scn.new_object("forest_bg_1_" + name, "forest_background", vec2(begin_x, 0)); + Asset bg_1_asset{"asset/background/forest/forestBG1_1_TVOS.png"}; + bg_1.add_component(bg_1_asset, Sprite::Data{ + .sorting_in_layer = 3, + .order_in_layer = 2, + .size = vec2(0, 800), + }); + GameObject bg_2 + = scn.new_object("forest_bg_2_" + name, "forest_background", vec2(begin_x, 0)); + Asset bg_2_1_asset{"asset/background/forest/forestBG2_1_TVOS.png"}; + bg_2.add_component(bg_2_1_asset, Sprite::Data{ + .sorting_in_layer = 3, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(200, 0), + }); + Asset bg_2_2_asset{"asset/background/forest/forestBG2_2_TVOS.png"}; + bg_2.add_component(bg_2_2_asset, Sprite::Data{ + .sorting_in_layer = 3, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(-200, 0), + }); + GameObject bg_3 + = scn.new_object("forest_bg_3_" + name, "forest_background", vec2(begin_x, 0)); + Asset bg_3_1_asset{"asset/background/forest/forestBG3_1_TVOS.png"}; + bg_3.add_component(bg_3_1_asset, Sprite::Data{ + .sorting_in_layer = 3, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(300, 0), + }); + Asset bg_3_2_asset{"asset/background/forest/forestBG3_2_TVOS.png"}; + bg_3.add_component(bg_3_2_asset, Sprite::Data{ + .sorting_in_layer = 3, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(100, 0), + }); + Asset bg_3_3_asset{"asset/background/forest/forestBG3_3_TVOS.png"}; + bg_3.add_component(bg_3_3_asset, Sprite::Data{ + .sorting_in_layer = 3, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(-100, 0), + }); + Asset bg_3_4_asset{"asset/background/forest/forestBG3_4_TVOS.png"}; + bg_3.add_component(bg_3_4_asset, Sprite::Data{ + .sorting_in_layer = 3, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(-300, 0), + }); + + bg_2.add_component(Rigidbody::Data{ + .linear_velocity = vec2(30, 0), + }); + bg_3.add_component(Rigidbody::Data{ + .linear_velocity = vec2(40, 0), + }); +} diff --git a/game/background/ForestSubScene.h b/game/background/ForestSubScene.h new file mode 100644 index 0000000..0a04001 --- /dev/null +++ b/game/background/ForestSubScene.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace crepe { +class Scene; +} + +class ForestSubScene { +public: + float create(crepe::Scene & scn, float begin_x, std::string unique_bg_name); + +private: + void add_background(crepe::Scene & scn, float begin_x, std::string name); +}; diff --git a/game/background/HallwaySubScene.cpp b/game/background/HallwaySubScene.cpp new file mode 100644 index 0000000..486b8c6 --- /dev/null +++ b/game/background/HallwaySubScene.cpp @@ -0,0 +1,128 @@ +#include "HallwaySubScene.h" + +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_num, + Color sector_color) { + GameObject begin = scn.new_object("hallway_begin", "background", vec2(begin_x, 0)); + Asset begin_asset{"asset/background/hallway/hallway1FG_1_TVOS.png"}; + begin.add_component(begin_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 0, + .size = vec2(0, 800), + }); + begin_x += 600; + + this->add_sector_number(begin, vec2(-200, 0), sector_num, sector_color); + this->add_lamp(begin, vec2(330, -120), 11); + this->add_lamp(begin, vec2(430, -120), 9); + + GameObject middle_1 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); + Asset middle_asset{"asset/background/hallway/hallway1FG_2_TVOS.png"}; + middle_1.add_component(middle_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 2, + .size = vec2(0, 800), + }); + begin_x += 600; + + GameObject middle_2 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); + Asset middle_asset_2{"asset/background/hallway/hallway1FG_2_TVOS.png"}; + middle_2.add_component(middle_asset_2, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 3, + .size = vec2(0, 800), + }); + begin_x += 200; + + GameObject middle_3 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); + Asset middle_asset_3{"asset/background/hallway/hallway1FG_2_TVOS.png"}; + middle_3.add_component(middle_asset_3, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 4, + .size = vec2(0, 800), + }); + begin_x += 400; + + this->add_lamp(middle_3, vec2(0, -120)); + + GameObject middle_4 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); + Asset middle_asset_4{"asset/background/hallway/hallway1FG_2_TVOS.png"}; + middle_4.add_component(middle_asset_4, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 5, + .size = vec2(0, 800), + }); + begin_x += 600; + + GameObject end = scn.new_object("hallway_end", "background", vec2(begin_x, 0)); + Asset end_asset{"asset/background/hallway/hallway1FG_1_TVOS.png"}; + end.add_component(end_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 1, + .size = vec2(0, 800), + }); + begin_x += 600; + + return begin_x; +} + +void HallwaySubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) { + Asset lamp_asset{"asset/background/hallway/alarmLight_TVOS.png"}; + obj.add_component(lamp_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset, + }); + Asset lamp_glow_asset{"asset/background/hallway/alarmGlow_TVOS.png"}; + Sprite & lamp_glow_sprite = obj.add_component( + lamp_glow_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 1, + .size = vec2(0, 300), + .position_offset = offset - vec2(65, -30), + }); + obj.add_component(lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1), + Animator::Data{ + .fps = fps, + .looping = true, + }); +} + +void HallwaySubScene::add_sector_number(GameObject & obj, vec2 offset, unsigned int sector_num, + Color sector_color) { + Asset sector_text_asset{"asset/background/hallway/sectorText_TVOS.png"}; + obj.add_component(sector_text_asset, Sprite::Data{ + .color = sector_color, + .sorting_in_layer = 5, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset, + }); + Asset sector_num_asset{"asset/background/hallway/sectorNumbers_TVOS.png"}; + Sprite & sector_num_sprite = obj.add_component( + sector_num_asset, Sprite::Data{ + .color = sector_color, + .sorting_in_layer = 5, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset + vec2(200, 0), + }); + Animator & sector_num_anim = obj.add_component( + sector_num_sprite, ivec2(256, 128), uvec2(4, 4), Animator::Data{}); + int column = (sector_num - 1) / 4; + int row = (sector_num - 1) % 4; + sector_num_anim.set_anim(column); + for (int i = 0; i < row; i++) { + sector_num_anim.next_anim(); + } + sector_num_anim.pause(); +} diff --git a/game/background/HallwaySubScene.h b/game/background/HallwaySubScene.h new file mode 100644 index 0000000..acc9329 --- /dev/null +++ b/game/background/HallwaySubScene.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +namespace crepe { +class Scene; +class GameObject; +class Color; +} // namespace crepe + +class HallwaySubScene { +public: + float create(crepe::Scene & scn, float begin_x, unsigned int sector_num, + crepe::Color sector_color); + +private: + void add_lamp(crepe::GameObject & obj, crepe::vec2 offset, unsigned int fps = 10); + + void add_sector_number(crepe::GameObject & obj, crepe::vec2 offset, + unsigned int sector_num, crepe::Color sector_color); +}; diff --git a/game/background/StartSubScene.cpp b/game/background/StartSubScene.cpp new file mode 100644 index 0000000..5d810c2 --- /dev/null +++ b/game/background/StartSubScene.cpp @@ -0,0 +1,442 @@ +#include "StartSubScene.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +float StartSubScene::create(Scene & scn, float begin_x) { + this->create_wall_fragments(scn, begin_x - 300); + + GameObject begin = scn.new_object("start_begin", "background", vec2(begin_x, 0)); + Asset begin_asset{"asset/background/start/titleFG_1_TVOS.png"}; + begin.add_component(begin_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 0, + .size = vec2(0, 800), + }); + GameObject hole = scn.new_object("start_hole", "background", vec2(begin_x - 250, 140)); + Asset hole_asset{"asset/background/start/titleWallHole.png"}; + Sprite & hole_sprite = hole.add_component(hole_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 1, + .size = vec2(0, 200), + }); + hole_sprite.active = false; + begin_x += 700; + + this->add_table(begin, vec2(-150, 150)); + this->add_light(begin, vec2(-125, -150)); + this->add_jetpack_stand(begin, vec2(-125, 200)); + + GameObject end = scn.new_object("start_end", "background", vec2(begin_x, 0)); + Asset end_asset{"asset/background/start/titleFG_2_TVOS.png"}; + end.add_component(end_asset, Sprite::Data{ + .sorting_in_layer = 4, + .order_in_layer = 1, + .size = vec2(0, 800), + }); + begin_x += 100; + + this->add_lamp(end, vec2(-350, -95)); + + return begin_x; +} + +void StartSubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) { + Asset lamp_asset{"asset/background/start/alarmLight_TVOS.png"}; + obj.add_component(lamp_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset, + }); + Asset lamp_glow_asset{"asset/background/start/alarmGlow_TVOS.png"}; + Sprite & lamp_glow_sprite = obj.add_component( + lamp_glow_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 1, + .size = vec2(0, 300), + .position_offset = offset - vec2(65, -55), + }); + lamp_glow_sprite.active = false; + obj.add_component(lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1), + Animator::Data{ + .fps = fps, + .looping = true, + }); +} + +void StartSubScene::add_table(GameObject & obj, vec2 offset) { + Asset table_asset{"asset/background/start/table.png"}; + obj.add_component(table_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset, + }); + Asset gramophone_asset{"asset/background/start/gramophone_TVOS.png"}; + Sprite & gramophone_sprite = obj.add_component( + gramophone_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 1, + .size = vec2(0, 100), + .position_offset = offset + vec2(0, -50), + }); + obj.add_component(gramophone_sprite, ivec2(64, 128), uvec2(2, 1), + Animator::Data{ + .fps = 10, + .looping = true, + }); +} + +void StartSubScene::add_light(crepe::GameObject & obj, crepe::vec2 offset) { + Asset light_asset{"asset/background/start/title_light_TVOS.png"}; + obj.add_component(light_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = offset, + }); + Asset light_glow_asset{"asset/background/start/lightEffect2.png"}; + obj.add_component(light_glow_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 1, + .size = vec2(0, 100), + .position_offset = offset + vec2(0, 75), + }); + Asset light_effect_asset{"asset/background/start/lightEffect.png"}; + obj.add_component(light_effect_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset + vec2(0, 350), + }); +} + +void StartSubScene::add_jetpack_stand(crepe::GameObject & obj, crepe::vec2 offset) { + Asset jetpack_stand_asset{"asset/background/start/JetpackStand.png"}; + Sprite & jetpeck_stand_sprite + = obj.add_component(jetpack_stand_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 1, + .size = vec2(0, 70), + .position_offset = offset, + }); + obj.add_component(jetpeck_stand_sprite, ivec2(34, 46), uvec2(2, 1), + Animator::Data{ + .fps = 10, + .looping = true, + }) + .pause(); + Asset do_not_steal = {"asset/background/start/doNotTouchSign_TVOS.png"}; + obj.add_component(do_not_steal, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 1, + .size = vec2(0, 100), + .position_offset = offset + vec2(-75, -25), + }); +} + +void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { + GameObject frag_1 = scn.new_object("frag_1", "wall_fragment", vec2(begin_x, 200)); + Asset frag_1_asset{"asset/background/start/StartWall_frag1.png"}; + Sprite & frag_1_sprite + = frag_1.add_component(frag_1_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 5, + .size = vec2(0, 50), + }); + frag_1_sprite.active = false; + Rigidbody & frag_1_rb = frag_1.add_component(Rigidbody::Data{ + .gravity_scale = 10, + .linear_velocity = vec2(400, 400), + .linear_velocity_coefficient = vec2(0.5, 0.6), + .angular_velocity = 500, + .angular_velocity_coefficient = 0.55, + .elasticity_coefficient = 0.5, + .collision_layer = 5, + }); + frag_1_rb.active = false; + frag_1.add_component(25); + + GameObject frag_2 = scn.new_object("frag_2", "wall_fragment", vec2(begin_x, 180)); + Asset frag_2_asset{"asset/background/start/StartWall_frag2.png"}; + Sprite & frag_2_sprite + = frag_2.add_component(frag_2_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 5, + .size = vec2(0, 50), + }); + frag_2_sprite.active = false; + Rigidbody & frag_2_rb = frag_2.add_component(Rigidbody::Data{ + .gravity_scale = 20, + .linear_velocity = vec2(400, 400), + .linear_velocity_coefficient = vec2(0.35, 0.4), + .angular_velocity = 400, + .angular_velocity_coefficient = 0.55, + .elasticity_coefficient = 0.5, + .collision_layer = 5, + }); + frag_2_rb.active = false; + frag_2.add_component(55); + + GameObject frag_3 = scn.new_object("frag_3", "wall_fragment", vec2(begin_x, 170)); + Asset frag_3_asset{"asset/background/start/StartWall_frag3.png"}; + Sprite & frag_3_sprite + = frag_3.add_component(frag_3_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 5, + .size = vec2(0, 50), + }); + frag_3_sprite.active = false; + Rigidbody & frag_3_rb = frag_3.add_component(Rigidbody::Data{ + .gravity_scale = 30, + .linear_velocity = vec2(400, 400), + .linear_velocity_coefficient = vec2(0.3, 0.3), + .angular_velocity = 300, + .angular_velocity_coefficient = 0.55, + .elasticity_coefficient = 0.5, + .collision_layer = 5, + }); + frag_3_rb.active = false; + frag_3.add_component(35); + + GameObject frag_4 = scn.new_object("frag_4", "wall_fragment", vec2(begin_x, 160)); + Asset frag_4_asset{"asset/background/start/StartWall_frag4.png"}; + Sprite & frag_4_sprite + = frag_4.add_component(frag_4_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 5, + .size = vec2(0, 50), + }); + frag_4_sprite.active = false; + Rigidbody & frag_4_rb = frag_4.add_component(Rigidbody::Data{ + .gravity_scale = 40, + .linear_velocity = vec2(700, 400), + .linear_velocity_coefficient = vec2(0.2, 0.2), + .angular_velocity = 200, + .angular_velocity_coefficient = 0.55, + .elasticity_coefficient = 0.5, + .collision_layer = 5, + }); + frag_4_rb.active = false; + frag_4.add_component(60); + + GameObject frag_5 = scn.new_object("frag_5", "wall_fragment", vec2(begin_x, 150)); + Asset frag_5_asset{"asset/background/start/StartWall_frag5.png"}; + Sprite & frag_5_sprite + = frag_5.add_component(frag_5_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 5, + .size = vec2(0, 50), + }); + frag_5_sprite.active = false; + Rigidbody & frag_5_rb = frag_5.add_component(Rigidbody::Data{ + .gravity_scale = 50, + .linear_velocity = vec2(600, 800), + .linear_velocity_coefficient = vec2(0.25, 0.15), + .angular_velocity = 100, + .angular_velocity_coefficient = 0.55, + .elasticity_coefficient = 0.5, + .collision_layer = 5, + }); + frag_5_rb.active = false; + frag_5.add_component(5); + + GameObject frag_6 = scn.new_object("frag_6", "wall_fragment", vec2(begin_x, 140)); + Asset frag_6_asset{"asset/background/start/StartWall_frag6.png"}; + Sprite & frag_6_sprite + = frag_6.add_component(frag_6_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 5, + .size = vec2(0, 50), + }); + frag_6_sprite.active = false; + Rigidbody & frag_6_rb = frag_6.add_component(Rigidbody::Data{ + .gravity_scale = 30, + .linear_velocity = vec2(300, 800), + .linear_velocity_coefficient = vec2(0.35, 0.25), + .angular_velocity = 100, + .angular_velocity_coefficient = 0.55, + .elasticity_coefficient = 0.5, + .collision_layer = 5, + }); + frag_6_rb.active = false; + frag_6.add_component(30); + + GameObject frag_7 = scn.new_object("frag_7", "wall_fragment", vec2(begin_x, 130)); + Asset frag_7_asset{"asset/background/start/StartWall_frag7.png"}; + Sprite & frag_7_sprite + = frag_7.add_component(frag_7_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 5, + .size = vec2(0, 50), + }); + frag_7_sprite.active = false; + Rigidbody & frag_7_rb = frag_7.add_component(Rigidbody::Data{ + .gravity_scale = 20, + .linear_velocity = vec2(400, 500), + .linear_velocity_coefficient = vec2(0.45, 0.6), + .angular_velocity = 800, + .angular_velocity_coefficient = 0.55, + .elasticity_coefficient = 0.5, + .collision_layer = 5, + }); + frag_7_rb.active = false; + frag_7.add_component(45); + + GameObject frag_8 = scn.new_object("frag_8", "wall_fragment", vec2(begin_x, 120)); + Asset frag_8_asset{"asset/background/start/StartWall_frag8.png"}; + Sprite & frag_8_sprite + = frag_8.add_component(frag_8_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 5, + .size = vec2(0, 50), + }); + frag_8_sprite.active = false; + Rigidbody & frag_8_rb = frag_8.add_component(Rigidbody::Data{ + .gravity_scale = 30, + .linear_velocity = vec2(400, 400), + .linear_velocity_coefficient = vec2(0.5, 0.6), + .angular_velocity = 500, + .angular_velocity_coefficient = 0.55, + .elasticity_coefficient = 0.5, + .collision_layer = 5, + }); + frag_8_rb.active = false; + frag_8.add_component(25); + + GameObject frag_9 = scn.new_object("frag_9", "wall_fragment", vec2(begin_x, 110)); + Asset frag_9_asset{"asset/background/start/StartWall_frag9.png"}; + Sprite & frag_9_sprite + = frag_9.add_component(frag_9_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 5, + .size = vec2(0, 50), + }); + frag_9_sprite.active = false; + Rigidbody & frag_9_rb = frag_9.add_component(Rigidbody::Data{ + .gravity_scale = 40, + .linear_velocity = vec2(200, 400), + .linear_velocity_coefficient = vec2(0.5, 0.25), + .angular_velocity = 500, + .angular_velocity_coefficient = 0.55, + .elasticity_coefficient = 0.5, + .collision_layer = 5, + }); + frag_9_rb.active = false; + frag_9.add_component(15); + + GameObject frag_10 = scn.new_object("frag_10", "wall_fragment", vec2(begin_x, 100)); + Asset frag_10_asset{"asset/background/start/StartWall_frag10.png"}; + Sprite & frag_10_sprite + = frag_10.add_component(frag_10_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 5, + .size = vec2(0, 50), + }); + frag_10_sprite.active = false; + Rigidbody & frag_10_rb = frag_10.add_component(Rigidbody::Data{ + .gravity_scale = 50, + .linear_velocity = vec2(400, 900), + .linear_velocity_coefficient = vec2(0.35, 0.4), + .angular_velocity = 300, + .angular_velocity_coefficient = 0.55, + .elasticity_coefficient = 0.5, + .collision_layer = 5, + }); + frag_10_rb.active = false; + frag_10.add_component(60); + + GameObject frag_11 = scn.new_object("frag_11", "wall_fragment", vec2(begin_x, 90)); + Asset frag_11_asset{"asset/background/start/StartWall_frag11.png"}; + Sprite & frag_11_sprite + = frag_11.add_component(frag_11_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 5, + .size = vec2(0, 50), + }); + frag_11_sprite.active = false; + Rigidbody & frag_11_rb = frag_11.add_component(Rigidbody::Data{ + .gravity_scale = 60, + .linear_velocity = vec2(600, 800), + .linear_velocity_coefficient = vec2(0.3, 0.3), + .angular_velocity = 200, + .angular_velocity_coefficient = 0.55, + .elasticity_coefficient = 0.5, + .collision_layer = 5, + }); + frag_11_rb.active = false; + frag_11.add_component(5); + + GameObject frag_12 = scn.new_object("frag_12", "wall_fragment", vec2(begin_x, 80)); + Asset frag_12_asset{"asset/background/start/StartWall_frag12.png"}; + Sprite & frag_12_sprite + = frag_12.add_component(frag_12_asset, Sprite::Data{ + .sorting_in_layer = 5, + .order_in_layer = 5, + .size = vec2(0, 50), + }); + frag_12_sprite.active = false; + Rigidbody & frag_12_rb = frag_12.add_component(Rigidbody::Data{ + .gravity_scale = 70, + .linear_velocity = vec2(500, 800), + .linear_velocity_coefficient = vec2(0.25, 0.15), + .angular_velocity = 100, + .angular_velocity_coefficient = 0.55, + .elasticity_coefficient = 0.5, + .collision_layer = 5, + }); + frag_12_rb.active = false; + frag_12.add_component(50); + + GameObject smoke_particles_1 + = scn.new_object("smoke_particles", "particle_emitter", vec2(begin_x - 100, 200)); + Asset smoke_asset_1{"asset/particles/smoke.png"}; + Sprite & smoke_sprite_1 = smoke_particles_1.add_component( + smoke_asset_1, Sprite::Data{ + .color = Color(255, 255, 255, 50), + .sorting_in_layer = 15, + .order_in_layer = 0, + .size = vec2(0, 100), + }); + ParticleEmitter & emitter_1 = smoke_particles_1.add_component( + smoke_sprite_1, ParticleEmitter::Data{ + .emission_rate = 20, + .min_speed = 40, + .max_speed = 100, + .min_angle = -30, + .max_angle = 10, + .end_lifespan = 4, + }); + emitter_1.active = false; + + GameObject smoke_particles_2 + = scn.new_object("smoke_particles", "particle_emitter", vec2(begin_x - 100, 200)); + Asset smoke_asset_2{"asset/particles/smoke.png"}; + Sprite & smoke_sprite_2 = smoke_particles_2.add_component( + smoke_asset_2, Sprite::Data{ + .color = Color(255, 255, 255, 50), + .sorting_in_layer = 15, + .order_in_layer = 0, + .size = vec2(0, 70), + }); + ParticleEmitter & emitter_2 = smoke_particles_2.add_component( + smoke_sprite_2, ParticleEmitter::Data{ + .emission_rate = 30, + .min_speed = 40, + .max_speed = 100, + .min_angle = -45, + .max_angle = 5, + .end_lifespan = 3, + }); + emitter_2.active = false; +} diff --git a/game/background/StartSubScene.h b/game/background/StartSubScene.h new file mode 100644 index 0000000..c83e3d5 --- /dev/null +++ b/game/background/StartSubScene.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +namespace crepe { +class Scene; +class GameObject; +} // namespace crepe + +class StartSubScene { +public: + float create(crepe::Scene & scn, float begin_x); + +private: + void add_lamp(crepe::GameObject & obj, crepe::vec2 offset, unsigned int fps = 10); + void add_table(crepe::GameObject & obj, crepe::vec2 offset); + void add_light(crepe::GameObject & obj, crepe::vec2 offset); + void add_jetpack_stand(crepe::GameObject & obj, crepe::vec2 offset); + void create_wall_fragments(crepe::Scene & scn, float begin_x); +}; -- cgit v1.2.3 From d2af158ac63ab05b2fbfdcdf1b483662e48c0544 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Sat, 21 Dec 2024 11:36:37 +0100 Subject: Added Config.h --- game/Config.h | 11 ++ game/PlayerSubScene.cpp | 29 ++--- game/background/AquariumSubScene.cpp | 146 ++++++++++++---------- game/background/ForestSubScene.cpp | 108 +++++++++-------- game/background/HallwaySubScene.cpp | 71 ++++++----- game/background/StartSubScene.cpp | 228 ++++++++++++++++++----------------- mwe/events/include/event.h | 2 +- src/crepe/system/InputSystem.h | 6 +- 8 files changed, 325 insertions(+), 276 deletions(-) create mode 100644 game/Config.h diff --git a/game/Config.h b/game/Config.h new file mode 100644 index 0000000..7a83ee6 --- /dev/null +++ b/game/Config.h @@ -0,0 +1,11 @@ +#pragma once + +static constexpr int SORT_IN_LAY_BACK_BACKGROUND = 3; +static constexpr int SORT_IN_LAY_BACKGROUND = 4; +static constexpr int SORT_IN_LAY_FORE_BACKGROUND = 5; +static constexpr int SORT_IN_LAY_PARTICLES_BACKGROUND = 6; +static constexpr int SORT_IN_LAY_OBSTACLES = 8; +static constexpr int SORT_IN_LAY_PLAYER = 10; +static constexpr int SORT_IN_LAY_PARTICLES_FOREGROUND = 15; + + diff --git a/game/PlayerSubScene.cpp b/game/PlayerSubScene.cpp index 01a383a..d81dd34 100644 --- a/game/PlayerSubScene.cpp +++ b/game/PlayerSubScene.cpp @@ -1,4 +1,5 @@ #include "PlayerSubScene.h" +#include "Config.h" #include "PlayerScript.h" #include @@ -13,25 +14,25 @@ using namespace std; PlayerSubScene::PlayerSubScene(Scene & scn) { GameObject player = scn.new_object("player", "player", vec2(-100, 200)); Asset player_body_asset{"asset/barry/defaultBody.png"}; - Sprite & player_body_sprite - = player.add_component(player_body_asset, Sprite::Data{ - .sorting_in_layer = 10, - .order_in_layer = 0, - .size = vec2(0, 50), - }); + Sprite & player_body_sprite = player.add_component( + player_body_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 0, + .size = vec2(0, 50), + }); player.add_component(player_body_sprite, ivec2(32, 32), uvec2(4, 8), Animator::Data{ .fps = 5, .looping = true, }); Asset player_head_asset{"asset/barry/defaultHead.png"}; - Sprite & player_head_sprite - = player.add_component(player_head_asset, Sprite::Data{ - .sorting_in_layer = 10, - .order_in_layer = 1, - .size = vec2(0, 50), - .position_offset = vec2(0, -20), - }); + Sprite & player_head_sprite = player.add_component( + player_head_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 1, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + }); player.add_component(player_head_sprite, ivec2(32, 32), uvec2(4, 8), Animator::Data{ .fps = 5, @@ -40,7 +41,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { Asset player_jetpack_asset{"asset/barry/jetpackDefault.png"}; Sprite & player_jetpack_sprite = player.add_component( player_jetpack_asset, Sprite::Data{ - .sorting_in_layer = 10, + .sorting_in_layer = SORT_IN_LAY_PLAYER, .order_in_layer = 2, .size = vec2(0, 60), .position_offset = vec2(-20, 0), diff --git a/game/background/AquariumSubScene.cpp b/game/background/AquariumSubScene.cpp index 40e22b7..9994a9e 100644 --- a/game/background/AquariumSubScene.cpp +++ b/game/background/AquariumSubScene.cpp @@ -1,5 +1,7 @@ #include "AquariumSubScene.h" +#include "../Config.h" + #include #include #include @@ -15,21 +17,23 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { GameObject aquarium_begin = scn.new_object("aquarium_begin", "background", vec2(begin_x, 0)); Asset aquarium_begin_asset{"asset/background/aquarium/glassTubeFG_1_TVOS.png"}; - aquarium_begin.add_component(aquarium_begin_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 0, - .size = vec2(0, 800), - }); + aquarium_begin.add_component(aquarium_begin_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 800), + }); begin_x += 600; GameObject aquarium_middle_1 = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); Asset aquarium_middle_1_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_1.add_component(aquarium_middle_1_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 2, - .size = vec2(0, 800), - }); + aquarium_middle_1.add_component(aquarium_middle_1_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, 800), + }); begin_x += 400; this->add_background(scn, begin_x - 200); @@ -37,21 +41,23 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { GameObject aquarium_middle_2 = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); Asset aquarium_middle_2_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_2.add_component(aquarium_middle_2_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 3, - .size = vec2(0, 800), - }); + aquarium_middle_2.add_component(aquarium_middle_2_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 3, + .size = vec2(0, 800), + }); begin_x += 400; GameObject aquarium_middle_3 = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); Asset aquarium_middle_3_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_3.add_component(aquarium_middle_3_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 4, - .size = vec2(0, 800), - }); + aquarium_middle_3.add_component(aquarium_middle_3_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 4, + .size = vec2(0, 800), + }); begin_x += 400; this->add_background(scn, begin_x - 200); @@ -59,22 +65,24 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { GameObject aquarium_middle_4 = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); Asset aquarium_middle_4_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_4.add_component(aquarium_middle_4_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 5, - .size = vec2(0, 800), - }); + aquarium_middle_4.add_component(aquarium_middle_4_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 800), + }); begin_x += 600; this->add_background(scn, begin_x); GameObject aquarium_end = scn.new_object("aquarium_end", "background", vec2(begin_x, 0)); Asset aquarium_end_asset{"asset/background/aquarium/glassTubeFG_2_TVOS.png"}; - aquarium_end.add_component(aquarium_end_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 1, - .size = vec2(0, 800), - }); + aquarium_end.add_component(aquarium_end_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 800), + }); begin_x += 600; return begin_x; @@ -83,47 +91,53 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { void AquariumSubScene::add_background(Scene & scn, float begin_x) { GameObject bg_1 = scn.new_object("aquarium_bg_1", "aquarium_background", vec2(begin_x, 0)); Asset bg_1_1_asset{"asset/background/aquarium/AquariumBG1_1_TVOS.png"}; - bg_1.add_component(bg_1_1_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 2, - .size = vec2(0, 400), - .position_offset = vec2(-200, 100), - }); + bg_1.add_component(bg_1_1_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, 400), + .position_offset = vec2(-200, 100), + }); Asset bg_1_2_asset{"asset/background/aquarium/AquariumBG1_2_TVOS.png"}; - bg_1.add_component(bg_1_2_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 2, - .size = vec2(0, 400), - .position_offset = vec2(200, 100), - }); + bg_1.add_component(bg_1_2_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, 400), + .position_offset = vec2(200, 100), + }); GameObject bg_2 = scn.new_object("aquarium_bg_2", "aquarium_background", vec2(begin_x, 0)); Asset bg_2_1_asset{"asset/background/aquarium/AquariumBG2_1_TVOS.png"}; - bg_2.add_component(bg_2_1_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(200, -50), - }); + bg_2.add_component(bg_2_1_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(200, -50), + }); Asset bg_2_2_asset{"asset/background/aquarium/AquariumBG2_2_TVOS.png"}; - bg_2.add_component(bg_2_2_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(-200, -50), - }); + bg_2.add_component(bg_2_2_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(-200, -50), + }); GameObject bg_3 = scn.new_object("aquarium_bg_3", "aquarium_background", vec2(begin_x, 0)); Asset bg_3_1_asset{"asset/background/aquarium/AquariumBG3_1_TVOS.png"}; - bg_3.add_component(bg_3_1_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 0, - .size = vec2(0, 400), - .position_offset = vec2(200, -200), - }); + bg_3.add_component(bg_3_1_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 400), + .position_offset = vec2(200, -200), + }); Asset bg_3_2_asset{"asset/background/aquarium/AquariumBG3_2_TVOS.png"}; - bg_3.add_component(bg_3_2_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 0, - .size = vec2(0, 400), - .position_offset = vec2(-200, -200), - }); + bg_3.add_component(bg_3_2_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 400), + .position_offset = vec2(-200, -200), + }); } diff --git a/game/background/ForestSubScene.cpp b/game/background/ForestSubScene.cpp index 810ef17..f0848f2 100644 --- a/game/background/ForestSubScene.cpp +++ b/game/background/ForestSubScene.cpp @@ -1,6 +1,8 @@ #include "ForestSubScene.h" #include "ForestParallaxScript.h" +#include "../Config.h" + #include #include #include @@ -22,7 +24,7 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n GameObject begin = scn.new_object("forest_begin", "background", vec2(begin_x, 0)); Asset begin_asset{"asset/background/forest/forestFG_1_TVOS.png"}; begin.add_component(begin_asset, Sprite::Data{ - .sorting_in_layer = 4, + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 0, .size = vec2(0, 800), }); @@ -32,22 +34,24 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n GameObject middle_1 = scn.new_object("forest_middle", "background", vec2(begin_x, 0)); Asset middle_1_asset{"asset/background/forest/forestFG_3_TVOS.png"}; - middle_1.add_component(middle_1_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 2, - .size = vec2(0, 800), - }); + middle_1.add_component(middle_1_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, 800), + }); begin_x += 800; this->add_background(scn, begin_x, unique_bg_name); GameObject middle_2 = scn.new_object("forest_middle", "background", vec2(begin_x, 0)); Asset middle_2_asset{"asset/background/forest/forestFG_3_TVOS.png"}; - middle_2.add_component(middle_2_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 3, - .size = vec2(0, 800), - }); + middle_2.add_component(middle_2_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 3, + .size = vec2(0, 800), + }); begin_x += 800; this->add_background(scn, begin_x, unique_bg_name); @@ -55,7 +59,7 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n GameObject end = scn.new_object("forest_end", "background", vec2(begin_x, 0)); Asset end_asset{"asset/background/forest/forestFG_2_TVOS.png"}; end.add_component(end_asset, Sprite::Data{ - .sorting_in_layer = 4, + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 1, .size = vec2(0, 800), }); @@ -71,56 +75,62 @@ void ForestSubScene::add_background(Scene & scn, float begin_x, std::string name = scn.new_object("forest_bg_1_" + name, "forest_background", vec2(begin_x, 0)); Asset bg_1_asset{"asset/background/forest/forestBG1_1_TVOS.png"}; bg_1.add_component(bg_1_asset, Sprite::Data{ - .sorting_in_layer = 3, + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, .order_in_layer = 2, .size = vec2(0, 800), }); GameObject bg_2 = scn.new_object("forest_bg_2_" + name, "forest_background", vec2(begin_x, 0)); Asset bg_2_1_asset{"asset/background/forest/forestBG2_1_TVOS.png"}; - bg_2.add_component(bg_2_1_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(200, 0), - }); + bg_2.add_component(bg_2_1_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(200, 0), + }); Asset bg_2_2_asset{"asset/background/forest/forestBG2_2_TVOS.png"}; - bg_2.add_component(bg_2_2_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(-200, 0), - }); + bg_2.add_component(bg_2_2_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(-200, 0), + }); GameObject bg_3 = scn.new_object("forest_bg_3_" + name, "forest_background", vec2(begin_x, 0)); Asset bg_3_1_asset{"asset/background/forest/forestBG3_1_TVOS.png"}; - bg_3.add_component(bg_3_1_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(300, 0), - }); + bg_3.add_component(bg_3_1_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(300, 0), + }); Asset bg_3_2_asset{"asset/background/forest/forestBG3_2_TVOS.png"}; - bg_3.add_component(bg_3_2_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(100, 0), - }); + bg_3.add_component(bg_3_2_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(100, 0), + }); Asset bg_3_3_asset{"asset/background/forest/forestBG3_3_TVOS.png"}; - bg_3.add_component(bg_3_3_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(-100, 0), - }); + bg_3.add_component(bg_3_3_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(-100, 0), + }); Asset bg_3_4_asset{"asset/background/forest/forestBG3_4_TVOS.png"}; - bg_3.add_component(bg_3_4_asset, Sprite::Data{ - .sorting_in_layer = 3, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(-300, 0), - }); + bg_3.add_component(bg_3_4_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(-300, 0), + }); bg_2.add_component(Rigidbody::Data{ .linear_velocity = vec2(30, 0), diff --git a/game/background/HallwaySubScene.cpp b/game/background/HallwaySubScene.cpp index 486b8c6..b5e3635 100644 --- a/game/background/HallwaySubScene.cpp +++ b/game/background/HallwaySubScene.cpp @@ -1,5 +1,7 @@ #include "HallwaySubScene.h" +#include "../Config.h" + #include #include #include @@ -14,7 +16,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu GameObject begin = scn.new_object("hallway_begin", "background", vec2(begin_x, 0)); Asset begin_asset{"asset/background/hallway/hallway1FG_1_TVOS.png"}; begin.add_component(begin_asset, Sprite::Data{ - .sorting_in_layer = 4, + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 0, .size = vec2(0, 800), }); @@ -26,46 +28,50 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu GameObject middle_1 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); Asset middle_asset{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_1.add_component(middle_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 2, - .size = vec2(0, 800), - }); + middle_1.add_component(middle_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, 800), + }); begin_x += 600; GameObject middle_2 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); Asset middle_asset_2{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_2.add_component(middle_asset_2, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 3, - .size = vec2(0, 800), - }); + middle_2.add_component(middle_asset_2, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 3, + .size = vec2(0, 800), + }); begin_x += 200; GameObject middle_3 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); Asset middle_asset_3{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_3.add_component(middle_asset_3, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 4, - .size = vec2(0, 800), - }); + middle_3.add_component(middle_asset_3, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 4, + .size = vec2(0, 800), + }); begin_x += 400; this->add_lamp(middle_3, vec2(0, -120)); GameObject middle_4 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); Asset middle_asset_4{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_4.add_component(middle_asset_4, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 5, - .size = vec2(0, 800), - }); + middle_4.add_component(middle_asset_4, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 800), + }); begin_x += 600; GameObject end = scn.new_object("hallway_end", "background", vec2(begin_x, 0)); Asset end_asset{"asset/background/hallway/hallway1FG_1_TVOS.png"}; end.add_component(end_asset, Sprite::Data{ - .sorting_in_layer = 4, + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 1, .size = vec2(0, 800), }); @@ -77,7 +83,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu void HallwaySubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) { Asset lamp_asset{"asset/background/hallway/alarmLight_TVOS.png"}; obj.add_component(lamp_asset, Sprite::Data{ - .sorting_in_layer = 5, + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, .order_in_layer = 0, .size = vec2(0, 100), .position_offset = offset, @@ -85,7 +91,7 @@ void HallwaySubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) Asset lamp_glow_asset{"asset/background/hallway/alarmGlow_TVOS.png"}; Sprite & lamp_glow_sprite = obj.add_component( lamp_glow_asset, Sprite::Data{ - .sorting_in_layer = 5, + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, .order_in_layer = 1, .size = vec2(0, 300), .position_offset = offset - vec2(65, -30), @@ -100,18 +106,19 @@ void HallwaySubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) void HallwaySubScene::add_sector_number(GameObject & obj, vec2 offset, unsigned int sector_num, Color sector_color) { Asset sector_text_asset{"asset/background/hallway/sectorText_TVOS.png"}; - obj.add_component(sector_text_asset, Sprite::Data{ - .color = sector_color, - .sorting_in_layer = 5, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset, - }); + obj.add_component(sector_text_asset, + Sprite::Data{ + .color = sector_color, + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset, + }); Asset sector_num_asset{"asset/background/hallway/sectorNumbers_TVOS.png"}; Sprite & sector_num_sprite = obj.add_component( sector_num_asset, Sprite::Data{ .color = sector_color, - .sorting_in_layer = 5, + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, .order_in_layer = 0, .size = vec2(0, 100), .position_offset = offset + vec2(200, 0), diff --git a/game/background/StartSubScene.cpp b/game/background/StartSubScene.cpp index 5d810c2..547b00d 100644 --- a/game/background/StartSubScene.cpp +++ b/game/background/StartSubScene.cpp @@ -1,5 +1,7 @@ #include "StartSubScene.h" +#include "../Config.h" + #include #include #include @@ -18,17 +20,18 @@ float StartSubScene::create(Scene & scn, float begin_x) { GameObject begin = scn.new_object("start_begin", "background", vec2(begin_x, 0)); Asset begin_asset{"asset/background/start/titleFG_1_TVOS.png"}; begin.add_component(begin_asset, Sprite::Data{ - .sorting_in_layer = 4, + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 0, .size = vec2(0, 800), }); GameObject hole = scn.new_object("start_hole", "background", vec2(begin_x - 250, 140)); Asset hole_asset{"asset/background/start/titleWallHole.png"}; - Sprite & hole_sprite = hole.add_component(hole_asset, Sprite::Data{ - .sorting_in_layer = 4, - .order_in_layer = 1, - .size = vec2(0, 200), - }); + Sprite & hole_sprite = hole.add_component( + hole_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 200), + }); hole_sprite.active = false; begin_x += 700; @@ -39,7 +42,7 @@ float StartSubScene::create(Scene & scn, float begin_x) { GameObject end = scn.new_object("start_end", "background", vec2(begin_x, 0)); Asset end_asset{"asset/background/start/titleFG_2_TVOS.png"}; end.add_component(end_asset, Sprite::Data{ - .sorting_in_layer = 4, + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 1, .size = vec2(0, 800), }); @@ -53,7 +56,7 @@ float StartSubScene::create(Scene & scn, float begin_x) { void StartSubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) { Asset lamp_asset{"asset/background/start/alarmLight_TVOS.png"}; obj.add_component(lamp_asset, Sprite::Data{ - .sorting_in_layer = 5, + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, .order_in_layer = 0, .size = vec2(0, 100), .position_offset = offset, @@ -61,7 +64,7 @@ void StartSubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) { Asset lamp_glow_asset{"asset/background/start/alarmGlow_TVOS.png"}; Sprite & lamp_glow_sprite = obj.add_component( lamp_glow_asset, Sprite::Data{ - .sorting_in_layer = 5, + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, .order_in_layer = 1, .size = vec2(0, 300), .position_offset = offset - vec2(65, -55), @@ -77,7 +80,7 @@ void StartSubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) { void StartSubScene::add_table(GameObject & obj, vec2 offset) { Asset table_asset{"asset/background/start/table.png"}; obj.add_component(table_asset, Sprite::Data{ - .sorting_in_layer = 5, + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, .order_in_layer = 0, .size = vec2(0, 100), .position_offset = offset, @@ -85,7 +88,7 @@ void StartSubScene::add_table(GameObject & obj, vec2 offset) { Asset gramophone_asset{"asset/background/start/gramophone_TVOS.png"}; Sprite & gramophone_sprite = obj.add_component( gramophone_asset, Sprite::Data{ - .sorting_in_layer = 5, + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, .order_in_layer = 1, .size = vec2(0, 100), .position_offset = offset + vec2(0, -50), @@ -100,36 +103,38 @@ void StartSubScene::add_table(GameObject & obj, vec2 offset) { void StartSubScene::add_light(crepe::GameObject & obj, crepe::vec2 offset) { Asset light_asset{"asset/background/start/title_light_TVOS.png"}; obj.add_component(light_asset, Sprite::Data{ - .sorting_in_layer = 5, + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, .order_in_layer = 0, .size = vec2(0, 200), .position_offset = offset, }); Asset light_glow_asset{"asset/background/start/lightEffect2.png"}; - obj.add_component(light_glow_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 1, - .size = vec2(0, 100), - .position_offset = offset + vec2(0, 75), - }); + obj.add_component(light_glow_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 100), + .position_offset = offset + vec2(0, 75), + }); Asset light_effect_asset{"asset/background/start/lightEffect.png"}; - obj.add_component(light_effect_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset + vec2(0, 350), - }); + obj.add_component(light_effect_asset, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset + vec2(0, 350), + }); } void StartSubScene::add_jetpack_stand(crepe::GameObject & obj, crepe::vec2 offset) { Asset jetpack_stand_asset{"asset/background/start/JetpackStand.png"}; - Sprite & jetpeck_stand_sprite - = obj.add_component(jetpack_stand_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 1, - .size = vec2(0, 70), - .position_offset = offset, - }); + Sprite & jetpeck_stand_sprite = obj.add_component( + jetpack_stand_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 70), + .position_offset = offset, + }); obj.add_component(jetpeck_stand_sprite, ivec2(34, 46), uvec2(2, 1), Animator::Data{ .fps = 10, @@ -137,23 +142,24 @@ void StartSubScene::add_jetpack_stand(crepe::GameObject & obj, crepe::vec2 offse }) .pause(); Asset do_not_steal = {"asset/background/start/doNotTouchSign_TVOS.png"}; - obj.add_component(do_not_steal, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 1, - .size = vec2(0, 100), - .position_offset = offset + vec2(-75, -25), - }); + obj.add_component(do_not_steal, + Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 100), + .position_offset = offset + vec2(-75, -25), + }); } void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject frag_1 = scn.new_object("frag_1", "wall_fragment", vec2(begin_x, 200)); Asset frag_1_asset{"asset/background/start/StartWall_frag1.png"}; - Sprite & frag_1_sprite - = frag_1.add_component(frag_1_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + Sprite & frag_1_sprite = frag_1.add_component( + frag_1_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + }); frag_1_sprite.active = false; Rigidbody & frag_1_rb = frag_1.add_component(Rigidbody::Data{ .gravity_scale = 10, @@ -169,12 +175,12 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject frag_2 = scn.new_object("frag_2", "wall_fragment", vec2(begin_x, 180)); Asset frag_2_asset{"asset/background/start/StartWall_frag2.png"}; - Sprite & frag_2_sprite - = frag_2.add_component(frag_2_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + Sprite & frag_2_sprite = frag_2.add_component( + frag_2_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + }); frag_2_sprite.active = false; Rigidbody & frag_2_rb = frag_2.add_component(Rigidbody::Data{ .gravity_scale = 20, @@ -190,12 +196,12 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject frag_3 = scn.new_object("frag_3", "wall_fragment", vec2(begin_x, 170)); Asset frag_3_asset{"asset/background/start/StartWall_frag3.png"}; - Sprite & frag_3_sprite - = frag_3.add_component(frag_3_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + Sprite & frag_3_sprite = frag_3.add_component( + frag_3_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + }); frag_3_sprite.active = false; Rigidbody & frag_3_rb = frag_3.add_component(Rigidbody::Data{ .gravity_scale = 30, @@ -211,12 +217,12 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject frag_4 = scn.new_object("frag_4", "wall_fragment", vec2(begin_x, 160)); Asset frag_4_asset{"asset/background/start/StartWall_frag4.png"}; - Sprite & frag_4_sprite - = frag_4.add_component(frag_4_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + Sprite & frag_4_sprite = frag_4.add_component( + frag_4_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + }); frag_4_sprite.active = false; Rigidbody & frag_4_rb = frag_4.add_component(Rigidbody::Data{ .gravity_scale = 40, @@ -232,12 +238,12 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject frag_5 = scn.new_object("frag_5", "wall_fragment", vec2(begin_x, 150)); Asset frag_5_asset{"asset/background/start/StartWall_frag5.png"}; - Sprite & frag_5_sprite - = frag_5.add_component(frag_5_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + Sprite & frag_5_sprite = frag_5.add_component( + frag_5_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + }); frag_5_sprite.active = false; Rigidbody & frag_5_rb = frag_5.add_component(Rigidbody::Data{ .gravity_scale = 50, @@ -253,12 +259,12 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject frag_6 = scn.new_object("frag_6", "wall_fragment", vec2(begin_x, 140)); Asset frag_6_asset{"asset/background/start/StartWall_frag6.png"}; - Sprite & frag_6_sprite - = frag_6.add_component(frag_6_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + Sprite & frag_6_sprite = frag_6.add_component( + frag_6_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + }); frag_6_sprite.active = false; Rigidbody & frag_6_rb = frag_6.add_component(Rigidbody::Data{ .gravity_scale = 30, @@ -274,12 +280,12 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject frag_7 = scn.new_object("frag_7", "wall_fragment", vec2(begin_x, 130)); Asset frag_7_asset{"asset/background/start/StartWall_frag7.png"}; - Sprite & frag_7_sprite - = frag_7.add_component(frag_7_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + Sprite & frag_7_sprite = frag_7.add_component( + frag_7_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + }); frag_7_sprite.active = false; Rigidbody & frag_7_rb = frag_7.add_component(Rigidbody::Data{ .gravity_scale = 20, @@ -295,12 +301,12 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject frag_8 = scn.new_object("frag_8", "wall_fragment", vec2(begin_x, 120)); Asset frag_8_asset{"asset/background/start/StartWall_frag8.png"}; - Sprite & frag_8_sprite - = frag_8.add_component(frag_8_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + Sprite & frag_8_sprite = frag_8.add_component( + frag_8_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + }); frag_8_sprite.active = false; Rigidbody & frag_8_rb = frag_8.add_component(Rigidbody::Data{ .gravity_scale = 30, @@ -316,12 +322,12 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject frag_9 = scn.new_object("frag_9", "wall_fragment", vec2(begin_x, 110)); Asset frag_9_asset{"asset/background/start/StartWall_frag9.png"}; - Sprite & frag_9_sprite - = frag_9.add_component(frag_9_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + Sprite & frag_9_sprite = frag_9.add_component( + frag_9_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + }); frag_9_sprite.active = false; Rigidbody & frag_9_rb = frag_9.add_component(Rigidbody::Data{ .gravity_scale = 40, @@ -337,12 +343,12 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject frag_10 = scn.new_object("frag_10", "wall_fragment", vec2(begin_x, 100)); Asset frag_10_asset{"asset/background/start/StartWall_frag10.png"}; - Sprite & frag_10_sprite - = frag_10.add_component(frag_10_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + Sprite & frag_10_sprite = frag_10.add_component( + frag_10_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + }); frag_10_sprite.active = false; Rigidbody & frag_10_rb = frag_10.add_component(Rigidbody::Data{ .gravity_scale = 50, @@ -358,12 +364,12 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject frag_11 = scn.new_object("frag_11", "wall_fragment", vec2(begin_x, 90)); Asset frag_11_asset{"asset/background/start/StartWall_frag11.png"}; - Sprite & frag_11_sprite - = frag_11.add_component(frag_11_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + Sprite & frag_11_sprite = frag_11.add_component( + frag_11_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + }); frag_11_sprite.active = false; Rigidbody & frag_11_rb = frag_11.add_component(Rigidbody::Data{ .gravity_scale = 60, @@ -379,12 +385,12 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject frag_12 = scn.new_object("frag_12", "wall_fragment", vec2(begin_x, 80)); Asset frag_12_asset{"asset/background/start/StartWall_frag12.png"}; - Sprite & frag_12_sprite - = frag_12.add_component(frag_12_asset, Sprite::Data{ - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + Sprite & frag_12_sprite = frag_12.add_component( + frag_12_asset, Sprite::Data{ + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + }); frag_12_sprite.active = false; Rigidbody & frag_12_rb = frag_12.add_component(Rigidbody::Data{ .gravity_scale = 70, @@ -404,7 +410,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { Sprite & smoke_sprite_1 = smoke_particles_1.add_component( smoke_asset_1, Sprite::Data{ .color = Color(255, 255, 255, 50), - .sorting_in_layer = 15, + .sorting_in_layer = SORT_IN_LAY_PARTICLES_FOREGROUND, .order_in_layer = 0, .size = vec2(0, 100), }); @@ -425,7 +431,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { Sprite & smoke_sprite_2 = smoke_particles_2.add_component( smoke_asset_2, Sprite::Data{ .color = Color(255, 255, 255, 50), - .sorting_in_layer = 15, + .sorting_in_layer = SORT_IN_LAY_PARTICLES_FOREGROUND, .order_in_layer = 0, .size = vec2(0, 70), }); diff --git a/mwe/events/include/event.h b/mwe/events/include/event.h index ee1bf52..e1b220b 100644 --- a/mwe/events/include/event.h +++ b/mwe/events/include/event.h @@ -148,7 +148,7 @@ private: }; class ShutDownEvent : public Event { public: - ShutDownEvent() : Event("ShutDownEvent") {}; + ShutDownEvent() : Event("ShutDownEvent"){}; REGISTER_EVENT_TYPE(ShutDownEvent) diff --git a/src/crepe/system/InputSystem.h b/src/crepe/system/InputSystem.h index 45b238b..2cb80e5 100644 --- a/src/crepe/system/InputSystem.h +++ b/src/crepe/system/InputSystem.h @@ -23,7 +23,7 @@ public: /** * \param metadata Metadata of the button pressed */ - ButtonPressEvent(const Metadata & metadata) : metadata(metadata) {}; + ButtonPressEvent(const Metadata & metadata) : metadata(metadata){}; }; //! Event triggered when the mouse enters a button class ButtonEnterEvent : public Event { @@ -33,7 +33,7 @@ public: /** * \param metadata Metadata of the button pressed */ - ButtonEnterEvent(const Metadata & metadata) : metadata(metadata) {}; + ButtonEnterEvent(const Metadata & metadata) : metadata(metadata){}; }; //! Event triggered when the mouse leaves a button class ButtonExitEvent : public Event { @@ -43,7 +43,7 @@ public: /** * \param metadata Metadata of the button pressed */ - ButtonExitEvent(const Metadata & metadata) : metadata(metadata) {}; + ButtonExitEvent(const Metadata & metadata) : metadata(metadata){}; }; /** -- cgit v1.2.3 From 799a376aeecd9bdc712e89324cbe9153206839c9 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Sat, 21 Dec 2024 11:38:19 +0100 Subject: Added comments --- game/Config.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/game/Config.h b/game/Config.h index 7a83ee6..0d6f880 100644 --- a/game/Config.h +++ b/game/Config.h @@ -1,11 +1,9 @@ #pragma once -static constexpr int SORT_IN_LAY_BACK_BACKGROUND = 3; -static constexpr int SORT_IN_LAY_BACKGROUND = 4; -static constexpr int SORT_IN_LAY_FORE_BACKGROUND = 5; -static constexpr int SORT_IN_LAY_PARTICLES_BACKGROUND = 6; -static constexpr int SORT_IN_LAY_OBSTACLES = 8; -static constexpr int SORT_IN_LAY_PLAYER = 10; -static constexpr int SORT_IN_LAY_PARTICLES_FOREGROUND = 15; - - +static constexpr int SORT_IN_LAY_BACK_BACKGROUND = 3; // For all scenes +static constexpr int SORT_IN_LAY_BACKGROUND = 4; // For all scenes +static constexpr int SORT_IN_LAY_FORE_BACKGROUND = 5; // For all scenes +static constexpr int SORT_IN_LAY_PARTICLES_BACKGROUND = 6; // For all scenes +static constexpr int SORT_IN_LAY_OBSTACLES = 8; // Only for GameScene +static constexpr int SORT_IN_LAY_PLAYER = 10; // Only for GameScene +static constexpr int SORT_IN_LAY_PARTICLES_FOREGROUND = 15; // Only for GameScene -- cgit v1.2.3 From e72dc913e7b35bcd2f6ba8107ea46e383afd25e1 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Sat, 21 Dec 2024 11:52:48 +0100 Subject: Added more to Config.h --- game/Config.h | 6 ++++++ game/GameScene.cpp | 3 ++- game/background/AquariumSubScene.cpp | 12 ++++++------ game/background/ForestSubScene.cpp | 8 ++++---- game/background/HallwaySubScene.cpp | 12 ++++++------ game/background/StartSubScene.cpp | 4 ++-- 6 files changed, 26 insertions(+), 19 deletions(-) diff --git a/game/Config.h b/game/Config.h index 0d6f880..7c16b47 100644 --- a/game/Config.h +++ b/game/Config.h @@ -7,3 +7,9 @@ static constexpr int SORT_IN_LAY_PARTICLES_BACKGROUND = 6; // For all scenes static constexpr int SORT_IN_LAY_OBSTACLES = 8; // Only for GameScene static constexpr int SORT_IN_LAY_PLAYER = 10; // Only for GameScene static constexpr int SORT_IN_LAY_PARTICLES_FOREGROUND = 15; // Only for GameScene + +static constexpr int GAME_HEIGHT = 800; // In game units + +static constexpr int VIEWPORT_X = 1100; // In game units +// 'GAME_HEIGHT' (below) should be replaced by '500' when game development is finished +static constexpr int VIEWPORT_Y = GAME_HEIGHT; // In game units diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 9606244..db1a753 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -1,4 +1,5 @@ #include "GameScene.h" +#include "Config.h" #include "MoveCameraManualyScript.h" #include "PlayerSubScene.h" #include "StartGameScript.h" @@ -29,7 +30,7 @@ void GameScene::load_scene() { BackgroundSubScene background(*this); GameObject camera = new_object("camera", "camera", vec2(650, 0)); - camera.add_component(ivec2(990, 720), vec2(1100, 800), + camera.add_component(ivec2(990, 720), vec2(VIEWPORT_X, VIEWPORT_Y), Camera::Data{ .bg_color = Color::RED, }); diff --git a/game/background/AquariumSubScene.cpp b/game/background/AquariumSubScene.cpp index 9994a9e..579e633 100644 --- a/game/background/AquariumSubScene.cpp +++ b/game/background/AquariumSubScene.cpp @@ -21,7 +21,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 0, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; @@ -32,7 +32,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 2, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 400; @@ -45,7 +45,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 3, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 400; @@ -56,7 +56,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 4, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 400; @@ -69,7 +69,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 5, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; @@ -81,7 +81,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 1, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; diff --git a/game/background/ForestSubScene.cpp b/game/background/ForestSubScene.cpp index f0848f2..7eac53a 100644 --- a/game/background/ForestSubScene.cpp +++ b/game/background/ForestSubScene.cpp @@ -26,7 +26,7 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n begin.add_component(begin_asset, Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 0, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 800; @@ -38,7 +38,7 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 2, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 800; @@ -50,7 +50,7 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 3, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 800; @@ -61,7 +61,7 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n end.add_component(end_asset, Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 1, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; diff --git a/game/background/HallwaySubScene.cpp b/game/background/HallwaySubScene.cpp index b5e3635..2aa9bab 100644 --- a/game/background/HallwaySubScene.cpp +++ b/game/background/HallwaySubScene.cpp @@ -18,7 +18,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu begin.add_component(begin_asset, Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 0, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; @@ -32,7 +32,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 2, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; @@ -42,7 +42,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 3, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 200; @@ -52,7 +52,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 4, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 400; @@ -64,7 +64,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 5, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; @@ -73,7 +73,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu end.add_component(end_asset, Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 1, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 600; diff --git a/game/background/StartSubScene.cpp b/game/background/StartSubScene.cpp index 547b00d..c769a5f 100644 --- a/game/background/StartSubScene.cpp +++ b/game/background/StartSubScene.cpp @@ -22,7 +22,7 @@ float StartSubScene::create(Scene & scn, float begin_x) { begin.add_component(begin_asset, Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 0, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); GameObject hole = scn.new_object("start_hole", "background", vec2(begin_x - 250, 140)); Asset hole_asset{"asset/background/start/titleWallHole.png"}; @@ -44,7 +44,7 @@ float StartSubScene::create(Scene & scn, float begin_x) { end.add_component(end_asset, Sprite::Data{ .sorting_in_layer = SORT_IN_LAY_BACKGROUND, .order_in_layer = 1, - .size = vec2(0, 800), + .size = vec2(0, GAME_HEIGHT), }); begin_x += 100; -- cgit v1.2.3 From 94f99f931e22b5eecbc26b19038788e620ff27ee Mon Sep 17 00:00:00 2001 From: Max-001 Date: Sat, 21 Dec 2024 11:53:29 +0100 Subject: Deleted iostream include --- game/GameScene.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/game/GameScene.cpp b/game/GameScene.cpp index db1a753..a224cfd 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -21,7 +21,6 @@ #include #include #include -#include using namespace crepe; using namespace std; -- cgit v1.2.3 From e7599e648ea24d5e8a27bd9f4f162ef1a7c53d21 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Sat, 21 Dec 2024 12:25:27 +0100 Subject: Added collision layers to Config.h --- game/Config.h | 6 ++++++ game/GameScene.cpp | 13 +++++++++++++ game/PlayerSubScene.cpp | 3 ++- game/background/StartSubScene.cpp | 38 +++++++++++++++++++++++++------------- 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/game/Config.h b/game/Config.h index 7c16b47..ec753df 100644 --- a/game/Config.h +++ b/game/Config.h @@ -8,6 +8,12 @@ static constexpr int SORT_IN_LAY_OBSTACLES = 8; // Only for GameScene static constexpr int SORT_IN_LAY_PLAYER = 10; // Only for GameScene static constexpr int SORT_IN_LAY_PARTICLES_FOREGROUND = 15; // Only for GameScene +static constexpr int COLL_LAY_BOT_TOP = 1; // Only for GameScene +static constexpr int COLL_LAY_BOT_LOW = 2; // Only for GameScene +static constexpr int COLL_LAY_BOT_HIGH = 3; // Only for GameScene +static constexpr int COLL_LAY_PLAYER = 4; // Only for GameScene +static constexpr int COLL_LAY_WALL_FRAGS = 5; // Only for GameScene + static constexpr int GAME_HEIGHT = 800; // In game units static constexpr int VIEWPORT_X = 1100; // In game units diff --git a/game/GameScene.cpp b/game/GameScene.cpp index a224cfd..91da092 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -41,11 +41,24 @@ void GameScene::load_scene() { GameObject floor = new_object("floor", "game_world", vec2(0, 325)); floor.add_component(Rigidbody::Data{ .body_type = Rigidbody::BodyType::STATIC, + .collision_layer = COLL_LAY_BOT_TOP, }); floor.add_component(vec2(INFINITY, 200)); + GameObject floor_low = new_object("floor_low", "game_world", vec2(0, 350)); + floor_low.add_component(Rigidbody::Data{ + .body_type = Rigidbody::BodyType::STATIC, + .collision_layer = COLL_LAY_BOT_LOW, + }); + floor_low.add_component(vec2(INFINITY, 200)); + GameObject floor_high = new_object("floor_high", "game_world", vec2(0, 300)); + floor_high.add_component(Rigidbody::Data{ + .body_type = Rigidbody::BodyType::STATIC, + .collision_layer = COLL_LAY_BOT_HIGH, + }); GameObject ceiling = new_object("ceiling", "game_world", vec2(0, -325)); ceiling.add_component(Rigidbody::Data{ .body_type = Rigidbody::BodyType::STATIC, + .collision_layer = COLL_LAY_BOT_TOP, }); ceiling.add_component(vec2(INFINITY, 200)); diff --git a/game/PlayerSubScene.cpp b/game/PlayerSubScene.cpp index d81dd34..b361a82 100644 --- a/game/PlayerSubScene.cpp +++ b/game/PlayerSubScene.cpp @@ -56,7 +56,8 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .gravity_scale = 20, .body_type = Rigidbody::BodyType::DYNAMIC, .linear_velocity = vec2(100, 0), - .collision_layer = 10, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_PLAYER, }); player.add_component(vec2(50, 50)); player.add_component().set_script().active = false; diff --git a/game/background/StartSubScene.cpp b/game/background/StartSubScene.cpp index c769a5f..a918c05 100644 --- a/game/background/StartSubScene.cpp +++ b/game/background/StartSubScene.cpp @@ -168,7 +168,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 500, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_1_rb.active = false; frag_1.add_component(25); @@ -189,7 +190,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 400, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_2_rb.active = false; frag_2.add_component(55); @@ -210,7 +212,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 300, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_3_rb.active = false; frag_3.add_component(35); @@ -231,7 +234,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 200, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_4_rb.active = false; frag_4.add_component(60); @@ -252,7 +256,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 100, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_5_rb.active = false; frag_5.add_component(5); @@ -273,7 +278,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 100, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_6_rb.active = false; frag_6.add_component(30); @@ -294,7 +300,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 800, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_7_rb.active = false; frag_7.add_component(45); @@ -315,7 +322,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 500, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_8_rb.active = false; frag_8.add_component(25); @@ -336,7 +344,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 500, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_9_rb.active = false; frag_9.add_component(15); @@ -357,12 +366,13 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 300, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_10_rb.active = false; frag_10.add_component(60); - GameObject frag_11 = scn.new_object("frag_11", "wall_fragment", vec2(begin_x, 90)); + GameObject frag_11 = scn.new_object("frag_11", "wall_fragment", vec2(begin_x, 70)); Asset frag_11_asset{"asset/background/start/StartWall_frag11.png"}; Sprite & frag_11_sprite = frag_11.add_component( frag_11_asset, Sprite::Data{ @@ -378,7 +388,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 200, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_11_rb.active = false; frag_11.add_component(5); @@ -399,7 +410,8 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .angular_velocity = 100, .angular_velocity_coefficient = 0.55, .elasticity_coefficient = 0.5, - .collision_layer = 5, + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_WALL_FRAGS, }); frag_12_rb.active = false; frag_12.add_component(50); -- cgit v1.2.3 From e2162171c7ab72f450f73a0908946aa4a4dee5ee Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 22 Dec 2024 11:53:57 +0100 Subject: `make format` --- game/makefile | 5 +++++ mwe/events/include/event.h | 2 +- src/crepe/system/InputSystem.h | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 game/makefile diff --git a/game/makefile b/game/makefile new file mode 100644 index 0000000..3fedf7f --- /dev/null +++ b/game/makefile @@ -0,0 +1,5 @@ +.PHONY: FORCE + +format: FORCE + $(MAKE) -C .. $@ + diff --git a/mwe/events/include/event.h b/mwe/events/include/event.h index e1b220b..ee1bf52 100644 --- a/mwe/events/include/event.h +++ b/mwe/events/include/event.h @@ -148,7 +148,7 @@ private: }; class ShutDownEvent : public Event { public: - ShutDownEvent() : Event("ShutDownEvent"){}; + ShutDownEvent() : Event("ShutDownEvent") {}; REGISTER_EVENT_TYPE(ShutDownEvent) diff --git a/src/crepe/system/InputSystem.h b/src/crepe/system/InputSystem.h index 2cb80e5..45b238b 100644 --- a/src/crepe/system/InputSystem.h +++ b/src/crepe/system/InputSystem.h @@ -23,7 +23,7 @@ public: /** * \param metadata Metadata of the button pressed */ - ButtonPressEvent(const Metadata & metadata) : metadata(metadata){}; + ButtonPressEvent(const Metadata & metadata) : metadata(metadata) {}; }; //! Event triggered when the mouse enters a button class ButtonEnterEvent : public Event { @@ -33,7 +33,7 @@ public: /** * \param metadata Metadata of the button pressed */ - ButtonEnterEvent(const Metadata & metadata) : metadata(metadata){}; + ButtonEnterEvent(const Metadata & metadata) : metadata(metadata) {}; }; //! Event triggered when the mouse leaves a button class ButtonExitEvent : public Event { @@ -43,7 +43,7 @@ public: /** * \param metadata Metadata of the button pressed */ - ButtonExitEvent(const Metadata & metadata) : metadata(metadata){}; + ButtonExitEvent(const Metadata & metadata) : metadata(metadata) {}; }; /** -- cgit v1.2.3 From 61148c757a1f742ff09e40e5347e74e638c7371c Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 22 Dec 2024 12:32:22 +0100 Subject: update clang-format options --- .clang-format | 3 + game/GameScene.cpp | 20 +- game/MoveCameraManualyScript.cpp | 5 +- game/PlayerSubScene.cpp | 84 ++-- game/background/AquariumSubScene.cpp | 204 ++++---- game/background/ForestParallaxScript.cpp | 5 +- game/background/ForestSubScene.cpp | 194 ++++---- game/background/HallwaySubScene.cpp | 190 ++++--- game/background/HallwaySubScene.h | 11 +- game/background/StartSubScene.cpp | 491 +++++++++++-------- mwe/ecs-homemade/inc/ComponentManager.hpp | 4 +- mwe/ecs-homemade/src/ComponentManager.cpp | 5 +- mwe/events/include/event.h | 4 +- mwe/events/include/eventHandler.h | 7 +- mwe/events/include/eventManager.h | 25 +- mwe/events/src/event.cpp | 5 +- mwe/events/src/eventManager.cpp | 5 +- mwe/events/src/loopManager.cpp | 6 +- mwe/events/src/uiObject.cpp | 6 +- mwe/events/src/window.cpp | 6 +- mwe/gameloop/include/gameObject.h | 5 +- mwe/gameloop/src/gameObject.cpp | 5 +- mwe/gameloop/src/loopManager.cpp | 10 +- mwe/gameloop/src/window.cpp | 6 +- mwe/resource-manager/main.cpp | 5 +- mwe/resource-manager/map_layer.cpp | 18 +- mwe/resource-manager/map_layer.h | 4 +- mwe/resource-manager/stb_image.h | 788 ++++++++++++++++++------------ src/crepe/Particle.cpp | 5 +- src/crepe/Particle.h | 4 +- src/crepe/api/AI.cpp | 33 +- src/crepe/api/AI.h | 12 +- src/crepe/api/Animator.cpp | 6 +- src/crepe/api/Animator.h | 6 +- src/crepe/api/Asset.cpp | 2 +- src/crepe/api/AudioSource.h | 2 +- src/crepe/api/BoxCollider.cpp | 5 +- src/crepe/api/BoxCollider.h | 5 +- src/crepe/api/Camera.cpp | 5 +- src/crepe/api/Camera.h | 6 +- src/crepe/api/CircleCollider.cpp | 5 +- src/crepe/api/CircleCollider.h | 5 +- src/crepe/api/Color.cpp | 16 +- src/crepe/api/Engine.cpp | 12 +- src/crepe/api/Engine.h | 18 +- src/crepe/api/GameObject.cpp | 12 +- src/crepe/api/GameObject.h | 6 +- src/crepe/api/ParticleEmitter.cpp | 7 +- src/crepe/api/Scene.cpp | 6 +- src/crepe/api/Scene.h | 7 +- src/crepe/api/Script.h | 12 +- src/crepe/api/Script.hpp | 11 +- src/crepe/api/Text.cpp | 6 +- src/crepe/api/Text.h | 6 +- src/crepe/api/Transform.cpp | 2 +- src/crepe/facade/FontFacade.cpp | 5 +- src/crepe/facade/SDLContext.cpp | 61 ++- src/crepe/facade/SDLContext.h | 7 +- src/crepe/manager/ComponentManager.cpp | 22 +- src/crepe/manager/ComponentManager.h | 7 +- src/crepe/manager/ComponentManager.hpp | 20 +- src/crepe/manager/EventManager.h | 4 +- src/crepe/manager/EventManager.hpp | 14 +- src/crepe/manager/LoopTimerManager.cpp | 6 +- src/crepe/manager/LoopTimerManager.h | 12 +- src/crepe/manager/ResourceManager.hpp | 13 +- src/crepe/manager/SceneManager.cpp | 10 +- src/crepe/manager/SystemManager.hpp | 10 +- src/crepe/system/AISystem.cpp | 21 +- src/crepe/system/CollisionSystem.cpp | 81 +-- src/crepe/system/CollisionSystem.h | 40 +- src/crepe/system/InputSystem.cpp | 36 +- src/crepe/system/InputSystem.h | 21 +- src/crepe/system/ParticleSystem.cpp | 17 +- src/crepe/system/RenderSystem.cpp | 6 +- src/crepe/system/ScriptSystem.cpp | 5 +- src/crepe/util/dbg.h | 11 +- src/example/AITest.cpp | 50 +- src/example/button.cpp | 16 +- src/example/loadfont.cpp | 12 +- src/example/rendering_particle.cpp | 54 +- src/example/replay.cpp | 19 +- src/test/AssetTest.cpp | 6 +- src/test/AudioTest.cpp | 6 +- src/test/CollisionTest.cpp | 83 ++-- src/test/ECSTest.cpp | 68 +-- src/test/EventTest.cpp | 35 +- src/test/InputTest.cpp | 35 +- src/test/LoopManagerTest.cpp | 2 +- src/test/LoopTimerTest.cpp | 2 +- src/test/ParticleTest.cpp | 76 +-- src/test/PhysicsTest.cpp | 10 +- src/test/Profiling.cpp | 91 ++-- src/test/RenderSystemTest.cpp | 92 ++-- src/test/ReplayManagerTest.cpp | 6 +- src/test/ResourceManagerTest.cpp | 6 +- src/test/SaveManagerTest.cpp | 4 +- src/test/SceneManagerTest.cpp | 20 +- src/test/ScriptSaveManagerTest.cpp | 4 +- src/test/ScriptSceneTest.cpp | 2 +- src/test/ScriptTest.h | 10 +- src/test/ValueBrokerTest.cpp | 4 +- 102 files changed, 2004 insertions(+), 1481 deletions(-) diff --git a/.clang-format b/.clang-format index 1ee37ec..9ebf218 100644 --- a/.clang-format +++ b/.clang-format @@ -24,6 +24,9 @@ AlignEscapedNewlines: DontAlign BreakBeforeBinaryOperators: All AlwaysBreakTemplateDeclarations: Yes PackConstructorInitializers: CurrentLine +# only option that doesn't result in copious indentation +AlignAfterOpenBracket: BlockIndent +SpaceBeforeCpp11BracedList: true ... # vim: ft=yaml diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 91da092..2511567 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -29,34 +29,36 @@ void GameScene::load_scene() { BackgroundSubScene background(*this); GameObject camera = new_object("camera", "camera", vec2(650, 0)); - camera.add_component(ivec2(990, 720), vec2(VIEWPORT_X, VIEWPORT_Y), - Camera::Data{ - .bg_color = Color::RED, - }); + camera.add_component( + ivec2(990, 720), vec2(VIEWPORT_X, VIEWPORT_Y), + Camera::Data { + .bg_color = Color::RED, + } + ); camera.add_component().set_script(); - camera.add_component(Rigidbody::Data{}); + camera.add_component(Rigidbody::Data {}); PlayerSubScene player(*this); GameObject floor = new_object("floor", "game_world", vec2(0, 325)); - floor.add_component(Rigidbody::Data{ + floor.add_component(Rigidbody::Data { .body_type = Rigidbody::BodyType::STATIC, .collision_layer = COLL_LAY_BOT_TOP, }); floor.add_component(vec2(INFINITY, 200)); GameObject floor_low = new_object("floor_low", "game_world", vec2(0, 350)); - floor_low.add_component(Rigidbody::Data{ + floor_low.add_component(Rigidbody::Data { .body_type = Rigidbody::BodyType::STATIC, .collision_layer = COLL_LAY_BOT_LOW, }); floor_low.add_component(vec2(INFINITY, 200)); GameObject floor_high = new_object("floor_high", "game_world", vec2(0, 300)); - floor_high.add_component(Rigidbody::Data{ + floor_high.add_component(Rigidbody::Data { .body_type = Rigidbody::BodyType::STATIC, .collision_layer = COLL_LAY_BOT_HIGH, }); GameObject ceiling = new_object("ceiling", "game_world", vec2(0, -325)); - ceiling.add_component(Rigidbody::Data{ + ceiling.add_component(Rigidbody::Data { .body_type = Rigidbody::BodyType::STATIC, .collision_layer = COLL_LAY_BOT_TOP, }); diff --git a/game/MoveCameraManualyScript.cpp b/game/MoveCameraManualyScript.cpp index 0181333..9d75a75 100644 --- a/game/MoveCameraManualyScript.cpp +++ b/game/MoveCameraManualyScript.cpp @@ -4,8 +4,9 @@ using namespace crepe; using namespace std; void MoveCameraManualyScript::init() { - subscribe( - [this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); }); + subscribe([this](const KeyPressEvent & ev) -> bool { + return this->keypressed(ev); + }); } bool MoveCameraManualyScript::keypressed(const KeyPressEvent & event) { diff --git a/game/PlayerSubScene.cpp b/game/PlayerSubScene.cpp index b361a82..00b7810 100644 --- a/game/PlayerSubScene.cpp +++ b/game/PlayerSubScene.cpp @@ -13,46 +13,58 @@ using namespace std; PlayerSubScene::PlayerSubScene(Scene & scn) { GameObject player = scn.new_object("player", "player", vec2(-100, 200)); - Asset player_body_asset{"asset/barry/defaultBody.png"}; + Asset player_body_asset {"asset/barry/defaultBody.png"}; Sprite & player_body_sprite = player.add_component( - player_body_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_PLAYER, - .order_in_layer = 0, - .size = vec2(0, 50), - }); - player.add_component(player_body_sprite, ivec2(32, 32), uvec2(4, 8), - Animator::Data{ - .fps = 5, - .looping = true, - }); - Asset player_head_asset{"asset/barry/defaultHead.png"}; + player_body_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 0, + .size = vec2(0, 50), + } + ); + player.add_component( + player_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = 5, + .looping = true, + } + ); + Asset player_head_asset {"asset/barry/defaultHead.png"}; Sprite & player_head_sprite = player.add_component( - player_head_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_PLAYER, - .order_in_layer = 1, - .size = vec2(0, 50), - .position_offset = vec2(0, -20), - }); - player.add_component(player_head_sprite, ivec2(32, 32), uvec2(4, 8), - Animator::Data{ - .fps = 5, - .looping = true, - }); - Asset player_jetpack_asset{"asset/barry/jetpackDefault.png"}; + player_head_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 1, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + player.add_component( + player_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = 5, + .looping = true, + } + ); + Asset player_jetpack_asset {"asset/barry/jetpackDefault.png"}; Sprite & player_jetpack_sprite = player.add_component( - player_jetpack_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_PLAYER, - .order_in_layer = 2, - .size = vec2(0, 60), - .position_offset = vec2(-20, 0), - }); + player_jetpack_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 2, + .size = vec2(0, 60), + .position_offset = vec2(-20, 0), + } + ); player_jetpack_sprite.active = false; - player.add_component(player_jetpack_sprite, ivec2(32, 44), uvec2(4, 4), - Animator::Data{ - .fps = 5, - .looping = true, - }); - player.add_component(Rigidbody::Data{ + player.add_component( + player_jetpack_sprite, ivec2(32, 44), uvec2(4, 4), + Animator::Data { + .fps = 5, + .looping = true, + } + ); + player.add_component(Rigidbody::Data { .gravity_scale = 20, .body_type = Rigidbody::BodyType::DYNAMIC, .linear_velocity = vec2(100, 0), diff --git a/game/background/AquariumSubScene.cpp b/game/background/AquariumSubScene.cpp index 579e633..8d5202a 100644 --- a/game/background/AquariumSubScene.cpp +++ b/game/background/AquariumSubScene.cpp @@ -16,73 +16,85 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { GameObject aquarium_begin = scn.new_object("aquarium_begin", "background", vec2(begin_x, 0)); - Asset aquarium_begin_asset{"asset/background/aquarium/glassTubeFG_1_TVOS.png"}; - aquarium_begin.add_component(aquarium_begin_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, GAME_HEIGHT), - }); + Asset aquarium_begin_asset {"asset/background/aquarium/glassTubeFG_1_TVOS.png"}; + aquarium_begin.add_component( + aquarium_begin_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; GameObject aquarium_middle_1 = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); - Asset aquarium_middle_1_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_1.add_component(aquarium_middle_1_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 2, - .size = vec2(0, GAME_HEIGHT), - }); + Asset aquarium_middle_1_asset {"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; + aquarium_middle_1.add_component( + aquarium_middle_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 400; this->add_background(scn, begin_x - 200); GameObject aquarium_middle_2 = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); - Asset aquarium_middle_2_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_2.add_component(aquarium_middle_2_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 3, - .size = vec2(0, GAME_HEIGHT), - }); + Asset aquarium_middle_2_asset {"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; + aquarium_middle_2.add_component( + aquarium_middle_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 3, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 400; GameObject aquarium_middle_3 = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); - Asset aquarium_middle_3_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_3.add_component(aquarium_middle_3_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 4, - .size = vec2(0, GAME_HEIGHT), - }); + Asset aquarium_middle_3_asset {"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; + aquarium_middle_3.add_component( + aquarium_middle_3_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 4, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 400; this->add_background(scn, begin_x - 200); GameObject aquarium_middle_4 = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); - Asset aquarium_middle_4_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_4.add_component(aquarium_middle_4_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, GAME_HEIGHT), - }); + Asset aquarium_middle_4_asset {"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; + aquarium_middle_4.add_component( + aquarium_middle_4_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; this->add_background(scn, begin_x); GameObject aquarium_end = scn.new_object("aquarium_end", "background", vec2(begin_x, 0)); - Asset aquarium_end_asset{"asset/background/aquarium/glassTubeFG_2_TVOS.png"}; - aquarium_end.add_component(aquarium_end_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, GAME_HEIGHT), - }); + Asset aquarium_end_asset {"asset/background/aquarium/glassTubeFG_2_TVOS.png"}; + aquarium_end.add_component( + aquarium_end_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; return begin_x; @@ -90,54 +102,66 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { void AquariumSubScene::add_background(Scene & scn, float begin_x) { GameObject bg_1 = scn.new_object("aquarium_bg_1", "aquarium_background", vec2(begin_x, 0)); - Asset bg_1_1_asset{"asset/background/aquarium/AquariumBG1_1_TVOS.png"}; - bg_1.add_component(bg_1_1_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 2, - .size = vec2(0, 400), - .position_offset = vec2(-200, 100), - }); - Asset bg_1_2_asset{"asset/background/aquarium/AquariumBG1_2_TVOS.png"}; - bg_1.add_component(bg_1_2_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 2, - .size = vec2(0, 400), - .position_offset = vec2(200, 100), - }); + Asset bg_1_1_asset {"asset/background/aquarium/AquariumBG1_1_TVOS.png"}; + bg_1.add_component( + bg_1_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, 400), + .position_offset = vec2(-200, 100), + } + ); + Asset bg_1_2_asset {"asset/background/aquarium/AquariumBG1_2_TVOS.png"}; + bg_1.add_component( + bg_1_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, 400), + .position_offset = vec2(200, 100), + } + ); GameObject bg_2 = scn.new_object("aquarium_bg_2", "aquarium_background", vec2(begin_x, 0)); - Asset bg_2_1_asset{"asset/background/aquarium/AquariumBG2_1_TVOS.png"}; - bg_2.add_component(bg_2_1_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(200, -50), - }); - Asset bg_2_2_asset{"asset/background/aquarium/AquariumBG2_2_TVOS.png"}; - bg_2.add_component(bg_2_2_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(-200, -50), - }); + Asset bg_2_1_asset {"asset/background/aquarium/AquariumBG2_1_TVOS.png"}; + bg_2.add_component( + bg_2_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(200, -50), + } + ); + Asset bg_2_2_asset {"asset/background/aquarium/AquariumBG2_2_TVOS.png"}; + bg_2.add_component( + bg_2_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(-200, -50), + } + ); GameObject bg_3 = scn.new_object("aquarium_bg_3", "aquarium_background", vec2(begin_x, 0)); - Asset bg_3_1_asset{"asset/background/aquarium/AquariumBG3_1_TVOS.png"}; - bg_3.add_component(bg_3_1_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 400), - .position_offset = vec2(200, -200), - }); - Asset bg_3_2_asset{"asset/background/aquarium/AquariumBG3_2_TVOS.png"}; - bg_3.add_component(bg_3_2_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 400), - .position_offset = vec2(-200, -200), - }); + Asset bg_3_1_asset {"asset/background/aquarium/AquariumBG3_1_TVOS.png"}; + bg_3.add_component( + bg_3_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 400), + .position_offset = vec2(200, -200), + } + ); + Asset bg_3_2_asset {"asset/background/aquarium/AquariumBG3_2_TVOS.png"}; + bg_3.add_component( + bg_3_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 400), + .position_offset = vec2(-200, -200), + } + ); } diff --git a/game/background/ForestParallaxScript.cpp b/game/background/ForestParallaxScript.cpp index 27e30eb..c72f85d 100644 --- a/game/background/ForestParallaxScript.cpp +++ b/game/background/ForestParallaxScript.cpp @@ -3,8 +3,9 @@ using namespace crepe; using namespace std; -ForestParallaxScript::ForestParallaxScript(float begin_x, float end_x, - std::string unique_bg_name) +ForestParallaxScript::ForestParallaxScript( + float begin_x, float end_x, std::string unique_bg_name +) : begin_x(begin_x), end_x(end_x), name(unique_bg_name) {} diff --git a/game/background/ForestSubScene.cpp b/game/background/ForestSubScene.cpp index 7eac53a..a807a36 100644 --- a/game/background/ForestSubScene.cpp +++ b/game/background/ForestSubScene.cpp @@ -17,52 +17,63 @@ using namespace std; float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_name) { GameObject script = scn.new_object("forest_script", "background"); script.add_component().set_script( - begin_x - 400, begin_x + 3000 + 400, unique_bg_name); + begin_x - 400, begin_x + 3000 + 400, unique_bg_name + ); this->add_background(scn, begin_x, unique_bg_name); GameObject begin = scn.new_object("forest_begin", "background", vec2(begin_x, 0)); - Asset begin_asset{"asset/background/forest/forestFG_1_TVOS.png"}; - begin.add_component(begin_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, GAME_HEIGHT), - }); + Asset begin_asset {"asset/background/forest/forestFG_1_TVOS.png"}; + begin.add_component( + begin_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 800; this->add_background(scn, begin_x, unique_bg_name); GameObject middle_1 = scn.new_object("forest_middle", "background", vec2(begin_x, 0)); - Asset middle_1_asset{"asset/background/forest/forestFG_3_TVOS.png"}; - middle_1.add_component(middle_1_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 2, - .size = vec2(0, GAME_HEIGHT), - }); + Asset middle_1_asset {"asset/background/forest/forestFG_3_TVOS.png"}; + middle_1.add_component( + middle_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 800; this->add_background(scn, begin_x, unique_bg_name); GameObject middle_2 = scn.new_object("forest_middle", "background", vec2(begin_x, 0)); - Asset middle_2_asset{"asset/background/forest/forestFG_3_TVOS.png"}; - middle_2.add_component(middle_2_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 3, - .size = vec2(0, GAME_HEIGHT), - }); + Asset middle_2_asset {"asset/background/forest/forestFG_3_TVOS.png"}; + middle_2.add_component( + middle_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 3, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 800; this->add_background(scn, begin_x, unique_bg_name); GameObject end = scn.new_object("forest_end", "background", vec2(begin_x, 0)); - Asset end_asset{"asset/background/forest/forestFG_2_TVOS.png"}; - end.add_component(end_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, GAME_HEIGHT), - }); + Asset end_asset {"asset/background/forest/forestFG_2_TVOS.png"}; + end.add_component( + end_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; this->add_background(scn, begin_x + 200, unique_bg_name); @@ -73,69 +84,84 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n void ForestSubScene::add_background(Scene & scn, float begin_x, std::string name) { GameObject bg_1 = scn.new_object("forest_bg_1_" + name, "forest_background", vec2(begin_x, 0)); - Asset bg_1_asset{"asset/background/forest/forestBG1_1_TVOS.png"}; - bg_1.add_component(bg_1_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 2, - .size = vec2(0, 800), - }); + Asset bg_1_asset {"asset/background/forest/forestBG1_1_TVOS.png"}; + bg_1.add_component( + bg_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, 800), + } + ); GameObject bg_2 = scn.new_object("forest_bg_2_" + name, "forest_background", vec2(begin_x, 0)); - Asset bg_2_1_asset{"asset/background/forest/forestBG2_1_TVOS.png"}; - bg_2.add_component(bg_2_1_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(200, 0), - }); - Asset bg_2_2_asset{"asset/background/forest/forestBG2_2_TVOS.png"}; - bg_2.add_component(bg_2_2_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(-200, 0), - }); + Asset bg_2_1_asset {"asset/background/forest/forestBG2_1_TVOS.png"}; + bg_2.add_component( + bg_2_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(200, 0), + } + ); + Asset bg_2_2_asset {"asset/background/forest/forestBG2_2_TVOS.png"}; + bg_2.add_component( + bg_2_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(-200, 0), + } + ); GameObject bg_3 = scn.new_object("forest_bg_3_" + name, "forest_background", vec2(begin_x, 0)); - Asset bg_3_1_asset{"asset/background/forest/forestBG3_1_TVOS.png"}; - bg_3.add_component(bg_3_1_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(300, 0), - }); - Asset bg_3_2_asset{"asset/background/forest/forestBG3_2_TVOS.png"}; - bg_3.add_component(bg_3_2_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(100, 0), - }); - Asset bg_3_3_asset{"asset/background/forest/forestBG3_3_TVOS.png"}; - bg_3.add_component(bg_3_3_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(-100, 0), - }); - Asset bg_3_4_asset{"asset/background/forest/forestBG3_4_TVOS.png"}; - bg_3.add_component(bg_3_4_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(-300, 0), - }); - - bg_2.add_component(Rigidbody::Data{ + Asset bg_3_1_asset {"asset/background/forest/forestBG3_1_TVOS.png"}; + bg_3.add_component( + bg_3_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(300, 0), + } + ); + Asset bg_3_2_asset {"asset/background/forest/forestBG3_2_TVOS.png"}; + bg_3.add_component( + bg_3_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(100, 0), + } + ); + Asset bg_3_3_asset {"asset/background/forest/forestBG3_3_TVOS.png"}; + bg_3.add_component( + bg_3_3_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(-100, 0), + } + ); + Asset bg_3_4_asset {"asset/background/forest/forestBG3_4_TVOS.png"}; + bg_3.add_component( + bg_3_4_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(-300, 0), + } + ); + + bg_2.add_component(Rigidbody::Data { .linear_velocity = vec2(30, 0), }); - bg_3.add_component(Rigidbody::Data{ + bg_3.add_component(Rigidbody::Data { .linear_velocity = vec2(40, 0), }); } diff --git a/game/background/HallwaySubScene.cpp b/game/background/HallwaySubScene.cpp index 2aa9bab..4d96c94 100644 --- a/game/background/HallwaySubScene.cpp +++ b/game/background/HallwaySubScene.cpp @@ -11,15 +11,19 @@ using namespace crepe; using namespace std; -float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_num, - Color sector_color) { +float HallwaySubScene::create( + Scene & scn, float begin_x, unsigned int sector_num, Color sector_color +) { GameObject begin = scn.new_object("hallway_begin", "background", vec2(begin_x, 0)); - Asset begin_asset{"asset/background/hallway/hallway1FG_1_TVOS.png"}; - begin.add_component(begin_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, GAME_HEIGHT), - }); + Asset begin_asset {"asset/background/hallway/hallway1FG_1_TVOS.png"}; + begin.add_component( + begin_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; this->add_sector_number(begin, vec2(-200, 0), sector_num, sector_color); @@ -27,104 +31,128 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu this->add_lamp(begin, vec2(430, -120), 9); GameObject middle_1 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); - Asset middle_asset{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_1.add_component(middle_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 2, - .size = vec2(0, GAME_HEIGHT), - }); + Asset middle_asset {"asset/background/hallway/hallway1FG_2_TVOS.png"}; + middle_1.add_component( + middle_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; GameObject middle_2 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); - Asset middle_asset_2{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_2.add_component(middle_asset_2, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 3, - .size = vec2(0, GAME_HEIGHT), - }); + Asset middle_asset_2 {"asset/background/hallway/hallway1FG_2_TVOS.png"}; + middle_2.add_component( + middle_asset_2, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 3, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 200; GameObject middle_3 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); - Asset middle_asset_3{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_3.add_component(middle_asset_3, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 4, - .size = vec2(0, GAME_HEIGHT), - }); + Asset middle_asset_3 {"asset/background/hallway/hallway1FG_2_TVOS.png"}; + middle_3.add_component( + middle_asset_3, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 4, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 400; this->add_lamp(middle_3, vec2(0, -120)); GameObject middle_4 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); - Asset middle_asset_4{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_4.add_component(middle_asset_4, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, GAME_HEIGHT), - }); + Asset middle_asset_4 {"asset/background/hallway/hallway1FG_2_TVOS.png"}; + middle_4.add_component( + middle_asset_4, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; GameObject end = scn.new_object("hallway_end", "background", vec2(begin_x, 0)); - Asset end_asset{"asset/background/hallway/hallway1FG_1_TVOS.png"}; - end.add_component(end_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, GAME_HEIGHT), - }); + Asset end_asset {"asset/background/hallway/hallway1FG_1_TVOS.png"}; + end.add_component( + end_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; return begin_x; } void HallwaySubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) { - Asset lamp_asset{"asset/background/hallway/alarmLight_TVOS.png"}; - obj.add_component(lamp_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset, - }); - Asset lamp_glow_asset{"asset/background/hallway/alarmGlow_TVOS.png"}; + Asset lamp_asset {"asset/background/hallway/alarmLight_TVOS.png"}; + obj.add_component( + lamp_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset, + } + ); + Asset lamp_glow_asset {"asset/background/hallway/alarmGlow_TVOS.png"}; Sprite & lamp_glow_sprite = obj.add_component( - lamp_glow_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 300), - .position_offset = offset - vec2(65, -30), - }); - obj.add_component(lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1), - Animator::Data{ - .fps = fps, - .looping = true, - }); + lamp_glow_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 300), + .position_offset = offset - vec2(65, -30), + } + ); + obj.add_component( + lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1), + Animator::Data { + .fps = fps, + .looping = true, + } + ); } -void HallwaySubScene::add_sector_number(GameObject & obj, vec2 offset, unsigned int sector_num, - Color sector_color) { - Asset sector_text_asset{"asset/background/hallway/sectorText_TVOS.png"}; - obj.add_component(sector_text_asset, - Sprite::Data{ - .color = sector_color, - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset, - }); - Asset sector_num_asset{"asset/background/hallway/sectorNumbers_TVOS.png"}; +void HallwaySubScene::add_sector_number( + GameObject & obj, vec2 offset, unsigned int sector_num, Color sector_color +) { + Asset sector_text_asset {"asset/background/hallway/sectorText_TVOS.png"}; + obj.add_component( + sector_text_asset, + Sprite::Data { + .color = sector_color, + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset, + } + ); + Asset sector_num_asset {"asset/background/hallway/sectorNumbers_TVOS.png"}; Sprite & sector_num_sprite = obj.add_component( - sector_num_asset, Sprite::Data{ - .color = sector_color, - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset + vec2(200, 0), - }); + sector_num_asset, + Sprite::Data { + .color = sector_color, + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset + vec2(200, 0), + } + ); Animator & sector_num_anim = obj.add_component( - sector_num_sprite, ivec2(256, 128), uvec2(4, 4), Animator::Data{}); + sector_num_sprite, ivec2(256, 128), uvec2(4, 4), Animator::Data {} + ); int column = (sector_num - 1) / 4; int row = (sector_num - 1) % 4; sector_num_anim.set_anim(column); diff --git a/game/background/HallwaySubScene.h b/game/background/HallwaySubScene.h index acc9329..c38b4a9 100644 --- a/game/background/HallwaySubScene.h +++ b/game/background/HallwaySubScene.h @@ -10,12 +10,15 @@ class Color; class HallwaySubScene { public: - float create(crepe::Scene & scn, float begin_x, unsigned int sector_num, - crepe::Color sector_color); + float create( + crepe::Scene & scn, float begin_x, unsigned int sector_num, crepe::Color sector_color + ); private: void add_lamp(crepe::GameObject & obj, crepe::vec2 offset, unsigned int fps = 10); - void add_sector_number(crepe::GameObject & obj, crepe::vec2 offset, - unsigned int sector_num, crepe::Color sector_color); + void add_sector_number( + crepe::GameObject & obj, crepe::vec2 offset, unsigned int sector_num, + crepe::Color sector_color + ); }; diff --git a/game/background/StartSubScene.cpp b/game/background/StartSubScene.cpp index a918c05..d68287b 100644 --- a/game/background/StartSubScene.cpp +++ b/game/background/StartSubScene.cpp @@ -18,20 +18,25 @@ float StartSubScene::create(Scene & scn, float begin_x) { this->create_wall_fragments(scn, begin_x - 300); GameObject begin = scn.new_object("start_begin", "background", vec2(begin_x, 0)); - Asset begin_asset{"asset/background/start/titleFG_1_TVOS.png"}; - begin.add_component(begin_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, GAME_HEIGHT), - }); + Asset begin_asset {"asset/background/start/titleFG_1_TVOS.png"}; + begin.add_component( + begin_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, GAME_HEIGHT), + } + ); GameObject hole = scn.new_object("start_hole", "background", vec2(begin_x - 250, 140)); - Asset hole_asset{"asset/background/start/titleWallHole.png"}; + Asset hole_asset {"asset/background/start/titleWallHole.png"}; Sprite & hole_sprite = hole.add_component( - hole_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 200), - }); + hole_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 200), + } + ); hole_sprite.active = false; begin_x += 700; @@ -40,12 +45,15 @@ float StartSubScene::create(Scene & scn, float begin_x) { this->add_jetpack_stand(begin, vec2(-125, 200)); GameObject end = scn.new_object("start_end", "background", vec2(begin_x, 0)); - Asset end_asset{"asset/background/start/titleFG_2_TVOS.png"}; - end.add_component(end_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, GAME_HEIGHT), - }); + Asset end_asset {"asset/background/start/titleFG_2_TVOS.png"}; + end.add_component( + end_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 100; this->add_lamp(end, vec2(-350, -95)); @@ -54,114 +62,143 @@ float StartSubScene::create(Scene & scn, float begin_x) { } void StartSubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) { - Asset lamp_asset{"asset/background/start/alarmLight_TVOS.png"}; - obj.add_component(lamp_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset, - }); - Asset lamp_glow_asset{"asset/background/start/alarmGlow_TVOS.png"}; + Asset lamp_asset {"asset/background/start/alarmLight_TVOS.png"}; + obj.add_component( + lamp_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset, + } + ); + Asset lamp_glow_asset {"asset/background/start/alarmGlow_TVOS.png"}; Sprite & lamp_glow_sprite = obj.add_component( - lamp_glow_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 300), - .position_offset = offset - vec2(65, -55), - }); + lamp_glow_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 300), + .position_offset = offset - vec2(65, -55), + } + ); lamp_glow_sprite.active = false; - obj.add_component(lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1), - Animator::Data{ - .fps = fps, - .looping = true, - }); + obj.add_component( + lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1), + Animator::Data { + .fps = fps, + .looping = true, + } + ); } void StartSubScene::add_table(GameObject & obj, vec2 offset) { - Asset table_asset{"asset/background/start/table.png"}; - obj.add_component(table_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset, - }); - Asset gramophone_asset{"asset/background/start/gramophone_TVOS.png"}; + Asset table_asset {"asset/background/start/table.png"}; + obj.add_component( + table_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset, + } + ); + Asset gramophone_asset {"asset/background/start/gramophone_TVOS.png"}; Sprite & gramophone_sprite = obj.add_component( - gramophone_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 100), - .position_offset = offset + vec2(0, -50), - }); - obj.add_component(gramophone_sprite, ivec2(64, 128), uvec2(2, 1), - Animator::Data{ - .fps = 10, - .looping = true, - }); + gramophone_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 100), + .position_offset = offset + vec2(0, -50), + } + ); + obj.add_component( + gramophone_sprite, ivec2(64, 128), uvec2(2, 1), + Animator::Data { + .fps = 10, + .looping = true, + } + ); } void StartSubScene::add_light(crepe::GameObject & obj, crepe::vec2 offset) { - Asset light_asset{"asset/background/start/title_light_TVOS.png"}; - obj.add_component(light_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = offset, - }); - Asset light_glow_asset{"asset/background/start/lightEffect2.png"}; - obj.add_component(light_glow_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 100), - .position_offset = offset + vec2(0, 75), - }); - Asset light_effect_asset{"asset/background/start/lightEffect.png"}; - obj.add_component(light_effect_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset + vec2(0, 350), - }); + Asset light_asset {"asset/background/start/title_light_TVOS.png"}; + obj.add_component( + light_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = offset, + } + ); + Asset light_glow_asset {"asset/background/start/lightEffect2.png"}; + obj.add_component( + light_glow_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 100), + .position_offset = offset + vec2(0, 75), + } + ); + Asset light_effect_asset {"asset/background/start/lightEffect.png"}; + obj.add_component( + light_effect_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset + vec2(0, 350), + } + ); } void StartSubScene::add_jetpack_stand(crepe::GameObject & obj, crepe::vec2 offset) { - Asset jetpack_stand_asset{"asset/background/start/JetpackStand.png"}; + Asset jetpack_stand_asset {"asset/background/start/JetpackStand.png"}; Sprite & jetpeck_stand_sprite = obj.add_component( - jetpack_stand_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 70), - .position_offset = offset, - }); - obj.add_component(jetpeck_stand_sprite, ivec2(34, 46), uvec2(2, 1), - Animator::Data{ - .fps = 10, - .looping = true, - }) + jetpack_stand_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 70), + .position_offset = offset, + } + ); + obj.add_component( + jetpeck_stand_sprite, ivec2(34, 46), uvec2(2, 1), + Animator::Data { + .fps = 10, + .looping = true, + } + ) .pause(); Asset do_not_steal = {"asset/background/start/doNotTouchSign_TVOS.png"}; - obj.add_component(do_not_steal, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 100), - .position_offset = offset + vec2(-75, -25), - }); + obj.add_component( + do_not_steal, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 100), + .position_offset = offset + vec2(-75, -25), + } + ); } void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject frag_1 = scn.new_object("frag_1", "wall_fragment", vec2(begin_x, 200)); - Asset frag_1_asset{"asset/background/start/StartWall_frag1.png"}; + Asset frag_1_asset {"asset/background/start/StartWall_frag1.png"}; Sprite & frag_1_sprite = frag_1.add_component( - frag_1_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_1_sprite.active = false; - Rigidbody & frag_1_rb = frag_1.add_component(Rigidbody::Data{ + Rigidbody & frag_1_rb = frag_1.add_component(Rigidbody::Data { .gravity_scale = 10, .linear_velocity = vec2(400, 400), .linear_velocity_coefficient = vec2(0.5, 0.6), @@ -175,15 +212,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_1.add_component(25); GameObject frag_2 = scn.new_object("frag_2", "wall_fragment", vec2(begin_x, 180)); - Asset frag_2_asset{"asset/background/start/StartWall_frag2.png"}; + Asset frag_2_asset {"asset/background/start/StartWall_frag2.png"}; Sprite & frag_2_sprite = frag_2.add_component( - frag_2_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_2_sprite.active = false; - Rigidbody & frag_2_rb = frag_2.add_component(Rigidbody::Data{ + Rigidbody & frag_2_rb = frag_2.add_component(Rigidbody::Data { .gravity_scale = 20, .linear_velocity = vec2(400, 400), .linear_velocity_coefficient = vec2(0.35, 0.4), @@ -197,15 +236,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_2.add_component(55); GameObject frag_3 = scn.new_object("frag_3", "wall_fragment", vec2(begin_x, 170)); - Asset frag_3_asset{"asset/background/start/StartWall_frag3.png"}; + Asset frag_3_asset {"asset/background/start/StartWall_frag3.png"}; Sprite & frag_3_sprite = frag_3.add_component( - frag_3_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_3_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_3_sprite.active = false; - Rigidbody & frag_3_rb = frag_3.add_component(Rigidbody::Data{ + Rigidbody & frag_3_rb = frag_3.add_component(Rigidbody::Data { .gravity_scale = 30, .linear_velocity = vec2(400, 400), .linear_velocity_coefficient = vec2(0.3, 0.3), @@ -219,15 +260,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_3.add_component(35); GameObject frag_4 = scn.new_object("frag_4", "wall_fragment", vec2(begin_x, 160)); - Asset frag_4_asset{"asset/background/start/StartWall_frag4.png"}; + Asset frag_4_asset {"asset/background/start/StartWall_frag4.png"}; Sprite & frag_4_sprite = frag_4.add_component( - frag_4_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_4_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_4_sprite.active = false; - Rigidbody & frag_4_rb = frag_4.add_component(Rigidbody::Data{ + Rigidbody & frag_4_rb = frag_4.add_component(Rigidbody::Data { .gravity_scale = 40, .linear_velocity = vec2(700, 400), .linear_velocity_coefficient = vec2(0.2, 0.2), @@ -241,15 +284,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_4.add_component(60); GameObject frag_5 = scn.new_object("frag_5", "wall_fragment", vec2(begin_x, 150)); - Asset frag_5_asset{"asset/background/start/StartWall_frag5.png"}; + Asset frag_5_asset {"asset/background/start/StartWall_frag5.png"}; Sprite & frag_5_sprite = frag_5.add_component( - frag_5_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_5_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_5_sprite.active = false; - Rigidbody & frag_5_rb = frag_5.add_component(Rigidbody::Data{ + Rigidbody & frag_5_rb = frag_5.add_component(Rigidbody::Data { .gravity_scale = 50, .linear_velocity = vec2(600, 800), .linear_velocity_coefficient = vec2(0.25, 0.15), @@ -263,15 +308,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_5.add_component(5); GameObject frag_6 = scn.new_object("frag_6", "wall_fragment", vec2(begin_x, 140)); - Asset frag_6_asset{"asset/background/start/StartWall_frag6.png"}; + Asset frag_6_asset {"asset/background/start/StartWall_frag6.png"}; Sprite & frag_6_sprite = frag_6.add_component( - frag_6_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_6_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_6_sprite.active = false; - Rigidbody & frag_6_rb = frag_6.add_component(Rigidbody::Data{ + Rigidbody & frag_6_rb = frag_6.add_component(Rigidbody::Data { .gravity_scale = 30, .linear_velocity = vec2(300, 800), .linear_velocity_coefficient = vec2(0.35, 0.25), @@ -285,15 +332,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_6.add_component(30); GameObject frag_7 = scn.new_object("frag_7", "wall_fragment", vec2(begin_x, 130)); - Asset frag_7_asset{"asset/background/start/StartWall_frag7.png"}; + Asset frag_7_asset {"asset/background/start/StartWall_frag7.png"}; Sprite & frag_7_sprite = frag_7.add_component( - frag_7_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_7_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_7_sprite.active = false; - Rigidbody & frag_7_rb = frag_7.add_component(Rigidbody::Data{ + Rigidbody & frag_7_rb = frag_7.add_component(Rigidbody::Data { .gravity_scale = 20, .linear_velocity = vec2(400, 500), .linear_velocity_coefficient = vec2(0.45, 0.6), @@ -307,15 +356,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_7.add_component(45); GameObject frag_8 = scn.new_object("frag_8", "wall_fragment", vec2(begin_x, 120)); - Asset frag_8_asset{"asset/background/start/StartWall_frag8.png"}; + Asset frag_8_asset {"asset/background/start/StartWall_frag8.png"}; Sprite & frag_8_sprite = frag_8.add_component( - frag_8_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_8_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_8_sprite.active = false; - Rigidbody & frag_8_rb = frag_8.add_component(Rigidbody::Data{ + Rigidbody & frag_8_rb = frag_8.add_component(Rigidbody::Data { .gravity_scale = 30, .linear_velocity = vec2(400, 400), .linear_velocity_coefficient = vec2(0.5, 0.6), @@ -329,15 +380,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_8.add_component(25); GameObject frag_9 = scn.new_object("frag_9", "wall_fragment", vec2(begin_x, 110)); - Asset frag_9_asset{"asset/background/start/StartWall_frag9.png"}; + Asset frag_9_asset {"asset/background/start/StartWall_frag9.png"}; Sprite & frag_9_sprite = frag_9.add_component( - frag_9_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_9_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_9_sprite.active = false; - Rigidbody & frag_9_rb = frag_9.add_component(Rigidbody::Data{ + Rigidbody & frag_9_rb = frag_9.add_component(Rigidbody::Data { .gravity_scale = 40, .linear_velocity = vec2(200, 400), .linear_velocity_coefficient = vec2(0.5, 0.25), @@ -351,15 +404,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_9.add_component(15); GameObject frag_10 = scn.new_object("frag_10", "wall_fragment", vec2(begin_x, 100)); - Asset frag_10_asset{"asset/background/start/StartWall_frag10.png"}; + Asset frag_10_asset {"asset/background/start/StartWall_frag10.png"}; Sprite & frag_10_sprite = frag_10.add_component( - frag_10_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_10_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_10_sprite.active = false; - Rigidbody & frag_10_rb = frag_10.add_component(Rigidbody::Data{ + Rigidbody & frag_10_rb = frag_10.add_component(Rigidbody::Data { .gravity_scale = 50, .linear_velocity = vec2(400, 900), .linear_velocity_coefficient = vec2(0.35, 0.4), @@ -373,15 +428,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_10.add_component(60); GameObject frag_11 = scn.new_object("frag_11", "wall_fragment", vec2(begin_x, 70)); - Asset frag_11_asset{"asset/background/start/StartWall_frag11.png"}; + Asset frag_11_asset {"asset/background/start/StartWall_frag11.png"}; Sprite & frag_11_sprite = frag_11.add_component( - frag_11_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_11_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_11_sprite.active = false; - Rigidbody & frag_11_rb = frag_11.add_component(Rigidbody::Data{ + Rigidbody & frag_11_rb = frag_11.add_component(Rigidbody::Data { .gravity_scale = 60, .linear_velocity = vec2(600, 800), .linear_velocity_coefficient = vec2(0.3, 0.3), @@ -395,15 +452,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_11.add_component(5); GameObject frag_12 = scn.new_object("frag_12", "wall_fragment", vec2(begin_x, 80)); - Asset frag_12_asset{"asset/background/start/StartWall_frag12.png"}; + Asset frag_12_asset {"asset/background/start/StartWall_frag12.png"}; Sprite & frag_12_sprite = frag_12.add_component( - frag_12_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_12_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_12_sprite.active = false; - Rigidbody & frag_12_rb = frag_12.add_component(Rigidbody::Data{ + Rigidbody & frag_12_rb = frag_12.add_component(Rigidbody::Data { .gravity_scale = 70, .linear_velocity = vec2(500, 800), .linear_velocity_coefficient = vec2(0.25, 0.15), @@ -418,43 +477,51 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject smoke_particles_1 = scn.new_object("smoke_particles", "particle_emitter", vec2(begin_x - 100, 200)); - Asset smoke_asset_1{"asset/particles/smoke.png"}; + Asset smoke_asset_1 {"asset/particles/smoke.png"}; Sprite & smoke_sprite_1 = smoke_particles_1.add_component( - smoke_asset_1, Sprite::Data{ - .color = Color(255, 255, 255, 50), - .sorting_in_layer = SORT_IN_LAY_PARTICLES_FOREGROUND, - .order_in_layer = 0, - .size = vec2(0, 100), - }); + smoke_asset_1, + Sprite::Data { + .color = Color(255, 255, 255, 50), + .sorting_in_layer = SORT_IN_LAY_PARTICLES_FOREGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + } + ); ParticleEmitter & emitter_1 = smoke_particles_1.add_component( - smoke_sprite_1, ParticleEmitter::Data{ - .emission_rate = 20, - .min_speed = 40, - .max_speed = 100, - .min_angle = -30, - .max_angle = 10, - .end_lifespan = 4, - }); + smoke_sprite_1, + ParticleEmitter::Data { + .emission_rate = 20, + .min_speed = 40, + .max_speed = 100, + .min_angle = -30, + .max_angle = 10, + .end_lifespan = 4, + } + ); emitter_1.active = false; GameObject smoke_particles_2 = scn.new_object("smoke_particles", "particle_emitter", vec2(begin_x - 100, 200)); - Asset smoke_asset_2{"asset/particles/smoke.png"}; + Asset smoke_asset_2 {"asset/particles/smoke.png"}; Sprite & smoke_sprite_2 = smoke_particles_2.add_component( - smoke_asset_2, Sprite::Data{ - .color = Color(255, 255, 255, 50), - .sorting_in_layer = SORT_IN_LAY_PARTICLES_FOREGROUND, - .order_in_layer = 0, - .size = vec2(0, 70), - }); + smoke_asset_2, + Sprite::Data { + .color = Color(255, 255, 255, 50), + .sorting_in_layer = SORT_IN_LAY_PARTICLES_FOREGROUND, + .order_in_layer = 0, + .size = vec2(0, 70), + } + ); ParticleEmitter & emitter_2 = smoke_particles_2.add_component( - smoke_sprite_2, ParticleEmitter::Data{ - .emission_rate = 30, - .min_speed = 40, - .max_speed = 100, - .min_angle = -45, - .max_angle = 5, - .end_lifespan = 3, - }); + smoke_sprite_2, + ParticleEmitter::Data { + .emission_rate = 30, + .min_speed = 40, + .max_speed = 100, + .min_angle = -45, + .max_angle = 5, + .end_lifespan = 3, + } + ); emitter_2.active = false; } diff --git a/mwe/ecs-homemade/inc/ComponentManager.hpp b/mwe/ecs-homemade/inc/ComponentManager.hpp index af9c3a1..7d26df4 100644 --- a/mwe/ecs-homemade/inc/ComponentManager.hpp +++ b/mwe/ecs-homemade/inc/ComponentManager.hpp @@ -54,8 +54,8 @@ void ComponentManager::DeleteComponents() { } template -std::vector> -ComponentManager::GetComponentsByID(std::uint32_t id) const { +std::vector> ComponentManager::GetComponentsByID(std::uint32_t id +) const { //Determine the type of T (this is used as the key of the unordered_map<>) std::type_index type = typeid(T); diff --git a/mwe/ecs-homemade/src/ComponentManager.cpp b/mwe/ecs-homemade/src/ComponentManager.cpp index 33ba12e..835bdda 100644 --- a/mwe/ecs-homemade/src/ComponentManager.cpp +++ b/mwe/ecs-homemade/src/ComponentManager.cpp @@ -9,9 +9,8 @@ ComponentManager::ComponentManager() {} void ComponentManager::DeleteAllComponentsOfId(std::uint32_t id) { for (auto & [type, componentArray] : mComponents) { //Loop through all the types (in the unordered_map<>) - if (id - < componentArray - .size()) { //Make sure that the id (that we are looking for) is within the boundaries of the vector<> + if (id < componentArray.size( + )) { //Make sure that the id (that we are looking for) is within the boundaries of the vector<> componentArray[id].clear(); //Clear the components at this specific id } } diff --git a/mwe/events/include/event.h b/mwe/events/include/event.h index ee1bf52..6df98ee 100644 --- a/mwe/events/include/event.h +++ b/mwe/events/include/event.h @@ -27,8 +27,8 @@ public: virtual ~Event() = default; virtual std::uint32_t getEventType() const = 0; virtual std::string toString() const; - void addArgument(const std::string & key, - const std::variant & value); + void + addArgument(const std::string & key, const std::variant & value); std::variant getArgument(const std::string & key) const; diff --git a/mwe/events/include/eventHandler.h b/mwe/events/include/eventHandler.h index 3a83b15..8598cee 100644 --- a/mwe/events/include/eventHandler.h +++ b/mwe/events/include/eventHandler.h @@ -22,8 +22,9 @@ private: template class EventHandlerWrapper : public IEventHandlerWrapper { public: - explicit EventHandlerWrapper(const EventHandler & handler, - const bool destroyOnSuccess = false) + explicit EventHandlerWrapper( + const EventHandler & handler, const bool destroyOnSuccess = false + ) : m_handler(handler), m_handlerType(m_handler.target_type().name()), m_destroyOnSuccess(destroyOnSuccess) { @@ -42,5 +43,5 @@ private: EventHandler m_handler; const std::string m_handlerType; - bool m_destroyOnSuccess{false}; + bool m_destroyOnSuccess {false}; }; diff --git a/mwe/events/include/eventManager.h b/mwe/events/include/eventManager.h index 30e927f..43906e8 100644 --- a/mwe/events/include/eventManager.h +++ b/mwe/events/include/eventManager.h @@ -18,8 +18,8 @@ public: } void shutdown(); - void subscribe(int eventType, std::unique_ptr && handler, - int eventId); + void + subscribe(int eventType, std::unique_ptr && handler, int eventId); void unsubscribe(int eventType, const std::string & handlerName, int eventId); void triggerEvent(const Event & event_, int eventId); void queueEvent(std::unique_ptr && event_, int eventId); @@ -35,19 +35,23 @@ private: }; template -inline void subscribe(const EventHandler & callback, int eventId = 0, - const bool unsubscribeOnSuccess = false) { +inline void subscribe( + const EventHandler & callback, int eventId = 0, + const bool unsubscribeOnSuccess = false +) { std::unique_ptr handler = std::make_unique>(callback, unsubscribeOnSuccess); - EventManager::getInstance().subscribe(EventType::getStaticEventType(), std::move(handler), - eventId); + EventManager::getInstance().subscribe( + EventType::getStaticEventType(), std::move(handler), eventId + ); } template inline void unsubscribe(const EventHandler & callback, int eventId = 0) { const std::string handlerName = callback.target_type().name(); - EventManager::getInstance().unsubscribe(EventType::getStaticEventType(), handlerName, - eventId); + EventManager::getInstance().unsubscribe( + EventType::getStaticEventType(), handlerName, eventId + ); } inline void triggerEvent(const Event & triggeredEvent, int eventId = 0) { @@ -55,6 +59,7 @@ inline void triggerEvent(const Event & triggeredEvent, int eventId = 0) { } inline void queueEvent(std::unique_ptr && queuedEvent, int eventId = 0) { - EventManager::getInstance().queueEvent(std::forward>(queuedEvent), - eventId); + EventManager::getInstance().queueEvent( + std::forward>(queuedEvent), eventId + ); } diff --git a/mwe/events/src/event.cpp b/mwe/events/src/event.cpp index 0040c73..5177199 100644 --- a/mwe/events/src/event.cpp +++ b/mwe/events/src/event.cpp @@ -3,8 +3,9 @@ // Event class methods Event::Event(std::string eventType) { eventData["eventType"] = eventType; } -void Event::addArgument(const std::string & key, - const std::variant & value) { +void Event::addArgument( + const std::string & key, const std::variant & value +) { eventData[key] = value; } diff --git a/mwe/events/src/eventManager.cpp b/mwe/events/src/eventManager.cpp index 9e7d880..b77a0a3 100644 --- a/mwe/events/src/eventManager.cpp +++ b/mwe/events/src/eventManager.cpp @@ -2,8 +2,9 @@ void EventManager::shutdown() { subscribers.clear(); } -void EventManager::subscribe(int eventType, std::unique_ptr && handler, - int eventId) { +void EventManager::subscribe( + int eventType, std::unique_ptr && handler, int eventId +) { if (eventId) { std::unordered_map< int, std::unordered_map>>>:: diff --git a/mwe/events/src/loopManager.cpp b/mwe/events/src/loopManager.cpp index c58a5e7..7be10df 100644 --- a/mwe/events/src/loopManager.cpp +++ b/mwe/events/src/loopManager.cpp @@ -51,8 +51,10 @@ void onKey(const KeyPressedEvent & e) { std::cout << "keycode pressed: " << keyCode << std::endl; } void onMouse(const MousePressedEvent & e) { - fprintf(stderr, "mouse Position X: %d Y: %d\n", e.getMousePosition().first, - e.getMousePosition().second); + fprintf( + stderr, "mouse Position X: %d Y: %d\n", e.getMousePosition().first, + e.getMousePosition().second + ); } void LoopManager::setup() { gameRunning = window.initWindow(); diff --git a/mwe/events/src/uiObject.cpp b/mwe/events/src/uiObject.cpp index 947d1a2..6b5b326 100644 --- a/mwe/events/src/uiObject.cpp +++ b/mwe/events/src/uiObject.cpp @@ -10,7 +10,7 @@ Text::Text(int width, int height) : UIObject(width, height), size(12), font(nullptr), - color{255, 255, 255} { // Default size and color + color {255, 255, 255} { // Default size and color alignment.horizontal = Alignment::Horizontal::CENTER; alignment.vertical = Alignment::Vertical::MIDDLE; alignment.mode = Alignment::PositioningMode::RELATIVE; @@ -21,8 +21,8 @@ TextInput::TextInput(int width, int height) textBuffer(""), placeholder(""), isActive(false), - textColor{255, 255, 255}, - backgroundColor{0, 0, 0}, + textColor {255, 255, 255}, + backgroundColor {0, 0, 0}, maxLength(100), font(nullptr) { alignment.horizontal = Alignment::Horizontal::LEFT; diff --git a/mwe/events/src/window.cpp b/mwe/events/src/window.cpp index af2b627..5cdd425 100644 --- a/mwe/events/src/window.cpp +++ b/mwe/events/src/window.cpp @@ -11,8 +11,10 @@ bool WindowManager::initWindow() { return false; } - window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); + window = SDL_CreateWindow( + "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, + SCREEN_HEIGHT, SDL_WINDOW_SHOWN + ); if (!window) { std::cerr << "Error creating SDL Window.\n"; return false; diff --git a/mwe/gameloop/include/gameObject.h b/mwe/gameloop/include/gameObject.h index 2764215..1955b59 100644 --- a/mwe/gameloop/include/gameObject.h +++ b/mwe/gameloop/include/gameObject.h @@ -3,8 +3,9 @@ class GameObject { public: GameObject(); - GameObject(std::string name, float x, float y, float width, float height, float velX, - float velY); + GameObject( + std::string name, float x, float y, float width, float height, float velX, float velY + ); std::string getName() const; float getX() const; float getY() const; diff --git a/mwe/gameloop/src/gameObject.cpp b/mwe/gameloop/src/gameObject.cpp index 809e25f..31503d1 100644 --- a/mwe/gameloop/src/gameObject.cpp +++ b/mwe/gameloop/src/gameObject.cpp @@ -24,8 +24,9 @@ void GameObject::setVelX(float value) { velX = value; } void GameObject::setVelY(float value) { velY = value; } -GameObject::GameObject(std::string name, float x, float y, float width, float height, - float velX, float velY) +GameObject::GameObject( + std::string name, float x, float y, float width, float height, float velX, float velY +) : name(name), x(x), y(y), diff --git a/mwe/gameloop/src/loopManager.cpp b/mwe/gameloop/src/loopManager.cpp index fb06995..70cea4c 100644 --- a/mwe/gameloop/src/loopManager.cpp +++ b/mwe/gameloop/src/loopManager.cpp @@ -18,11 +18,13 @@ void LoopManager::processInput() { if (event.key.keysym.sym == SDLK_ESCAPE) { gameRunning = false; } else if (event.key.keysym.sym == SDLK_i) { - LoopTimer::getInstance().setGameScale(LoopTimer::getInstance().getGameScale() - + 0.1); + LoopTimer::getInstance().setGameScale( + LoopTimer::getInstance().getGameScale() + 0.1 + ); } else if (event.key.keysym.sym == SDLK_k) { - LoopTimer::getInstance().setGameScale(LoopTimer::getInstance().getGameScale() - - 0.1); + LoopTimer::getInstance().setGameScale( + LoopTimer::getInstance().getGameScale() - 0.1 + ); } break; diff --git a/mwe/gameloop/src/window.cpp b/mwe/gameloop/src/window.cpp index 8f802e1..df17773 100644 --- a/mwe/gameloop/src/window.cpp +++ b/mwe/gameloop/src/window.cpp @@ -36,8 +36,10 @@ bool WindowManager::initWindow() { fprintf(stderr, "Error inititalising SDL.\n"); return false; } - window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); + window = SDL_CreateWindow( + "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, + SCREEN_HEIGHT, SDL_WINDOW_SHOWN + ); if (!window) { fprintf(stderr, "Error creating SDL Window. \n"); return false; diff --git a/mwe/resource-manager/main.cpp b/mwe/resource-manager/main.cpp index 1910af8..e83d35f 100644 --- a/mwe/resource-manager/main.cpp +++ b/mwe/resource-manager/main.cpp @@ -23,8 +23,9 @@ int main() { SDL_Event event; - SDL_Window * window = SDL_CreateWindow("Tessting resources", SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, 640, 480, 0); + SDL_Window * window = SDL_CreateWindow( + "Tessting resources", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0 + ); SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0); diff --git a/mwe/resource-manager/map_layer.cpp b/mwe/resource-manager/map_layer.cpp index 17792a6..82f8f24 100644 --- a/mwe/resource-manager/map_layer.cpp +++ b/mwe/resource-manager/map_layer.cpp @@ -9,8 +9,9 @@ MapLayer::MapLayer() {} MapLayer::~MapLayer() { m_subsets.clear(); } -bool MapLayer::create(const tmx::Map & map, std::uint32_t layerIndex, - const std::vector & textures) { +bool MapLayer::create( + const tmx::Map & map, std::uint32_t layerIndex, const std::vector & textures +) { const auto & layers = map.getLayers(); assert(layers[layerIndex]->getType() == tmx::Layer::Type::Tile); @@ -68,9 +69,10 @@ bool MapLayer::create(const tmx::Map & map, std::uint32_t layerIndex, verts.emplace_back(vert); vert = {{tilePosX + mapTileSize.x, tilePosY}, vertColour, {u + uNorm, v}}; verts.emplace_back(vert); - vert = {{tilePosX + mapTileSize.x, tilePosY + mapTileSize.y}, - vertColour, - {u + uNorm, v + vNorm}}; + vert + = {{tilePosX + mapTileSize.x, tilePosY + mapTileSize.y}, + vertColour, + {u + uNorm, v + vNorm}}; verts.emplace_back(vert); } } @@ -89,7 +91,9 @@ bool MapLayer::create(const tmx::Map & map, std::uint32_t layerIndex, void MapLayer::draw(SDL_Renderer * renderer) const { assert(renderer); for (const auto & s : m_subsets) { - SDL_RenderGeometry(renderer, s.texture, s.vertexData.data(), - static_cast(s.vertexData.size()), nullptr, 0); + SDL_RenderGeometry( + renderer, s.texture, s.vertexData.data(), + static_cast(s.vertexData.size()), nullptr, 0 + ); } } diff --git a/mwe/resource-manager/map_layer.h b/mwe/resource-manager/map_layer.h index fb656ed..2adbc0f 100644 --- a/mwe/resource-manager/map_layer.h +++ b/mwe/resource-manager/map_layer.h @@ -10,8 +10,8 @@ public: explicit MapLayer(); ~MapLayer(); - bool create(const tmx::Map &, std::uint32_t index, - const std::vector & textures); + bool + create(const tmx::Map &, std::uint32_t index, const std::vector & textures); void draw(SDL_Renderer *) const; private: diff --git a/mwe/resource-manager/stb_image.h b/mwe/resource-manager/stb_image.h index 3462f3a..43fa6a6 100644 --- a/mwe/resource-manager/stb_image.h +++ b/mwe/resource-manager/stb_image.h @@ -409,9 +409,12 @@ extern "C" { typedef struct { int (*read)( void * user, char * data, - int size); // fill 'data' with 'size' bytes. return number of bytes actually read - void (*skip)(void * user, - int n); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative + int size + ); // fill 'data' with 'size' bytes. return number of bytes actually read + void (*skip)( + void * user, + int n + ); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative int (*eof)(void * user); // returns nonzero if we are at end of file/data } stbi_io_callbacks; @@ -420,24 +423,29 @@ typedef struct { // 8-bits-per-channel interface // -STBIDEF stbi_uc * stbi_load_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * channels_in_file, int desired_channels); -STBIDEF stbi_uc * stbi_load_from_callbacks(stbi_io_callbacks const * clbk, void * user, - int * x, int * y, int * channels_in_file, - int desired_channels); +STBIDEF stbi_uc * stbi_load_from_memory( + stbi_uc const * buffer, int len, int * x, int * y, int * channels_in_file, + int desired_channels +); +STBIDEF stbi_uc * stbi_load_from_callbacks( + stbi_io_callbacks const * clbk, void * user, int * x, int * y, int * channels_in_file, + int desired_channels +); #ifndef STBI_NO_STDIO -STBIDEF stbi_uc * stbi_load(char const * filename, int * x, int * y, int * channels_in_file, - int desired_channels); -STBIDEF stbi_uc * stbi_load_from_file(FILE * f, int * x, int * y, int * channels_in_file, - int desired_channels); +STBIDEF stbi_uc * stbi_load( + char const * filename, int * x, int * y, int * channels_in_file, int desired_channels +); +STBIDEF stbi_uc * +stbi_load_from_file(FILE * f, int * x, int * y, int * channels_in_file, int desired_channels); // for stbi_load_from_file, file pointer is left pointing immediately after image #endif #ifndef STBI_NO_GIF -STBIDEF stbi_uc * stbi_load_gif_from_memory(stbi_uc const * buffer, int len, int ** delays, - int * x, int * y, int * z, int * comp, - int req_comp); +STBIDEF stbi_uc * stbi_load_gif_from_memory( + stbi_uc const * buffer, int len, int ** delays, int * x, int * y, int * z, int * comp, + int req_comp +); #endif #ifdef STBI_WINDOWS_UTF8 @@ -449,17 +457,22 @@ STBIDEF int stbi_convert_wchar_to_utf8(char * buffer, size_t bufferlen, const wc // 16-bits-per-channel interface // -STBIDEF stbi_us * stbi_load_16_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * channels_in_file, int desired_channels); -STBIDEF stbi_us * stbi_load_16_from_callbacks(stbi_io_callbacks const * clbk, void * user, - int * x, int * y, int * channels_in_file, - int desired_channels); +STBIDEF stbi_us * stbi_load_16_from_memory( + stbi_uc const * buffer, int len, int * x, int * y, int * channels_in_file, + int desired_channels +); +STBIDEF stbi_us * stbi_load_16_from_callbacks( + stbi_io_callbacks const * clbk, void * user, int * x, int * y, int * channels_in_file, + int desired_channels +); #ifndef STBI_NO_STDIO -STBIDEF stbi_us * stbi_load_16(char const * filename, int * x, int * y, int * channels_in_file, - int desired_channels); -STBIDEF stbi_us * stbi_load_from_file_16(FILE * f, int * x, int * y, int * channels_in_file, - int desired_channels); +STBIDEF stbi_us * stbi_load_16( + char const * filename, int * x, int * y, int * channels_in_file, int desired_channels +); +STBIDEF stbi_us * stbi_load_from_file_16( + FILE * f, int * x, int * y, int * channels_in_file, int desired_channels +); #endif //////////////////////////////////// @@ -467,17 +480,21 @@ STBIDEF stbi_us * stbi_load_from_file_16(FILE * f, int * x, int * y, int * chann // float-per-channel interface // #ifndef STBI_NO_LINEAR -STBIDEF float * stbi_loadf_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * channels_in_file, int desired_channels); -STBIDEF float * stbi_loadf_from_callbacks(stbi_io_callbacks const * clbk, void * user, int * x, - int * y, int * channels_in_file, - int desired_channels); +STBIDEF float * stbi_loadf_from_memory( + stbi_uc const * buffer, int len, int * x, int * y, int * channels_in_file, + int desired_channels +); +STBIDEF float * stbi_loadf_from_callbacks( + stbi_io_callbacks const * clbk, void * user, int * x, int * y, int * channels_in_file, + int desired_channels +); #ifndef STBI_NO_STDIO -STBIDEF float * stbi_loadf(char const * filename, int * x, int * y, int * channels_in_file, - int desired_channels); -STBIDEF float * stbi_loadf_from_file(FILE * f, int * x, int * y, int * channels_in_file, - int desired_channels); +STBIDEF float * stbi_loadf( + char const * filename, int * x, int * y, int * channels_in_file, int desired_channels +); +STBIDEF float * +stbi_loadf_from_file(FILE * f, int * x, int * y, int * channels_in_file, int desired_channels); #endif #endif @@ -507,10 +524,11 @@ STBIDEF const char * stbi_failure_reason(void); STBIDEF void stbi_image_free(void * retval_from_stbi_load); // get image dimensions & components without fully decoding -STBIDEF int stbi_info_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * comp); -STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const * clbk, void * user, int * x, - int * y, int * comp); +STBIDEF int +stbi_info_from_memory(stbi_uc const * buffer, int len, int * x, int * y, int * comp); +STBIDEF int stbi_info_from_callbacks( + stbi_io_callbacks const * clbk, void * user, int * x, int * y, int * comp +); STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const * buffer, int len); STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const * clbk, void * user); @@ -542,17 +560,18 @@ STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_fli // ZLIB client - used by PNG, available for other purposes -STBIDEF char * stbi_zlib_decode_malloc_guesssize(const char * buffer, int len, - int initial_size, int * outlen); -STBIDEF char * stbi_zlib_decode_malloc_guesssize_headerflag(const char * buffer, int len, - int initial_size, int * outlen, - int parse_header); +STBIDEF char * stbi_zlib_decode_malloc_guesssize( + const char * buffer, int len, int initial_size, int * outlen +); +STBIDEF char * stbi_zlib_decode_malloc_guesssize_headerflag( + const char * buffer, int len, int initial_size, int * outlen, int parse_header +); STBIDEF char * stbi_zlib_decode_malloc(const char * buffer, int len, int * outlen); STBIDEF int stbi_zlib_decode_buffer(char * obuffer, int olen, const char * ibuffer, int ilen); STBIDEF char * stbi_zlib_decode_noheader_malloc(const char * buffer, int len, int * outlen); -STBIDEF int stbi_zlib_decode_noheader_buffer(char * obuffer, int olen, const char * ibuffer, - int ilen); +STBIDEF int +stbi_zlib_decode_noheader_buffer(char * obuffer, int olen, const char * ibuffer, int ilen); #ifdef __cplusplus } @@ -910,68 +929,79 @@ typedef struct { #ifndef STBI_NO_JPEG static int stbi__jpeg_test(stbi__context * s); -static void * stbi__jpeg_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); +static void * stbi__jpeg_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); static int stbi__jpeg_info(stbi__context * s, int * x, int * y, int * comp); #endif #ifndef STBI_NO_PNG static int stbi__png_test(stbi__context * s); -static void * stbi__png_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); +static void * stbi__png_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); static int stbi__png_info(stbi__context * s, int * x, int * y, int * comp); static int stbi__png_is16(stbi__context * s); #endif #ifndef STBI_NO_BMP static int stbi__bmp_test(stbi__context * s); -static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); +static void * stbi__bmp_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); static int stbi__bmp_info(stbi__context * s, int * x, int * y, int * comp); #endif #ifndef STBI_NO_TGA static int stbi__tga_test(stbi__context * s); -static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); +static void * stbi__tga_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); static int stbi__tga_info(stbi__context * s, int * x, int * y, int * comp); #endif #ifndef STBI_NO_PSD static int stbi__psd_test(stbi__context * s); -static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri, int bpc); +static void * stbi__psd_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri, + int bpc +); static int stbi__psd_info(stbi__context * s, int * x, int * y, int * comp); static int stbi__psd_is16(stbi__context * s); #endif #ifndef STBI_NO_HDR static int stbi__hdr_test(stbi__context * s); -static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); +static float * stbi__hdr_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); static int stbi__hdr_info(stbi__context * s, int * x, int * y, int * comp); #endif #ifndef STBI_NO_PIC static int stbi__pic_test(stbi__context * s); -static void * stbi__pic_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); +static void * stbi__pic_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); static int stbi__pic_info(stbi__context * s, int * x, int * y, int * comp); #endif #ifndef STBI_NO_GIF static int stbi__gif_test(stbi__context * s); -static void * stbi__gif_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); -static void * stbi__load_gif_main(stbi__context * s, int ** delays, int * x, int * y, int * z, - int * comp, int req_comp); +static void * stbi__gif_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); +static void * stbi__load_gif_main( + stbi__context * s, int ** delays, int * x, int * y, int * z, int * comp, int req_comp +); static int stbi__gif_info(stbi__context * s, int * x, int * y, int * comp); #endif #ifndef STBI_NO_PNM static int stbi__pnm_test(stbi__context * s); -static void * stbi__pnm_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); +static void * stbi__pnm_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); static int stbi__pnm_info(stbi__context * s, int * x, int * y, int * comp); static int stbi__pnm_is16(stbi__context * s); #endif @@ -1135,8 +1165,10 @@ STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_fli : stbi__vertically_flip_on_load_global) #endif // STBI_THREAD_LOCAL -static void * stbi__load_main(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri, int bpc) { +static void * stbi__load_main( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri, + int bpc +) { memset(ri, 0, sizeof(*ri)); // make sure it's initialized if we add new fields ri->bits_per_channel = 8; // default is 8 so most paths don't have to be changed @@ -1198,9 +1230,8 @@ static stbi_uc * stbi__convert_16_to_8(stbi__uint16 * orig, int w, int h, int ch if (reduced == NULL) return stbi__errpuc("outofmem", "Out of memory"); for (i = 0; i < img_len; ++i) - reduced[i] - = (stbi_uc) ((orig[i] >> 8) - & 0xFF); // top half of each byte is sufficient approx of 16->8 bit scaling + reduced[i] = (stbi_uc) ((orig[i] >> 8) & 0xFF + ); // top half of each byte is sufficient approx of 16->8 bit scaling STBI_FREE(orig); return reduced; @@ -1215,10 +1246,8 @@ static stbi__uint16 * stbi__convert_8_to_16(stbi_uc * orig, int w, int h, int ch if (enlarged == NULL) return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory"); for (i = 0; i < img_len; ++i) - enlarged[i] - = (stbi__uint16) ((orig[i] << 8) - + orig - [i]); // replicate to high and low byte, maps 0->0, 255->0xffff + enlarged[i] = (stbi__uint16) ((orig[i] << 8) + orig[i] + ); // replicate to high and low byte, maps 0->0, 255->0xffff STBI_FREE(orig); return enlarged; @@ -1248,8 +1277,8 @@ static void stbi__vertical_flip(void * image, int w, int h, int bytes_per_pixel) } #ifndef STBI_NO_GIF -static void stbi__vertical_flip_slices(void * image, int w, int h, int z, - int bytes_per_pixel) { +static void +stbi__vertical_flip_slices(void * image, int w, int h, int z, int bytes_per_pixel) { int slice; int slice_size = w * h * bytes_per_pixel; @@ -1261,8 +1290,9 @@ static void stbi__vertical_flip_slices(void * image, int w, int h, int z, } #endif -static unsigned char * stbi__load_and_postprocess_8bit(stbi__context * s, int * x, int * y, - int * comp, int req_comp) { +static unsigned char * stbi__load_and_postprocess_8bit( + stbi__context * s, int * x, int * y, int * comp, int req_comp +) { stbi__result_info ri; void * result = stbi__load_main(s, x, y, comp, req_comp, &ri, 8); @@ -1272,8 +1302,9 @@ static unsigned char * stbi__load_and_postprocess_8bit(stbi__context * s, int * STBI_ASSERT(ri.bits_per_channel == 8 || ri.bits_per_channel == 16); if (ri.bits_per_channel != 8) { - result = stbi__convert_16_to_8((stbi__uint16 *) result, *x, *y, - req_comp == 0 ? *comp : req_comp); + result = stbi__convert_16_to_8( + (stbi__uint16 *) result, *x, *y, req_comp == 0 ? *comp : req_comp + ); ri.bits_per_channel = 8; } @@ -1287,8 +1318,9 @@ static unsigned char * stbi__load_and_postprocess_8bit(stbi__context * s, int * return (unsigned char *) result; } -static stbi__uint16 * stbi__load_and_postprocess_16bit(stbi__context * s, int * x, int * y, - int * comp, int req_comp) { +static stbi__uint16 * stbi__load_and_postprocess_16bit( + stbi__context * s, int * x, int * y, int * comp, int req_comp +) { stbi__result_info ri; void * result = stbi__load_main(s, x, y, comp, req_comp, &ri, 16); @@ -1298,8 +1330,9 @@ static stbi__uint16 * stbi__load_and_postprocess_16bit(stbi__context * s, int * STBI_ASSERT(ri.bits_per_channel == 8 || ri.bits_per_channel == 16); if (ri.bits_per_channel != 16) { - result = stbi__convert_8_to_16((stbi_uc *) result, *x, *y, - req_comp == 0 ? *comp : req_comp); + result = stbi__convert_8_to_16( + (stbi_uc *) result, *x, *y, req_comp == 0 ? *comp : req_comp + ); ri.bits_per_channel = 16; } @@ -1315,8 +1348,8 @@ static stbi__uint16 * stbi__load_and_postprocess_16bit(stbi__context * s, int * } #if !defined(STBI_NO_HDR) && !defined(STBI_NO_LINEAR) -static void stbi__float_postprocess(float * result, int * x, int * y, int * comp, - int req_comp) { +static void +stbi__float_postprocess(float * result, int * x, int * y, int * comp, int req_comp) { if (stbi__vertically_flip_on_load && result != NULL) { int channels = req_comp ? req_comp : *comp; stbi__vertical_flip(result, *x, *y, channels * sizeof(float)); @@ -1328,19 +1361,22 @@ static void stbi__float_postprocess(float * result, int * x, int * y, int * comp #if defined(_WIN32) && defined(STBI_WINDOWS_UTF8) STBI_EXTERN -__declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int cp, unsigned long flags, - const char * str, int cbmb, - wchar_t * widestr, int cchwide); +__declspec(dllimport) int __stdcall MultiByteToWideChar( + unsigned int cp, unsigned long flags, const char * str, int cbmb, wchar_t * widestr, + int cchwide +); STBI_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte( unsigned int cp, unsigned long flags, const wchar_t * widestr, int cchwide, char * str, - int cbmb, const char * defchar, int * used_default); + int cbmb, const char * defchar, int * used_default +); #endif #if defined(_WIN32) && defined(STBI_WINDOWS_UTF8) -STBIDEF int stbi_convert_wchar_to_utf8(char * buffer, size_t bufferlen, - const wchar_t * input) { - return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, (int) bufferlen, NULL, - NULL); +STBIDEF int +stbi_convert_wchar_to_utf8(char * buffer, size_t bufferlen, const wchar_t * input) { + return WideCharToMultiByte( + 65001 /* UTF8 */, 0, input, -1, buffer, (int) bufferlen, NULL, NULL + ); } #endif @@ -1350,13 +1386,16 @@ static FILE * stbi__fopen(char const * filename, char const * mode) { wchar_t wMode[64]; wchar_t wFilename[1024]; if (0 - == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, - sizeof(wFilename) / sizeof(*wFilename))) + == MultiByteToWideChar( + 65001 /* UTF8 */, 0, filename, -1, wFilename, + sizeof(wFilename) / sizeof(*wFilename) + )) return 0; if (0 - == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, - sizeof(wMode) / sizeof(*wMode))) + == MultiByteToWideChar( + 65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode) / sizeof(*wMode) + )) return 0; #if defined(_MSC_VER) && _MSC_VER >= 1400 @@ -1373,8 +1412,8 @@ static FILE * stbi__fopen(char const * filename, char const * mode) { return f; } -STBIDEF stbi_uc * stbi_load(char const * filename, int * x, int * y, int * comp, - int req_comp) { +STBIDEF stbi_uc * +stbi_load(char const * filename, int * x, int * y, int * comp, int req_comp) { FILE * f = stbi__fopen(filename, "rb"); unsigned char * result; if (!f) return stbi__errpuc("can't fopen", "Unable to open file"); @@ -1395,8 +1434,8 @@ STBIDEF stbi_uc * stbi_load_from_file(FILE * f, int * x, int * y, int * comp, in return result; } -STBIDEF stbi__uint16 * stbi_load_from_file_16(FILE * f, int * x, int * y, int * comp, - int req_comp) { +STBIDEF stbi__uint16 * +stbi_load_from_file_16(FILE * f, int * x, int * y, int * comp, int req_comp) { stbi__uint16 * result; stbi__context s; stbi__start_file(&s, f); @@ -1408,8 +1447,8 @@ STBIDEF stbi__uint16 * stbi_load_from_file_16(FILE * f, int * x, int * y, int * return result; } -STBIDEF stbi_us * stbi_load_16(char const * filename, int * x, int * y, int * comp, - int req_comp) { +STBIDEF stbi_us * +stbi_load_16(char const * filename, int * x, int * y, int * comp, int req_comp) { FILE * f = stbi__fopen(filename, "rb"); stbi__uint16 * result; if (!f) return (stbi_us *) stbi__errpuc("can't fopen", "Unable to open file"); @@ -1420,39 +1459,45 @@ STBIDEF stbi_us * stbi_load_16(char const * filename, int * x, int * y, int * co #endif //!STBI_NO_STDIO -STBIDEF stbi_us * stbi_load_16_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * channels_in_file, int desired_channels) { +STBIDEF stbi_us * stbi_load_16_from_memory( + stbi_uc const * buffer, int len, int * x, int * y, int * channels_in_file, + int desired_channels +) { stbi__context s; stbi__start_mem(&s, buffer, len); return stbi__load_and_postprocess_16bit(&s, x, y, channels_in_file, desired_channels); } -STBIDEF stbi_us * stbi_load_16_from_callbacks(stbi_io_callbacks const * clbk, void * user, - int * x, int * y, int * channels_in_file, - int desired_channels) { +STBIDEF stbi_us * stbi_load_16_from_callbacks( + stbi_io_callbacks const * clbk, void * user, int * x, int * y, int * channels_in_file, + int desired_channels +) { stbi__context s; stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user); return stbi__load_and_postprocess_16bit(&s, x, y, channels_in_file, desired_channels); } -STBIDEF stbi_uc * stbi_load_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * comp, int req_comp) { +STBIDEF stbi_uc * stbi_load_from_memory( + stbi_uc const * buffer, int len, int * x, int * y, int * comp, int req_comp +) { stbi__context s; stbi__start_mem(&s, buffer, len); return stbi__load_and_postprocess_8bit(&s, x, y, comp, req_comp); } -STBIDEF stbi_uc * stbi_load_from_callbacks(stbi_io_callbacks const * clbk, void * user, - int * x, int * y, int * comp, int req_comp) { +STBIDEF stbi_uc * stbi_load_from_callbacks( + stbi_io_callbacks const * clbk, void * user, int * x, int * y, int * comp, int req_comp +) { stbi__context s; stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user); return stbi__load_and_postprocess_8bit(&s, x, y, comp, req_comp); } #ifndef STBI_NO_GIF -STBIDEF stbi_uc * stbi_load_gif_from_memory(stbi_uc const * buffer, int len, int ** delays, - int * x, int * y, int * z, int * comp, - int req_comp) { +STBIDEF stbi_uc * stbi_load_gif_from_memory( + stbi_uc const * buffer, int len, int ** delays, int * x, int * y, int * z, int * comp, + int req_comp +) { unsigned char * result; stbi__context s; stbi__start_mem(&s, buffer, len); @@ -1467,8 +1512,8 @@ STBIDEF stbi_uc * stbi_load_gif_from_memory(stbi_uc const * buffer, int len, int #endif #ifndef STBI_NO_LINEAR -static float * stbi__loadf_main(stbi__context * s, int * x, int * y, int * comp, - int req_comp) { +static float * +stbi__loadf_main(stbi__context * s, int * x, int * y, int * comp, int req_comp) { unsigned char * data; #ifndef STBI_NO_HDR if (stbi__hdr_test(s)) { @@ -1483,15 +1528,17 @@ static float * stbi__loadf_main(stbi__context * s, int * x, int * y, int * comp, return stbi__errpf("unknown image type", "Image not of any known type, or corrupt"); } -STBIDEF float * stbi_loadf_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * comp, int req_comp) { +STBIDEF float * stbi_loadf_from_memory( + stbi_uc const * buffer, int len, int * x, int * y, int * comp, int req_comp +) { stbi__context s; stbi__start_mem(&s, buffer, len); return stbi__loadf_main(&s, x, y, comp, req_comp); } -STBIDEF float * stbi_loadf_from_callbacks(stbi_io_callbacks const * clbk, void * user, int * x, - int * y, int * comp, int req_comp) { +STBIDEF float * stbi_loadf_from_callbacks( + stbi_io_callbacks const * clbk, void * user, int * x, int * y, int * comp, int req_comp +) { stbi__context s; stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user); return stbi__loadf_main(&s, x, y, comp, req_comp); @@ -1745,8 +1792,9 @@ static stbi_uc stbi__compute_y(int r, int g, int b) { && defined(STBI_NO_PNM) // nothing #else -static unsigned char * stbi__convert_format(unsigned char * data, int img_n, int req_comp, - unsigned int x, unsigned int y) { +static unsigned char * stbi__convert_format( + unsigned char * data, int img_n, int req_comp, unsigned int x, unsigned int y +) { int i, j; unsigned char * good; @@ -1843,8 +1891,9 @@ static stbi__uint16 stbi__compute_y_16(int r, int g, int b) { #if defined(STBI_NO_PNG) && defined(STBI_NO_PSD) // nothing #else -static stbi__uint16 * stbi__convert_format16(stbi__uint16 * data, int img_n, int req_comp, - unsigned int x, unsigned int y) { +static stbi__uint16 * stbi__convert_format16( + stbi__uint16 * data, int img_n, int req_comp, unsigned int x, unsigned int y +) { int i, j; stbi__uint16 * good; @@ -1920,8 +1969,9 @@ static stbi__uint16 * stbi__convert_format16(stbi__uint16 * data, int img_n, int STBI_ASSERT(0); STBI_FREE(data); STBI_FREE(good); - return (stbi__uint16 *) stbi__errpuc("unsupported", - "Unsupported format conversion"); + return (stbi__uint16 *) stbi__errpuc( + "unsupported", "Unsupported format conversion" + ); } #undef STBI__CASE } @@ -2079,10 +2129,13 @@ typedef struct { // kernels void (*idct_block_kernel)(stbi_uc * out, int out_stride, short data[64]); - void (*YCbCr_to_RGB_kernel)(stbi_uc * out, const stbi_uc * y, const stbi_uc * pcb, - const stbi_uc * pcr, int count, int step); - stbi_uc * (*resample_row_hv_2_kernel)(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, - int w, int hs); + void (*YCbCr_to_RGB_kernel)( + stbi_uc * out, const stbi_uc * y, const stbi_uc * pcb, const stbi_uc * pcr, int count, + int step + ); + stbi_uc * (*resample_row_hv_2_kernel)( + stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, int hs + ); } stbi__jpeg; static int stbi__build_huffman(stbi__huffman * h, int * count) { @@ -2215,8 +2268,9 @@ stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg * j, stbi__huffman * h) c = ((j->code_buffer >> (32 - k)) & stbi__bmask[k]) + h->delta[k]; if (c < 0 || c >= 256) // symbol id out of bounds! return -1; - STBI_ASSERT((((j->code_buffer) >> (32 - h->size[c])) & stbi__bmask[h->size[c]]) - == h->code[c]); + STBI_ASSERT( + (((j->code_buffer) >> (32 - h->size[c])) & stbi__bmask[h->size[c]]) == h->code[c] + ); // convert the id to a symbol j->code_bits -= k; @@ -2280,9 +2334,10 @@ static const stbi_uc stbi__jpeg_dezigzag[64 + 15] 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63}; // decode one 64-entry block-- -static int stbi__jpeg_decode_block(stbi__jpeg * j, short data[64], stbi__huffman * hdc, - stbi__huffman * hac, stbi__int16 * fac, int b, - stbi__uint16 * dequant) { +static int stbi__jpeg_decode_block( + stbi__jpeg * j, short data[64], stbi__huffman * hdc, stbi__huffman * hac, + stbi__int16 * fac, int b, stbi__uint16 * dequant +) { int diff, dc, k; int t; @@ -2314,8 +2369,9 @@ static int stbi__jpeg_decode_block(stbi__jpeg * j, short data[64], stbi__huffman k += (r >> 4) & 15; // run s = r & 15; // combined length if (s > j->code_bits) - return stbi__err("bad huffman code", - "Combined length longer than code bits available"); + return stbi__err( + "bad huffman code", "Combined length longer than code bits available" + ); j->code_buffer <<= s; j->code_bits -= s; // decode into unzigzag'd location @@ -2340,8 +2396,8 @@ static int stbi__jpeg_decode_block(stbi__jpeg * j, short data[64], stbi__huffman return 1; } -static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg * j, short data[64], stbi__huffman * hdc, - int b) { +static int +stbi__jpeg_decode_block_prog_dc(stbi__jpeg * j, short data[64], stbi__huffman * hdc, int b) { int diff, dc; int t; if (j->spec_end != 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); @@ -2371,8 +2427,9 @@ static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg * j, short data[64], stbi_ // @OPTIMIZE: store non-zigzagged during the decode passes, // and only de-zigzag when dequantizing -static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg * j, short data[64], stbi__huffman * hac, - stbi__int16 * fac) { +static int stbi__jpeg_decode_block_prog_ac( + stbi__jpeg * j, short data[64], stbi__huffman * hac, stbi__int16 * fac +) { int k; if (j->spec_start == 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); @@ -2395,8 +2452,9 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg * j, short data[64], stbi_ k += (r >> 4) & 15; // run s = r & 15; // combined length if (s > j->code_bits) - return stbi__err("bad huffman code", - "Combined length longer than code bits available"); + return stbi__err( + "bad huffman code", "Combined length longer than code bits available" + ); j->code_buffer <<= s; j->code_bits -= s; zig = stbi__jpeg_dezigzag[k++]; @@ -2443,7 +2501,8 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg * j, short data[64], stbi_ int r, s; int rs = stbi__jpeg_huff_decode( j, - hac); // @OPTIMIZE see if we can use the fast path here, advance-by-r is so slow, eh + hac + ); // @OPTIMIZE see if we can use the fast path here, advance-by-r is so slow, eh if (rs < 0) return stbi__err("bad huffman code", "Corrupt JPEG"); s = rs & 15; r = rs >> 4; @@ -2691,18 +2750,24 @@ static void stbi__idct_simd(stbi_uc * out, int out_stride, short data[64]) { = dct_const(stbi__f2f(0.5411961f), stbi__f2f(0.5411961f) + stbi__f2f(-1.847759065f)); __m128i rot0_1 = dct_const(stbi__f2f(0.5411961f) + stbi__f2f(0.765366865f), stbi__f2f(0.5411961f)); - __m128i rot1_0 = dct_const(stbi__f2f(1.175875602f) + stbi__f2f(-0.899976223f), - stbi__f2f(1.175875602f)); - __m128i rot1_1 = dct_const(stbi__f2f(1.175875602f), - stbi__f2f(1.175875602f) + stbi__f2f(-2.562915447f)); - __m128i rot2_0 = dct_const(stbi__f2f(-1.961570560f) + stbi__f2f(0.298631336f), - stbi__f2f(-1.961570560f)); - __m128i rot2_1 = dct_const(stbi__f2f(-1.961570560f), - stbi__f2f(-1.961570560f) + stbi__f2f(3.072711026f)); - __m128i rot3_0 = dct_const(stbi__f2f(-0.390180644f) + stbi__f2f(2.053119869f), - stbi__f2f(-0.390180644f)); - __m128i rot3_1 = dct_const(stbi__f2f(-0.390180644f), - stbi__f2f(-0.390180644f) + stbi__f2f(1.501321110f)); + __m128i rot1_0 = dct_const( + stbi__f2f(1.175875602f) + stbi__f2f(-0.899976223f), stbi__f2f(1.175875602f) + ); + __m128i rot1_1 = dct_const( + stbi__f2f(1.175875602f), stbi__f2f(1.175875602f) + stbi__f2f(-2.562915447f) + ); + __m128i rot2_0 = dct_const( + stbi__f2f(-1.961570560f) + stbi__f2f(0.298631336f), stbi__f2f(-1.961570560f) + ); + __m128i rot2_1 = dct_const( + stbi__f2f(-1.961570560f), stbi__f2f(-1.961570560f) + stbi__f2f(3.072711026f) + ); + __m128i rot3_0 = dct_const( + stbi__f2f(-0.390180644f) + stbi__f2f(2.053119869f), stbi__f2f(-0.390180644f) + ); + __m128i rot3_1 = dct_const( + stbi__f2f(-0.390180644f), stbi__f2f(-0.390180644f) + stbi__f2f(1.501321110f) + ); // rounding biases in column/row passes, see stbi__idct_block for explanation. __m128i bias_0 = _mm_set1_epi32(512); @@ -3091,13 +3156,15 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg * z) { for (j = 0; j < h; ++j) { for (i = 0; i < w; ++i) { int ha = z->img_comp[n].ha; - if (!stbi__jpeg_decode_block(z, data, z->huff_dc + z->img_comp[n].hd, - z->huff_ac + ha, z->fast_ac[ha], n, - z->dequant[z->img_comp[n].tq])) + if (!stbi__jpeg_decode_block( + z, data, z->huff_dc + z->img_comp[n].hd, z->huff_ac + ha, + z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq] + )) return 0; - z->idct_block_kernel(z->img_comp[n].data + z->img_comp[n].w2 * j * 8 - + i * 8, - z->img_comp[n].w2, data); + z->idct_block_kernel( + z->img_comp[n].data + z->img_comp[n].w2 * j * 8 + i * 8, + z->img_comp[n].w2, data + ); // every data block is an MCU, so countdown the restart interval if (--z->todo <= 0) { if (z->code_bits < 24) stbi__grow_buffer_unsafe(z); @@ -3124,14 +3191,16 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg * z) { int x2 = (i * z->img_comp[n].h + x) * 8; int y2 = (j * z->img_comp[n].v + y) * 8; int ha = z->img_comp[n].ha; - if (!stbi__jpeg_decode_block(z, data, - z->huff_dc + z->img_comp[n].hd, - z->huff_ac + ha, z->fast_ac[ha], - n, z->dequant[z->img_comp[n].tq])) + if (!stbi__jpeg_decode_block( + z, data, z->huff_dc + z->img_comp[n].hd, + z->huff_ac + ha, z->fast_ac[ha], n, + z->dequant[z->img_comp[n].tq] + )) return 0; - z->idct_block_kernel(z->img_comp[n].data - + z->img_comp[n].w2 * y2 + x2, - z->img_comp[n].w2, data); + z->idct_block_kernel( + z->img_comp[n].data + z->img_comp[n].w2 * y2 + x2, + z->img_comp[n].w2, data + ); } } } @@ -3162,12 +3231,14 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg * z) { = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w); if (z->spec_start == 0) { if (!stbi__jpeg_decode_block_prog_dc( - z, data, &z->huff_dc[z->img_comp[n].hd], n)) + z, data, &z->huff_dc[z->img_comp[n].hd], n + )) return 0; } else { int ha = z->img_comp[n].ha; - if (!stbi__jpeg_decode_block_prog_ac(z, data, &z->huff_ac[ha], - z->fast_ac[ha])) + if (!stbi__jpeg_decode_block_prog_ac( + z, data, &z->huff_ac[ha], z->fast_ac[ha] + )) return 0; } // every data block is an MCU, so countdown the restart interval @@ -3195,7 +3266,8 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg * z) { short * data = z->img_comp[n].coeff + 64 * (x2 + y2 * z->img_comp[n].coeff_w); if (!stbi__jpeg_decode_block_prog_dc( - z, data, &z->huff_dc[z->img_comp[n].hd], n)) + z, data, &z->huff_dc[z->img_comp[n].hd], n + )) return 0; } } @@ -3231,9 +3303,10 @@ static void stbi__jpeg_finish(stbi__jpeg * z) { short * data = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w); stbi__jpeg_dequantize(data, z->dequant[z->img_comp[n].tq]); - z->idct_block_kernel(z->img_comp[n].data + z->img_comp[n].w2 * j * 8 - + i * 8, - z->img_comp[n].w2, data); + z->idct_block_kernel( + z->img_comp[n].data + z->img_comp[n].w2 * j * 8 + i * 8, + z->img_comp[n].w2, data + ); } } } @@ -3283,7 +3356,8 @@ static int stbi__process_marker(stbi__jpeg * z, int m) { if (n > 256) return stbi__err( "bad DHT header", - "Corrupt JPEG"); // Loop over i < n would write past end of values! + "Corrupt JPEG" + ); // Loop over i < n would write past end of values! L -= 17; if (tc == 0) { if (!stbi__build_huffman(z->huff_dc + th, sizes)) return 0; @@ -3410,13 +3484,16 @@ static int stbi__process_frame_header(stbi__jpeg * z, int scan) { if (Lf < 11) return stbi__err("bad SOF len", "Corrupt JPEG"); // JPEG p = stbi__get8(s); if (p != 8) - return stbi__err("only 8-bit", - "JPEG format not supported: 8-bit only"); // JPEG baseline + return stbi__err( + "only 8-bit", + "JPEG format not supported: 8-bit only" + ); // JPEG baseline s->img_y = stbi__get16be(s); if (s->img_y == 0) return stbi__err( "no header height", - "JPEG format not supported: delayed height"); // Legal, but we don't handle it--but neither does IJG + "JPEG format not supported: delayed height" + ); // Legal, but we don't handle it--but neither does IJG s->img_x = stbi__get16be(s); if (s->img_x == 0) return stbi__err("0 width", "Corrupt JPEG"); // JPEG requires if (s->img_y > STBI_MAX_DIMENSIONS) @@ -3493,8 +3570,9 @@ static int stbi__process_frame_header(stbi__jpeg * z, int scan) { z->img_comp[i].linebuf = NULL; z->img_comp[i].raw_data = stbi__malloc_mad2(z->img_comp[i].w2, z->img_comp[i].h2, 15); if (z->img_comp[i].raw_data == NULL) - return stbi__free_jpeg_components(z, i + 1, - stbi__err("outofmem", "Out of memory")); + return stbi__free_jpeg_components( + z, i + 1, stbi__err("outofmem", "Out of memory") + ); // align blocks for idct using mmx/sse z->img_comp[i].data = (stbi_uc *) (((size_t) z->img_comp[i].raw_data + 15) & ~15); if (z->progressive) { @@ -3504,8 +3582,9 @@ static int stbi__process_frame_header(stbi__jpeg * z, int scan) { z->img_comp[i].raw_coeff = stbi__malloc_mad3(z->img_comp[i].w2, z->img_comp[i].h2, sizeof(short), 15); if (z->img_comp[i].raw_coeff == NULL) - return stbi__free_jpeg_components(z, i + 1, - stbi__err("outofmem", "Out of memory")); + return stbi__free_jpeg_components( + z, i + 1, stbi__err("outofmem", "Out of memory") + ); z->img_comp[i].coeff = (short *) (((size_t) z->img_comp[i].raw_coeff + 15) & ~15); } } @@ -3603,13 +3682,14 @@ static int stbi__decode_jpeg_image(stbi__jpeg * j) { // static jfif-centered resampling (across block boundaries) -typedef stbi_uc * (*resample_row_func)(stbi_uc * out, stbi_uc * in0, stbi_uc * in1, int w, - int hs); +typedef stbi_uc * (*resample_row_func)( + stbi_uc * out, stbi_uc * in0, stbi_uc * in1, int w, int hs +); #define stbi__div4(x) ((stbi_uc) ((x) >> 2)) -static stbi_uc * resample_row_1(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, - int hs) { +static stbi_uc * +resample_row_1(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, int hs) { STBI_NOTUSED(out); STBI_NOTUSED(in_far); STBI_NOTUSED(w); @@ -3617,8 +3697,8 @@ static stbi_uc * resample_row_1(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_f return in_near; } -static stbi_uc * stbi__resample_row_v_2(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, - int w, int hs) { +static stbi_uc * +stbi__resample_row_v_2(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, int hs) { // need to generate two samples vertically for every one in input int i; STBI_NOTUSED(hs); @@ -3626,8 +3706,8 @@ static stbi_uc * stbi__resample_row_v_2(stbi_uc * out, stbi_uc * in_near, stbi_u return out; } -static stbi_uc * stbi__resample_row_h_2(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, - int w, int hs) { +static stbi_uc * +stbi__resample_row_h_2(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, int hs) { // need to generate two samples horizontally for every one in input int i; stbi_uc * input = in_near; @@ -3656,8 +3736,8 @@ static stbi_uc * stbi__resample_row_h_2(stbi_uc * out, stbi_uc * in_near, stbi_u #define stbi__div16(x) ((stbi_uc) ((x) >> 4)) -static stbi_uc * stbi__resample_row_hv_2(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, - int w, int hs) { +static stbi_uc * +stbi__resample_row_hv_2(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, int hs) { // need to generate 2x2 samples for every one in input int i, t0, t1; if (w == 1) { @@ -3681,8 +3761,9 @@ static stbi_uc * stbi__resample_row_hv_2(stbi_uc * out, stbi_uc * in_near, stbi_ } #if defined(STBI_SSE2) || defined(STBI_NEON) -static stbi_uc * stbi__resample_row_hv_2_simd(stbi_uc * out, stbi_uc * in_near, - stbi_uc * in_far, int w, int hs) { +static stbi_uc * stbi__resample_row_hv_2_simd( + stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, int hs +) { // need to generate 2x2 samples for every one in input int i = 0, t0, t1; @@ -3797,8 +3878,8 @@ static stbi_uc * stbi__resample_row_hv_2_simd(stbi_uc * out, stbi_uc * in_near, } #endif -static stbi_uc * stbi__resample_row_generic(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, - int w, int hs) { +static stbi_uc * +stbi__resample_row_generic(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, int hs) { // resample with nearest-neighbor int i, j; STBI_NOTUSED(in_far); @@ -3810,8 +3891,10 @@ static stbi_uc * stbi__resample_row_generic(stbi_uc * out, stbi_uc * in_near, st // this is a reduced-precision calculation of YCbCr-to-RGB introduced // to make sure the code produces the same results in both SIMD and scalar #define stbi__float2fixed(x) (((int) ((x) * 4096.0f + 0.5f)) << 8) -static void stbi__YCbCr_to_RGB_row(stbi_uc * out, const stbi_uc * y, const stbi_uc * pcb, - const stbi_uc * pcr, int count, int step) { +static void stbi__YCbCr_to_RGB_row( + stbi_uc * out, const stbi_uc * y, const stbi_uc * pcb, const stbi_uc * pcr, int count, + int step +) { int i; for (i = 0; i < count; ++i) { int y_fixed = (y[i] << 20) + (1 << 19); // rounding @@ -3846,8 +3929,10 @@ static void stbi__YCbCr_to_RGB_row(stbi_uc * out, const stbi_uc * y, const stbi_ } #if defined(STBI_SSE2) || defined(STBI_NEON) -static void stbi__YCbCr_to_RGB_simd(stbi_uc * out, stbi_uc const * y, stbi_uc const * pcb, - stbi_uc const * pcr, int count, int step) { +static void stbi__YCbCr_to_RGB_simd( + stbi_uc * out, stbi_uc const * y, stbi_uc const * pcb, stbi_uc const * pcr, int count, + int step +) { int i = 0; #ifdef STBI_SSE2 @@ -4031,8 +4116,8 @@ static stbi_uc stbi__blinn_8x8(stbi_uc x, stbi_uc y) { return (stbi_uc) ((t + (t >> 8)) >> 8); } -static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y, int * comp, - int req_comp) { +static stbi_uc * +load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y, int * comp, int req_comp) { int n, decode_n, is_rgb; z->s->img_n = 0; // make stbi__cleanup_jpeg safe @@ -4107,8 +4192,10 @@ static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y, int * for (k = 0; k < decode_n; ++k) { stbi__resample * r = &res_comp[k]; int y_bot = r->ystep >= (r->vs >> 1); - coutput[k] = r->resample(z->img_comp[k].linebuf, y_bot ? r->line1 : r->line0, - y_bot ? r->line0 : r->line1, r->w_lores, r->hs); + coutput[k] = r->resample( + z->img_comp[k].linebuf, y_bot ? r->line1 : r->line0, + y_bot ? r->line0 : r->line1, r->w_lores, r->hs + ); if (++r->ystep >= r->vs) { r->ystep = 0; r->line0 = r->line1; @@ -4206,8 +4293,9 @@ static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y, int * } } -static void * stbi__jpeg_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri) { +static void * stbi__jpeg_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +) { unsigned char * result; stbi__jpeg * j = (stbi__jpeg *) stbi__malloc(sizeof(stbi__jpeg)); if (!j) return stbi__errpuc("outofmem", "Out of memory"); @@ -4432,8 +4520,10 @@ stbi_inline static int stbi__zhuffman_decode(stbi__zbuf * a, stbi__zhuffman * z) return stbi__zhuffman_decode_slowpath(a, z); } -static int stbi__zexpand(stbi__zbuf * z, char * zout, - int n) // need to make room for n bytes +static int stbi__zexpand( + stbi__zbuf * z, char * zout, + int n +) // need to make room for n bytes { char * q; unsigned int cur, limit, old_limit; @@ -4500,7 +4590,8 @@ static int stbi__parse_huffman_block(stbi__zbuf * a) { if (z >= 286) return stbi__err( "bad huffman code", - "Corrupt PNG"); // per DEFLATE, length codes 286 and 287 must not appear in compressed data + "Corrupt PNG" + ); // per DEFLATE, length codes 286 and 287 must not appear in compressed data z -= 257; len = stbi__zlength_base[z]; if (stbi__zlength_extra[z]) len += stbi__zreceive(a, stbi__zlength_extra[z]); @@ -4508,7 +4599,8 @@ static int stbi__parse_huffman_block(stbi__zbuf * a) { if (z < 0 || z >= 30) return stbi__err( "bad huffman code", - "Corrupt PNG"); // per DEFLATE, distance codes 30 and 31 must not appear in compressed data + "Corrupt PNG" + ); // per DEFLATE, distance codes 30 and 31 must not appear in compressed data dist = stbi__zdist_base[z]; if (stbi__zdist_extra[z]) dist += stbi__zreceive(a, stbi__zdist_extra[z]); if (zout - a->zout_start < dist) return stbi__err("bad dist", "Corrupt PNG"); @@ -4617,8 +4709,10 @@ static int stbi__parse_zlib_header(stbi__zbuf * a) { if ((cmf * 256 + flg) % 31 != 0) return stbi__err("bad zlib header", "Corrupt PNG"); // zlib spec if (flg & 32) - return stbi__err("no preset dict", - "Corrupt PNG"); // preset dictionary not allowed in png + return stbi__err( + "no preset dict", + "Corrupt PNG" + ); // preset dictionary not allowed in png if (cm != 8) return stbi__err("bad compression", "Corrupt PNG"); // DEFLATE required for png @@ -4692,8 +4786,9 @@ static int stbi__do_zlib(stbi__zbuf * a, char * obuf, int olen, int exp, int par return stbi__parse_zlib(a, parse_header); } -STBIDEF char * stbi_zlib_decode_malloc_guesssize(const char * buffer, int len, - int initial_size, int * outlen) { +STBIDEF char * stbi_zlib_decode_malloc_guesssize( + const char * buffer, int len, int initial_size, int * outlen +) { stbi__zbuf a; char * p = (char *) stbi__malloc(initial_size); if (p == NULL) return NULL; @@ -4712,9 +4807,9 @@ STBIDEF char * stbi_zlib_decode_malloc(char const * buffer, int len, int * outle return stbi_zlib_decode_malloc_guesssize(buffer, len, 16384, outlen); } -STBIDEF char * stbi_zlib_decode_malloc_guesssize_headerflag(const char * buffer, int len, - int initial_size, int * outlen, - int parse_header) { +STBIDEF char * stbi_zlib_decode_malloc_guesssize_headerflag( + const char * buffer, int len, int initial_size, int * outlen, int parse_header +) { stbi__zbuf a; char * p = (char *) stbi__malloc(initial_size); if (p == NULL) return NULL; @@ -4752,8 +4847,8 @@ STBIDEF char * stbi_zlib_decode_noheader_malloc(char const * buffer, int len, in } } -STBIDEF int stbi_zlib_decode_noheader_buffer(char * obuffer, int olen, const char * ibuffer, - int ilen) { +STBIDEF int +stbi_zlib_decode_noheader_buffer(char * obuffer, int olen, const char * ibuffer, int ilen) { stbi__zbuf a; a.zbuffer = (stbi_uc *) ibuffer; a.zbuffer_end = (stbi_uc *) ibuffer + ilen; @@ -4831,8 +4926,8 @@ static const stbi_uc stbi__depth_scale_table[9] = {0, 0xff, 0x55, 0, 0x11, 0, 0, // adds an extra all-255 alpha channel // dest == src is legal // img_n must be 1 or 3 -static void stbi__create_png_alpha_expand8(stbi_uc * dest, stbi_uc * src, stbi__uint32 x, - int img_n) { +static void +stbi__create_png_alpha_expand8(stbi_uc * dest, stbi_uc * src, stbi__uint32 x, int img_n) { int i; // must process data backwards since we allow dest==src if (img_n == 1) { @@ -4852,9 +4947,10 @@ static void stbi__create_png_alpha_expand8(stbi_uc * dest, stbi_uc * src, stbi__ } // create the png data from post-deflated data -static int stbi__create_png_image_raw(stbi__png * a, stbi_uc * raw, stbi__uint32 raw_len, - int out_n, stbi__uint32 x, stbi__uint32 y, int depth, - int color) { +static int stbi__create_png_image_raw( + stbi__png * a, stbi_uc * raw, stbi__uint32 raw_len, int out_n, stbi__uint32 x, + stbi__uint32 y, int depth, int color +) { int bytes = (depth == 16 ? 2 : 1); stbi__context * s = a->s; stbi__uint32 i, j, stride = x * out_n * bytes; @@ -4869,8 +4965,10 @@ static int stbi__create_png_image_raw(stbi__png * a, stbi_uc * raw, stbi__uint32 int width = x; STBI_ASSERT(out_n == s->img_n || out_n == s->img_n + 1); - a->out = (stbi_uc *) stbi__malloc_mad3(x, y, output_bytes, - 0); // extra bytes to write off the end into + a->out = (stbi_uc *) stbi__malloc_mad3( + x, y, output_bytes, + 0 + ); // extra bytes to write off the end into if (!a->out) return stbi__err("outofmem", "Out of memory"); // note: error exits here don't need to clean up a->out individually, @@ -4937,11 +5035,13 @@ static int stbi__create_png_image_raw(stbi__png * a, stbi_uc * raw, stbi__uint32 case STBI__F_paeth: for (k = 0; k < filter_bytes; ++k) cur[k] = STBI__BYTECAST( - raw[k] + prior[k]); // prior[k] == stbi__paeth(0,prior[k],0) + raw[k] + prior[k] + ); // prior[k] == stbi__paeth(0,prior[k],0) for (k = filter_bytes; k < nk; ++k) - cur[k] = STBI__BYTECAST(raw[k] - + stbi__paeth(cur[k - filter_bytes], prior[k], - prior[k - filter_bytes])); + cur[k] = STBI__BYTECAST( + raw[k] + + stbi__paeth(cur[k - filter_bytes], prior[k], prior[k - filter_bytes]) + ); break; case STBI__F_avg_first: memcpy(cur, raw, filter_bytes); @@ -5022,16 +5122,18 @@ static int stbi__create_png_image_raw(stbi__png * a, stbi_uc * raw, stbi__uint32 return 1; } -static int stbi__create_png_image(stbi__png * a, stbi_uc * image_data, - stbi__uint32 image_data_len, int out_n, int depth, int color, - int interlaced) { +static int stbi__create_png_image( + stbi__png * a, stbi_uc * image_data, stbi__uint32 image_data_len, int out_n, int depth, + int color, int interlaced +) { int bytes = (depth == 16 ? 2 : 1); int out_bytes = out_n * bytes; stbi_uc * final; int p; if (!interlaced) - return stbi__create_png_image_raw(a, image_data, image_data_len, out_n, a->s->img_x, - a->s->img_y, depth, color); + return stbi__create_png_image_raw( + a, image_data, image_data_len, out_n, a->s->img_x, a->s->img_y, depth, color + ); // de-interlacing final = (stbi_uc *) stbi__malloc_mad3(a->s->img_x, a->s->img_y, out_bytes, 0); @@ -5047,8 +5149,9 @@ static int stbi__create_png_image(stbi__png * a, stbi_uc * image_data, y = (a->s->img_y - yorig[p] + yspc[p] - 1) / yspc[p]; if (x && y) { stbi__uint32 img_len = ((((a->s->img_n * x * depth) + 7) >> 3) + 1) * y; - if (!stbi__create_png_image_raw(a, image_data, image_data_len, out_n, x, y, depth, - color)) { + if (!stbi__create_png_image_raw( + a, image_data, image_data_len, out_n, x, y, depth, color + )) { STBI_FREE(final); return 0; } @@ -5056,8 +5159,10 @@ static int stbi__create_png_image(stbi__png * a, stbi_uc * image_data, for (i = 0; i < x; ++i) { int out_y = j * yspc[p] + yorig[p]; int out_x = i * xspc[p] + xorig[p]; - memcpy(final + out_y * a->s->img_x * out_bytes + out_x * out_bytes, - a->out + (j * x + i) * out_bytes, out_bytes); + memcpy( + final + out_y * a->s->img_x * out_bytes + out_x * out_bytes, + a->out + (j * x + i) * out_bytes, out_bytes + ); } } STBI_FREE(a->out); @@ -5270,8 +5375,9 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) { z->depth = stbi__get8(s); if (z->depth != 1 && z->depth != 2 && z->depth != 4 && z->depth != 8 && z->depth != 16) - return stbi__err("1/2/4/8/16-bit only", - "PNG not supported: 1/2/4/8/16-bit only"); + return stbi__err( + "1/2/4/8/16-bit only", "PNG not supported: 1/2/4/8/16-bit only" + ); color = stbi__get8(s); if (color > 6) return stbi__err("bad ctype", "Corrupt PNG"); if (color == 3 && z->depth == 16) return stbi__err("bad ctype", "Corrupt PNG"); @@ -5385,15 +5491,17 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) { raw_len = bpl * s->img_y * s->img_n /* pixels */ + s->img_y /* filter mode per row */; z->expanded = (stbi_uc *) stbi_zlib_decode_malloc_guesssize_headerflag( - (char *) z->idata, ioff, raw_len, (int *) &raw_len, !is_iphone); + (char *) z->idata, ioff, raw_len, (int *) &raw_len, !is_iphone + ); if (z->expanded == NULL) return 0; // zlib should set error STBI_FREE(z->idata); z->idata = NULL; if ((req_comp == s->img_n + 1 && req_comp != 3 && !pal_img_n) || has_trans) s->img_out_n = s->img_n + 1; else s->img_out_n = s->img_n; - if (!stbi__create_png_image(z, z->expanded, raw_len, s->img_out_n, z->depth, - color, interlace)) + if (!stbi__create_png_image( + z, z->expanded, raw_len, s->img_out_n, z->depth, color, interlace + )) return 0; if (has_trans) { if (z->depth == 16) { @@ -5432,8 +5540,9 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) { invalid_chunk[2] = STBI__BYTECAST(c.type >> 8); invalid_chunk[3] = STBI__BYTECAST(c.type >> 0); #endif - return stbi__err(invalid_chunk, - "PNG not supported: unknown PNG chunk type"); + return stbi__err( + invalid_chunk, "PNG not supported: unknown PNG chunk type" + ); } stbi__skip(s, c.length); break; @@ -5443,25 +5552,30 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) { } } -static void * stbi__do_png(stbi__png * p, int * x, int * y, int * n, int req_comp, - stbi__result_info * ri) { +static void * +stbi__do_png(stbi__png * p, int * x, int * y, int * n, int req_comp, stbi__result_info * ri) { void * result = NULL; if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error"); if (stbi__parse_png_file(p, STBI__SCAN_load, req_comp)) { if (p->depth <= 8) ri->bits_per_channel = 8; else if (p->depth == 16) ri->bits_per_channel = 16; else - return stbi__errpuc("bad bits_per_channel", - "PNG not supported: unsupported color depth"); + return stbi__errpuc( + "bad bits_per_channel", "PNG not supported: unsupported color depth" + ); result = p->out; p->out = NULL; if (req_comp && req_comp != p->s->img_out_n) { if (ri->bits_per_channel == 8) - result = stbi__convert_format((unsigned char *) result, p->s->img_out_n, - req_comp, p->s->img_x, p->s->img_y); + result = stbi__convert_format( + (unsigned char *) result, p->s->img_out_n, req_comp, p->s->img_x, + p->s->img_y + ); else - result = stbi__convert_format16((stbi__uint16 *) result, p->s->img_out_n, - req_comp, p->s->img_x, p->s->img_y); + result = stbi__convert_format16( + (stbi__uint16 *) result, p->s->img_out_n, req_comp, p->s->img_x, + p->s->img_y + ); p->s->img_out_n = req_comp; if (result == NULL) return result; } @@ -5479,8 +5593,9 @@ static void * stbi__do_png(stbi__png * p, int * x, int * y, int * n, int req_com return result; } -static void * stbi__png_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri) { +static void * stbi__png_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +) { stbi__png p; p.s = s; return stbi__do_png(&p, x, y, comp, req_comp, ri); @@ -5667,12 +5782,16 @@ static void * stbi__bmp_parse_header(stbi__context * s, stbi__bmp_data * info) { if (compress == 1 || compress == 2) return stbi__errpuc("BMP RLE", "BMP type not supported: RLE"); if (compress >= 4) - return stbi__errpuc("BMP JPEG/PNG", - "BMP type not supported: unsupported " - "compression"); // this includes PNG/JPEG modes + return stbi__errpuc( + "BMP JPEG/PNG", + "BMP type not supported: unsupported " + "compression" + ); // this includes PNG/JPEG modes if (compress == 3 && info->bpp != 16 && info->bpp != 32) - return stbi__errpuc("bad BMP", - "bad BMP"); // bitfields requires 16 or 32 bits/pixel + return stbi__errpuc( + "bad BMP", + "bad BMP" + ); // bitfields requires 16 or 32 bits/pixel stbi__get32le(s); // discard sizeof stbi__get32le(s); // discard hres stbi__get32le(s); // discard vres @@ -5723,8 +5842,9 @@ static void * stbi__bmp_parse_header(stbi__context * s, stbi__bmp_data * info) { return (void *) 1; } -static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri) { +static void * stbi__bmp_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +) { stbi_uc * out; unsigned int mr = 0, mg = 0, mb = 0, ma = 0, all_a; stbi_uc pal[256][4]; @@ -5804,8 +5924,9 @@ static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp, in if (info.hsz != 12) stbi__get8(s); pal[i][3] = 255; } - stbi__skip(s, info.offset - info.extra_read - info.hsz - - psize * (info.hsz == 12 ? 3 : 4)); + stbi__skip( + s, info.offset - info.extra_read - info.hsz - psize * (info.hsz == 12 ? 3 : 4) + ); if (info.bpp == 1) width = (s->img_x + 7) >> 3; else if (info.bpp == 4) width = (s->img_x + 1) >> 1; else if (info.bpp == 8) width = s->img_x; @@ -6023,8 +6144,9 @@ static int stbi__tga_info(stbi__context * s, int * x, int * y, int * comp) { } tga_comp = stbi__tga_get_comp(tga_colormap_bpp, 0, NULL); } else { - tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, - (tga_image_type == 3) || (tga_image_type == 11), NULL); + tga_comp = stbi__tga_get_comp( + tga_bits_per_pixel, (tga_image_type == 3) || (tga_image_type == 11), NULL + ); } if (!tga_comp) { stbi__rewind(s); @@ -6087,8 +6209,9 @@ static void stbi__tga_read_rgb16(stbi__context * s, stbi_uc * out) { // so let's treat all 15 and 16bit TGAs as RGB with no alpha. } -static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri) { +static void * stbi__tga_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +) { // read in the TGA header stuff int tga_offset = stbi__get8(s); int tga_indexed = stbi__get8(s); @@ -6325,8 +6448,10 @@ static int stbi__psd_decode_rle(stbi__context * s, stbi_uc * p, int pixelCount) return 1; } -static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri, int bpc) { +static void * stbi__psd_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri, + int bpc +) { int pixelCount; int channelCount, compression; int channel, i; @@ -6349,8 +6474,9 @@ static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp, in // Read the number of channels (R, G, B, A, etc). channelCount = stbi__get16be(s); if (channelCount < 0 || channelCount > 16) - return stbi__errpuc("wrong channel count", - "Unsupported number of channels in PSD image"); + return stbi__errpuc( + "wrong channel count", "Unsupported number of channels in PSD image" + ); // Read the rows and columns of the image. h = stbi__get32be(s); @@ -6575,8 +6701,8 @@ static void stbi__copyval(int channel, stbi_uc * dest, const stbi_uc * src) { if (channel & mask) dest[i] = src[i]; } -static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height, int * comp, - stbi_uc * result) { +static stbi_uc * +stbi__pic_load_core(stbi__context * s, int width, int height, int * comp, stbi_uc * result) { int act_comp = 0, num_packets = 0, y, chained; stbi__pic_packet packets[10]; @@ -6632,8 +6758,9 @@ static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height, i count = stbi__get8(s); if (stbi__at_eof(s)) - return stbi__errpuc("bad file", - "file too short (pure read count)"); + return stbi__errpuc( + "bad file", "file too short (pure read count)" + ); if (count > left) count = (stbi_uc) left; @@ -6650,8 +6777,9 @@ static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height, i while (left > 0) { int count = stbi__get8(s), i; if (stbi__at_eof(s)) - return stbi__errpuc("bad file", - "file too short (mixed read count)"); + return stbi__errpuc( + "bad file", "file too short (mixed read count)" + ); if (count >= 128) { // Repeated stbi_uc value[4]; @@ -6684,8 +6812,9 @@ static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height, i return result; } -static void * stbi__pic_load(stbi__context * s, int * px, int * py, int * comp, int req_comp, - stbi__result_info * ri) { +static void * stbi__pic_load( + stbi__context * s, int * px, int * py, int * comp, int req_comp, stbi__result_info * ri +) { stbi_uc * result; int i, x, y, internal_comp; STBI_NOTUSED(ri); @@ -6780,8 +6909,9 @@ static int stbi__gif_test(stbi__context * s) { return r; } -static void stbi__gif_parse_colortable(stbi__context * s, stbi_uc pal[256][4], int num_entries, - int transp) { +static void stbi__gif_parse_colortable( + stbi__context * s, stbi_uc pal[256][4], int num_entries, int transp +) { int i; for (i = 0; i < num_entries; ++i) { pal[i][2] = stbi__get8(s); @@ -6957,8 +7087,9 @@ static stbi_uc * stbi__process_gif_raster(stbi__context * s, stbi__gif * g) { // this function is designed to support animated gifs, although stb_image doesn't support it // two back is the image from two frames ago, used for a very specific disposal format -static stbi_uc * stbi__gif_load_next(stbi__context * s, stbi__gif * g, int * comp, - int req_comp, stbi_uc * two_back) { +static stbi_uc * stbi__gif_load_next( + stbi__context * s, stbi__gif * g, int * comp, int req_comp, stbi_uc * two_back +) { int dispose; int first_frame; int pi; @@ -6983,8 +7114,10 @@ static stbi_uc * stbi__gif_load_next(stbi__context * s, stbi__gif * g, int * com // background colour is only used for pixels that are not rendered first frame, after that "background" // color refers to the color that was there the previous frame. memset(g->out, 0x00, 4 * pcount); - memset(g->background, 0x00, - 4 * pcount); // state of the background (starts transparent) + memset( + g->background, 0x00, + 4 * pcount + ); // state of the background (starts transparent) memset(g->history, 0x00, pcount); // pixels that were affected previous frame first_frame = 1; @@ -7066,8 +7199,10 @@ static stbi_uc * stbi__gif_load_next(stbi__context * s, stbi__gif * g, int * com } if (g->lflags & 0x80) { - stbi__gif_parse_colortable(s, g->lpal, 2 << (g->lflags & 7), - g->eflags & 0x01 ? g->transparent : -1); + stbi__gif_parse_colortable( + s, g->lpal, 2 << (g->lflags & 7), + g->eflags & 0x01 ? g->transparent : -1 + ); g->color_table = (stbi_uc *) g->lpal; } else if (g->flags & 0x80) { g->color_table = (stbi_uc *) g->pal; @@ -7101,8 +7236,8 @@ static stbi_uc * stbi__gif_load_next(stbi__context * s, stbi__gif * g, int * com if (len == 4) { g->eflags = stbi__get8(s); g->delay = 10 - * stbi__get16le( - s); // delay - 1/100th of a second, saving as 1/1000ths. + * stbi__get16le(s + ); // delay - 1/100th of a second, saving as 1/1000ths. // unset old transparent if (g->transparent >= 0) { @@ -7148,8 +7283,9 @@ static void * stbi__load_gif_main_outofmem(stbi__gif * g, stbi_uc * out, int ** return stbi__errpuc("outofmem", "Out of memory"); } -static void * stbi__load_gif_main(stbi__context * s, int ** delays, int * x, int * y, int * z, - int * comp, int req_comp) { +static void * stbi__load_gif_main( + stbi__context * s, int ** delays, int * x, int * y, int * z, int * comp, int req_comp +) { if (stbi__gif_test(s)) { int layers = 0; stbi_uc * u = 0; @@ -7188,8 +7324,9 @@ static void * stbi__load_gif_main(stbi__context * s, int ** delays, int * x, int } if (delays) { - int * new_delays = (int *) STBI_REALLOC_SIZED(*delays, delays_size, - sizeof(int) * layers); + int * new_delays = (int *) STBI_REALLOC_SIZED( + *delays, delays_size, sizeof(int) * layers + ); if (!new_delays) return stbi__load_gif_main_outofmem(&g, out, delays); *delays = new_delays; delays_size = layers * sizeof(int); @@ -7231,8 +7368,9 @@ static void * stbi__load_gif_main(stbi__context * s, int ** delays, int * x, int } } -static void * stbi__gif_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri) { +static void * stbi__gif_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +) { stbi_uc * u = 0; stbi__gif g; memset(&g, 0, sizeof(g)); @@ -7336,8 +7474,9 @@ static void stbi__hdr_convert(float * output, stbi_uc * input, int req_comp) { } } -static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri) { +static float * stbi__hdr_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +) { char buffer[STBI__HDR_BUFLEN]; char * token; int valid = 0; @@ -7404,8 +7543,9 @@ static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp, i stbi_uc rgbe[4]; main_decode_loop: stbi__getn(s, rgbe, 4); - stbi__hdr_convert(hdr_data + j * width * req_comp + i * req_comp, rgbe, - req_comp); + stbi__hdr_convert( + hdr_data + j * width * req_comp + i * req_comp, rgbe, req_comp + ); } } } else { @@ -7472,8 +7612,9 @@ static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp, i } } for (i = 0; i < width; ++i) - stbi__hdr_convert(hdr_data + (j * width + i) * req_comp, scanline + i * 4, - req_comp); + stbi__hdr_convert( + hdr_data + (j * width + i) * req_comp, scanline + i * 4, req_comp + ); } if (scanline) STBI_FREE(scanline); } @@ -7689,8 +7830,9 @@ static int stbi__pnm_test(stbi__context * s) { return 1; } -static void * stbi__pnm_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri) { +static void * stbi__pnm_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +) { stbi_uc * out; STBI_NOTUSED(ri); @@ -7710,8 +7852,9 @@ static void * stbi__pnm_load(stbi__context * s, int * x, int * y, int * comp, in if (!stbi__mad4sizes_valid(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0)) return stbi__errpuc("too large", "PNM too large"); - out = (stbi_uc *) stbi__malloc_mad4(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, - 0); + out = (stbi_uc *) stbi__malloc_mad4( + s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0 + ); if (!out) return stbi__errpuc("outofmem", "Out of memory"); if (!stbi__getn(s, out, s->img_n * s->img_x * s->img_y * (ri->bits_per_channel / 8))) { STBI_FREE(out); @@ -7720,8 +7863,9 @@ static void * stbi__pnm_load(stbi__context * s, int * x, int * y, int * comp, in if (req_comp && req_comp != s->img_n) { if (ri->bits_per_channel == 16) { - out = (stbi_uc *) stbi__convert_format16((stbi__uint16 *) out, s->img_n, req_comp, - s->img_x, s->img_y); + out = (stbi_uc *) stbi__convert_format16( + (stbi__uint16 *) out, s->img_n, req_comp, s->img_x, s->img_y + ); } else { out = stbi__convert_format(out, s->img_n, req_comp, s->img_x, s->img_y); } @@ -7753,8 +7897,10 @@ static int stbi__pnm_getinteger(stbi__context * s, char * c) { value = value * 10 + (*c - '0'); *c = (char) stbi__get8(s); if ((value > 214748364) || (value == 214748364 && *c > '7')) - return stbi__err("integer parse overflow", - "Parsing an integer in the PPM header overflowed a 32-bit int"); + return stbi__err( + "integer parse overflow", + "Parsing an integer in the PPM header overflowed a 32-bit int" + ); } return value; @@ -7795,8 +7941,9 @@ static int stbi__pnm_info(stbi__context * s, int * x, int * y, int * comp) { maxv = stbi__pnm_getinteger(s, &c); // read max value if (maxv > 65535) - return stbi__err("max value > 65535", - "PPM image supports only 8-bit and 16-bit images"); + return stbi__err( + "max value > 65535", "PPM image supports only 8-bit and 16-bit images" + ); else if (maxv > 255) return 16; else return 8; } @@ -7902,15 +8049,16 @@ STBIDEF int stbi_is_16_bit_from_file(FILE * f) { } #endif // !STBI_NO_STDIO -STBIDEF int stbi_info_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * comp) { +STBIDEF int +stbi_info_from_memory(stbi_uc const * buffer, int len, int * x, int * y, int * comp) { stbi__context s; stbi__start_mem(&s, buffer, len); return stbi__info_main(&s, x, y, comp); } -STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const * c, void * user, int * x, - int * y, int * comp) { +STBIDEF int stbi_info_from_callbacks( + stbi_io_callbacks const * c, void * user, int * x, int * y, int * comp +) { stbi__context s; stbi__start_callbacks(&s, (stbi_io_callbacks *) c, user); return stbi__info_main(&s, x, y, comp); diff --git a/src/crepe/Particle.cpp b/src/crepe/Particle.cpp index b340826..27fa97f 100644 --- a/src/crepe/Particle.cpp +++ b/src/crepe/Particle.cpp @@ -2,8 +2,9 @@ using namespace crepe; -void Particle::reset(unsigned int lifespan, const vec2 & position, const vec2 & velocity, - float angle) { +void Particle::reset( + unsigned int lifespan, const vec2 & position, const vec2 & velocity, float angle +) { // Initialize the particle state this->time_in_life = 0; this->lifespan = lifespan; diff --git a/src/crepe/Particle.h b/src/crepe/Particle.h index ee0cd66..c013de5 100644 --- a/src/crepe/Particle.h +++ b/src/crepe/Particle.h @@ -41,8 +41,8 @@ public: * \param velocity The initial velocity of the particle. * \param angle The angle of the particle's trajectory or orientation. */ - void reset(unsigned int lifespan, const vec2 & position, const vec2 & velocity, - float angle); + void + reset(unsigned int lifespan, const vec2 & position, const vec2 & velocity, float angle); /** * \brief Updates the particle's state. * diff --git a/src/crepe/api/AI.cpp b/src/crepe/api/AI.cpp index 2195249..2fedaf4 100644 --- a/src/crepe/api/AI.cpp +++ b/src/crepe/api/AI.cpp @@ -8,8 +8,9 @@ namespace crepe { AI::AI(game_object_id_t id, float max_force) : Component(id), max_force(max_force) {} -void AI::make_circle_path(float radius, const vec2 & center, float start_angle, - bool clockwise) { +void AI::make_circle_path( + float radius, const vec2 & center, float start_angle, bool clockwise +) { if (radius <= 0) { throw std::runtime_error("Radius must be greater than 0"); } @@ -25,19 +26,25 @@ void AI::make_circle_path(float radius, const vec2 & center, float start_angle, if (clockwise) { for (float i = start_angle; i < 2 * M_PI + start_angle; i += step) { - path.push_back(vec2{static_cast(center.x + radius * cos(i)), - static_cast(center.y + radius * sin(i))}); + path.push_back(vec2 { + static_cast(center.x + radius * cos(i)), + static_cast(center.y + radius * sin(i)) + }); } } else { for (float i = start_angle; i > start_angle - 2 * M_PI; i -= step) { - path.push_back(vec2{static_cast(center.x + radius * cos(i)), - static_cast(center.y + radius * sin(i))}); + path.push_back(vec2 { + static_cast(center.x + radius * cos(i)), + static_cast(center.y + radius * sin(i)) + }); } } } -void AI::make_oval_path(float radius_x, float radius_y, const vec2 & center, float start_angle, - bool clockwise, float rotation) { +void AI::make_oval_path( + float radius_x, float radius_y, const vec2 & center, float start_angle, bool clockwise, + float rotation +) { if (radius_x <= 0 && radius_y <= 0) { throw std::runtime_error("Radius must be greater than 0"); } @@ -73,14 +80,16 @@ void AI::make_oval_path(float radius_x, float radius_y, const vec2 & center, flo if (clockwise) { for (float i = start_angle; i < 2 * M_PI + start_angle; i += step) { - vec2 point = {static_cast(center.x + radius_x * cos(i)), - static_cast(center.y + radius_y * sin(i))}; + vec2 point + = {static_cast(center.x + radius_x * cos(i)), + static_cast(center.y + radius_y * sin(i))}; path.push_back(rotate_point(point, center)); } } else { for (float i = start_angle; i > start_angle - 2 * M_PI; i -= step) { - vec2 point = {static_cast(center.x + radius_x * cos(i)), - static_cast(center.y + radius_y * sin(i))}; + vec2 point + = {static_cast(center.x + radius_x * cos(i)), + static_cast(center.y + radius_y * sin(i))}; path.push_back(rotate_point(point, center)); } } diff --git a/src/crepe/api/AI.h b/src/crepe/api/AI.h index c780a91..bee11b3 100644 --- a/src/crepe/api/AI.h +++ b/src/crepe/api/AI.h @@ -70,8 +70,10 @@ public: * \param start_angle The start angle of the circle (in radians) * \param clockwise The direction of the circle */ - void make_circle_path(float radius, const vec2 & center = {0, 0}, float start_angle = 0, - bool clockwise = true); + void make_circle_path( + float radius, const vec2 & center = {0, 0}, float start_angle = 0, + bool clockwise = true + ); /** * \brief Make an oval path (for the path following behavior) * @@ -84,8 +86,10 @@ public: * \param clockwise The direction of the oval * \param rotation The rotation of the oval (in radians) */ - void make_oval_path(float radius_x, float radius_y, const vec2 & center = {0, 0}, - float start_angle = 0, bool clockwise = true, float rotation = 0); + void make_oval_path( + float radius_x, float radius_y, const vec2 & center = {0, 0}, float start_angle = 0, + bool clockwise = true, float rotation = 0 + ); public: //! The maximum force that can be applied to the entity (higher values will make the entity adjust faster) diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index b7eefb8..c558d86 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -7,8 +7,10 @@ using namespace crepe; -Animator::Animator(game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size, - const uvec2 & grid_size, const Animator::Data & data) +Animator::Animator( + game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size, + const uvec2 & grid_size, const Animator::Data & data +) : Component(id), spritesheet(spritesheet), grid_size(grid_size), diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index 5918800..102894d 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -83,8 +83,10 @@ public: * This constructor sets up the Animator with the given parameters, and initializes the * animation system. */ - Animator(game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size, - const uvec2 & grid_size, const Animator::Data & data); + Animator( + game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size, + const uvec2 & grid_size, const Animator::Data & data + ); ~Animator(); // dbg_trace public: diff --git a/src/crepe/api/Asset.cpp b/src/crepe/api/Asset.cpp index e148367..bab82e7 100644 --- a/src/crepe/api/Asset.cpp +++ b/src/crepe/api/Asset.cpp @@ -50,5 +50,5 @@ string Asset::whereami() const noexcept { bool Asset::operator==(const Asset & other) const noexcept { return this->src == other.src; } size_t std::hash::operator()(const Asset & asset) const noexcept { - return std::hash{}(asset.get_path()); + return std::hash {}(asset.get_path()); }; diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h index b20e490..eaa56e8 100644 --- a/src/crepe/api/AudioSource.h +++ b/src/crepe/api/AudioSource.h @@ -68,7 +68,7 @@ private: typeof(loop) last_loop = loop; //! \} //! This source's voice handle - SoundHandle voice{}; + SoundHandle voice {}; }; } // namespace crepe diff --git a/src/crepe/api/BoxCollider.cpp b/src/crepe/api/BoxCollider.cpp index a893d41..f6b358d 100644 --- a/src/crepe/api/BoxCollider.cpp +++ b/src/crepe/api/BoxCollider.cpp @@ -4,7 +4,8 @@ using namespace crepe; -BoxCollider::BoxCollider(game_object_id_t game_object_id, const vec2 & dimensions, - const vec2 & offset) +BoxCollider::BoxCollider( + game_object_id_t game_object_id, const vec2 & dimensions, const vec2 & offset +) : Collider(game_object_id, offset), dimensions(dimensions) {} diff --git a/src/crepe/api/BoxCollider.h b/src/crepe/api/BoxCollider.h index d643e7f..229b90f 100644 --- a/src/crepe/api/BoxCollider.h +++ b/src/crepe/api/BoxCollider.h @@ -13,8 +13,9 @@ namespace crepe { */ class BoxCollider : public Collider { public: - BoxCollider(game_object_id_t game_object_id, const vec2 & dimensions, - const vec2 & offset = {0, 0}); + BoxCollider( + game_object_id_t game_object_id, const vec2 & dimensions, const vec2 & offset = {0, 0} + ); //! Width and height of the box collider vec2 dimensions; diff --git a/src/crepe/api/Camera.cpp b/src/crepe/api/Camera.cpp index 19a3296..b1466b5 100644 --- a/src/crepe/api/Camera.cpp +++ b/src/crepe/api/Camera.cpp @@ -6,8 +6,9 @@ using namespace crepe; -Camera::Camera(game_object_id_t id, const ivec2 & screen, const vec2 & viewport_size, - const Data & data) +Camera::Camera( + game_object_id_t id, const ivec2 & screen, const vec2 & viewport_size, const Data & data +) : Component(id), screen(screen), viewport_size(viewport_size), diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h index 54d9a73..3191b04 100644 --- a/src/crepe/api/Camera.h +++ b/src/crepe/api/Camera.h @@ -44,8 +44,10 @@ public: * \param viewport_size is the view of the world in game units * \param data the camera component data */ - Camera(game_object_id_t id, const ivec2 & screen, const vec2 & viewport_size, - const Camera::Data & data); + Camera( + game_object_id_t id, const ivec2 & screen, const vec2 & viewport_size, + const Camera::Data & data + ); ~Camera(); // dbg_trace only public: diff --git a/src/crepe/api/CircleCollider.cpp b/src/crepe/api/CircleCollider.cpp index 90ab5e7..e72800c 100644 --- a/src/crepe/api/CircleCollider.cpp +++ b/src/crepe/api/CircleCollider.cpp @@ -2,7 +2,8 @@ using namespace crepe; -CircleCollider::CircleCollider(game_object_id_t game_object_id, float radius, - const vec2 & offset) +CircleCollider::CircleCollider( + game_object_id_t game_object_id, float radius, const vec2 & offset +) : Collider(game_object_id, offset), radius(radius) {} diff --git a/src/crepe/api/CircleCollider.h b/src/crepe/api/CircleCollider.h index 22da836..e6ad4fa 100644 --- a/src/crepe/api/CircleCollider.h +++ b/src/crepe/api/CircleCollider.h @@ -13,8 +13,9 @@ namespace crepe { */ class CircleCollider : public Collider { public: - CircleCollider(game_object_id_t game_object_id, float radius, - const vec2 & offset = {0, 0}); + CircleCollider( + game_object_id_t game_object_id, float radius, const vec2 & offset = {0, 0} + ); //! Radius of the circle collider. float radius; diff --git a/src/crepe/api/Color.cpp b/src/crepe/api/Color.cpp index 29bd77a..6858aa8 100644 --- a/src/crepe/api/Color.cpp +++ b/src/crepe/api/Color.cpp @@ -2,11 +2,11 @@ using namespace crepe; -const Color Color::WHITE{0xff, 0xff, 0xff}; -const Color Color::RED{0xff, 0x00, 0x00}; -const Color Color::GREEN{0x00, 0xff, 0x00}; -const Color Color::BLUE{0x00, 0x00, 0xff}; -const Color Color::BLACK{0x00, 0x00, 0x00}; -const Color Color::CYAN{0x00, 0xff, 0xff}; -const Color Color::YELLOW{0xff, 0xff, 0x00}; -const Color Color::MAGENTA{0xff, 0x00, 0xff}; +const Color Color::WHITE {0xff, 0xff, 0xff}; +const Color Color::RED {0xff, 0x00, 0x00}; +const Color Color::GREEN {0x00, 0xff, 0x00}; +const Color Color::BLUE {0x00, 0x00, 0xff}; +const Color Color::BLACK {0x00, 0x00, 0x00}; +const Color Color::CYAN {0x00, 0xff, 0xff}; +const Color Color::YELLOW {0xff, 0xff, 0x00}; +const Color Color::MAGENTA {0xff, 0x00, 0xff}; diff --git a/src/crepe/api/Engine.cpp b/src/crepe/api/Engine.cpp index 2e9d35a..cd9786b 100644 --- a/src/crepe/api/Engine.cpp +++ b/src/crepe/api/Engine.cpp @@ -46,8 +46,10 @@ void Engine::loop() { try { systems.fixed_update(); } catch (const exception & e) { - Log::logf(Log::Level::WARNING, - "Uncaught exception in fixed update function: {}\n", e.what()); + Log::logf( + Log::Level::WARNING, "Uncaught exception in fixed update function: {}\n", + e.what() + ); } timer.advance_fixed_elapsed_time(); } @@ -55,8 +57,10 @@ void Engine::loop() { try { systems.frame_update(); } catch (const exception & e) { - Log::logf(Log::Level::WARNING, "Uncaught exception in frame update function: {}\n", - e.what()); + Log::logf( + Log::Level::WARNING, "Uncaught exception in frame update function: {}\n", + e.what() + ); } timer.enforce_frame_rate(); } diff --git a/src/crepe/api/Engine.h b/src/crepe/api/Engine.h index 700a0cd..452a856 100644 --- a/src/crepe/api/Engine.h +++ b/src/crepe/api/Engine.h @@ -54,26 +54,26 @@ private: Mediator mediator; //! SystemManager - SystemManager system_manager{mediator}; + SystemManager system_manager {mediator}; //! SDLContext instance - SDLContext sdl_context{mediator}; + SDLContext sdl_context {mediator}; //! Resource manager instance - ResourceManager resource_manager{mediator}; + ResourceManager resource_manager {mediator}; //! Component manager instance - ComponentManager component_manager{mediator}; + ComponentManager component_manager {mediator}; //! Scene manager instance - SceneManager scene_manager{mediator}; + SceneManager scene_manager {mediator}; //! LoopTimerManager instance - LoopTimerManager loop_timer{mediator}; + LoopTimerManager loop_timer {mediator}; //! EventManager instance - EventManager event_manager{mediator}; + EventManager event_manager {mediator}; //! Save manager instance - SaveManager save_manager{mediator}; + SaveManager save_manager {mediator}; //! ReplayManager instance - ReplayManager replay_manager{mediator}; + ReplayManager replay_manager {mediator}; }; } // namespace crepe diff --git a/src/crepe/api/GameObject.cpp b/src/crepe/api/GameObject.cpp index 9b94cad..100e210 100644 --- a/src/crepe/api/GameObject.cpp +++ b/src/crepe/api/GameObject.cpp @@ -7,13 +7,15 @@ using namespace crepe; using namespace std; -GameObject::GameObject(Mediator & mediator, game_object_id_t id, const std::string & name, - const std::string & tag, const vec2 & position, double rotation, - double scale) +GameObject::GameObject( + Mediator & mediator, game_object_id_t id, const std::string & name, + const std::string & tag, const vec2 & position, double rotation, double scale +) : id(id), mediator(mediator), - transform(mediator.component_manager->add_component(this->id, position, - rotation, scale)), + transform(mediator.component_manager->add_component( + this->id, position, rotation, scale + )), metadata(mediator.component_manager->add_component(this->id, name, tag)) {} void GameObject::set_parent(const GameObject & parent) { diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h index 572ce3a..043913a 100644 --- a/src/crepe/api/GameObject.h +++ b/src/crepe/api/GameObject.h @@ -30,8 +30,10 @@ private: * \param rotation The rotation of the GameObject * \param scale The scale of the GameObject */ - GameObject(Mediator & mediator, game_object_id_t id, const std::string & name, - const std::string & tag, const vec2 & position, double rotation, double scale); + GameObject( + Mediator & mediator, game_object_id_t id, const std::string & name, + const std::string & tag, const vec2 & position, double rotation, double scale + ); //! ComponentManager instances GameObject friend class ComponentManager; diff --git a/src/crepe/api/ParticleEmitter.cpp b/src/crepe/api/ParticleEmitter.cpp index 9a70334..341c1e2 100644 --- a/src/crepe/api/ParticleEmitter.cpp +++ b/src/crepe/api/ParticleEmitter.cpp @@ -4,8 +4,9 @@ using namespace crepe; using namespace std; -ParticleEmitter::ParticleEmitter(game_object_id_t game_object_id, const Sprite & sprite, - const Data & data) +ParticleEmitter::ParticleEmitter( + game_object_id_t game_object_id, const Sprite & sprite, const Data & data +) : Component(game_object_id), sprite(sprite), data(data) { @@ -15,7 +16,7 @@ ParticleEmitter::ParticleEmitter(game_object_id_t game_object_id, const Sprite & } unique_ptr ParticleEmitter::save() const { - return unique_ptr{new ParticleEmitter(*this)}; + return unique_ptr {new ParticleEmitter(*this)}; } void ParticleEmitter::restore(const Component & snapshot) { diff --git a/src/crepe/api/Scene.cpp b/src/crepe/api/Scene.cpp index ad729d2..84da7e8 100644 --- a/src/crepe/api/Scene.cpp +++ b/src/crepe/api/Scene.cpp @@ -4,8 +4,10 @@ using namespace crepe; SaveManager & Scene::get_save_manager() const { return mediator->save_manager; } -GameObject Scene::new_object(const std::string & name, const std::string & tag, - const vec2 & position, double rotation, double scale) { +GameObject Scene::new_object( + const std::string & name, const std::string & tag, const vec2 & position, double rotation, + double scale +) { // Forward the call to ComponentManager's new_object method return mediator->component_manager->new_object(name, tag, position, rotation, scale); } diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index d552a43..b50a0fc 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -69,9 +69,10 @@ public: SaveManager & get_save_manager() const; //! \copydoc ComponentManager::new_object - GameObject new_object(const std::string & name, const std::string & tag = "", - const vec2 & position = {0, 0}, double rotation = 0, - double scale = 1); + GameObject new_object( + const std::string & name, const std::string & tag = "", const vec2 & position = {0, 0}, + double rotation = 0, double scale = 1 + ); //! \copydoc ResourceManager::set_persistent void set_persistent(const Asset & asset, bool persistent); diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index bbee920..b000d9d 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -129,12 +129,14 @@ protected: void subscribe(const EventHandler & callback); //! \copydoc EventManager::trigger_event template - void trigger_event(const EventType & event = {}, - event_channel_t channel = EventManager::CHANNEL_ALL); + void trigger_event( + const EventType & event = {}, event_channel_t channel = EventManager::CHANNEL_ALL + ); //! \copydoc EventManager::queue_event template - void queue_event(const EventType & event = {}, - event_channel_t channel = EventManager::CHANNEL_ALL); + void queue_event( + const EventType & event = {}, event_channel_t channel = EventManager::CHANNEL_ALL + ); //! \} /** @@ -179,7 +181,7 @@ protected: OptionalRef & mediator; replay(OptionalRef & mediator) : mediator(mediator) {} friend class Script; - } replay{mediator}; + } replay {mediator}; /** * \brief Utility function to retrieve the keyboard state diff --git a/src/crepe/api/Script.hpp b/src/crepe/api/Script.hpp index 4462a41..c7fa6ff 100644 --- a/src/crepe/api/Script.hpp +++ b/src/crepe/api/Script.hpp @@ -14,7 +14,8 @@ T & Script::get_component() const { RefVector all_components = this->get_components(); if (all_components.size() < 1) throw runtime_error( - format("Script: no component found with type = {}", typeid(T).name())); + format("Script: no component found with type = {}", typeid(T).name()) + ); return all_components.back().get(); } @@ -35,8 +36,9 @@ void Script::logf(std::format_string fmt, Args &&... args) { } template -void Script::subscribe_internal(const EventHandler & callback, - event_channel_t channel) { +void Script::subscribe_internal( + const EventHandler & callback, event_channel_t channel +) { EventManager & mgr = this->mediator->event_manager; subscription_t listener = mgr.subscribe( [this, callback](const EventType & data) -> bool { @@ -54,7 +56,8 @@ void Script::subscribe_internal(const EventHandler & callback, // call user-provided callback return callback(data); }, - channel); + channel + ); this->listeners.push_back(listener); } diff --git a/src/crepe/api/Text.cpp b/src/crepe/api/Text.cpp index 4a94180..b24f0ac 100644 --- a/src/crepe/api/Text.cpp +++ b/src/crepe/api/Text.cpp @@ -2,8 +2,10 @@ using namespace crepe; -Text::Text(game_object_id_t id, const vec2 & dimensions, const vec2 & offset, - const std::string & font_family, const Data & data, const std::string & text) +Text::Text( + game_object_id_t id, const vec2 & dimensions, const vec2 & offset, + const std::string & font_family, const Data & data, const std::string & text +) : UIObject(id, dimensions, offset), text(text), data(data), diff --git a/src/crepe/api/Text.h b/src/crepe/api/Text.h index da40141..0289b85 100644 --- a/src/crepe/api/Text.h +++ b/src/crepe/api/Text.h @@ -48,8 +48,10 @@ public: * \param data Data struct containing extra text parameters. * \param font Optional font asset that can be passed or left empty. */ - Text(game_object_id_t id, const vec2 & dimensions, const vec2 & offset, - const std::string & font_family, const Data & data, const std::string & text = ""); + Text( + game_object_id_t id, const vec2 & dimensions, const vec2 & offset, + const std::string & font_family, const Data & data, const std::string & text = "" + ); //! Label text. std::string text = ""; diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp index fcfce14..b70174c 100644 --- a/src/crepe/api/Transform.cpp +++ b/src/crepe/api/Transform.cpp @@ -14,7 +14,7 @@ Transform::Transform(game_object_id_t id, const vec2 & point, double rotation, d } unique_ptr Transform::save() const { - return unique_ptr{new Transform(*this)}; + return unique_ptr {new Transform(*this)}; } void Transform::restore(const Component & snapshot) { diff --git a/src/crepe/facade/FontFacade.cpp b/src/crepe/facade/FontFacade.cpp index 87f95ab..e284f5a 100644 --- a/src/crepe/facade/FontFacade.cpp +++ b/src/crepe/facade/FontFacade.cpp @@ -20,8 +20,9 @@ Asset FontFacade::get_font_asset(const string & font_family) { = FcNameParse(reinterpret_cast(font_family.c_str())); if (raw_pattern == NULL) throw runtime_error("Failed to create font pattern."); - unique_ptr> pattern{ - raw_pattern, [](FcPattern * p) { FcPatternDestroy(p); }}; + unique_ptr> pattern { + raw_pattern, [](FcPattern * p) { FcPatternDestroy(p); } + }; FcConfig * config = FcConfigGetCurrent(); if (config == NULL) throw runtime_error("Failed to get current Fontconfig configuration."); diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 64c1fe2..859f966 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -41,9 +41,10 @@ SDLContext::SDLContext(Mediator & mediator) { } auto & cfg = Config::get_instance().window_settings; - SDL_Window * tmp_window - = SDL_CreateWindow(cfg.window_title.c_str(), SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, cfg.default_size.x, cfg.default_size.y, 0); + SDL_Window * tmp_window = SDL_CreateWindow( + cfg.window_title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + cfg.default_size.x, cfg.default_size.y, 0 + ); if (!tmp_window) { throw runtime_error(format("SDLContext: SDL_Window error: {}", SDL_GetError())); } @@ -52,8 +53,8 @@ SDLContext::SDLContext(Mediator & mediator) { SDL_Renderer * tmp_renderer = SDL_CreateRenderer(this->game_window.get(), -1, SDL_RENDERER_ACCELERATED); if (!tmp_renderer) { - throw runtime_error( - format("SDLContext: SDL_CreateRenderer error: {}", SDL_GetError())); + throw runtime_error(format("SDLContext: SDL_CreateRenderer error: {}", SDL_GetError()) + ); } this->game_renderer @@ -108,7 +109,7 @@ const keyboard_state_t & SDLContext::get_keyboard_state() { MouseButton SDLContext::sdl_to_mousebutton(Uint8 sdl_button) { static const std::array MOUSE_BUTTON_LOOKUP_TABLE = [] { - std::array table{}; + std::array table {}; table.fill(MouseButton::NONE); table[SDL_BUTTON_LEFT] = MouseButton::LEFT_MOUSE; @@ -164,7 +165,7 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const { - size / 2 + cam_aux_data.bar_size; } - return SDL_FRect{ + return SDL_FRect { .x = screen_pos.x, .y = screen_pos.y, .w = size.x, @@ -188,7 +189,7 @@ void SDLContext::draw(const RenderContext & ctx) { srcrect_ptr = &srcrect; } - SDL_FRect dstrect = this->get_dst_rect(SDLContext::DestinationRectangleData{ + SDL_FRect dstrect = this->get_dst_rect(SDLContext::DestinationRectangleData { .sprite = ctx.sprite, .texture = ctx.texture, .pos = ctx.pos, @@ -198,8 +199,10 @@ void SDLContext::draw(const RenderContext & ctx) { double angle = ctx.angle + data.angle_offset; this->set_color_texture(ctx.texture, ctx.sprite.data.color); - SDL_RenderCopyExF(this->game_renderer.get(), ctx.texture.get_img(), srcrect_ptr, &dstrect, - angle, NULL, render_flip); + SDL_RenderCopyExF( + this->game_renderer.get(), ctx.texture.get_img(), srcrect_ptr, &dstrect, angle, NULL, + render_flip + ); } void SDLContext::draw_text(const RenderText & data) { @@ -210,7 +213,7 @@ void SDLContext::draw_text(const RenderText & data) { std::unique_ptr> font_surface; std::unique_ptr> font_texture; - SDL_Color color{ + SDL_Color color { .r = text.data.text_color.r, .g = text.data.text_color.g, .b = text.data.text_color.b, @@ -232,20 +235,21 @@ void SDLContext::draw_text(const RenderText & data) { = {tmp_font_texture, [](SDL_Texture * texture) { SDL_DestroyTexture(texture); }}; vec2 size = text.dimensions * cam_aux_data.render_scale * data.transform.scale; - vec2 screen_pos - = (absoluut_pos - cam_aux_data.cam_pos + (cam_aux_data.zoomed_viewport) / 2) - * cam_aux_data.render_scale - - size / 2 + cam_aux_data.bar_size; + vec2 screen_pos = (absoluut_pos - cam_aux_data.cam_pos + (cam_aux_data.zoomed_viewport) / 2 + ) * cam_aux_data.render_scale + - size / 2 + cam_aux_data.bar_size; - SDL_FRect dstrect{ + SDL_FRect dstrect { .x = screen_pos.x, .y = screen_pos.y, .w = size.x, .h = size.y, }; - SDL_RenderCopyExF(this->game_renderer.get(), font_texture.get(), NULL, &dstrect, - data.transform.rotation, NULL, SDL_FLIP_NONE); + SDL_RenderCopyExF( + this->game_renderer.get(), font_texture.get(), NULL, &dstrect, data.transform.rotation, + NULL, SDL_FLIP_NONE + ); } void SDLContext::update_camera_view(const Camera & cam, const vec2 & new_pos) { @@ -291,8 +295,10 @@ void SDLContext::update_camera_view(const Camera & cam, const vec2 & new_pos) { render_scale.x = render_scale.y = scale; } - SDL_SetRenderDrawColor(this->game_renderer.get(), cam_data.bg_color.r, cam_data.bg_color.g, - cam_data.bg_color.b, cam_data.bg_color.a); + SDL_SetRenderDrawColor( + this->game_renderer.get(), cam_data.bg_color.r, cam_data.bg_color.g, + cam_data.bg_color.b, cam_data.bg_color.a + ); SDL_Rect bg = { .x = 0, @@ -427,11 +433,12 @@ std::vector SDLContext::get_events() { return event_list; } -void SDLContext::handle_window_event(const SDL_WindowEvent & window_event, - std::vector & event_list) { +void SDLContext::handle_window_event( + const SDL_WindowEvent & window_event, std::vector & event_list +) { switch (window_event.event) { case SDL_WINDOWEVENT_EXPOSED: - event_list.push_back(EventData{EventType::WINDOW_EXPOSE}); + event_list.push_back(EventData {EventType::WINDOW_EXPOSE}); break; case SDL_WINDOWEVENT_RESIZED: event_list.push_back(EventData{ @@ -455,16 +462,16 @@ void SDLContext::handle_window_event(const SDL_WindowEvent & window_event, break; case SDL_WINDOWEVENT_MINIMIZED: - event_list.push_back(EventData{EventType::WINDOW_MINIMIZE}); + event_list.push_back(EventData {EventType::WINDOW_MINIMIZE}); break; case SDL_WINDOWEVENT_MAXIMIZED: - event_list.push_back(EventData{EventType::WINDOW_MAXIMIZE}); + event_list.push_back(EventData {EventType::WINDOW_MAXIMIZE}); break; case SDL_WINDOWEVENT_FOCUS_GAINED: - event_list.push_back(EventData{EventType::WINDOW_FOCUS_GAIN}); + event_list.push_back(EventData {EventType::WINDOW_FOCUS_GAIN}); break; case SDL_WINDOWEVENT_FOCUS_LOST: - event_list.push_back(EventData{EventType::WINDOW_FOCUS_LOST}); + event_list.push_back(EventData {EventType::WINDOW_FOCUS_LOST}); break; } } diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index e570073..bc118f9 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -116,8 +116,9 @@ public: * This method checks if any window events are triggered and adds them to the event_list. * */ - void handle_window_event(const SDL_WindowEvent & window_event, - std::vector & event_list); + void handle_window_event( + const SDL_WindowEvent & window_event, std::vector & event_list + ); /** * \brief Converts an SDL scan code to the custom Keycode type. * @@ -254,7 +255,7 @@ private: private: //! instance of the font_facade - FontFacade font_facade{}; + FontFacade font_facade {}; public: /** diff --git a/src/crepe/manager/ComponentManager.cpp b/src/crepe/manager/ComponentManager.cpp index 745ddae..245419d 100644 --- a/src/crepe/manager/ComponentManager.cpp +++ b/src/crepe/manager/ComponentManager.cpp @@ -46,14 +46,16 @@ void ComponentManager::delete_all_components() { this->next_id = 0; } -GameObject ComponentManager::new_object(const string & name, const string & tag, - const vec2 & position, double rotation, double scale) { +GameObject ComponentManager::new_object( + const string & name, const string & tag, const vec2 & position, double rotation, + double scale +) { // Find the first available id (taking persistent objects into account) while (this->persistent[this->next_id]) { this->next_id++; } - GameObject object{this->mediator, this->next_id, name, tag, position, rotation, scale}; + GameObject object {this->mediator, this->next_id, name, tag, position, rotation, scale}; this->next_id++; return object; @@ -64,23 +66,25 @@ void ComponentManager::set_persistent(game_object_id_t id, bool persistent) { } set ComponentManager::get_objects_by_name(const string & name) const { - return this->get_objects_by_predicate( - [name](const Metadata & data) { return data.name == name; }); + return this->get_objects_by_predicate([name](const Metadata & data) { + return data.name == name; + }); } set ComponentManager::get_objects_by_tag(const string & tag) const { - return this->get_objects_by_predicate( - [tag](const Metadata & data) { return data.tag == tag; }); + return this->get_objects_by_predicate([tag](const Metadata & data) { + return data.tag == tag; + }); } ComponentManager::Snapshot ComponentManager::save() { - Snapshot snapshot{}; + Snapshot snapshot {}; for (const auto & [type, by_id_index] : this->components) { for (game_object_id_t id = 0; id < by_id_index.size(); id++) { const auto & components = by_id_index[id]; for (size_t index = 0; index < components.size(); index++) { const Component & component = *components[index]; - snapshot.components.push_back(SnapshotComponent{ + snapshot.components.push_back(SnapshotComponent { .type = type, .id = id, .index = index, diff --git a/src/crepe/manager/ComponentManager.h b/src/crepe/manager/ComponentManager.h index c3a5b4a..2eb1f7e 100644 --- a/src/crepe/manager/ComponentManager.h +++ b/src/crepe/manager/ComponentManager.h @@ -38,9 +38,10 @@ public: * * \note This method automatically assigns a new entity ID */ - GameObject new_object(const std::string & name, const std::string & tag = "", - const vec2 & position = {0, 0}, double rotation = 0, - double scale = 1); + GameObject new_object( + const std::string & name, const std::string & tag = "", const vec2 & position = {0, 0}, + double rotation = 0, double scale = 1 + ); public: /** diff --git a/src/crepe/manager/ComponentManager.hpp b/src/crepe/manager/ComponentManager.hpp index 9e70865..6d32edb 100644 --- a/src/crepe/manager/ComponentManager.hpp +++ b/src/crepe/manager/ComponentManager.hpp @@ -11,8 +11,10 @@ template T & ComponentManager::add_component(game_object_id_t id, Args &&... args) { using namespace std; - static_assert(is_base_of::value, - "add_component must recieve a derivative class of Component"); + static_assert( + is_base_of::value, + "add_component must recieve a derivative class of Component" + ); // Determine the type of T (this is used as the key of the unordered_map<>) type_index type = typeid(T); @@ -40,8 +42,8 @@ T & ComponentManager::add_component(game_object_id_t id, Args &&... args) { // Check if the vector size is not greater than get_instances_max int max_instances = instance->get_instances_max(); if (max_instances != -1 && components[type][id].size() >= max_instances) { - throw std::runtime_error( - "Exceeded maximum number of instances for this component type"); + throw std::runtime_error("Exceeded maximum number of instances for this component type" + ); } // store its unique_ptr in the vector<> @@ -95,8 +97,10 @@ template RefVector ComponentManager::get_components_by_id(game_object_id_t id) const { using namespace std; - static_assert(is_base_of::value, - "get_components_by_id must recieve a derivative class of Component"); + static_assert( + is_base_of::value, + "get_components_by_id must recieve a derivative class of Component" + ); type_index type = typeid(T); if (!this->components.contains(type)) return {}; @@ -170,8 +174,8 @@ ComponentManager::get_objects_by_predicate(const std::function } template -RefVector -ComponentManager::get_components_by_ids(const std::set & ids) const { +RefVector ComponentManager::get_components_by_ids(const std::set & ids +) const { using namespace std; RefVector out = {}; diff --git a/src/crepe/manager/EventManager.h b/src/crepe/manager/EventManager.h index 0a57fb1..5766a0c 100644 --- a/src/crepe/manager/EventManager.h +++ b/src/crepe/manager/EventManager.h @@ -49,8 +49,8 @@ public: * \return A unique subscription ID associated with the registered callback. */ template - subscription_t subscribe(const EventHandler & callback, - event_channel_t channel = CHANNEL_ALL); + subscription_t + subscribe(const EventHandler & callback, event_channel_t channel = CHANNEL_ALL); /** * \brief Unsubscribe a previously registered callback. diff --git a/src/crepe/manager/EventManager.hpp b/src/crepe/manager/EventManager.hpp index b2090d0..1f44943 100644 --- a/src/crepe/manager/EventManager.hpp +++ b/src/crepe/manager/EventManager.hpp @@ -5,22 +5,24 @@ namespace crepe { template -subscription_t EventManager::subscribe(const EventHandler & callback, - event_channel_t channel) { +subscription_t +EventManager::subscribe(const EventHandler & callback, event_channel_t channel) { subscription_counter++; std::type_index event_type = typeid(EventType); std::unique_ptr> handler = std::make_unique>(callback); std::vector & handlers = this->subscribers[event_type]; - handlers.emplace_back(CallbackEntry{ - .callback = std::move(handler), .channel = channel, .id = subscription_counter}); + handlers.emplace_back(CallbackEntry { + .callback = std::move(handler), .channel = channel, .id = subscription_counter + }); return subscription_counter; } template void EventManager::queue_event(const EventType & event, event_channel_t channel) { - static_assert(std::is_base_of::value, - "EventType must derive from Event"); + static_assert( + std::is_base_of::value, "EventType must derive from Event" + ); this->events_queue.push_back(QueueEntry{ // unique_ptr w/ custom destructor implementation is used because the base Event interface // can't be polymorphic (= have default virtual destructor) diff --git a/src/crepe/manager/LoopTimerManager.cpp b/src/crepe/manager/LoopTimerManager.cpp index e78f92f..b4cd07f 100644 --- a/src/crepe/manager/LoopTimerManager.cpp +++ b/src/crepe/manager/LoopTimerManager.cpp @@ -17,9 +17,9 @@ LoopTimerManager::LoopTimerManager(Mediator & mediator) : Manager(mediator) { void LoopTimerManager::start() { this->last_frame_time = std::chrono::steady_clock::now(); - this->elapsed_time = elapsed_time_t{0}; - this->elapsed_fixed_time = elapsed_time_t{0}; - this->delta_time = duration_t{0}; + this->elapsed_time = elapsed_time_t {0}; + this->elapsed_fixed_time = elapsed_time_t {0}; + this->delta_time = duration_t {0}; } void LoopTimerManager::update() { diff --git a/src/crepe/manager/LoopTimerManager.h b/src/crepe/manager/LoopTimerManager.h index 2f1e6b6..279d6b2 100644 --- a/src/crepe/manager/LoopTimerManager.h +++ b/src/crepe/manager/LoopTimerManager.h @@ -157,17 +157,17 @@ private: //! Time scale for speeding up or slowing down the game (0 = pause, < 1 = slow down, 1 = normal speed, > 1 = speed up). float time_scale = 1; //! Maximum delta time in seconds to avoid large jumps. - duration_t maximum_delta_time{0.25}; + duration_t maximum_delta_time {0.25}; //! Delta time for the current frame in seconds. - duration_t delta_time{0.0}; + duration_t delta_time {0.0}; //! Target time per frame in seconds - duration_t frame_target_time{1.0 / target_fps}; + duration_t frame_target_time {1.0 / target_fps}; //! Fixed delta time for fixed updates in seconds. - duration_t fixed_delta_time{1.0 / 50.0}; + duration_t fixed_delta_time {1.0 / 50.0}; //! Total elapsed game time in microseconds. - elapsed_time_t elapsed_time{0}; + elapsed_time_t elapsed_time {0}; //! Total elapsed time for fixed updates in microseconds. - elapsed_time_t elapsed_fixed_time{0}; + elapsed_time_t elapsed_fixed_time {0}; typedef std::chrono::steady_clock::time_point time_point_t; //! Time of the last frame. diff --git a/src/crepe/manager/ResourceManager.hpp b/src/crepe/manager/ResourceManager.hpp index cf5c949..4ca6be0 100644 --- a/src/crepe/manager/ResourceManager.hpp +++ b/src/crepe/manager/ResourceManager.hpp @@ -9,17 +9,20 @@ namespace crepe { template T & ResourceManager::get(const Asset & asset) { using namespace std; - static_assert(is_base_of::value, - "cache must recieve a derivative class of Resource"); + static_assert( + is_base_of::value, "cache must recieve a derivative class of Resource" + ); CacheEntry & entry = this->get_entry(asset); if (entry.resource == nullptr) entry.resource = make_unique(asset, this->mediator); T * concrete_resource = dynamic_cast(entry.resource.get()); if (concrete_resource == nullptr) - throw runtime_error(format("ResourceManager: mismatch between requested type and " - "actual type of resource ({})", - asset.get_path())); + throw runtime_error(format( + "ResourceManager: mismatch between requested type and " + "actual type of resource ({})", + asset.get_path() + )); return *concrete_resource; } diff --git a/src/crepe/manager/SceneManager.cpp b/src/crepe/manager/SceneManager.cpp index d4ca90b..e6f92db 100644 --- a/src/crepe/manager/SceneManager.cpp +++ b/src/crepe/manager/SceneManager.cpp @@ -17,10 +17,12 @@ void SceneManager::load_next_scene() { // next scene not set if (this->next_scene.empty()) return; - auto it = find_if(this->scenes.begin(), this->scenes.end(), - [&next_scene = this->next_scene](unique_ptr & scene) { - return scene.get()->get_name() == next_scene; - }); + auto it = find_if( + this->scenes.begin(), this->scenes.end(), + [&next_scene = this->next_scene](unique_ptr & scene) { + return scene.get()->get_name() == next_scene; + } + ); // next scene not found if (it == this->scenes.end()) return; diff --git a/src/crepe/manager/SystemManager.hpp b/src/crepe/manager/SystemManager.hpp index 8d06eb1..addd274 100644 --- a/src/crepe/manager/SystemManager.hpp +++ b/src/crepe/manager/SystemManager.hpp @@ -11,8 +11,9 @@ namespace crepe { template T & SystemManager::get_system() { using namespace std; - static_assert(is_base_of::value, - "get_system must recieve a derivative class of System"); + static_assert( + is_base_of::value, "get_system must recieve a derivative class of System" + ); const type_info & type = typeid(T); if (!this->systems.contains(type)) @@ -28,8 +29,9 @@ T & SystemManager::get_system() { template void SystemManager::load_system() { using namespace std; - static_assert(is_base_of::value, - "load_system must recieve a derivative class of System"); + static_assert( + is_base_of::value, "load_system must recieve a derivative class of System" + ); const type_info & type = typeid(T); if (this->systems.contains(type)) diff --git a/src/crepe/system/AISystem.cpp b/src/crepe/system/AISystem.cpp index 0f35010..94445c7 100644 --- a/src/crepe/system/AISystem.cpp +++ b/src/crepe/system/AISystem.cpp @@ -28,7 +28,8 @@ void AISystem::fixed_update() { = mgr.get_components_by_id(ai.game_object_id); if (rigidbodies.empty()) { throw std::runtime_error( - "AI component must be attached to a GameObject with a Rigidbody component"); + "AI component must be attached to a GameObject with a Rigidbody component" + ); } Rigidbody & rigidbody = rigidbodies.front().get(); if (!rigidbody.active) { @@ -110,8 +111,8 @@ bool AISystem::accumulate_force(const AI & ai, vec2 & running_total, vec2 & forc return true; } -vec2 AISystem::seek(const AI & ai, const Rigidbody & rigidbody, - const Transform & transform) const { +vec2 AISystem::seek(const AI & ai, const Rigidbody & rigidbody, const Transform & transform) + const { // Calculate the desired velocity vec2 desired_velocity = ai.seek_target - transform.position; desired_velocity.normalize(); @@ -120,12 +121,12 @@ vec2 AISystem::seek(const AI & ai, const Rigidbody & rigidbody, return desired_velocity - rigidbody.data.linear_velocity; } -vec2 AISystem::flee(const AI & ai, const Rigidbody & rigidbody, - const Transform & transform) const { +vec2 AISystem::flee(const AI & ai, const Rigidbody & rigidbody, const Transform & transform) + const { // Calculate the desired velocity if the entity is within the panic distance vec2 desired_velocity = transform.position - ai.flee_target; if (desired_velocity.length_squared() > ai.square_flee_panic_distance) { - return vec2{0, 0}; + return vec2 {0, 0}; } desired_velocity.normalize(); desired_velocity *= rigidbody.data.max_linear_velocity; @@ -133,8 +134,8 @@ vec2 AISystem::flee(const AI & ai, const Rigidbody & rigidbody, return desired_velocity - rigidbody.data.linear_velocity; } -vec2 AISystem::arrive(const AI & ai, const Rigidbody & rigidbody, - const Transform & transform) const { +vec2 AISystem::arrive(const AI & ai, const Rigidbody & rigidbody, const Transform & transform) + const { // Calculate the desired velocity (taking into account the deceleration rate) vec2 to_target = ai.arrive_target - transform.position; float distance = to_target.length(); @@ -150,12 +151,12 @@ vec2 AISystem::arrive(const AI & ai, const Rigidbody & rigidbody, return desired_velocity - rigidbody.data.linear_velocity; } - return vec2{0, 0}; + return vec2 {0, 0}; } vec2 AISystem::path_follow(AI & ai, const Rigidbody & rigidbody, const Transform & transform) { if (ai.path.empty()) { - return vec2{0, 0}; + return vec2 {0, 0}; } // Get the target node diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index 654d4c6..571ac70 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -50,9 +50,11 @@ void CollisionSystem::fixed_update() { for (BoxCollider & boxcollider : boxcolliders) { if (boxcollider.game_object_id != id) continue; if (!boxcollider.active) continue; - all_colliders.push_back({.id = id, - .collider = collider_variant{boxcollider}, - .info = {transform, rigidbody, metadata}}); + all_colliders.push_back( + {.id = id, + .collider = collider_variant {boxcollider}, + .info = {transform, rigidbody, metadata}} + ); } // Check if the circlecollider is active and has the same id as the rigidbody. RefVector circlecolliders @@ -60,9 +62,11 @@ void CollisionSystem::fixed_update() { for (CircleCollider & circlecollider : circlecolliders) { if (circlecollider.game_object_id != id) continue; if (!circlecollider.active) continue; - all_colliders.push_back({.id = id, - .collider = collider_variant{circlecollider}, - .info = {transform, rigidbody, metadata}}); + all_colliders.push_back( + {.id = id, + .collider = collider_variant {circlecollider}, + .info = {transform, rigidbody, metadata}} + ); } } @@ -110,8 +114,9 @@ CollisionSystem::gather_collisions(std::vector & colliders) { return collisions_ret; } -bool CollisionSystem::should_collide(const CollisionInternal & self, - const CollisionInternal & other) const { +bool CollisionSystem::should_collide( + const CollisionInternal & self, const CollisionInternal & other +) const { const Rigidbody::Data & self_rigidbody = self.info.rigidbody.data; const Rigidbody::Data & other_rigidbody = other.info.rigidbody.data; @@ -133,9 +138,9 @@ bool CollisionSystem::should_collide(const CollisionInternal & self, return false; } -CollisionSystem::CollisionInternalType -CollisionSystem::get_collider_type(const collider_variant & collider1, - const collider_variant & collider2) const { +CollisionSystem::CollisionInternalType CollisionSystem::get_collider_type( + const collider_variant & collider1, const collider_variant & collider2 +) const { if (std::holds_alternative>(collider1)) { if (std::holds_alternative>(collider2)) { return CollisionInternalType::CIRCLE_CIRCLE; @@ -151,8 +156,9 @@ CollisionSystem::get_collider_type(const collider_variant & collider1, } } -bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionInternal & other, - const CollisionInternalType & type) { +bool CollisionSystem::detect_collision( + CollisionInternal & self, CollisionInternal & other, const CollisionInternalType & type +) { vec2 resolution; switch (type) { case CollisionInternalType::BOX_BOX: { @@ -177,10 +183,11 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern = {.collider = std::get>(self.collider), .transform = self.info.transform, .rigidbody = self.info.rigidbody}; - const CircleColliderInternal CIRCLE2 = { - .collider = std::get>(other.collider), - .transform = other.info.transform, - .rigidbody = other.info.rigidbody}; + const CircleColliderInternal CIRCLE2 + = {.collider + = std::get>(other.collider), + .transform = other.info.transform, + .rigidbody = other.info.rigidbody}; // Get resolution vector from box-circle collision detection resolution = this->get_box_circle_detection(BOX1, CIRCLE2); // If no collision (NaN values), return false @@ -195,10 +202,11 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern = {.collider = std::get>(self.collider), .transform = self.info.transform, .rigidbody = self.info.rigidbody}; - const CircleColliderInternal CIRCLE2 = { - .collider = std::get>(other.collider), - .transform = other.info.transform, - .rigidbody = other.info.rigidbody}; + const CircleColliderInternal CIRCLE2 + = {.collider + = std::get>(other.collider), + .transform = other.info.transform, + .rigidbody = other.info.rigidbody}; // Get resolution vector from circle-circle collision detection resolution = this->get_circle_circle_detection(CIRCLE1, CIRCLE2); // If no collision (NaN values), return false @@ -239,9 +247,10 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern return true; } -vec2 CollisionSystem::get_box_box_detection(const BoxColliderInternal & box1, - const BoxColliderInternal & box2) const { - vec2 resolution{NAN, NAN}; +vec2 CollisionSystem::get_box_box_detection( + const BoxColliderInternal & box1, const BoxColliderInternal & box2 +) const { + vec2 resolution {NAN, NAN}; // Get current positions of colliders vec2 pos1 = AbsolutePosition::get_position(box1.transform, box1.collider.offset); vec2 pos2 = AbsolutePosition::get_position(box2.transform, box2.collider.offset); @@ -282,8 +291,9 @@ vec2 CollisionSystem::get_box_box_detection(const BoxColliderInternal & box1, return resolution; } -vec2 CollisionSystem::get_box_circle_detection(const BoxColliderInternal & box, - const CircleColliderInternal & circle) const { +vec2 CollisionSystem::get_box_circle_detection( + const BoxColliderInternal & box, const CircleColliderInternal & circle +) const { /// Get current positions of colliders vec2 box_pos = AbsolutePosition::get_position(box.transform, box.collider.offset); vec2 circle_pos = AbsolutePosition::get_position(circle.transform, circle.collider.offset); @@ -324,14 +334,15 @@ vec2 CollisionSystem::get_box_circle_detection(const BoxColliderInternal & box, float penetration_depth = scaled_circle_radius - distance; // Compute the resolution vector - return vec2{collision_normal * penetration_depth}; + return vec2 {collision_normal * penetration_depth}; } // No collision - return vec2{NAN, NAN}; + return vec2 {NAN, NAN}; } vec2 CollisionSystem::get_circle_circle_detection( - const CircleColliderInternal & circle1, const CircleColliderInternal & circle2) const { + const CircleColliderInternal & circle1, const CircleColliderInternal & circle2 +) const { // Get current positions of colliders vec2 final_position1 = AbsolutePosition::get_position(circle1.transform, circle1.collider.offset); @@ -371,7 +382,7 @@ vec2 CollisionSystem::get_circle_circle_detection( return resolution; } // No collision - return vec2{NAN, NAN}; + return vec2 {NAN, NAN}; ; } @@ -402,17 +413,17 @@ CollisionSystem::resolution_correction(vec2 & resolution, const Rigidbody::Data return resolution_direction; } -CollisionSystem::CollisionInfo -CollisionSystem::get_collision_info(const CollisionInternal & in_self, - const CollisionInternal & in_other) const { +CollisionSystem::CollisionInfo CollisionSystem::get_collision_info( + const CollisionInternal & in_self, const CollisionInternal & in_other +) const { - crepe::CollisionSystem::ColliderInfo self{ + crepe::CollisionSystem::ColliderInfo self { .transform = in_self.info.transform, .rigidbody = in_self.info.rigidbody, .metadata = in_self.info.metadata, }; - crepe::CollisionSystem::ColliderInfo other{ + crepe::CollisionSystem::ColliderInfo other { .transform = in_other.info.transform, .rigidbody = in_other.info.rigidbody, .metadata = in_other.info.metadata, diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index 3fb9723..ff2d35f 100644 --- a/src/crepe/system/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h @@ -60,8 +60,8 @@ public: private: //! A variant type that can hold either a BoxCollider or a CircleCollider. - using collider_variant = std::variant, - std::reference_wrapper>; + using collider_variant = std::variant< + std::reference_wrapper, std::reference_wrapper>; //! Enum representing the types of collider pairs for collision detection. enum class CollisionInternalType { @@ -114,8 +114,9 @@ private: * \param collider2 Second collider variant (BoxCollider or CircleCollider). * \return The combined type of the two colliders. */ - CollisionInternalType get_collider_type(const collider_variant & collider1, - const collider_variant & collider2) const; + CollisionInternalType get_collider_type( + const collider_variant & collider1, const collider_variant & collider2 + ) const; private: /** @@ -128,8 +129,8 @@ private: * \param data1 Collision data for the first collider. * \param data2 Collision data for the second collider. */ - CollisionInfo get_collision_info(const CollisionInternal & data1, - const CollisionInternal & data2) const; + CollisionInfo + get_collision_info(const CollisionInternal & data1, const CollisionInternal & data2) const; /** * \brief Corrects the collision resolution vector and determines its direction. @@ -221,8 +222,10 @@ private: * \param other_metadata Rigidbody of second object * \return Returns true if there is at least one comparison found. */ - bool should_collide(const CollisionInternal & self, - const CollisionInternal & other) const; //done + bool should_collide( + const CollisionInternal & self, + const CollisionInternal & other + ) const; //done /** * \brief Checks for collision between two colliders. @@ -236,8 +239,10 @@ private: * \param type The type of collider pair. * \return True if a collision is detected, otherwise false. */ - bool detect_collision(CollisionInternal & first_info, CollisionInternal & second_info, - const CollisionInternalType & type); + bool detect_collision( + CollisionInternal & first_info, CollisionInternal & second_info, + const CollisionInternalType & type + ); /** * \brief Detects collisions between two BoxColliders. @@ -250,8 +255,9 @@ private: * \param box2 Information about the second BoxCollider. * \return If colliding, returns the resolution vector; otherwise, returns {NaN, NaN}. */ - vec2 get_box_box_detection(const BoxColliderInternal & box1, - const BoxColliderInternal & box2) const; + vec2 get_box_box_detection( + const BoxColliderInternal & box1, const BoxColliderInternal & box2 + ) const; /** * \brief Check collision for box on circle collider @@ -264,8 +270,9 @@ private: * \param circle2 Information about the circleCollider. * \return If colliding, returns the resolution vector; otherwise, returns {NaN, NaN}. */ - vec2 get_box_circle_detection(const BoxColliderInternal & box1, - const CircleColliderInternal & circle2) const; + vec2 get_box_circle_detection( + const BoxColliderInternal & box1, const CircleColliderInternal & circle2 + ) const; /** * \brief Check collision for circle on circle collider @@ -278,8 +285,9 @@ private: * \param circle2 Information about the second circleCollider. * \return If colliding, returns the resolution vector; otherwise, returns {NaN, NaN}. */ - vec2 get_circle_circle_detection(const CircleColliderInternal & circle1, - const CircleColliderInternal & circle2) const; + vec2 get_circle_circle_detection( + const CircleColliderInternal & circle1, const CircleColliderInternal & circle2 + ) const; }; /** diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index 8e9f763..b4a0633 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -44,8 +44,9 @@ void InputSystem::fixed_update() { } } -void InputSystem::handle_mouse_event(const EventData & event, const vec2 & camera_origin, - const Camera & current_cam) { +void InputSystem::handle_mouse_event( + const EventData & event, const vec2 & camera_origin, const Camera & current_cam +) { EventManager & event_mgr = this->mediator.event_manager; vec2 adjusted_mouse; adjusted_mouse.x = event.data.mouse_data.mouse_position.x + camera_origin.x; @@ -82,8 +83,9 @@ void InputSystem::handle_mouse_event(const EventData & event, const vec2 & camer .mouse_pos = adjusted_mouse, .button = event.data.mouse_data.mouse_button, }); - this->handle_click(event.data.mouse_data.mouse_button, adjusted_mouse, - current_cam); + this->handle_click( + event.data.mouse_data.mouse_button, adjusted_mouse, current_cam + ); } break; } @@ -115,7 +117,8 @@ void InputSystem::handle_non_mouse_event(const EventData & event) { case EventType::KEY_DOWN: event_mgr.queue_event( - {.repeat = event.data.key_data.key_repeat, .key = event.data.key_data.key}); + {.repeat = event.data.key_data.key_repeat, .key = event.data.key_data.key} + ); break; case EventType::KEY_UP: event_mgr.queue_event({.key = event.data.key_data.key}); @@ -128,11 +131,13 @@ void InputSystem::handle_non_mouse_event(const EventData & event) { break; case EventType::WINDOW_RESIZE: event_mgr.queue_event( - WindowResizeEvent{.dimensions = event.data.window_data.resize_dimension}); + WindowResizeEvent {.dimensions = event.data.window_data.resize_dimension} + ); break; case EventType::WINDOW_MOVE: event_mgr.queue_event( - {.delta_move = event.data.window_data.move_delta}); + {.delta_move = event.data.window_data.move_delta} + ); break; case EventType::WINDOW_MINIMIZE: event_mgr.queue_event({}); @@ -151,8 +156,9 @@ void InputSystem::handle_non_mouse_event(const EventData & event) { } } -void InputSystem::handle_move(const EventData & event_data, const vec2 & mouse_pos, - const Camera & current_cam) { +void InputSystem::handle_move( + const EventData & event_data, const vec2 & mouse_pos, const Camera & current_cam +) { ComponentManager & mgr = this->mediator.component_manager; EventManager & event_mgr = this->mediator.event_manager; const RefVector