diff options
author | max-001 <maxsmits21@kpnmail.nl> | 2024-12-17 13:32:10 +0100 |
---|---|---|
committer | max-001 <maxsmits21@kpnmail.nl> | 2024-12-17 13:32:10 +0100 |
commit | 67d90ae322818ab51b2796a757f9c18e470b13fe (patch) | |
tree | f03a90c8b97fe6786ad92d34d45ca9961f56202c /src/example | |
parent | fd5392e2a4617db5669178169c289dd966064393 (diff) |
Scene starts at x=0
Diffstat (limited to 'src/example')
-rw-r--r-- | src/example/Background.cpp | 2 | ||||
-rw-r--r-- | src/example/GameScene.cpp | 18 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/example/Background.cpp b/src/example/Background.cpp index f348936..0ad2c0c 100644 --- a/src/example/Background.cpp +++ b/src/example/Background.cpp @@ -15,7 +15,7 @@ Background::Background(Scene & scn) { Forest forest; Aquarium aquarium; - float begin_x = 0; + float begin_x = 400; begin_x = start.create(scn, begin_x); diff --git a/src/example/GameScene.cpp b/src/example/GameScene.cpp index 107f964..4422514 100644 --- a/src/example/GameScene.cpp +++ b/src/example/GameScene.cpp @@ -49,24 +49,28 @@ public: = this->get_components_by_name<Transform>("player").front(); // Create hole in wall and activate panic lamp - if (player_transform.position.x == -310) { + if (player_transform.position.x > 75 && !this->created_hole) { Sprite & lamp_sprite = this->get_components_by_name<Sprite>("start_end").back(); lamp_sprite.active = true; Sprite & hole_sprite = this->get_components_by_name<Sprite>("start_hole").front(); hole_sprite.active = true; + + this->created_hole = true; } // Take jetpack from jetpack stand - if (player_transform.position.x == -100) { + if (player_transform.position.x > 275 && !this->took_jetpack) { Animator & jetpack_stand_anim = this->get_components_by_name<Animator>("start_begin").back(); jetpack_stand_anim.next_anim(); Sprite & jetpack_sprite = this->get_components_by_name<Sprite>("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 == 150) { + if (player_transform.position.x > 500) { Rigidbody & rb = this->get_components_by_name<Rigidbody>("camera").front(); rb.data.linear_velocity = vec2(100, 0); BehaviorScript & player_script @@ -77,6 +81,10 @@ public: this_script.active = false; } } + +private: + bool created_hole = false; + bool took_jetpack = false; }; class PlayerScript : public Script { @@ -100,7 +108,7 @@ private: void GameScene::load_scene() { Background background(*this); - GameObject camera = new_object("camera", "camera", vec2(250, 0)); + GameObject camera = new_object("camera", "camera", vec2(650, 0)); camera.add_component<Camera>(ivec2(990, 720), vec2(1100, 800), Camera::Data{ .bg_color = Color::RED, @@ -110,7 +118,7 @@ void GameScene::load_scene() { .linear_velocity = vec2(0, 0), }); - GameObject player = new_object("player", "player", vec2(-500, 200)); + GameObject player = new_object("player", "player", vec2(-100, 200)); Asset player_body_asset{"asset/jetpack_joyride/barry/defaultBody.png"}; Sprite & player_body_sprite = player.add_component<Sprite>(player_body_asset, Sprite::Data{ |