From b445a1716a46dc875e0b2180c1a1b6022ec7a6d3 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Wed, 8 Jan 2025 14:10:27 +0100 Subject: missile/preview/schedular/PreviewScene --- game/missile/SpawnEvent.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 game/missile/SpawnEvent.h (limited to 'game/missile/SpawnEvent.h') diff --git a/game/missile/SpawnEvent.h b/game/missile/SpawnEvent.h new file mode 100644 index 0000000..ce301fd --- /dev/null +++ b/game/missile/SpawnEvent.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +#include "../Config.h" + +struct MissileSpawnEvent : public crepe::Event {}; + +class MissileSpawnEventHandler : public crepe::Script { +private: + static constexpr int MISSILE_OFFSET = VIEWPORT_X / 1.8; + static constexpr int RANGE = GAME_HEIGHT / 4; + static constexpr int MIN_RANGE = -RANGE; + static constexpr int MAX_RANGE = RANGE; + +public: + void init(); + bool on_event(const MissileSpawnEvent & ev); +}; -- cgit v1.2.3 From eb3d9ec9baa0b95b95d741a0615adaf4c8c1d3c0 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Wed, 8 Jan 2025 16:32:03 +0100 Subject: added preset with nothing --- game/missile/MissileSubScene.cpp | 4 +++- game/missile/SpawnEvent.h | 2 +- game/scheduler/ObjectsScheduler.cpp | 21 ++++++++++++++------- 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'game/missile/SpawnEvent.h') diff --git a/game/missile/MissileSubScene.cpp b/game/missile/MissileSubScene.cpp index db49f88..59d8221 100644 --- a/game/missile/MissileSubScene.cpp +++ b/game/missile/MissileSubScene.cpp @@ -65,6 +65,7 @@ void MissileSubScene::create(crepe::Scene & scn) { missle.add_component( missle_sprite, ivec2 {32, 32}, uvec2 {4, 1}, Animator::Data { + .fps = 15, .looping = true, } ); @@ -72,6 +73,7 @@ void MissileSubScene::create(crepe::Scene & scn) { missle.add_component( missle_thruster_sprite, ivec2 {64, 64}, uvec2 {4, 2}, Animator::Data { + .fps = 15, .looping = true, } ); @@ -86,7 +88,7 @@ void MissileSubScene::create(crepe::Scene & scn) { missile_explosion_sprite.active = false; explosion_anim.active = false; - std::uniform_int_distribution<> dist(140, 200); + std::uniform_int_distribution<> dist(200, 250); missle.add_component(Rigidbody::Data { .body_type = Rigidbody::BodyType::KINEMATIC, .max_linear_velocity = static_cast(dist(gen)), diff --git a/game/missile/SpawnEvent.h b/game/missile/SpawnEvent.h index ce301fd..58293d7 100644 --- a/game/missile/SpawnEvent.h +++ b/game/missile/SpawnEvent.h @@ -9,7 +9,7 @@ struct MissileSpawnEvent : public crepe::Event {}; class MissileSpawnEventHandler : public crepe::Script { private: - static constexpr int MISSILE_OFFSET = VIEWPORT_X / 1.8; + static constexpr int MISSILE_OFFSET = VIEWPORT_X; static constexpr int RANGE = GAME_HEIGHT / 4; static constexpr int MIN_RANGE = -RANGE; static constexpr int MAX_RANGE = RANGE; diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index 02d84c1..60e3f47 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -2,8 +2,8 @@ #include "ObjectsScheduler.h" -#include "../Random.h" #include "../Config.h" +#include "../Random.h" #include "../missile/SpawnEvent.h" #include "api/Rigidbody.h" #include "api/Transform.h" @@ -11,20 +11,25 @@ #include "prefab/ZapperPoolSubScene.h" using namespace crepe; -void ObjectsScheduler::preset_0() { trigger_event(MissileSpawnEvent {}); } +void ObjectsScheduler::preset_0() { + trigger_event(MissileSpawnEvent {}); + trigger_event(MissileSpawnEvent {}); +} void ObjectsScheduler::preset_1() { trigger_event(MissileSpawnEvent {}); } void ObjectsScheduler::preset_2() { trigger_event(CreateZapperEvent {}); } -void ObjectsScheduler::preset_3() {} +void ObjectsScheduler::preset_3() { trigger_event(CreateZapperEvent {}); } void ObjectsScheduler::preset_4() {} -void ObjectsScheduler::boss_fight_1() { +void ObjectsScheduler::boss_fight_1() { this->get_components_by_name("camera").front().get().data.linear_velocity.x = 0; this->get_components_by_name("player").front().get().data.linear_velocity.x = 0; - this->trigger_event(BattleStartEvent{.num_enemies = 2}); + this->trigger_event(BattleStartEvent {.num_enemies = 2}); } bool ObjectsScheduler::boss_fight_1_event() { - this->get_components_by_name("camera").front().get().data.linear_velocity.x = PLAYER_SPEED * 0.02; - this->get_components_by_name("player").front().get().data.linear_velocity.x = PLAYER_SPEED * 0.02; + this->get_components_by_name("camera").front().get().data.linear_velocity.x + = PLAYER_SPEED * 0.02; + this->get_components_by_name("player").front().get().data.linear_velocity.x + = PLAYER_SPEED * 0.02; return false; } @@ -32,6 +37,8 @@ void ObjectsScheduler::init() { this->obstacles.push_back([this]() { preset_0(); }); this->obstacles.push_back([this]() { preset_1(); }); this->obstacles.push_back([this]() { preset_2(); }); + this->obstacles.push_back([this]() { preset_3(); }); + this->obstacles.push_back([this]() { preset_4(); }); this->obstacles.push_back([this]() { boss_fight_1(); }); -- cgit v1.2.3 From a981a42a7378ed51155590215557e52553031272 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Fri, 10 Jan 2025 16:26:05 +0100 Subject: missile solution, cannot find @max issue --- game/PreviewScene.cpp | 24 +++++++++--------------- game/missile/AlertScript.cpp | 2 +- game/missile/MissileScript.cpp | 9 ++------- game/missile/SpawnEvent.cpp | 10 +++++----- game/missile/SpawnEvent.h | 2 +- game/preview/NpcScript.cpp | 9 ++------- game/preview/NpcScript.h | 5 +---- game/preview/NpcSubScene.cpp | 6 +----- game/preview/PrevPlayerSubScene.cpp | 6 +----- 9 files changed, 23 insertions(+), 50 deletions(-) (limited to 'game/missile/SpawnEvent.h') 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::Data {}); + camera.add_component().set_script(); camera.add_component().set_script(); camera.add_component().set_script(); @@ -77,13 +77,16 @@ void PreviewScene::load_scene() { .collision_layer = COLL_LAY_BOT_TOP, }); ceiling.add_component(vec2(INFINITY, 200)); + GameObject world = this->new_object("world", "TAG", vec2 {0, 0}, 0, 1); - world.add_component(Rigidbody::Data { .body_type = Rigidbody::BodyType::STATIC, - .collision_layers = {0}, + .collision_layer = COLL_LAY_BOT_TOP, }); + world.add_component(vec2(100,INFINITY), vec2(VIEWPORT_X,VIEWPORT_Y)); + world.add_component(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("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(); auto sprites = this->get_components(); auto collider = this->get_component(); - auto & fly_sound = this->get_components().front().get(); auto & this_script = this->get_components().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(); @@ -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().back().get(); @@ -79,6 +73,7 @@ void MissileScript::fixed_update(crepe::duration_t dt) { const auto & cam = this->get_components_by_name("camera").front().get(); const auto & velocity = this->get_component().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("missile"); auto alert_sprites = this->get_components_by_name("missile_alert"); - auto alert_transforms = this->get_components_by_name("missile_alert"); + + auto missile_transforms = this->get_components_by_name("missile"); auto colliders = this->get_components_by_name("missile"); auto missile_behaviorscripts = this->get_components_by_name("missile"); auto missile_audiosources = this->get_components_by_name("missile"); + auto & camera_transform = this->get_components_by_name("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(); auto & npc = this->get_component(); auto & transform = this->get_component(); - 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 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("npc_x", 500); - ValueBroker npc_y = savemgr.get("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("player_x", 500); - ValueBroker player_y = savemgr.get("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( player_body_asset, -- cgit v1.2.3 From 7b6c3cc3986d122b9c5ec0b1ddab80aac62d778b Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Sat, 11 Jan 2025 14:36:35 +0100 Subject: improved missile spawn location --- game/missile/SpawnEvent.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'game/missile/SpawnEvent.h') diff --git a/game/missile/SpawnEvent.h b/game/missile/SpawnEvent.h index 3b9638c..84b1987 100644 --- a/game/missile/SpawnEvent.h +++ b/game/missile/SpawnEvent.h @@ -10,9 +10,8 @@ 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.5; - static constexpr int MIN_RANGE = -RANGE; - static constexpr int MAX_RANGE = RANGE; + static constexpr int MIN_RANGE = -150; + static constexpr int MAX_RANGE = 150; public: void init(); -- cgit v1.2.3