From 03aea832aa0bc2edba2cc5ab4d9f8eba42d355be Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 20 Dec 2024 11:36:36 +0100 Subject: add game folder --- game/main.cpp | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 game/main.cpp (limited to 'game/main.cpp') diff --git a/game/main.cpp b/game/main.cpp new file mode 100644 index 0000000..af14ed5 --- /dev/null +++ b/game/main.cpp @@ -0,0 +1,3 @@ +int main() { + +} -- cgit v1.2.3 From 74f70c61a37c94727e1411696f050cf588cf3446 Mon Sep 17 00:00:00 2001 From: max-001 Date: Fri, 20 Dec 2024 12:05:52 +0100 Subject: Fix merge issues --- game/main.cpp | 4 +- src/example/FontExample.cpp | 55 ----------------------- src/example/ForestParallaxScript.cpp | 2 +- src/example/ForestParallaxScript.h | 2 +- src/example/PlayerScript.cpp | 2 +- src/example/PlayerScript.h | 2 +- src/example/StartGameScript.cpp | 2 +- src/example/StartGameScript.h | 2 +- src/example/StartSubScene.cpp | 24 +++++------ src/example/game.cpp | 8 ++-- src/example/loadfont.cpp | 49 --------------------- src/example/replay.cpp | 84 ------------------------------------ 12 files changed, 23 insertions(+), 213 deletions(-) delete mode 100644 src/example/FontExample.cpp delete mode 100644 src/example/loadfont.cpp delete mode 100644 src/example/replay.cpp (limited to 'game/main.cpp') diff --git a/game/main.cpp b/game/main.cpp index af14ed5..237c8ce 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -1,3 +1 @@ -int main() { - -} +int main() {} diff --git a/src/example/FontExample.cpp b/src/example/FontExample.cpp deleted file mode 100644 index 6a334b1..0000000 --- a/src/example/FontExample.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace crepe; -using namespace std; -using namespace std::chrono; -class TestScript : public Script { -public: - steady_clock::time_point start_time; - virtual void init() override { start_time = steady_clock::now(); } - virtual void update() override { - auto now = steady_clock::now(); - auto elapsed = duration_cast(now - start_time).count(); - - if (elapsed >= 5) { - Mediator & med = mediator; - EventManager & event_mgr = med.event_manager; - event_mgr.trigger_event(); - } - } -}; -class TestScene : public Scene { -public: - void load_scene() override { - GameObject text_object = this->new_object("test", "test", vec2{0, 0}, 0, 1); - text_object.add_component(vec2(100, 100), vec2(0, 0), "OpenSymbol", - Text::Data{}); - text_object.add_component().set_script(); - text_object.add_component(ivec2{300, 300}, vec2{100, 100}, Camera::Data{}); - } - std::string get_name() const override { return "hey"; } -}; -int main() { - // Config& config = Config::get_instance(); - // config.log.level = Log::Level::TRACE; - LoopManager engine; - engine.add_scene(); - engine.start(); - - return 0; -} diff --git a/src/example/ForestParallaxScript.cpp b/src/example/ForestParallaxScript.cpp index 782cdf0..27e30eb 100644 --- a/src/example/ForestParallaxScript.cpp +++ b/src/example/ForestParallaxScript.cpp @@ -9,7 +9,7 @@ ForestParallaxScript::ForestParallaxScript(float begin_x, float end_x, end_x(end_x), name(unique_bg_name) {} -void ForestParallaxScript::update() { +void ForestParallaxScript::fixed_update(crepe::duration_t dt) { RefVector vec_2 = this->get_components_by_name("forest_bg_2_" + name); RefVector vec_3 diff --git a/src/example/ForestParallaxScript.h b/src/example/ForestParallaxScript.h index 39b7ecb..a65a684 100644 --- a/src/example/ForestParallaxScript.h +++ b/src/example/ForestParallaxScript.h @@ -6,7 +6,7 @@ class ForestParallaxScript : public crepe::Script { public: ForestParallaxScript(float begin_x, float end_x, std::string unique_bg_name); - void update(); + void fixed_update(crepe::duration_t dt); private: const float begin_x; diff --git a/src/example/PlayerScript.cpp b/src/example/PlayerScript.cpp index a147e06..1c388f5 100644 --- a/src/example/PlayerScript.cpp +++ b/src/example/PlayerScript.cpp @@ -5,7 +5,7 @@ using namespace crepe; using namespace std; -void PlayerScript::update() { +void PlayerScript::fixed_update(crepe::duration_t dt) { Rigidbody & rb = this->get_components_by_name("player").front(); if (this->get_key_state(Keycode::SPACE)) rb.add_force_linear(vec2(0, -10)); } diff --git a/src/example/PlayerScript.h b/src/example/PlayerScript.h index 254dd41..84c4f7f 100644 --- a/src/example/PlayerScript.h +++ b/src/example/PlayerScript.h @@ -4,5 +4,5 @@ class PlayerScript : public crepe::Script { public: - void update(); + void fixed_update(crepe::duration_t dt); }; diff --git a/src/example/StartGameScript.cpp b/src/example/StartGameScript.cpp index 00f419d..50ba86c 100644 --- a/src/example/StartGameScript.cpp +++ b/src/example/StartGameScript.cpp @@ -7,7 +7,7 @@ using namespace crepe; using namespace std; -void StartGameScript::update() { +void StartGameScript::fixed_update(crepe::duration_t dt) { Transform & player_transform = this->get_components_by_name("player").front(); // Create hole in wall and activate panic lamp diff --git a/src/example/StartGameScript.h b/src/example/StartGameScript.h index f3534d0..ad62e1a 100644 --- a/src/example/StartGameScript.h +++ b/src/example/StartGameScript.h @@ -4,7 +4,7 @@ class StartGameScript : public crepe::Script { public: - void update(); + void fixed_update(crepe::duration_t dt); private: bool created_hole = false; diff --git a/src/example/StartSubScene.cpp b/src/example/StartSubScene.cpp index 9006dc7..e943396 100644 --- a/src/example/StartSubScene.cpp +++ b/src/example/StartSubScene.cpp @@ -161,7 +161,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.5, 0.6), .angular_velocity = 500, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_1_rb.active = false; frag_1.add_component(25); @@ -181,7 +181,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.35, 0.4), .angular_velocity = 400, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_2_rb.active = false; frag_2.add_component(55); @@ -201,7 +201,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.3, 0.3), .angular_velocity = 300, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_3_rb.active = false; frag_3.add_component(35); @@ -221,7 +221,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.2, 0.2), .angular_velocity = 200, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_4_rb.active = false; frag_4.add_component(60); @@ -241,7 +241,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.25, 0.15), .angular_velocity = 100, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_5_rb.active = false; frag_5.add_component(5); @@ -261,7 +261,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.35, 0.25), .angular_velocity = 100, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_6_rb.active = false; frag_6.add_component(30); @@ -281,7 +281,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.45, 0.6), .angular_velocity = 800, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_7_rb.active = false; frag_7.add_component(45); @@ -301,7 +301,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.5, 0.6), .angular_velocity = 500, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_8_rb.active = false; frag_8.add_component(25); @@ -321,7 +321,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.5, 0.25), .angular_velocity = 500, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_9_rb.active = false; frag_9.add_component(15); @@ -341,7 +341,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.35, 0.4), .angular_velocity = 300, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_10_rb.active = false; frag_10.add_component(60); @@ -361,7 +361,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.3, 0.3), .angular_velocity = 200, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_11_rb.active = false; frag_11.add_component(5); @@ -381,7 +381,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { .linear_velocity_coefficient = vec2(0.25, 0.15), .angular_velocity = 100, .angular_velocity_coefficient = 0.55, - .elastisity_coefficient = 0.5, + .elasticity_coefficient = 0.5, }); frag_12_rb.active = false; frag_12.add_component(50); diff --git a/src/example/game.cpp b/src/example/game.cpp index 378a64a..b9f98fc 100644 --- a/src/example/game.cpp +++ b/src/example/game.cpp @@ -1,13 +1,13 @@ #include "GameScene.h" -#include +#include using namespace crepe; using namespace std; int main(int argc, char * argv[]) { - LoopManager gameloop; + Engine gameloop; gameloop.add_scene(); - gameloop.start(); - return 0; + + return gameloop.main(); } diff --git a/src/example/loadfont.cpp b/src/example/loadfont.cpp deleted file mode 100644 index e459332..0000000 --- a/src/example/loadfont.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace crepe; -int main() { - - // SDLFontContext font_facade; - Mediator mediator; - FontFacade font_facade{}; - SDLContext sdl_context{mediator}; - // ComponentManager component_manager{mediator}; - ResourceManager resource_manager{mediator}; - try { - // Correct way to create a unique pointer for Text - std::unique_ptr label = std::make_unique( - 1, vec2(100, 100), vec2(0, 0), "OpenSymbol", Text::Data{}, "test text"); - // std::cout << "Path: " << label->font.get_path() << std::endl; - Asset asset1 = font_facade.get_font_asset("OpenSymbol"); - std::cout << asset1.get_path() << std::endl; - std::unique_ptr label2 = std::make_unique( - 1, vec2(100, 100), vec2(0, 0), "fsaafdafsdafsdafsdasfdds", Text::Data{}); - Asset asset = Asset("test test"); - label->font.emplace(asset); - std::cout << label->font.value().get_path() << std::endl; - // label2->font = std::make_optional(asset); - // std::cout << "Path: " << label2->font.get_path() << std::endl; - ResourceManager & resource_mgr = mediator.resource_manager; - const Font & res = resource_manager.get(label->font.value()); - // TTF_Font * test_font = res.get_font(); - // if (test_font == NULL) { - // std::cout << "error with font" << std::endl; - // } else { - // std::cout << "correct font retrieved" << std::endl; - // } - } catch (const std::exception & e) { - std::cout << "Standard exception thrown: " << e.what() << std::endl; - } - - return 0; -} diff --git a/src/example/replay.cpp b/src/example/replay.cpp deleted file mode 100644 index 82fd478..0000000 --- a/src/example/replay.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include -#include - -using namespace crepe; -using namespace std; - -class AnimationScript : public Script { - Transform * transform; - float t = 0; - - void init() { transform = &get_component(); } - - void update() { - t += 0.05; - transform->position = {sin(t), cos(t)}; - } -}; - -class Timeline : public Script { - unsigned i = 0; - recording_t recording; - - void update() { - switch (i++) { - default: - break; - case 10: - logf("record start"); - replay.record_start(); - break; - case 60: - logf("record end, playing recording"); - this->recording = replay.record_end(); - replay.play(this->recording); - break; - case 61: - logf("done, releasing recording"); - replay.release(this->recording); - break; - case 72: - logf("exit"); - queue_event(); - break; - }; - } -}; - -class TestScene : public Scene { -public: - using Scene::Scene; - - void load_scene() { - Mediator & mediator = this->mediator; - ComponentManager & mgr = mediator.component_manager; - - GameObject cam = mgr.new_object("cam"); - cam.add_component(ivec2{640, 480}, vec2{3, 3}, - Camera::Data{ - .bg_color = Color::WHITE, - }); - - GameObject square = mgr.new_object("square"); - square.add_component(Asset{"asset/texture/square.png"}, Sprite::Data{ - .size = {0.5, 0.5}, - }); - square.add_component().set_script(); - - GameObject scapegoat = mgr.new_object(""); - scapegoat.add_component().set_script(); - } - - string get_name() const { return "scene1"; } -}; - -int main(int argc, char * argv[]) { - Config & cfg = Config::get_instance(); - cfg.log.level = Log::Level::DEBUG; - - Engine engine; - - engine.add_scene(); - return engine.main(); -} -- cgit v1.2.3 From 6570bf598a3b3768fe34827529df5ea0b4b26f0e Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 20 Dec 2024 12:52:15 +0100 Subject: move game files --- game/AquariumSubScene.cpp | 135 ++++++++++ game/AquariumSubScene.h | 13 + game/BackgroundSubScene.cpp | 37 +++ game/BackgroundSubScene.h | 10 + game/CMakeLists.txt | 11 + game/ForestParallaxScript.cpp | 28 ++ game/ForestParallaxScript.h | 15 ++ game/ForestSubScene.cpp | 131 ++++++++++ game/ForestSubScene.h | 15 ++ game/GameScene.cpp | 55 ++++ game/GameScene.h | 11 + game/HallwaySubScene.cpp | 128 +++++++++ game/HallwaySubScene.h | 21 ++ game/MoveCameraManualyScript.cpp | 22 ++ game/MoveCameraManualyScript.h | 11 + game/PlayerScript.cpp | 11 + game/PlayerScript.h | 8 + game/PlayerSubScene.cpp | 62 +++++ game/PlayerSubScene.h | 10 + game/StartGameScript.cpp | 61 +++++ game/StartGameScript.h | 12 + game/StartSubScene.cpp | 442 ++++++++++++++++++++++++++++++++ game/StartSubScene.h | 20 ++ game/main.cpp | 325 ++++++++++++++++++++++- src/example/AITest.cpp | 90 +++++++ src/example/AquariumSubScene.cpp | 135 ---------- src/example/AquariumSubScene.h | 13 - src/example/BackgroundSubScene.cpp | 37 --- src/example/BackgroundSubScene.h | 10 - src/example/CMakeLists.txt | 49 ++-- src/example/ForestParallaxScript.cpp | 28 -- src/example/ForestParallaxScript.h | 15 -- src/example/ForestSubScene.cpp | 131 ---------- src/example/ForestSubScene.h | 15 -- src/example/GameScene.cpp | 55 ---- src/example/GameScene.h | 11 - src/example/HallwaySubScene.cpp | 128 --------- src/example/HallwaySubScene.h | 21 -- src/example/MoveCameraManualyScript.cpp | 22 -- src/example/MoveCameraManualyScript.h | 11 - src/example/PlayerScript.cpp | 11 - src/example/PlayerScript.h | 8 - src/example/PlayerSubScene.cpp | 62 ----- src/example/PlayerSubScene.h | 10 - src/example/StartGameScript.cpp | 61 ----- src/example/StartGameScript.h | 12 - src/example/StartSubScene.cpp | 442 -------------------------------- src/example/StartSubScene.h | 20 -- src/example/button.cpp | 41 +++ src/example/game.cpp | 324 ----------------------- src/example/loadfont.cpp | 49 ++++ src/example/rendering_particle.cpp | 76 ++++++ src/example/replay.cpp | 84 ++++++ 53 files changed, 1953 insertions(+), 1612 deletions(-) create mode 100644 game/AquariumSubScene.cpp create mode 100644 game/AquariumSubScene.h create mode 100644 game/BackgroundSubScene.cpp create mode 100644 game/BackgroundSubScene.h create mode 100644 game/ForestParallaxScript.cpp create mode 100644 game/ForestParallaxScript.h create mode 100644 game/ForestSubScene.cpp create mode 100644 game/ForestSubScene.h create mode 100644 game/GameScene.cpp create mode 100644 game/GameScene.h create mode 100644 game/HallwaySubScene.cpp create mode 100644 game/HallwaySubScene.h create mode 100644 game/MoveCameraManualyScript.cpp create mode 100644 game/MoveCameraManualyScript.h create mode 100644 game/PlayerScript.cpp create mode 100644 game/PlayerScript.h create mode 100644 game/PlayerSubScene.cpp create mode 100644 game/PlayerSubScene.h create mode 100644 game/StartGameScript.cpp create mode 100644 game/StartGameScript.h create mode 100644 game/StartSubScene.cpp create mode 100644 game/StartSubScene.h create mode 100644 src/example/AITest.cpp delete mode 100644 src/example/AquariumSubScene.cpp delete mode 100644 src/example/AquariumSubScene.h delete mode 100644 src/example/BackgroundSubScene.cpp delete mode 100644 src/example/BackgroundSubScene.h delete mode 100644 src/example/ForestParallaxScript.cpp delete mode 100644 src/example/ForestParallaxScript.h delete mode 100644 src/example/ForestSubScene.cpp delete mode 100644 src/example/ForestSubScene.h delete mode 100644 src/example/GameScene.cpp delete mode 100644 src/example/GameScene.h delete mode 100644 src/example/HallwaySubScene.cpp delete mode 100644 src/example/HallwaySubScene.h delete mode 100644 src/example/MoveCameraManualyScript.cpp delete mode 100644 src/example/MoveCameraManualyScript.h delete mode 100644 src/example/PlayerScript.cpp delete mode 100644 src/example/PlayerScript.h delete mode 100644 src/example/PlayerSubScene.cpp delete mode 100644 src/example/PlayerSubScene.h delete mode 100644 src/example/StartGameScript.cpp delete mode 100644 src/example/StartGameScript.h delete mode 100644 src/example/StartSubScene.cpp delete mode 100644 src/example/StartSubScene.h create mode 100644 src/example/button.cpp delete mode 100644 src/example/game.cpp create mode 100644 src/example/loadfont.cpp create mode 100644 src/example/rendering_particle.cpp create mode 100644 src/example/replay.cpp (limited to 'game/main.cpp') diff --git a/game/AquariumSubScene.cpp b/game/AquariumSubScene.cpp new file mode 100644 index 0000000..4f13acf --- /dev/null +++ b/game/AquariumSubScene.cpp @@ -0,0 +1,135 @@ +#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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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 new file mode 100644 index 0000000..2a188bc --- /dev/null +++ b/game/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/BackgroundSubScene.cpp b/game/BackgroundSubScene.cpp new file mode 100644 index 0000000..6fdc598 --- /dev/null +++ b/game/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/BackgroundSubScene.h b/game/BackgroundSubScene.h new file mode 100644 index 0000000..06bdac4 --- /dev/null +++ b/game/BackgroundSubScene.h @@ -0,0 +1,10 @@ +#pragma once + +namespace crepe { +class Scene; +} + +class BackgroundSubScene { +public: + BackgroundSubScene(crepe::Scene & scn); +}; diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 26d937a..dc55523 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -9,6 +9,17 @@ project(game C CXX) add_subdirectory(../src crepe) add_executable(main + AquariumSubScene.cpp + BackgroundSubScene.cpp + ForestParallaxScript.cpp + ForestSubScene.cpp + GameScene.cpp + HallwaySubScene.cpp + MoveCameraManualyScript.cpp + PlayerScript.cpp + PlayerSubScene.cpp + StartGameScript.cpp + StartSubScene.cpp main.cpp ) diff --git a/game/ForestParallaxScript.cpp b/game/ForestParallaxScript.cpp new file mode 100644 index 0000000..27e30eb --- /dev/null +++ b/game/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/ForestParallaxScript.h b/game/ForestParallaxScript.h new file mode 100644 index 0000000..a65a684 --- /dev/null +++ b/game/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/ForestSubScene.cpp b/game/ForestSubScene.cpp new file mode 100644 index 0000000..9be875d --- /dev/null +++ b/game/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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 new file mode 100644 index 0000000..0a04001 --- /dev/null +++ b/game/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/GameScene.cpp b/game/GameScene.cpp new file mode 100644 index 0000000..c280474 --- /dev/null +++ b/game/GameScene.cpp @@ -0,0 +1,55 @@ +#include "GameScene.h" +#include "BackgroundSubScene.h" +#include "MoveCameraManualyScript.h" +#include "PlayerSubScene.h" +#include "StartGameScript.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +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::Data{ + .bg_color = Color::RED, + }); + camera.add_component().set_script(); + camera.add_component(Rigidbody::Data{}); + + PlayerSubScene player(*this); + + GameObject floor = new_object("floor", "game_world", vec2(0, 325)); + floor.add_component(Rigidbody::Data{ + .body_type = Rigidbody::BodyType::STATIC, + }); + floor.add_component(vec2(INFINITY, 200)); + GameObject ceiling = new_object("ceiling", "game_world", vec2(0, -325)); + ceiling.add_component(Rigidbody::Data{ + .body_type = Rigidbody::BodyType::STATIC, + }); + ceiling.add_component(vec2(INFINITY, 200)); + + GameObject start_game_script = new_object("start_game_script", "script", vec2(0, 0)); + start_game_script.add_component().set_script(); +} + +string GameScene::get_name() const { return "scene1"; } diff --git a/game/GameScene.h b/game/GameScene.h new file mode 100644 index 0000000..16e2919 --- /dev/null +++ b/game/GameScene.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +class GameScene : public crepe::Scene { +public: + void load_scene(); + + std::string get_name() const; +}; diff --git a/game/HallwaySubScene.cpp b/game/HallwaySubScene.cpp new file mode 100644 index 0000000..4fe2267 --- /dev/null +++ b/game/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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 new file mode 100644 index 0000000..acc9329 --- /dev/null +++ b/game/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/MoveCameraManualyScript.cpp b/game/MoveCameraManualyScript.cpp new file mode 100644 index 0000000..0181333 --- /dev/null +++ b/game/MoveCameraManualyScript.cpp @@ -0,0 +1,22 @@ +#include "MoveCameraManualyScript.h" + +using namespace crepe; +using namespace std; + +void MoveCameraManualyScript::init() { + subscribe( + [this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); }); +} + +bool MoveCameraManualyScript::keypressed(const KeyPressEvent & event) { + if (event.key == Keycode::RIGHT) { + Transform & cam = this->get_components_by_name("camera").front(); + cam.position.x += 100; + return true; + } else if (event.key == Keycode::LEFT) { + Transform & cam = this->get_components_by_name("camera").front(); + cam.position.x -= 100; + return true; + } + return false; +} diff --git a/game/MoveCameraManualyScript.h b/game/MoveCameraManualyScript.h new file mode 100644 index 0000000..5a09055 --- /dev/null +++ b/game/MoveCameraManualyScript.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +class MoveCameraManualyScript : public crepe::Script { +public: + void init(); + +private: + bool keypressed(const crepe::KeyPressEvent & event); +}; diff --git a/game/PlayerScript.cpp b/game/PlayerScript.cpp new file mode 100644 index 0000000..1c388f5 --- /dev/null +++ b/game/PlayerScript.cpp @@ -0,0 +1,11 @@ +#include "PlayerScript.h" + +#include + +using namespace crepe; +using namespace std; + +void PlayerScript::fixed_update(crepe::duration_t dt) { + Rigidbody & rb = this->get_components_by_name("player").front(); + if (this->get_key_state(Keycode::SPACE)) rb.add_force_linear(vec2(0, -10)); +} diff --git a/game/PlayerScript.h b/game/PlayerScript.h new file mode 100644 index 0000000..84c4f7f --- /dev/null +++ b/game/PlayerScript.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +class PlayerScript : public crepe::Script { +public: + void fixed_update(crepe::duration_t dt); +}; diff --git a/game/PlayerSubScene.cpp b/game/PlayerSubScene.cpp new file mode 100644 index 0000000..4f4ba9f --- /dev/null +++ b/game/PlayerSubScene.cpp @@ -0,0 +1,62 @@ +#include "PlayerSubScene.h" +#include "PlayerScript.h" + +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +PlayerSubScene::PlayerSubScene(Scene & scn) { + GameObject player = scn.new_object("player", "player", vec2(-100, 200)); + Asset player_body_asset{"asset/jetpack_joyride/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), + }); + player.add_component(player_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data{ + .fps = 5, + .looping = true, + }); + Asset player_head_asset{"asset/jetpack_joyride/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), + }); + player.add_component(player_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data{ + .fps = 5, + .looping = true, + }); + Asset player_jetpack_asset{"asset/jetpack_joyride/barry/jetpackDefault.png"}; + Sprite & player_jetpack_sprite = player.add_component( + player_jetpack_asset, Sprite::Data{ + .sorting_in_layer = 10, + .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{ + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(100, 0), + .collision_layer = 10, + }); + player.add_component(vec2(50, 50)); + player.add_component().set_script().active = false; +} diff --git a/game/PlayerSubScene.h b/game/PlayerSubScene.h new file mode 100644 index 0000000..bf94c32 --- /dev/null +++ b/game/PlayerSubScene.h @@ -0,0 +1,10 @@ +#pragma once + +namespace crepe { +class Scene; +} + +class PlayerSubScene { +public: + PlayerSubScene(crepe::Scene & scn); +}; diff --git a/game/StartGameScript.cpp b/game/StartGameScript.cpp new file mode 100644 index 0000000..50ba86c --- /dev/null +++ b/game/StartGameScript.cpp @@ -0,0 +1,61 @@ +#include "StartGameScript.h" + +#include +#include +#include + +using namespace crepe; +using namespace std; + +void StartGameScript::fixed_update(crepe::duration_t dt) { + Transform & player_transform = this->get_components_by_name("player").front(); + + // Create hole in wall and activate panic lamp + if (player_transform.position.x > 75 && !this->created_hole) { + Sprite & lamp_sprite = this->get_components_by_name("start_end").back(); + lamp_sprite.active = true; + Sprite & hole_sprite = this->get_components_by_name("start_hole").front(); + hole_sprite.active = true; + + RefVector frags_rg + = this->get_components_by_tag("wall_fragment"); + RefVector frags_sprite = this->get_components_by_tag("wall_fragment"); + for (Rigidbody & frag_rg : frags_rg) { + frag_rg.active = true; + } + for (Sprite & frag_sprite : frags_sprite) { + frag_sprite.active = true; + } + + RefVector smoke_emitters + = this->get_components_by_name("smoke_particles"); + for (ParticleEmitter & emitter : smoke_emitters) { + emitter.active = true; + } + + this->created_hole = true; + } + + // Take jetpack from jetpack stand + if (player_transform.position.x > 275 && !this->took_jetpack) { + Animator & jetpack_stand_anim + = this->get_components_by_name("start_begin").back(); + jetpack_stand_anim.next_anim(); + Sprite & jetpack_sprite = this->get_components_by_name("player").back(); + jetpack_sprite.active = true; + + this->took_jetpack = true; + } + + // Start camera movement, enable player jumping and disable this script + if (player_transform.position.x > 500) { + Rigidbody & rb = this->get_components_by_name("camera").front(); + rb.data.linear_velocity = vec2(100, 0); + BehaviorScript & player_script + = this->get_components_by_name("player").front(); + player_script.active = true; + BehaviorScript & this_script + = this->get_components_by_name("start_game_script").front(); + this_script.active = false; + } +} diff --git a/game/StartGameScript.h b/game/StartGameScript.h new file mode 100644 index 0000000..ad62e1a --- /dev/null +++ b/game/StartGameScript.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +class StartGameScript : public crepe::Script { +public: + void fixed_update(crepe::duration_t dt); + +private: + bool created_hole = false; + bool took_jetpack = false; +}; diff --git a/game/StartSubScene.cpp b/game/StartSubScene.cpp new file mode 100644 index 0000000..07738a4 --- /dev/null +++ b/game/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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 new file mode 100644 index 0000000..c83e3d5 --- /dev/null +++ b/game/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); +}; diff --git a/game/main.cpp b/game/main.cpp index 237c8ce..a028791 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -1 +1,324 @@ -int main() {} +#include "GameScene.h" + +#include +#include + +using namespace crepe; +using namespace std; + +class ScriptBox : public Script { +public: + bool oncollision(const CollisionEvent & test) { + Log::logf("Box {} on_collision() with {}", test.info.self.metadata.game_object_id, + test.info.other.metadata.game_object_id); + return true; + } + + void init() { + subscribe( + [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); }); + } +}; + +class ScriptCircle : public Script { +public: + bool oncollision(const CollisionEvent & test) { + Log::logf("Circle {} on_collision() with {}", test.info.self.metadata.game_object_id, + test.info.other.metadata.game_object_id); + return true; + } + + void init() { + subscribe( + [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); }); + } +}; + +class ScriptMoveToLeft : public Script { +public: + void update() { + Transform & transform = this->get_component(); + transform.position.x -= 0.02; + } +}; + +class ScriptMoveToRight : public Script { +public: + void update() { + Transform & transform = this->get_component(); + transform.position.x += 0.02; + } +}; + +class ConcreteScene1 : public Scene { +public: + void load_scene() { + GameObject camera = this->new_object("camera"); + camera.add_component(ivec2(1080, 720), vec2(10, 10), + Camera::Data{.bg_color = Color::WHITE, .zoom = 1}); + + GameObject reference = this->new_object("reference", "tag", vec2(0, 0), 0, 1); + Asset reference_asset = Asset("asset/texture/square.png"); + reference.add_component(reference_asset, Sprite::Data{ + .color = Color::RED, + .sorting_in_layer = 10, + .order_in_layer = 0, + .size = vec2(0.1, 0.1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(0, 0), + }); + + /*GameObject box_1 = this->new_object("box_1", "tag", vec2(0, 0), 0, 1); + Asset box_1_asset = Asset("asset/texture/square.png"); + box_1.add_component(box_1_asset, Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(0, 0.5), + }); + Asset box_1_asset2 = Asset("asset/texture/test_ap43.png"); + box_1.add_component(box_1_asset2, Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(0, -0.5), + });*/ + + /*GameObject particles = this->new_object("particles", "tag", vec2(-1, 0), 180, 1); + Asset particles_asset = Asset("asset/texture/test_ap43.png"); + Sprite & particles_sprite = particles.add_component(particles_asset, Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(0, 0), + }); + ParticleEmitter & particles_emitter = particles.add_component(particles_sprite, ParticleEmitter::Data{ + .offset = vec2(0, 0), + .emission_rate = 1, + .min_speed = 1, + .max_speed = 1, + .min_angle = 0, + .max_angle = 0, + .end_lifespan = 4, + });*/ + + const bool SCRIPT = false; + + const Rigidbody::BodyType BODYTYPE_LEFT = Rigidbody::BodyType::DYNAMIC; + const Rigidbody::BodyType BODYTYPE_RIGHT = Rigidbody::BodyType::DYNAMIC; + const bool BOUNCE_LEFT = false; + const bool BOUNCE_RIGHT = false; + const bool KINEMATIC_COLLISION = true; + const bool ONTOP = false; + + const float SCALE = 0.5; + const float OFFSET_X_LEFT = 0; + const float OFFSET_X_RIGHT = 0; + const float OFFSET_Y_LEFT = 0; + const float OFFSET_Y_RIGHT = 0; + + GameObject box_1 = this->new_object("box_1", "tag", + ONTOP ? vec2(-0.25, -4) : vec2(-2, -4), 0, SCALE); + Asset box_1_asset = Asset("asset/texture/square.png"); + box_1.add_component(box_1_asset, + Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), + }); + box_1.add_component(Rigidbody::Data{ + .gravity_scale = 0, + .body_type = BODYTYPE_LEFT, + .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0}, + .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0, + .kinematic_collision = KINEMATIC_COLLISION, + }); + box_1.add_component().set_script().active = SCRIPT; + box_1.add_component(vec2(1, 1), vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); + box_1.add_component().set_script(); + + GameObject circle_1 = this->new_object("ricle_1", "tag", + ONTOP ? vec2(0.25, -4) : vec2(2, -4), 0, SCALE); + Asset circle_1_asset = Asset("asset/texture/circle.png"); + circle_1.add_component( + circle_1_asset, Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), + }); + circle_1.add_component(Rigidbody::Data{ + .gravity_scale = 0, + .body_type = BODYTYPE_RIGHT, + .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0}, + .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0, + .kinematic_collision = KINEMATIC_COLLISION, + }); + circle_1.add_component().set_script().active + = SCRIPT; + circle_1.add_component(0.5, vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); + circle_1.add_component().set_script(); + + GameObject circle_2 = this->new_object( + "ricle_2", "tag", ONTOP ? vec2(-0.25, -1.5) : vec2(-2.5, -1.5), 0, SCALE); + Asset circle_2_asset = Asset("asset/texture/circle.png"); + circle_2.add_component( + circle_2_asset, Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), + }); + circle_2.add_component(Rigidbody::Data{ + .gravity_scale = 0, + .body_type = BODYTYPE_LEFT, + .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0}, + .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0, + .kinematic_collision = KINEMATIC_COLLISION, + }); + circle_2.add_component().set_script().active + = SCRIPT; + circle_2.add_component(0.5, vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); + circle_2.add_component().set_script(); + + GameObject box_2 = this->new_object( + "box_2", "tag", ONTOP ? vec2(0.25, -1.5) : vec2(2.5, -1.5), 0, SCALE); + Asset box_2_asset = Asset("asset/texture/square.png"); + box_2.add_component( + box_2_asset, Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), + }); + box_2.add_component(Rigidbody::Data{ + .gravity_scale = 0, + .body_type = BODYTYPE_RIGHT, + .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0}, + .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0, + .kinematic_collision = KINEMATIC_COLLISION, + }); + box_2.add_component().set_script().active = SCRIPT; + box_2.add_component(vec2(1, 1), vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); + box_2.add_component().set_script(); + + GameObject box_3 = this->new_object( + "box_3", "tag", ONTOP ? vec2(-0.25, 1.5) : vec2(-3, 1.5), 0, SCALE); + Asset box_3_asset = Asset("asset/texture/square.png"); + box_3.add_component(box_3_asset, + Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), + }); + box_3.add_component(Rigidbody::Data{ + .gravity_scale = 0, + .body_type = BODYTYPE_LEFT, + .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0}, + .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0, + .kinematic_collision = KINEMATIC_COLLISION, + }); + box_3.add_component().set_script().active = SCRIPT; + box_3.add_component(vec2(1, 1), vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); + box_3.add_component().set_script(); + + GameObject box_4 = this->new_object("box_4", "tag", + ONTOP ? vec2(0.25, 1.5) : vec2(3, 1.5), 0, SCALE); + Asset box_4_asset = Asset("asset/texture/square.png"); + box_4.add_component( + box_4_asset, Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), + }); + box_4.add_component(Rigidbody::Data{ + .gravity_scale = 0, + .body_type = BODYTYPE_RIGHT, + .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0}, + .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0, + .kinematic_collision = KINEMATIC_COLLISION, + }); + box_4.add_component().set_script().active = SCRIPT; + box_4.add_component(vec2(1, 1), vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); + box_4.add_component().set_script(); + + GameObject circle_3 = this->new_object( + "ricle_3", "tag", ONTOP ? vec2(-0.25, 4) : vec2(-3.5, 4), 0, SCALE); + Asset circle_3_asset = Asset("asset/texture/circle.png"); + circle_3.add_component( + circle_3_asset, Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), + }); + circle_3.add_component(Rigidbody::Data{ + .gravity_scale = 0, + .body_type = BODYTYPE_LEFT, + .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0}, + .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0, + .kinematic_collision = KINEMATIC_COLLISION, + }); + circle_3.add_component().set_script().active + = SCRIPT; + circle_3.add_component(0.5, vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); + circle_3.add_component().set_script(); + + GameObject circle_4 = this->new_object("ricle_4", "tag", + ONTOP ? vec2(0.25, 4) : vec2(3.5, 4), 0, SCALE); + Asset circle_4_asset = Asset("asset/texture/circle.png"); + circle_4.add_component( + circle_4_asset, Sprite::Data{ + .sorting_in_layer = 0, + .order_in_layer = 0, + .size = vec2(1, 1), + .angle_offset = 0, + .scale_offset = 1, + .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), + }); + circle_4.add_component(Rigidbody::Data{ + .gravity_scale = 0, + .body_type = BODYTYPE_RIGHT, + .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0}, + .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0, + .kinematic_collision = KINEMATIC_COLLISION, + }); + circle_4.add_component().set_script().active + = SCRIPT; + circle_4.add_component(0.5, vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); + circle_4.add_component().set_script(); + } + + string get_name() const { return "scene1"; } +}; + +int main(int argc, char * argv[]) { + Engine gameloop; + gameloop.add_scene(); + + return gameloop.main(); +} diff --git a/src/example/AITest.cpp b/src/example/AITest.cpp new file mode 100644 index 0000000..93ba500 --- /dev/null +++ b/src/example/AITest.cpp @@ -0,0 +1,90 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +class Script1 : public Script { + bool shutdown(const ShutDownEvent & event) { + // Very dirty way of shutting down the game + throw "ShutDownEvent"; + return true; + } + + bool mousemove(const MouseMoveEvent & event) { + /*RefVector aivec = this->get_components(); + AI & ai = aivec.front().get(); + ai.flee_target + = vec2{static_cast(event.mouse_x), static_cast(event.mouse_y)};*/ + return true; + } + + void init() { + subscribe( + [this](const ShutDownEvent & ev) -> bool { return this->shutdown(ev); }); + subscribe( + [this](const MouseMoveEvent & ev) -> bool { return this->mousemove(ev); }); + } +}; + +class Scene1 : public Scene { +public: + void load_scene() override { + Mediator & mediator = this->mediator; + ComponentManager & mgr = mediator.component_manager; + + GameObject game_object1 = mgr.new_object("", "", vec2{0, 0}, 0, 1); + GameObject game_object2 = mgr.new_object("", "", vec2{0, 0}, 0, 1); + + Asset img{"asset/texture/test_ap43.png"}; + + Sprite & test_sprite = game_object1.add_component( + img, Sprite::Data{ + .color = Color::MAGENTA, + .flip = Sprite::FlipSettings{false, false}, + .sorting_in_layer = 2, + .order_in_layer = 2, + .size = {0, 100}, + .angle_offset = 0, + .position_offset = {0, 0}, + }); + + AI & ai = game_object1.add_component(3000); + // ai.arrive_on(); + // ai.flee_on(); + ai.path_follow_on(); + ai.make_oval_path(500, 1000, {0, -1000}, 1.5708, true); + ai.make_oval_path(1000, 500, {0, 500}, 4.7124, false); + game_object1.add_component(Rigidbody::Data{ + .mass = 0.1f, + .max_linear_velocity = 40, + }); + game_object1.add_component().set_script(); + + game_object2.add_component(ivec2{1080, 720}, vec2{5000, 5000}, + Camera::Data{ + .bg_color = Color::WHITE, + .zoom = 1, + }); + } + + string get_name() const override { return "Scene1"; } +}; + +int main() { + LoopManager engine; + engine.add_scene(); + engine.start(); + + return 0; +} diff --git a/src/example/AquariumSubScene.cpp b/src/example/AquariumSubScene.cpp deleted file mode 100644 index 4f13acf..0000000 --- a/src/example/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/src/example/AquariumSubScene.h b/src/example/AquariumSubScene.h deleted file mode 100644 index 2a188bc..0000000 --- a/src/example/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/src/example/BackgroundSubScene.cpp b/src/example/BackgroundSubScene.cpp deleted file mode 100644 index 6fdc598..0000000 --- a/src/example/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/src/example/BackgroundSubScene.h b/src/example/BackgroundSubScene.h deleted file mode 100644 index 06bdac4..0000000 --- a/src/example/BackgroundSubScene.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -namespace crepe { -class Scene; -} - -class BackgroundSubScene { -public: - BackgroundSubScene(crepe::Scene & scn); -}; diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index 4b9f4f1..afe6cb7 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -1,32 +1,23 @@ -set(GAME_HEADERS - AquariumSubScene.h - BackgroundSubScene.h - ForestSubScene.h - ForestParallaxScript.h - HallwaySubScene.h - StartSubScene.h - GameScene.h - StartGameScript.h - MoveCameraManualyScript.h - PlayerSubScene.h - PlayerScript.h -) +# all examples +add_custom_target(examples) -set(GAME_SOURCES - game.cpp - AquariumSubScene.cpp - BackgroundSubScene.cpp - ForestSubScene.cpp - ForestParallaxScript.cpp - HallwaySubScene.cpp - StartSubScene.cpp - GameScene.cpp - StartGameScript.cpp - MoveCameraManualyScript.cpp - PlayerSubScene.cpp - PlayerScript.cpp -) +# add_example(target_name [SOURCES...]) +function(add_example target_name) + # if SOURCES is not specified + if(NOT ARGV1) + # A .cpp file with target_name exists, and should be used + set(sources ${target_name}.cpp) + else() + set(sources ${ARGV}) + endif() -add_executable(game ${GAME_SOURCES} ${GAME_HEADERS}) + add_executable(${target_name} EXCLUDE_FROM_ALL ${sources}) + target_link_libraries(${target_name} PUBLIC crepe) + add_dependencies(examples ${target_name}) +endfunction() -target_link_libraries(game PUBLIC crepe) +add_example(rendering_particle) +add_example(button) +add_example(replay) +add_example(loadfont) +add_example(AITest) diff --git a/src/example/ForestParallaxScript.cpp b/src/example/ForestParallaxScript.cpp deleted file mode 100644 index 27e30eb..0000000 --- a/src/example/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/src/example/ForestParallaxScript.h b/src/example/ForestParallaxScript.h deleted file mode 100644 index a65a684..0000000 --- a/src/example/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/src/example/ForestSubScene.cpp b/src/example/ForestSubScene.cpp deleted file mode 100644 index 9be875d..0000000 --- a/src/example/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/src/example/ForestSubScene.h b/src/example/ForestSubScene.h deleted file mode 100644 index 0a04001..0000000 --- a/src/example/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/src/example/GameScene.cpp b/src/example/GameScene.cpp deleted file mode 100644 index c280474..0000000 --- a/src/example/GameScene.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "GameScene.h" -#include "BackgroundSubScene.h" -#include "MoveCameraManualyScript.h" -#include "PlayerSubScene.h" -#include "StartGameScript.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace crepe; -using namespace std; - -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::Data{ - .bg_color = Color::RED, - }); - camera.add_component().set_script(); - camera.add_component(Rigidbody::Data{}); - - PlayerSubScene player(*this); - - GameObject floor = new_object("floor", "game_world", vec2(0, 325)); - floor.add_component(Rigidbody::Data{ - .body_type = Rigidbody::BodyType::STATIC, - }); - floor.add_component(vec2(INFINITY, 200)); - GameObject ceiling = new_object("ceiling", "game_world", vec2(0, -325)); - ceiling.add_component(Rigidbody::Data{ - .body_type = Rigidbody::BodyType::STATIC, - }); - ceiling.add_component(vec2(INFINITY, 200)); - - GameObject start_game_script = new_object("start_game_script", "script", vec2(0, 0)); - start_game_script.add_component().set_script(); -} - -string GameScene::get_name() const { return "scene1"; } diff --git a/src/example/GameScene.h b/src/example/GameScene.h deleted file mode 100644 index 16e2919..0000000 --- a/src/example/GameScene.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include -#include - -class GameScene : public crepe::Scene { -public: - void load_scene(); - - std::string get_name() const; -}; diff --git a/src/example/HallwaySubScene.cpp b/src/example/HallwaySubScene.cpp deleted file mode 100644 index 4fe2267..0000000 --- a/src/example/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/src/example/HallwaySubScene.h b/src/example/HallwaySubScene.h deleted file mode 100644 index acc9329..0000000 --- a/src/example/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/src/example/MoveCameraManualyScript.cpp b/src/example/MoveCameraManualyScript.cpp deleted file mode 100644 index 0181333..0000000 --- a/src/example/MoveCameraManualyScript.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "MoveCameraManualyScript.h" - -using namespace crepe; -using namespace std; - -void MoveCameraManualyScript::init() { - subscribe( - [this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); }); -} - -bool MoveCameraManualyScript::keypressed(const KeyPressEvent & event) { - if (event.key == Keycode::RIGHT) { - Transform & cam = this->get_components_by_name("camera").front(); - cam.position.x += 100; - return true; - } else if (event.key == Keycode::LEFT) { - Transform & cam = this->get_components_by_name("camera").front(); - cam.position.x -= 100; - return true; - } - return false; -} diff --git a/src/example/MoveCameraManualyScript.h b/src/example/MoveCameraManualyScript.h deleted file mode 100644 index 5a09055..0000000 --- a/src/example/MoveCameraManualyScript.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include - -class MoveCameraManualyScript : public crepe::Script { -public: - void init(); - -private: - bool keypressed(const crepe::KeyPressEvent & event); -}; diff --git a/src/example/PlayerScript.cpp b/src/example/PlayerScript.cpp deleted file mode 100644 index 1c388f5..0000000 --- a/src/example/PlayerScript.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "PlayerScript.h" - -#include - -using namespace crepe; -using namespace std; - -void PlayerScript::fixed_update(crepe::duration_t dt) { - Rigidbody & rb = this->get_components_by_name("player").front(); - if (this->get_key_state(Keycode::SPACE)) rb.add_force_linear(vec2(0, -10)); -} diff --git a/src/example/PlayerScript.h b/src/example/PlayerScript.h deleted file mode 100644 index 84c4f7f..0000000 --- a/src/example/PlayerScript.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include - -class PlayerScript : public crepe::Script { -public: - void fixed_update(crepe::duration_t dt); -}; diff --git a/src/example/PlayerSubScene.cpp b/src/example/PlayerSubScene.cpp deleted file mode 100644 index 4f4ba9f..0000000 --- a/src/example/PlayerSubScene.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "PlayerSubScene.h" -#include "PlayerScript.h" - -#include -#include -#include -#include -#include - -using namespace crepe; -using namespace std; - -PlayerSubScene::PlayerSubScene(Scene & scn) { - GameObject player = scn.new_object("player", "player", vec2(-100, 200)); - Asset player_body_asset{"asset/jetpack_joyride/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), - }); - player.add_component(player_body_sprite, ivec2(32, 32), uvec2(4, 8), - Animator::Data{ - .fps = 5, - .looping = true, - }); - Asset player_head_asset{"asset/jetpack_joyride/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), - }); - player.add_component(player_head_sprite, ivec2(32, 32), uvec2(4, 8), - Animator::Data{ - .fps = 5, - .looping = true, - }); - Asset player_jetpack_asset{"asset/jetpack_joyride/barry/jetpackDefault.png"}; - Sprite & player_jetpack_sprite = player.add_component( - player_jetpack_asset, Sprite::Data{ - .sorting_in_layer = 10, - .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{ - .gravity_scale = 20, - .body_type = Rigidbody::BodyType::DYNAMIC, - .linear_velocity = vec2(100, 0), - .collision_layer = 10, - }); - player.add_component(vec2(50, 50)); - player.add_component().set_script().active = false; -} diff --git a/src/example/PlayerSubScene.h b/src/example/PlayerSubScene.h deleted file mode 100644 index bf94c32..0000000 --- a/src/example/PlayerSubScene.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -namespace crepe { -class Scene; -} - -class PlayerSubScene { -public: - PlayerSubScene(crepe::Scene & scn); -}; diff --git a/src/example/StartGameScript.cpp b/src/example/StartGameScript.cpp deleted file mode 100644 index 50ba86c..0000000 --- a/src/example/StartGameScript.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "StartGameScript.h" - -#include -#include -#include - -using namespace crepe; -using namespace std; - -void StartGameScript::fixed_update(crepe::duration_t dt) { - Transform & player_transform = this->get_components_by_name("player").front(); - - // Create hole in wall and activate panic lamp - if (player_transform.position.x > 75 && !this->created_hole) { - Sprite & lamp_sprite = this->get_components_by_name("start_end").back(); - lamp_sprite.active = true; - Sprite & hole_sprite = this->get_components_by_name("start_hole").front(); - hole_sprite.active = true; - - RefVector frags_rg - = this->get_components_by_tag("wall_fragment"); - RefVector frags_sprite = this->get_components_by_tag("wall_fragment"); - for (Rigidbody & frag_rg : frags_rg) { - frag_rg.active = true; - } - for (Sprite & frag_sprite : frags_sprite) { - frag_sprite.active = true; - } - - RefVector smoke_emitters - = this->get_components_by_name("smoke_particles"); - for (ParticleEmitter & emitter : smoke_emitters) { - emitter.active = true; - } - - this->created_hole = true; - } - - // Take jetpack from jetpack stand - if (player_transform.position.x > 275 && !this->took_jetpack) { - Animator & jetpack_stand_anim - = this->get_components_by_name("start_begin").back(); - jetpack_stand_anim.next_anim(); - Sprite & jetpack_sprite = this->get_components_by_name("player").back(); - jetpack_sprite.active = true; - - this->took_jetpack = true; - } - - // Start camera movement, enable player jumping and disable this script - if (player_transform.position.x > 500) { - Rigidbody & rb = this->get_components_by_name("camera").front(); - rb.data.linear_velocity = vec2(100, 0); - BehaviorScript & player_script - = this->get_components_by_name("player").front(); - player_script.active = true; - BehaviorScript & this_script - = this->get_components_by_name("start_game_script").front(); - this_script.active = false; - } -} diff --git a/src/example/StartGameScript.h b/src/example/StartGameScript.h deleted file mode 100644 index ad62e1a..0000000 --- a/src/example/StartGameScript.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -class StartGameScript : public crepe::Script { -public: - void fixed_update(crepe::duration_t dt); - -private: - bool created_hole = false; - bool took_jetpack = false; -}; diff --git a/src/example/StartSubScene.cpp b/src/example/StartSubScene.cpp deleted file mode 100644 index 07738a4..0000000 --- a/src/example/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/jetpack_joyride/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/src/example/StartSubScene.h b/src/example/StartSubScene.h deleted file mode 100644 index c83e3d5..0000000 --- a/src/example/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/src/example/button.cpp b/src/example/button.cpp new file mode 100644 index 0000000..4220588 --- /dev/null +++ b/src/example/button.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace crepe; +using namespace std; + +int main(int argc, char * argv[]) { + Mediator mediator; + ComponentManager mgr{mediator}; + RenderSystem sys{mediator}; + EventManager event_mgr{mediator}; + InputSystem input_sys{mediator}; + SDLContext sdl_context{mediator}; + GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1); + auto & camera = obj.add_component( + ivec2{500, 500}, vec2{500, 500}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f}); + auto start = std::chrono::steady_clock::now(); + while (true) { + const keyboard_state_t & keyboard_state = sdl_context.get_keyboard_state(); + input_sys.update(); + sys.update(); + event_mgr.dispatch_events(); + SDL_Delay(30); + } + return 0; +} diff --git a/src/example/game.cpp b/src/example/game.cpp deleted file mode 100644 index a028791..0000000 --- a/src/example/game.cpp +++ /dev/null @@ -1,324 +0,0 @@ -#include "GameScene.h" - -#include -#include - -using namespace crepe; -using namespace std; - -class ScriptBox : public Script { -public: - bool oncollision(const CollisionEvent & test) { - Log::logf("Box {} on_collision() with {}", test.info.self.metadata.game_object_id, - test.info.other.metadata.game_object_id); - return true; - } - - void init() { - subscribe( - [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); }); - } -}; - -class ScriptCircle : public Script { -public: - bool oncollision(const CollisionEvent & test) { - Log::logf("Circle {} on_collision() with {}", test.info.self.metadata.game_object_id, - test.info.other.metadata.game_object_id); - return true; - } - - void init() { - subscribe( - [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); }); - } -}; - -class ScriptMoveToLeft : public Script { -public: - void update() { - Transform & transform = this->get_component(); - transform.position.x -= 0.02; - } -}; - -class ScriptMoveToRight : public Script { -public: - void update() { - Transform & transform = this->get_component(); - transform.position.x += 0.02; - } -}; - -class ConcreteScene1 : public Scene { -public: - void load_scene() { - GameObject camera = this->new_object("camera"); - camera.add_component(ivec2(1080, 720), vec2(10, 10), - Camera::Data{.bg_color = Color::WHITE, .zoom = 1}); - - GameObject reference = this->new_object("reference", "tag", vec2(0, 0), 0, 1); - Asset reference_asset = Asset("asset/texture/square.png"); - reference.add_component(reference_asset, Sprite::Data{ - .color = Color::RED, - .sorting_in_layer = 10, - .order_in_layer = 0, - .size = vec2(0.1, 0.1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(0, 0), - }); - - /*GameObject box_1 = this->new_object("box_1", "tag", vec2(0, 0), 0, 1); - Asset box_1_asset = Asset("asset/texture/square.png"); - box_1.add_component(box_1_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(0, 0.5), - }); - Asset box_1_asset2 = Asset("asset/texture/test_ap43.png"); - box_1.add_component(box_1_asset2, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(0, -0.5), - });*/ - - /*GameObject particles = this->new_object("particles", "tag", vec2(-1, 0), 180, 1); - Asset particles_asset = Asset("asset/texture/test_ap43.png"); - Sprite & particles_sprite = particles.add_component(particles_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(0, 0), - }); - ParticleEmitter & particles_emitter = particles.add_component(particles_sprite, ParticleEmitter::Data{ - .offset = vec2(0, 0), - .emission_rate = 1, - .min_speed = 1, - .max_speed = 1, - .min_angle = 0, - .max_angle = 0, - .end_lifespan = 4, - });*/ - - const bool SCRIPT = false; - - const Rigidbody::BodyType BODYTYPE_LEFT = Rigidbody::BodyType::DYNAMIC; - const Rigidbody::BodyType BODYTYPE_RIGHT = Rigidbody::BodyType::DYNAMIC; - const bool BOUNCE_LEFT = false; - const bool BOUNCE_RIGHT = false; - const bool KINEMATIC_COLLISION = true; - const bool ONTOP = false; - - const float SCALE = 0.5; - const float OFFSET_X_LEFT = 0; - const float OFFSET_X_RIGHT = 0; - const float OFFSET_Y_LEFT = 0; - const float OFFSET_Y_RIGHT = 0; - - GameObject box_1 = this->new_object("box_1", "tag", - ONTOP ? vec2(-0.25, -4) : vec2(-2, -4), 0, SCALE); - Asset box_1_asset = Asset("asset/texture/square.png"); - box_1.add_component(box_1_asset, - Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), - }); - box_1.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_LEFT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0}, - .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - box_1.add_component().set_script().active = SCRIPT; - box_1.add_component(vec2(1, 1), vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); - box_1.add_component().set_script(); - - GameObject circle_1 = this->new_object("ricle_1", "tag", - ONTOP ? vec2(0.25, -4) : vec2(2, -4), 0, SCALE); - Asset circle_1_asset = Asset("asset/texture/circle.png"); - circle_1.add_component( - circle_1_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), - }); - circle_1.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_RIGHT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0}, - .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - circle_1.add_component().set_script().active - = SCRIPT; - circle_1.add_component(0.5, vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); - circle_1.add_component().set_script(); - - GameObject circle_2 = this->new_object( - "ricle_2", "tag", ONTOP ? vec2(-0.25, -1.5) : vec2(-2.5, -1.5), 0, SCALE); - Asset circle_2_asset = Asset("asset/texture/circle.png"); - circle_2.add_component( - circle_2_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), - }); - circle_2.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_LEFT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0}, - .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - circle_2.add_component().set_script().active - = SCRIPT; - circle_2.add_component(0.5, vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); - circle_2.add_component().set_script(); - - GameObject box_2 = this->new_object( - "box_2", "tag", ONTOP ? vec2(0.25, -1.5) : vec2(2.5, -1.5), 0, SCALE); - Asset box_2_asset = Asset("asset/texture/square.png"); - box_2.add_component( - box_2_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), - }); - box_2.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_RIGHT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0}, - .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - box_2.add_component().set_script().active = SCRIPT; - box_2.add_component(vec2(1, 1), vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); - box_2.add_component().set_script(); - - GameObject box_3 = this->new_object( - "box_3", "tag", ONTOP ? vec2(-0.25, 1.5) : vec2(-3, 1.5), 0, SCALE); - Asset box_3_asset = Asset("asset/texture/square.png"); - box_3.add_component(box_3_asset, - Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), - }); - box_3.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_LEFT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0}, - .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - box_3.add_component().set_script().active = SCRIPT; - box_3.add_component(vec2(1, 1), vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); - box_3.add_component().set_script(); - - GameObject box_4 = this->new_object("box_4", "tag", - ONTOP ? vec2(0.25, 1.5) : vec2(3, 1.5), 0, SCALE); - Asset box_4_asset = Asset("asset/texture/square.png"); - box_4.add_component( - box_4_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), - }); - box_4.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_RIGHT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0}, - .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - box_4.add_component().set_script().active = SCRIPT; - box_4.add_component(vec2(1, 1), vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); - box_4.add_component().set_script(); - - GameObject circle_3 = this->new_object( - "ricle_3", "tag", ONTOP ? vec2(-0.25, 4) : vec2(-3.5, 4), 0, SCALE); - Asset circle_3_asset = Asset("asset/texture/circle.png"); - circle_3.add_component( - circle_3_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), - }); - circle_3.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_LEFT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0}, - .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - circle_3.add_component().set_script().active - = SCRIPT; - circle_3.add_component(0.5, vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); - circle_3.add_component().set_script(); - - GameObject circle_4 = this->new_object("ricle_4", "tag", - ONTOP ? vec2(0.25, 4) : vec2(3.5, 4), 0, SCALE); - Asset circle_4_asset = Asset("asset/texture/circle.png"); - circle_4.add_component( - circle_4_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), - }); - circle_4.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_RIGHT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0}, - .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - circle_4.add_component().set_script().active - = SCRIPT; - circle_4.add_component(0.5, vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); - circle_4.add_component().set_script(); - } - - string get_name() const { return "scene1"; } -}; - -int main(int argc, char * argv[]) { - Engine gameloop; - gameloop.add_scene(); - - return gameloop.main(); -} diff --git a/src/example/loadfont.cpp b/src/example/loadfont.cpp new file mode 100644 index 0000000..e459332 --- /dev/null +++ b/src/example/loadfont.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace crepe; +int main() { + + // SDLFontContext font_facade; + Mediator mediator; + FontFacade font_facade{}; + SDLContext sdl_context{mediator}; + // ComponentManager component_manager{mediator}; + ResourceManager resource_manager{mediator}; + try { + // Correct way to create a unique pointer for Text + std::unique_ptr label = std::make_unique( + 1, vec2(100, 100), vec2(0, 0), "OpenSymbol", Text::Data{}, "test text"); + // std::cout << "Path: " << label->font.get_path() << std::endl; + Asset asset1 = font_facade.get_font_asset("OpenSymbol"); + std::cout << asset1.get_path() << std::endl; + std::unique_ptr label2 = std::make_unique( + 1, vec2(100, 100), vec2(0, 0), "fsaafdafsdafsdafsdasfdds", Text::Data{}); + Asset asset = Asset("test test"); + label->font.emplace(asset); + std::cout << label->font.value().get_path() << std::endl; + // label2->font = std::make_optional(asset); + // std::cout << "Path: " << label2->font.get_path() << std::endl; + ResourceManager & resource_mgr = mediator.resource_manager; + const Font & res = resource_manager.get(label->font.value()); + // TTF_Font * test_font = res.get_font(); + // if (test_font == NULL) { + // std::cout << "error with font" << std::endl; + // } else { + // std::cout << "correct font retrieved" << std::endl; + // } + } catch (const std::exception & e) { + std::cout << "Standard exception thrown: " << e.what() << std::endl; + } + + return 0; +} diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp new file mode 100644 index 0000000..5440fdd --- /dev/null +++ b/src/example/rendering_particle.cpp @@ -0,0 +1,76 @@ + + +#include "api/Asset.h" +#include "api/Text.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +class TestScene : public Scene { +public: + void load_scene() { + GameObject game_object = new_object("", "", vec2{0, 0}, 0, 1); + + Color color(255, 255, 255, 255); + + Asset img{"asset/texture/square.png"}; + + Sprite & test_sprite = game_object.add_component( + img, Sprite::Data{ + .color = color, + .flip = Sprite::FlipSettings{false, false}, + .sorting_in_layer = 2, + .order_in_layer = 2, + .size = {1, 1}, + .angle_offset = 0, + .position_offset = {0, 1}, + .world_space = false, + }); + //auto & emitter = game_object.add_component(test_sprite, ParticleEmitter::Data{}); + + Sprite & test_sprite1 + = game_object.add_component(img, Sprite::Data{ + .color = color, + .size = {1, 1}, + .position_offset = {0, -1}, + .world_space = false, + }); + + auto & cam = game_object.add_component(ivec2{1280, 720}, vec2{5, 5}, + Camera::Data{ + .bg_color = Color::WHITE, + .postion_offset = {1000, 1000}, + }); + + /* + game_object.add_component(vec2{1, 1}, vec2{0, -0.5}, "ComicSansMS", + Text::Data{.text_color = Color::RED}, "test TEST"); + + game_object.add_component(vec2{1, 1}, vec2{0, 0.5}, "ComicSansMS", + Text::Data{.text_color = Color::BLACK}, "TEST test"); + */ + } + + string get_name() const { return "TestScene"; }; +}; + +int main(int argc, char * argv[]) { + LoopManager engine; + engine.add_scene(); + engine.start(); + return 0; +} diff --git a/src/example/replay.cpp b/src/example/replay.cpp new file mode 100644 index 0000000..82fd478 --- /dev/null +++ b/src/example/replay.cpp @@ -0,0 +1,84 @@ +#include +#include +#include + +using namespace crepe; +using namespace std; + +class AnimationScript : public Script { + Transform * transform; + float t = 0; + + void init() { transform = &get_component(); } + + void update() { + t += 0.05; + transform->position = {sin(t), cos(t)}; + } +}; + +class Timeline : public Script { + unsigned i = 0; + recording_t recording; + + void update() { + switch (i++) { + default: + break; + case 10: + logf("record start"); + replay.record_start(); + break; + case 60: + logf("record end, playing recording"); + this->recording = replay.record_end(); + replay.play(this->recording); + break; + case 61: + logf("done, releasing recording"); + replay.release(this->recording); + break; + case 72: + logf("exit"); + queue_event(); + break; + }; + } +}; + +class TestScene : public Scene { +public: + using Scene::Scene; + + void load_scene() { + Mediator & mediator = this->mediator; + ComponentManager & mgr = mediator.component_manager; + + GameObject cam = mgr.new_object("cam"); + cam.add_component(ivec2{640, 480}, vec2{3, 3}, + Camera::Data{ + .bg_color = Color::WHITE, + }); + + GameObject square = mgr.new_object("square"); + square.add_component(Asset{"asset/texture/square.png"}, Sprite::Data{ + .size = {0.5, 0.5}, + }); + square.add_component().set_script(); + + GameObject scapegoat = mgr.new_object(""); + scapegoat.add_component().set_script(); + } + + string get_name() const { return "scene1"; } +}; + +int main(int argc, char * argv[]) { + Config & cfg = Config::get_instance(); + cfg.log.level = Log::Level::DEBUG; + + Engine engine; + + engine.add_scene(); + return engine.main(); +} -- cgit v1.2.3 From 0ba89eff9283d5f9f59fa763a19f4616f1c66d74 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 20 Dec 2024 12:57:17 +0100 Subject: finish moving game --- game/.crepe-root | 0 game/AquariumSubScene.cpp | 24 ++-- game/ForestSubScene.cpp | 22 ++-- game/HallwaySubScene.cpp | 20 +-- game/PlayerSubScene.cpp | 6 +- game/StartSubScene.cpp | 52 ++++---- game/main.cpp | 317 +--------------------------------------------- 7 files changed, 65 insertions(+), 376 deletions(-) create mode 100644 game/.crepe-root (limited to 'game/main.cpp') diff --git a/game/.crepe-root b/game/.crepe-root new file mode 100644 index 0000000..e69de29 diff --git a/game/AquariumSubScene.cpp b/game/AquariumSubScene.cpp index 4f13acf..f4b20f6 100644 --- a/game/AquariumSubScene.cpp +++ b/game/AquariumSubScene.cpp @@ -15,7 +15,7 @@ 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/jetpack_joyride/background/aquarium/glassTubeFG_1_TVOS.png"}; + "asset/background/aquarium/glassTubeFG_1_TVOS.png"}; aquarium_begin.add_component(aquarium_begin_asset, Sprite::Data{ .sorting_in_layer = 4, .order_in_layer = 0, @@ -26,7 +26,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { GameObject aquarium_middle_1 = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); Asset aquarium_middle_1_asset{ - "asset/jetpack_joyride/background/aquarium/glassTubeFG_3_TVOS.png"}; + "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, @@ -39,7 +39,7 @@ 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/jetpack_joyride/background/aquarium/glassTubeFG_3_TVOS.png"}; + "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, @@ -50,7 +50,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { GameObject aquarium_middle_3 = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); Asset aquarium_middle_3_asset{ - "asset/jetpack_joyride/background/aquarium/glassTubeFG_3_TVOS.png"}; + "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, @@ -63,7 +63,7 @@ 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/jetpack_joyride/background/aquarium/glassTubeFG_3_TVOS.png"}; + "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, @@ -75,7 +75,7 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { GameObject aquarium_end = scn.new_object("aquarium_end", "background", vec2(begin_x, 0)); Asset aquarium_end_asset{ - "asset/jetpack_joyride/background/aquarium/glassTubeFG_2_TVOS.png"}; + "asset/background/aquarium/glassTubeFG_2_TVOS.png"}; aquarium_end.add_component(aquarium_end_asset, Sprite::Data{ .sorting_in_layer = 4, .order_in_layer = 1, @@ -88,14 +88,14 @@ 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/jetpack_joyride/background/aquarium/AquariumBG1_1_TVOS.png"}; + 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/jetpack_joyride/background/aquarium/AquariumBG1_2_TVOS.png"}; + 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, @@ -103,14 +103,14 @@ void AquariumSubScene::add_background(Scene & scn, float begin_x) { .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/jetpack_joyride/background/aquarium/AquariumBG2_1_TVOS.png"}; + 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/jetpack_joyride/background/aquarium/AquariumBG2_2_TVOS.png"}; + 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, @@ -118,14 +118,14 @@ void AquariumSubScene::add_background(Scene & scn, float begin_x) { .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/jetpack_joyride/background/aquarium/AquariumBG3_1_TVOS.png"}; + 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/jetpack_joyride/background/aquarium/AquariumBG3_2_TVOS.png"}; + 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, diff --git a/game/ForestSubScene.cpp b/game/ForestSubScene.cpp index 9be875d..810ef17 100644 --- a/game/ForestSubScene.cpp +++ b/game/ForestSubScene.cpp @@ -20,7 +20,7 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n 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/jetpack_joyride/background/forest/forestFG_1_TVOS.png"}; + 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, @@ -31,7 +31,7 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n 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/jetpack_joyride/background/forest/forestFG_3_TVOS.png"}; + 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, @@ -42,7 +42,7 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n 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/jetpack_joyride/background/forest/forestFG_3_TVOS.png"}; + 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, @@ -53,7 +53,7 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n 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/jetpack_joyride/background/forest/forestFG_2_TVOS.png"}; + 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, @@ -69,7 +69,7 @@ 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/jetpack_joyride/background/forest/forestBG1_1_TVOS.png"}; + 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, @@ -77,14 +77,14 @@ void ForestSubScene::add_background(Scene & scn, float begin_x, std::string name }); GameObject bg_2 = scn.new_object("forest_bg_2_" + name, "forest_background", vec2(begin_x, 0)); - Asset bg_2_1_asset{"asset/jetpack_joyride/background/forest/forestBG2_1_TVOS.png"}; + 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/jetpack_joyride/background/forest/forestBG2_2_TVOS.png"}; + 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, @@ -93,28 +93,28 @@ void ForestSubScene::add_background(Scene & scn, float begin_x, std::string name }); GameObject bg_3 = scn.new_object("forest_bg_3_" + name, "forest_background", vec2(begin_x, 0)); - Asset bg_3_1_asset{"asset/jetpack_joyride/background/forest/forestBG3_1_TVOS.png"}; + 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/jetpack_joyride/background/forest/forestBG3_2_TVOS.png"}; + 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/jetpack_joyride/background/forest/forestBG3_3_TVOS.png"}; + 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/jetpack_joyride/background/forest/forestBG3_4_TVOS.png"}; + 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, diff --git a/game/HallwaySubScene.cpp b/game/HallwaySubScene.cpp index 4fe2267..486b8c6 100644 --- a/game/HallwaySubScene.cpp +++ b/game/HallwaySubScene.cpp @@ -12,7 +12,7 @@ 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/jetpack_joyride/background/hallway/hallway1FG_1_TVOS.png"}; + 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, @@ -25,7 +25,7 @@ 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/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"}; + 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, @@ -34,7 +34,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu begin_x += 600; GameObject middle_2 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); - Asset middle_asset_2{"asset/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"}; + 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, @@ -43,7 +43,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu begin_x += 200; GameObject middle_3 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); - Asset middle_asset_3{"asset/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"}; + 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, @@ -54,7 +54,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu 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/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"}; + 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, @@ -63,7 +63,7 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu begin_x += 600; GameObject end = scn.new_object("hallway_end", "background", vec2(begin_x, 0)); - Asset end_asset{"asset/jetpack_joyride/background/hallway/hallway1FG_1_TVOS.png"}; + 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, @@ -75,14 +75,14 @@ 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/jetpack_joyride/background/hallway/alarmLight_TVOS.png"}; + 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/jetpack_joyride/background/hallway/alarmGlow_TVOS.png"}; + 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, @@ -99,7 +99,7 @@ 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/jetpack_joyride/background/hallway/sectorText_TVOS.png"}; + 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, @@ -107,7 +107,7 @@ void HallwaySubScene::add_sector_number(GameObject & obj, vec2 offset, unsigned .size = vec2(0, 100), .position_offset = offset, }); - Asset sector_num_asset{"asset/jetpack_joyride/background/hallway/sectorNumbers_TVOS.png"}; + 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, diff --git a/game/PlayerSubScene.cpp b/game/PlayerSubScene.cpp index 4f4ba9f..01a383a 100644 --- a/game/PlayerSubScene.cpp +++ b/game/PlayerSubScene.cpp @@ -12,7 +12,7 @@ using namespace std; PlayerSubScene::PlayerSubScene(Scene & scn) { GameObject player = scn.new_object("player", "player", vec2(-100, 200)); - Asset player_body_asset{"asset/jetpack_joyride/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 = 10, @@ -24,7 +24,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .fps = 5, .looping = true, }); - Asset player_head_asset{"asset/jetpack_joyride/barry/defaultHead.png"}; + Asset player_head_asset{"asset/barry/defaultHead.png"}; Sprite & player_head_sprite = player.add_component(player_head_asset, Sprite::Data{ .sorting_in_layer = 10, @@ -37,7 +37,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .fps = 5, .looping = true, }); - Asset player_jetpack_asset{"asset/jetpack_joyride/barry/jetpackDefault.png"}; + Asset player_jetpack_asset{"asset/barry/jetpackDefault.png"}; Sprite & player_jetpack_sprite = player.add_component( player_jetpack_asset, Sprite::Data{ .sorting_in_layer = 10, diff --git a/game/StartSubScene.cpp b/game/StartSubScene.cpp index 07738a4..5d810c2 100644 --- a/game/StartSubScene.cpp +++ b/game/StartSubScene.cpp @@ -16,14 +16,14 @@ 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/jetpack_joyride/background/start/titleFG_1_TVOS.png"}; + 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/jetpack_joyride/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 = 4, .order_in_layer = 1, @@ -37,7 +37,7 @@ 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/jetpack_joyride/background/start/titleFG_2_TVOS.png"}; + 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, @@ -51,14 +51,14 @@ float StartSubScene::create(Scene & scn, float begin_x) { } void StartSubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) { - Asset lamp_asset{"asset/jetpack_joyride/background/start/alarmLight_TVOS.png"}; + 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/jetpack_joyride/background/start/alarmGlow_TVOS.png"}; + 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, @@ -75,14 +75,14 @@ void StartSubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) { } void StartSubScene::add_table(GameObject & obj, vec2 offset) { - Asset table_asset{"asset/jetpack_joyride/background/start/table.png"}; + 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/jetpack_joyride/background/start/gramophone_TVOS.png"}; + Asset gramophone_asset{"asset/background/start/gramophone_TVOS.png"}; Sprite & gramophone_sprite = obj.add_component( gramophone_asset, Sprite::Data{ .sorting_in_layer = 5, @@ -98,21 +98,21 @@ void StartSubScene::add_table(GameObject & obj, vec2 offset) { } void StartSubScene::add_light(crepe::GameObject & obj, crepe::vec2 offset) { - Asset light_asset{"asset/jetpack_joyride/background/start/title_light_TVOS.png"}; + 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/jetpack_joyride/background/start/lightEffect2.png"}; + 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/jetpack_joyride/background/start/lightEffect.png"}; + 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, @@ -122,7 +122,7 @@ void StartSubScene::add_light(crepe::GameObject & obj, crepe::vec2 offset) { } void StartSubScene::add_jetpack_stand(crepe::GameObject & obj, crepe::vec2 offset) { - Asset jetpack_stand_asset{"asset/jetpack_joyride/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 = 5, @@ -136,7 +136,7 @@ void StartSubScene::add_jetpack_stand(crepe::GameObject & obj, crepe::vec2 offse .looping = true, }) .pause(); - Asset do_not_steal = {"asset/jetpack_joyride/background/start/doNotTouchSign_TVOS.png"}; + 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, @@ -147,7 +147,7 @@ void StartSubScene::add_jetpack_stand(crepe::GameObject & obj, crepe::vec2 offse 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/jetpack_joyride/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 = 5, @@ -168,7 +168,7 @@ 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/jetpack_joyride/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 = 5, @@ -189,7 +189,7 @@ 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/jetpack_joyride/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 = 5, @@ -210,7 +210,7 @@ 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/jetpack_joyride/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 = 5, @@ -231,7 +231,7 @@ 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/jetpack_joyride/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 = 5, @@ -252,7 +252,7 @@ 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/jetpack_joyride/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 = 5, @@ -273,7 +273,7 @@ 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/jetpack_joyride/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 = 5, @@ -294,7 +294,7 @@ 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/jetpack_joyride/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 = 5, @@ -315,7 +315,7 @@ 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/jetpack_joyride/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 = 5, @@ -336,7 +336,7 @@ 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/jetpack_joyride/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 = 5, @@ -357,7 +357,7 @@ 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, 90)); - Asset frag_11_asset{"asset/jetpack_joyride/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 = 5, @@ -378,7 +378,7 @@ 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/jetpack_joyride/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 = 5, @@ -400,7 +400,7 @@ 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/jetpack_joyride/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), @@ -421,7 +421,7 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject smoke_particles_2 = scn.new_object("smoke_particles", "particle_emitter", vec2(begin_x - 100, 200)); - Asset smoke_asset_2{"asset/jetpack_joyride/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), diff --git a/game/main.cpp b/game/main.cpp index a028791..325b66d 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -1,322 +1,11 @@ -#include "GameScene.h" - #include #include -using namespace crepe; -using namespace std; - -class ScriptBox : public Script { -public: - bool oncollision(const CollisionEvent & test) { - Log::logf("Box {} on_collision() with {}", test.info.self.metadata.game_object_id, - test.info.other.metadata.game_object_id); - return true; - } - - void init() { - subscribe( - [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); }); - } -}; - -class ScriptCircle : public Script { -public: - bool oncollision(const CollisionEvent & test) { - Log::logf("Circle {} on_collision() with {}", test.info.self.metadata.game_object_id, - test.info.other.metadata.game_object_id); - return true; - } - - void init() { - subscribe( - [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); }); - } -}; - -class ScriptMoveToLeft : public Script { -public: - void update() { - Transform & transform = this->get_component(); - transform.position.x -= 0.02; - } -}; - -class ScriptMoveToRight : public Script { -public: - void update() { - Transform & transform = this->get_component(); - transform.position.x += 0.02; - } -}; - -class ConcreteScene1 : public Scene { -public: - void load_scene() { - GameObject camera = this->new_object("camera"); - camera.add_component(ivec2(1080, 720), vec2(10, 10), - Camera::Data{.bg_color = Color::WHITE, .zoom = 1}); - - GameObject reference = this->new_object("reference", "tag", vec2(0, 0), 0, 1); - Asset reference_asset = Asset("asset/texture/square.png"); - reference.add_component(reference_asset, Sprite::Data{ - .color = Color::RED, - .sorting_in_layer = 10, - .order_in_layer = 0, - .size = vec2(0.1, 0.1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(0, 0), - }); - - /*GameObject box_1 = this->new_object("box_1", "tag", vec2(0, 0), 0, 1); - Asset box_1_asset = Asset("asset/texture/square.png"); - box_1.add_component(box_1_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(0, 0.5), - }); - Asset box_1_asset2 = Asset("asset/texture/test_ap43.png"); - box_1.add_component(box_1_asset2, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(0, -0.5), - });*/ - - /*GameObject particles = this->new_object("particles", "tag", vec2(-1, 0), 180, 1); - Asset particles_asset = Asset("asset/texture/test_ap43.png"); - Sprite & particles_sprite = particles.add_component(particles_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(0, 0), - }); - ParticleEmitter & particles_emitter = particles.add_component(particles_sprite, ParticleEmitter::Data{ - .offset = vec2(0, 0), - .emission_rate = 1, - .min_speed = 1, - .max_speed = 1, - .min_angle = 0, - .max_angle = 0, - .end_lifespan = 4, - });*/ - - const bool SCRIPT = false; - - const Rigidbody::BodyType BODYTYPE_LEFT = Rigidbody::BodyType::DYNAMIC; - const Rigidbody::BodyType BODYTYPE_RIGHT = Rigidbody::BodyType::DYNAMIC; - const bool BOUNCE_LEFT = false; - const bool BOUNCE_RIGHT = false; - const bool KINEMATIC_COLLISION = true; - const bool ONTOP = false; - - const float SCALE = 0.5; - const float OFFSET_X_LEFT = 0; - const float OFFSET_X_RIGHT = 0; - const float OFFSET_Y_LEFT = 0; - const float OFFSET_Y_RIGHT = 0; - - GameObject box_1 = this->new_object("box_1", "tag", - ONTOP ? vec2(-0.25, -4) : vec2(-2, -4), 0, SCALE); - Asset box_1_asset = Asset("asset/texture/square.png"); - box_1.add_component(box_1_asset, - Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), - }); - box_1.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_LEFT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0}, - .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - box_1.add_component().set_script().active = SCRIPT; - box_1.add_component(vec2(1, 1), vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); - box_1.add_component().set_script(); - - GameObject circle_1 = this->new_object("ricle_1", "tag", - ONTOP ? vec2(0.25, -4) : vec2(2, -4), 0, SCALE); - Asset circle_1_asset = Asset("asset/texture/circle.png"); - circle_1.add_component( - circle_1_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), - }); - circle_1.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_RIGHT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0}, - .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - circle_1.add_component().set_script().active - = SCRIPT; - circle_1.add_component(0.5, vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); - circle_1.add_component().set_script(); - - GameObject circle_2 = this->new_object( - "ricle_2", "tag", ONTOP ? vec2(-0.25, -1.5) : vec2(-2.5, -1.5), 0, SCALE); - Asset circle_2_asset = Asset("asset/texture/circle.png"); - circle_2.add_component( - circle_2_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), - }); - circle_2.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_LEFT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0}, - .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - circle_2.add_component().set_script().active - = SCRIPT; - circle_2.add_component(0.5, vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); - circle_2.add_component().set_script(); - - GameObject box_2 = this->new_object( - "box_2", "tag", ONTOP ? vec2(0.25, -1.5) : vec2(2.5, -1.5), 0, SCALE); - Asset box_2_asset = Asset("asset/texture/square.png"); - box_2.add_component( - box_2_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), - }); - box_2.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_RIGHT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0}, - .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - box_2.add_component().set_script().active = SCRIPT; - box_2.add_component(vec2(1, 1), vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); - box_2.add_component().set_script(); - - GameObject box_3 = this->new_object( - "box_3", "tag", ONTOP ? vec2(-0.25, 1.5) : vec2(-3, 1.5), 0, SCALE); - Asset box_3_asset = Asset("asset/texture/square.png"); - box_3.add_component(box_3_asset, - Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), - }); - box_3.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_LEFT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0}, - .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - box_3.add_component().set_script().active = SCRIPT; - box_3.add_component(vec2(1, 1), vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); - box_3.add_component().set_script(); - - GameObject box_4 = this->new_object("box_4", "tag", - ONTOP ? vec2(0.25, 1.5) : vec2(3, 1.5), 0, SCALE); - Asset box_4_asset = Asset("asset/texture/square.png"); - box_4.add_component( - box_4_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), - }); - box_4.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_RIGHT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0}, - .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - box_4.add_component().set_script().active = SCRIPT; - box_4.add_component(vec2(1, 1), vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); - box_4.add_component().set_script(); - - GameObject circle_3 = this->new_object( - "ricle_3", "tag", ONTOP ? vec2(-0.25, 4) : vec2(-3.5, 4), 0, SCALE); - Asset circle_3_asset = Asset("asset/texture/circle.png"); - circle_3.add_component( - circle_3_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT), - }); - circle_3.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_LEFT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{1, 0}, - .elasticity_coefficient = BOUNCE_LEFT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - circle_3.add_component().set_script().active - = SCRIPT; - circle_3.add_component(0.5, vec2(OFFSET_X_LEFT, OFFSET_Y_LEFT)); - circle_3.add_component().set_script(); - - GameObject circle_4 = this->new_object("ricle_4", "tag", - ONTOP ? vec2(0.25, 4) : vec2(3.5, 4), 0, SCALE); - Asset circle_4_asset = Asset("asset/texture/circle.png"); - circle_4.add_component( - circle_4_asset, Sprite::Data{ - .sorting_in_layer = 0, - .order_in_layer = 0, - .size = vec2(1, 1), - .angle_offset = 0, - .scale_offset = 1, - .position_offset = vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT), - }); - circle_4.add_component(Rigidbody::Data{ - .gravity_scale = 0, - .body_type = BODYTYPE_RIGHT, - .linear_velocity = SCRIPT ? vec2{0, 0} : vec2{-1, 0}, - .elasticity_coefficient = BOUNCE_RIGHT ? 0.5 : 0, - .kinematic_collision = KINEMATIC_COLLISION, - }); - circle_4.add_component().set_script().active - = SCRIPT; - circle_4.add_component(0.5, vec2(OFFSET_X_RIGHT, OFFSET_Y_RIGHT)); - circle_4.add_component().set_script(); - } +#include "GameScene.h" - string get_name() const { return "scene1"; } -}; +using namespace crepe; -int main(int argc, char * argv[]) { +int main() { Engine gameloop; gameloop.add_scene(); -- cgit v1.2.3 From 667ed9ac9b1e51ef87a5a0bca25566f39f087671 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 20 Dec 2024 15:52:54 +0100 Subject: updated cmake and added simple button --- game/CMakeLists.txt | 25 ++++++++++++++++++++++++- game/main.cpp | 3 ++- game/mainmenu/ButtonScript.cpp | 26 ++++++++++++++++++++++++++ game/mainmenu/ButtonScript.h | 11 +++++++++++ game/mainmenu/ButtonSubScene.cpp | 20 ++++++++++++++++++++ game/mainmenu/ButtonSubScene.h | 10 ++++++++++ game/mainmenu/MainMenuScene.cpp | 17 +++++++++++++++++ game/mainmenu/MainMenuScene.h | 11 +++++++++++ 8 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 game/mainmenu/ButtonScript.cpp create mode 100644 game/mainmenu/ButtonScript.h create mode 100644 game/mainmenu/ButtonSubScene.cpp create mode 100644 game/mainmenu/ButtonSubScene.h create mode 100644 game/mainmenu/MainMenuScene.cpp create mode 100644 game/mainmenu/MainMenuScene.h (limited to 'game/main.cpp') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index dc55523..8fae19f 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -8,7 +8,8 @@ set(CMAKE_BUILD_TYPE Debug) project(game C CXX) add_subdirectory(../src crepe) -add_executable(main + +set(SOURCES AquariumSubScene.cpp BackgroundSubScene.cpp ForestParallaxScript.cpp @@ -21,7 +22,29 @@ add_executable(main StartGameScript.cpp StartSubScene.cpp main.cpp + mainmenu/ButtonScript.cpp + mainmenu/ButtonSubScene.cpp + mainmenu/MainMenuScene.cpp +) + +set(HEADERS + AquariumSubScene.h + BackgroundSubScene.h + ForestParallaxScript.h + ForestSubScene.h + GameScene.h + HallwaySubScene.h + MoveCameraManualyScript.h + PlayerScript.h + PlayerSubScene.h + StartGameScript.h + StartSubScene.h + mainmenu/ButtonScript.h + mainmenu/ButtonSubScene.h + mainmenu/MainMenuScene.h ) +add_executable(main ${SOURCES} ${HEADERS}) + target_link_libraries(main PUBLIC crepe) diff --git a/game/main.cpp b/game/main.cpp index 325b66d..9c9f9ee 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -2,12 +2,13 @@ #include #include "GameScene.h" +#include "mainmenu/MainMenuScene.h" using namespace crepe; int main() { Engine gameloop; - gameloop.add_scene(); + gameloop.add_scene(); return gameloop.main(); } diff --git a/game/mainmenu/ButtonScript.cpp b/game/mainmenu/ButtonScript.cpp new file mode 100644 index 0000000..44ba381 --- /dev/null +++ b/game/mainmenu/ButtonScript.cpp @@ -0,0 +1,26 @@ +#include "ButtonScript.h" +#include "iostream" +using namespace crepe; +using namespace std; + +bool ButtonScript::on_button_press(const ButtonPressEvent& e){ + + cout << "button triggered:" << e.metadata.game_object_id << std::endl; + return false; +} +bool ButtonScript::on_button_enter(const ButtonEnterEvent& e){ + + cout << "button Enter:" << e.metadata.game_object_id << std::endl; + return false; +} +bool ButtonScript::on_button_exit(const ButtonExitEvent& e){ + + cout << "button Exit:" << e.metadata.game_object_id << std::endl; + return false; +} +void ButtonScript::init(){ + cout << "script init" << endl; + this->subscribe([this](const ButtonPressEvent& e) { return this->on_button_press(e); }); + this->subscribe([this](const ButtonEnterEvent& e) { return this->on_button_enter(e); }); + this->subscribe([this](const ButtonExitEvent& e) { return this->on_button_exit(e); }); +} diff --git a/game/mainmenu/ButtonScript.h b/game/mainmenu/ButtonScript.h new file mode 100644 index 0000000..96f52f4 --- /dev/null +++ b/game/mainmenu/ButtonScript.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +class ButtonScript : public crepe::Script { +public: + bool on_button_press(const crepe::ButtonPressEvent& e); + bool on_button_enter(const crepe::ButtonEnterEvent& e); + bool on_button_exit(const crepe::ButtonExitEvent& e); + void init(); +}; diff --git a/game/mainmenu/ButtonSubScene.cpp b/game/mainmenu/ButtonSubScene.cpp new file mode 100644 index 0000000..168b387 --- /dev/null +++ b/game/mainmenu/ButtonSubScene.cpp @@ -0,0 +1,20 @@ +#include "ButtonSubScene.h" +#include "ButtonScript.h" + +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +void ButtonSubScene::create(Scene & scn){ + GameObject button_object = scn.new_object("button"); + button_object.add_component