diff options
Diffstat (limited to 'game')
-rw-r--r-- | game/PreviewScene.cpp | 24 | ||||
-rw-r--r-- | game/missile/AlertScript.cpp | 2 | ||||
-rw-r--r-- | game/missile/MissileScript.cpp | 9 | ||||
-rw-r--r-- | game/missile/SpawnEvent.cpp | 10 | ||||
-rw-r--r-- | game/missile/SpawnEvent.h | 2 | ||||
-rw-r--r-- | game/preview/NpcScript.cpp | 9 | ||||
-rw-r--r-- | game/preview/NpcScript.h | 5 | ||||
-rw-r--r-- | game/preview/NpcSubScene.cpp | 6 | ||||
-rw-r--r-- | game/preview/PrevPlayerSubScene.cpp | 6 |
9 files changed, 23 insertions, 50 deletions
diff --git a/game/PreviewScene.cpp b/game/PreviewScene.cpp index d9801a7..1e64e41 100644 --- a/game/PreviewScene.cpp +++ b/game/PreviewScene.cpp @@ -49,7 +49,7 @@ void PreviewScene::load_scene() { .bg_color = Color::RED, } ); - camera.add_component<Rigidbody>(Rigidbody::Data {}); + camera.add_component<BehaviorScript>().set_script<MissileSpawnEventHandler>(); camera.add_component<BehaviorScript>().set_script<HudScript>(); camera.add_component<BehaviorScript>().set_script<SpeedScript>(); @@ -77,13 +77,16 @@ void PreviewScene::load_scene() { .collision_layer = COLL_LAY_BOT_TOP, }); ceiling.add_component<BoxCollider>(vec2(INFINITY, 200)); + GameObject world = this->new_object("world", "TAG", vec2 {0, 0}, 0, 1); - world.add_component<Rigidbody>(Rigidbody::Data { .body_type = Rigidbody::BodyType::STATIC, - .collision_layers = {0}, + .collision_layer = COLL_LAY_BOT_TOP, }); + world.add_component<BoxCollider>(vec2(100,INFINITY), vec2(VIEWPORT_X,VIEWPORT_Y)); + world.add_component<BoxCollider>(vec2(100,INFINITY), vec2(100,VIEWPORT_Y)); + PrevPlayerSubScene player(*this); NpcSubScene npc(*this); SmokeSubScene smoke(*this); @@ -111,6 +114,8 @@ void PreviewScene::load_scene() { } ); + + /* button.create( *this, ButtonSubScene::Data { @@ -158,18 +163,7 @@ void PreviewScene::load_scene() { .btn_side_color = ButtonSubScene::ButtonSideColor::ORANGE, } ); - - /* - - for (int i = 0; i < 200; ++i) { - int row = i / 10; - int col = i % 10; - float x = col * 25 + i; - float y = row * 25 - 400; - GameObject game_coin = this->new_object("coin", "coin", vec2 {x, y}, 0, 1); - Coin coin(game_coin, vec2 {0, 0}); - } - */ + */ } string PreviewScene::get_name() const { return "preview scene"; } diff --git a/game/missile/AlertScript.cpp b/game/missile/AlertScript.cpp index 24b4af9..0e6f5c5 100644 --- a/game/missile/AlertScript.cpp +++ b/game/missile/AlertScript.cpp @@ -18,7 +18,7 @@ void AlertScript::fixed_update(crepe::duration_t dt) { auto alert_transforms = this->get_components_by_name<Transform>("missile_alert"); int idx = 0; - for (int i = 0; i < missile_transforms.size(); i++) { + for (int i = 0; i < missile_transforms.size(); ++i) { const auto & missile_transform = missile_transforms[i].get(); if (this_transform.game_object_id == missile_transform.game_object_id) { idx = i; diff --git a/game/missile/MissileScript.cpp b/game/missile/MissileScript.cpp index bcc4f5b..f87dd20 100644 --- a/game/missile/MissileScript.cpp +++ b/game/missile/MissileScript.cpp @@ -27,7 +27,6 @@ void MissileScript::kill_missile() { auto animations = this->get_components<Animator>(); auto sprites = this->get_components<Sprite>(); auto collider = this->get_component<CircleCollider>(); - auto & fly_sound = this->get_components<AudioSource>().front().get(); auto & this_script = this->get_components<BehaviorScript>().front().get(); animations[0].get().active = false; @@ -36,11 +35,10 @@ void MissileScript::kill_missile() { sprites[0].get().active = false; sprites[1].get().active = false; sprites[2].get().active = true; + collider.active = false; this_script.active = false; this->seeking_disabled = false; - - fly_sound.stop(); } void MissileScript::activate() { auto anim = this->get_components<Animator>(); @@ -49,14 +47,10 @@ void MissileScript::activate() { anim[0].get().active = true; anim[1].get().active = true; anim[2].get().stop(); - //anim[3].get().active = true; - sprites[0].get().active = true; sprites[1].get().active = true; sprites[2].get().active = false; - //sprites[3].get().active = true; } - bool MissileScript::on_collision(const CollisionEvent & ev) { auto & explosion_sound = this->get_components<AudioSource>().back().get(); @@ -79,6 +73,7 @@ void MissileScript::fixed_update(crepe::duration_t dt) { const auto & cam = this->get_components_by_name<Transform>("camera").front().get(); const auto & velocity = this->get_component<Rigidbody>().data.linear_velocity; + if (missile.position.x < (cam.position.x - VIEWPORT_X / 1.8)) { this->kill_missile(); return; diff --git a/game/missile/SpawnEvent.cpp b/game/missile/SpawnEvent.cpp index c7209b7..6109686 100644 --- a/game/missile/SpawnEvent.cpp +++ b/game/missile/SpawnEvent.cpp @@ -20,16 +20,17 @@ void MissileSpawnEventHandler::init() { } bool MissileSpawnEventHandler::on_event(const MissileSpawnEvent & event) { - auto missile_transforms = this->get_components_by_name<Transform>("missile"); auto alert_sprites = this->get_components_by_name<Sprite>("missile_alert"); - auto alert_transforms = this->get_components_by_name<Transform>("missile_alert"); + + auto missile_transforms = this->get_components_by_name<Transform>("missile"); auto colliders = this->get_components_by_name<CircleCollider>("missile"); auto missile_behaviorscripts = this->get_components_by_name<BehaviorScript>("missile"); auto missile_audiosources = this->get_components_by_name<AudioSource>("missile"); + auto & camera_transform = this->get_components_by_name<Transform>("camera").front().get(); - for (size_t i = 0; i < missile_behaviorscripts.size(); ++i) { - auto & script = missile_behaviorscripts[i * 2].get(); + for (size_t i = 0; i < missile_transforms.size(); ++i) { + BehaviorScript & script = missile_behaviorscripts[i * 2].get(); if (script.active) continue; script.active = true; colliders[i].get().active = true; @@ -39,7 +40,6 @@ bool MissileSpawnEventHandler::on_event(const MissileSpawnEvent & event) { transform.position.x = camera_transform.position.x + this->MISSILE_OFFSET; transform.position.y = Random::i(this->MAX_RANGE, this->MIN_RANGE); - auto & alert_transform = alert_transforms[i].get(); auto & alert_sprite = alert_sprites[i].get(); alert_sprite.active = true; break; diff --git a/game/missile/SpawnEvent.h b/game/missile/SpawnEvent.h index 58293d7..3b9638c 100644 --- a/game/missile/SpawnEvent.h +++ b/game/missile/SpawnEvent.h @@ -10,7 +10,7 @@ struct MissileSpawnEvent : public crepe::Event {}; class MissileSpawnEventHandler : public crepe::Script { private: static constexpr int MISSILE_OFFSET = VIEWPORT_X; - static constexpr int RANGE = GAME_HEIGHT / 4; + static constexpr int RANGE = GAME_HEIGHT / 4.5; static constexpr int MIN_RANGE = -RANGE; static constexpr int MAX_RANGE = RANGE; diff --git a/game/preview/NpcScript.cpp b/game/preview/NpcScript.cpp index c4148f2..5a93c2b 100644 --- a/game/preview/NpcScript.cpp +++ b/game/preview/NpcScript.cpp @@ -7,16 +7,15 @@ using namespace std; using namespace crepe; -void NpcScript::init() {} void NpcScript::fixed_update(duration_t dt) { auto & rb = this->get_component<Rigidbody>(); auto & npc = this->get_component<Sprite>(); auto & transform = this->get_component<Transform>(); - if (transform.position.x < -990) { + if (transform.position.x < 200) { rb.data.linear_velocity.x *= -1; } - if (transform.position.x > 990) { + if (transform.position.x > 700) { rb.data.linear_velocity.x *= -1; } @@ -25,8 +24,4 @@ void NpcScript::fixed_update(duration_t dt) { } else { npc.data.flip = {false, false}; } - - auto & savemgr = this->get_save_manager(); - savemgr.set("npc_x", transform.position.x); - savemgr.set("npc_y", transform.position.y); } diff --git a/game/preview/NpcScript.h b/game/preview/NpcScript.h index 8d856fd..d278f83 100644 --- a/game/preview/NpcScript.h +++ b/game/preview/NpcScript.h @@ -1,11 +1,8 @@ +#pragma once #include <crepe/api/Script.h> class NpcScript : public crepe::Script { - -private: - public: - void init(); void fixed_update(crepe::duration_t dt); }; diff --git a/game/preview/NpcSubScene.cpp b/game/preview/NpcSubScene.cpp index bd6cfb2..a3781af 100644 --- a/game/preview/NpcSubScene.cpp +++ b/game/preview/NpcSubScene.cpp @@ -15,11 +15,7 @@ using namespace crepe; NpcSubScene::NpcSubScene(Scene & scn) { - auto & savemgr = scn.get_save_manager(); - ValueBroker npc_x = savemgr.get<float>("npc_x", 500); - ValueBroker npc_y = savemgr.get<float>("npc_y", 0); - - GameObject npc = scn.new_object("npc", "npc_tag", vec2 {npc_x.get(), npc_y.get()}, 0, 1); + GameObject npc = scn.new_object("npc", "npc_tag", vec2 {500, 0}, 0, 1); Asset npc_body {"asset/workers/worker1Body.png"}; Asset npc_head {"asset/workers/worker1Head.png"}; diff --git a/game/preview/PrevPlayerSubScene.cpp b/game/preview/PrevPlayerSubScene.cpp index b59a0af..4351deb 100644 --- a/game/preview/PrevPlayerSubScene.cpp +++ b/game/preview/PrevPlayerSubScene.cpp @@ -16,13 +16,9 @@ using namespace crepe; PrevPlayerSubScene::PrevPlayerSubScene(Scene & scn) { - auto & savemgr = scn.get_save_manager(); - - ValueBroker player_x = savemgr.get<float>("player_x", 500); - ValueBroker player_y = savemgr.get<float>("player_y", -100); GameObject player - = scn.new_object("player", "TAG", vec2 {player_x.get(), player_y.get()}, 0, 1); + = scn.new_object("player", "player", vec2 {800 , -100}, 0, 1); Asset player_body_asset {"asset/barry/defaultBody.png"}; Sprite & player_body_sprite = player.add_component<Sprite>( player_body_asset, |