#include "api/BehaviorScript.h" #include "api/CircleCollider.h" #include "api/Scene.h" #include "manager/ComponentManager.h" #include "manager/Mediator.h" #include "types.h" #include #include #include #include #include #include #include #include #include #include #include #include using namespace crepe; using namespace std; class Background { public: Background(ComponentManager & mgr) { this->start(mgr); this->hallway(mgr); this->forest(mgr); this->aquarium(mgr); this->forest(mgr); } void start(ComponentManager & mgr) { GameObject start_begin = mgr.new_object("start_begin", "background", vec2(begin_x, 0)); Asset start_begin_asset{"asset/jetpack_joyride/background/start/titleFG_1_TVOS.png"}; start_begin.add_component(start_begin_asset, Sprite::Data{ .sorting_in_layer = 4, .order_in_layer = 0, .size = vec2(0, 800), }); begin_x += 700; GameObject start_end = mgr.new_object("start_end", "background", vec2(begin_x, 0)); Asset start_end_asset{"asset/jetpack_joyride/background/start/titleFG_2_TVOS.png"}; start_end.add_component(start_end_asset, Sprite::Data{ .sorting_in_layer = 4, .order_in_layer = 1, .size = vec2(0, 800), }); begin_x += 100; } void hallway(ComponentManager & mgr) { GameObject hallway_begin = mgr.new_object("hallway_begin", "background", vec2(begin_x, 0)); Asset hallway_begin_asset{ "asset/jetpack_joyride/background/hallway/hallway1FG_1_TVOS.png"}; hallway_begin.add_component(hallway_begin_asset, Sprite::Data{ .sorting_in_layer = 4, .order_in_layer = 0, .size = vec2(0, 800), }); begin_x += 600; GameObject hallway_middle_1 = mgr.new_object("hallway_middle", "background", vec2(begin_x, 0)); Asset hallway_middle_asset{ "asset/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"}; hallway_middle_1.add_component(hallway_middle_asset, Sprite::Data{ .sorting_in_layer = 4, .order_in_layer = 2, .size = vec2(0, 800), }); begin_x += 600; GameObject hallway_middle_2 = mgr.new_object("hallway_middle", "background", vec2(begin_x, 0)); Asset hallway_middle_asset_2{ "asset/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"}; hallway_middle_2.add_component(hallway_middle_asset_2, Sprite::Data{ .sorting_in_layer = 4, .order_in_layer = 3, .size = vec2(0, 800), }); begin_x += 200; GameObject hallway_middle_3 = mgr.new_object("hallway_middle", "background", vec2(begin_x, 0)); Asset hallway_middle_asset_3{ "asset/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"}; hallway_middle_3.add_component(hallway_middle_asset_3, Sprite::Data{ .sorting_in_layer = 4, .order_in_layer = 4, .size = vec2(0, 800), }); begin_x += 400; GameObject hallway_middle_4 = mgr.new_object("hallway_middle", "background", vec2(begin_x, 0)); Asset hallway_middle_asset_4{ "asset/jetpack_joyride/background/hallway/hallway1FG_2_TVOS.png"}; hallway_middle_4.add_component(hallway_middle_asset_4, Sprite::Data{ .sorting_in_layer = 4, .order_in_layer = 5, .size = vec2(0, 800), }); begin_x += 600; GameObject hallway_end = mgr.new_object("hallway_end", "background", vec2(begin_x, 0)); Asset hallway_end_asset{ "asset/jetpack_joyride/background/hallway/hallway1FG_1_TVOS.png"}; hallway_end.add_component(hallway_end_asset, Sprite::Data{ .sorting_in_layer = 4, .order_in_layer = 1, .size = vec2(0, 800), }); begin_x += 600; } void forest(ComponentManager & mgr) { GameObject forest_begin = mgr.new_object("forest_begin", "background", vec2(begin_x, 0)); Asset forest_begin_asset{ "asset/jetpack_joyride/background/forest/forestFG_1_TVOS.png"}; forest_begin.add_component(forest_begin_asset, Sprite::Data{ .sorting_in_layer = 4, .order_in_layer = 0, .size = vec2(0, 800), }); begin_x += 800; GameObject forest_middle = mgr.new_object("forest_middle", "background", vec2(begin_x, 0)); Asset forest_middle_asset{ "asset/jetpack_joyride/background/forest/forestFG_3_TVOS.png"}; forest_middle.add_component(forest_middle_asset, Sprite::Data{ .sorting_in_layer = 4, .order_in_layer = 2, .size = vec2(0, 800), }); begin_x += 800; GameObject forest_end = mgr.new_object("forest_end", "background", vec2(begin_x, 0)); Asset forest_end_asset{"asset/jetpack_joyride/background/forest/forestFG_2_TVOS.png"}; forest_end.add_component(forest_end_asset, Sprite::Data{ .sorting_in_layer = 4, .order_in_layer = 1, .size = vec2(0, 800), }); begin_x += 600; } void aquarium(ComponentManager & mgr) { GameObject aquarium_begin = mgr.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 = mgr.new_object("aquarium_middle", "background", vec2(begin_x, 0)); Asset aquarium_middle_asset{ "asset/jetpack_joyride/background/aquarium/glassTubeFG_3_TVOS.png"}; aquarium_middle.add_component(aquarium_middle_asset, Sprite::Data{ .sorting_in_layer = 4, .order_in_layer = 2, .size = vec2(0, 800), }); begin_x += 600; GameObject aquarium_end = mgr.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; } private: float begin_x = 0; }; class MoveCameraScript : public Script { public: void init() { subscribe( [this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); }); } private: bool keypressed(const KeyPressEvent & event) { if (event.key == Keycode::RIGHT) { Transform & cam = this->get_components_by_name("camera").front(); cam.position.x += 100; } else if (event.key == Keycode::LEFT) { Transform & cam = this->get_components_by_name("camera").front(); cam.position.x -= 100; } return true; } }; class Scene1 : public Scene { public: void load_scene() { Mediator & m = this->mediator; ComponentManager & mgr = m.component_manager; Background background(mgr); GameObject camera = mgr.new_object("camera", "camera", vec2(600, 0)); camera.add_component(ivec2(1700, 720), vec2(2000, 800), Camera::Data{ .bg_color = Color::RED, }); camera.add_component().set_script(); } string get_name() const { return "scene1"; } }; int main(int argc, char * argv[]) { LoopManager gameloop; gameloop.add_scene(); gameloop.start(); return 0; }