From 1b382ecddb3156c1350feb309bdd9c389ee5c4eb Mon Sep 17 00:00:00 2001 From: max-001 Date: Fri, 13 Dec 2024 14:38:41 +0100 Subject: Added sector number --- src/example/game.cpp | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/example/game.cpp b/src/example/game.cpp index d447782..24aa137 100644 --- a/src/example/game.cpp +++ b/src/example/game.cpp @@ -17,6 +17,7 @@ #include #include #include +#include using namespace crepe; using namespace std; @@ -26,13 +27,13 @@ public: Background(ComponentManager & mgr) { this->start(mgr); - this->hallway(mgr); + this->hallway(mgr, 1, Color::YELLOW); this->forest(mgr); this->aquarium(mgr); - this->forest(mgr); + this->hallway(mgr, 2, Color::MAGENTA); } void start(ComponentManager & mgr) { @@ -80,7 +81,7 @@ public: }); } - void hallway(ComponentManager & mgr) { + void hallway(ComponentManager & mgr, unsigned int sector_num, Color sector_color) { GameObject begin = mgr.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{ @@ -90,6 +91,7 @@ public: }); begin_x += 600; + this->add_sector_number(begin, vec2(-200, 0), sector_num, sector_color); this->add_lamp_hallway(begin, vec2(-70, -120), 11); this->add_lamp_hallway(begin, vec2(30, -120), 9); @@ -164,6 +166,38 @@ public: }); } + void 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(); + } + void forest(ComponentManager & mgr) { GameObject forest_begin = mgr.new_object("forest_begin", "background", vec2(begin_x, 0)); -- cgit v1.2.3