From 7739a80176cea889ce240d18d354c5174825b25a Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 9 Jan 2025 14:46:30 +0100 Subject: workers during normal sequence working --- game/enemy/EnemyScript.cpp | 61 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 9 deletions(-) (limited to 'game/enemy/EnemyScript.cpp') diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index 5c03539..04d577a 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -2,6 +2,7 @@ #include "../Config.h" #include "../Random.h" #include "EnemyConfig.h" +#include #include #include #include @@ -9,7 +10,11 @@ #include #include #include +#include #include +#include "../Random.h" +#include "api/Color.h" +#include "api/Sprite.h" #include using namespace crepe; using namespace std; @@ -40,23 +45,33 @@ void EnemyScript::fixed_update(duration_t dt) { //transform.position += enemy_body.data.linear_velocity * dt.count(); float direction_to_player_y = player_transform.position.y - transform.position.y; float distance_to_player_y = std::abs(direction_to_player_y); + float adjustment_speed = speed * (distance_to_player_y / MAX_DISTANCE); - + //cout << "before clamp speed: " << adjustment_speed << endl; adjustment_speed = std::clamp(adjustment_speed, MIN_SPEED, MAX_SPEED); // Move the path nodes on the Y-axis + //cout << "adjusted_speed: " << adjustment_speed << endl; + Rigidbody& player_body = this->get_components_by_tag("player").front(); for (vec2 & path_node : ai_component.path) { path_node.y += (direction_to_player_y > 0 ? 1 : -1) * adjustment_speed * dt.count(); + path_node.x += player_body.data.linear_velocity.x * dt.count(); } //bullet fire logic: auto now = std::chrono::steady_clock::now(); std::chrono::duration elapsed = now - last_fired; if (elapsed > shot_delay) { - this->shoot(transform.position, 0); + this->shoot(transform.position); last_fired = now; this->shot_delay = std::chrono::duration(Random::f(4, 1)); } + std::chrono::duration elapsed_hit = now - last_hit; + //hit blink timer + if(elapsed_hit > blink_time){ + set_hit_blink(false); + } } + bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { this->speed = e.speed; AI & ai_component = this->get_component(); @@ -65,7 +80,7 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { Transform & cam_transform = this->get_components_by_name("camera").front(); vec2 half_screen = camera.viewport_size / 2; - float x_value = cam_transform.position.x + half_screen.x - 50 * (1 + e.column); + float x_value = cam_transform.position.x + half_screen.x - 70 * (1 + e.column); uniform_real_distribution dist( cam_transform.position.y - half_screen.y + 100, cam_transform.position.y + half_screen.y - 100 @@ -75,31 +90,52 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { = {cam_transform.position.x + camera.viewport_size.x / 2 + 100, random_height}; transform.position = spawn_location; ai_component.path.clear(); - ai_component.make_oval_path(10, 10, vec2 {x_value, random_height}, 1.5708, true); + ai_component.make_oval_path(10, 30, vec2 {x_value, random_height}, 1.5708, true); ai_component.active = true; this->last_fired = std::chrono::steady_clock::now(); return false; } +void EnemyScript::set_hit_blink(bool status){ + RefVector sprites = this->get_components(); + for(Sprite& sprite : sprites){ + if(status){ + sprite.data.color = Color::RED; + continue; + } + sprite.data.color = Color::WHITE; + } +} + bool EnemyScript::on_collide(const CollisionEvent & e) { if (e.info.other.metadata.tag == "player_bullet") { + this->health--; + last_hit = std::chrono::steady_clock::now(); + //Sprite& sprite; + set_hit_blink(true); + + } + if(health <= 0){ this->despawn_enemy(); } - Animator & body_animator = this->get_components().front(); - body_animator.data.col = 2; //body_animator.play(); - BehaviorScript & enemy_script = this->get_component(); - enemy_script.active = false; + return false; } + void EnemyScript::despawn_enemy() { Transform & transform = this->get_component(); + BehaviorScript & enemy_script = this->get_component(); + enemy_script.active = false; + Animator & body_animator = this->get_components().front(); + body_animator.data.col = 2; transform.position = ENEMY_POOL_LOCATION; AI & ai_component = this->get_component(); // Rigidbody& enemy_body ai_component.active = false; } -void EnemyScript::shoot(const vec2 & location, float angle) { + +void EnemyScript::shoot(const vec2 & location) { RefVector bullet_transforms = this->get_components_by_tag("enemy_bullet"); @@ -120,3 +156,10 @@ void EnemyScript::shoot(const vec2 & location, float angle) { } } } + +void EnemyScript::create_tank(){ + RefVector sprites = this->get_components(); + Sprite& tank_body = sprites[2]; + tank_body.active = true; + +} -- cgit v1.2.3 From c1f7b409bd6c883f7e9ff0f81afd3bee47469bdd Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 9 Jan 2025 14:50:28 +0100 Subject: removed iostream --- game/enemy/BattleScript.cpp | 2 -- game/enemy/EnemyScript.cpp | 6 +----- 2 files changed, 1 insertion(+), 7 deletions(-) (limited to 'game/enemy/EnemyScript.cpp') diff --git a/game/enemy/BattleScript.cpp b/game/enemy/BattleScript.cpp index 3eda89e..2d1e143 100644 --- a/game/enemy/BattleScript.cpp +++ b/game/enemy/BattleScript.cpp @@ -1,7 +1,6 @@ #include "BattleScript.h" #include "EnemyScript.h" #include -#include #include #include using namespace std; @@ -29,7 +28,6 @@ void BattleScript::fixed_update(duration_t dt) { } if (!enemies_alive) { this->battle_active = false; - cout << "battle won" << endl; this->trigger_event(); } } diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index 04d577a..2382847 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -2,7 +2,6 @@ #include "../Config.h" #include "../Random.h" #include "EnemyConfig.h" -#include #include #include #include @@ -42,17 +41,14 @@ void EnemyScript::fixed_update(duration_t dt) { Rigidbody & enemy_body = this->get_component(); AI & ai_component = this->get_component(); - //transform.position += enemy_body.data.linear_velocity * dt.count(); float direction_to_player_y = player_transform.position.y - transform.position.y; float distance_to_player_y = std::abs(direction_to_player_y); float adjustment_speed = speed * (distance_to_player_y / MAX_DISTANCE); - //cout << "before clamp speed: " << adjustment_speed << endl; adjustment_speed = std::clamp(adjustment_speed, MIN_SPEED, MAX_SPEED); - // Move the path nodes on the Y-axis - //cout << "adjusted_speed: " << adjustment_speed << endl; Rigidbody& player_body = this->get_components_by_tag("player").front(); + // move path nodes for (vec2 & path_node : ai_component.path) { path_node.y += (direction_to_player_y > 0 ? 1 : -1) * adjustment_speed * dt.count(); path_node.x += player_body.data.linear_velocity.x * dt.count(); -- cgit v1.2.3 From b091cb7910fa82e9fb00abdb163d277ba574f804 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 9 Jan 2025 14:54:51 +0100 Subject: make format --- game/enemy/BattleScript.cpp | 4 ++-- game/enemy/EnemyBulletSubScene.cpp | 2 +- game/enemy/EnemyScript.cpp | 28 ++++++++++++---------------- game/enemy/EnemyScript.h | 1 + game/enemy/EnemySubScene.cpp | 4 ++-- game/main.cpp | 2 +- game/scheduler/ObjectsScheduler.cpp | 20 ++++++++++---------- 7 files changed, 29 insertions(+), 32 deletions(-) (limited to 'game/enemy/EnemyScript.cpp') diff --git a/game/enemy/BattleScript.cpp b/game/enemy/BattleScript.cpp index 2d1e143..cfffcb3 100644 --- a/game/enemy/BattleScript.cpp +++ b/game/enemy/BattleScript.cpp @@ -40,10 +40,10 @@ void BattleScript::spawn_enemies(int amount) { RefVector enemy_scripts = this->get_components_by_tag("enemy"); std::uniform_real_distribution dist(70, 150); - + for (int i = 0; i < amount; i++) { BehaviorScript & script = enemy_scripts[i]; - if(script.active == true) continue; + if (script.active == true) continue; script.active = true; this->queue_event( SpawnEnemyEvent { diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp index eb43f0a..c0e94e0 100644 --- a/game/enemy/EnemyBulletSubScene.cpp +++ b/game/enemy/EnemyBulletSubScene.cpp @@ -29,7 +29,7 @@ int EnemyBulletSubScene::create(Scene & scn, int counter) { .body_type = Rigidbody::BodyType::KINEMATIC, .linear_velocity = vec2 {-400, 0}, .kinematic_collision = false, - .collision_layers = {COLL_LAY_BOT_TOP,COLL_LAY_MISSILE, COLL_LAY_ZAPPER}, + .collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_MISSILE, COLL_LAY_ZAPPER}, .collision_layer = COLL_LAY_BULLET }); bullet_body.active = false; diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index 2382847..8804f50 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -2,18 +2,17 @@ #include "../Config.h" #include "../Random.h" #include "EnemyConfig.h" +#include "api/Color.h" +#include "api/Sprite.h" #include #include #include #include #include #include -#include #include +#include #include -#include "../Random.h" -#include "api/Color.h" -#include "api/Sprite.h" #include using namespace crepe; using namespace std; @@ -43,11 +42,10 @@ void EnemyScript::fixed_update(duration_t dt) { float direction_to_player_y = player_transform.position.y - transform.position.y; float distance_to_player_y = std::abs(direction_to_player_y); - float adjustment_speed = speed * (distance_to_player_y / MAX_DISTANCE); adjustment_speed = std::clamp(adjustment_speed, MIN_SPEED, MAX_SPEED); - Rigidbody& player_body = this->get_components_by_tag("player").front(); + Rigidbody & player_body = this->get_components_by_tag("player").front(); // move path nodes for (vec2 & path_node : ai_component.path) { path_node.y += (direction_to_player_y > 0 ? 1 : -1) * adjustment_speed * dt.count(); @@ -63,7 +61,7 @@ void EnemyScript::fixed_update(duration_t dt) { } std::chrono::duration elapsed_hit = now - last_hit; //hit blink timer - if(elapsed_hit > blink_time){ + if (elapsed_hit > blink_time) { set_hit_blink(false); } } @@ -92,10 +90,10 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { return false; } -void EnemyScript::set_hit_blink(bool status){ +void EnemyScript::set_hit_blink(bool status) { RefVector sprites = this->get_components(); - for(Sprite& sprite : sprites){ - if(status){ + for (Sprite & sprite : sprites) { + if (status) { sprite.data.color = Color::RED; continue; } @@ -109,13 +107,12 @@ bool EnemyScript::on_collide(const CollisionEvent & e) { last_hit = std::chrono::steady_clock::now(); //Sprite& sprite; set_hit_blink(true); - } - if(health <= 0){ + if (health <= 0) { this->despawn_enemy(); } //body_animator.play(); - + return false; } @@ -153,9 +150,8 @@ void EnemyScript::shoot(const vec2 & location) { } } -void EnemyScript::create_tank(){ +void EnemyScript::create_tank() { RefVector sprites = this->get_components(); - Sprite& tank_body = sprites[2]; + Sprite & tank_body = sprites[2]; tank_body.active = true; - } diff --git a/game/enemy/EnemyScript.h b/game/enemy/EnemyScript.h index 24799a5..2bd9742 100644 --- a/game/enemy/EnemyScript.h +++ b/game/enemy/EnemyScript.h @@ -20,6 +20,7 @@ public: void create_tank(); void create_soldier(); void set_hit_blink(bool status); + private: std::random_device rd; std::default_random_engine engine; diff --git a/game/enemy/EnemySubScene.cpp b/game/enemy/EnemySubScene.cpp index edc537f..fe9fd63 100644 --- a/game/enemy/EnemySubScene.cpp +++ b/game/enemy/EnemySubScene.cpp @@ -74,7 +74,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { .looping = true, } ); - // tanky body + // tanky body Asset tank_body_asset {"asset/workers/workerFatBody.png"}; enemy.add_component(vec2(50, 50)); Sprite & tank_body_sprite = enemy.add_component( @@ -121,7 +121,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { } ); //gun - Asset enemy_pistol_asset{"asset/workers/gun.png"}; + Asset enemy_pistol_asset {"asset/workers/gun.png"}; Sprite & enemy_pistol_sprite = enemy.add_component( enemy_pistol_asset, Sprite::Data { diff --git a/game/main.cpp b/game/main.cpp index a34121e..751cbe5 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -17,7 +17,7 @@ int main() { Config::get_instance() = ENGINE_CONFIG; Engine gameloop; - + gameloop.add_scene(); gameloop.add_scene(); gameloop.add_scene(); diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index a802806..8415ef8 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -4,8 +4,8 @@ #include "../Config.h" #include "../Random.h" -#include "../missile/SpawnEvent.h" #include "../enemy/EnemyScript.h" +#include "../missile/SpawnEvent.h" #include "api/Rigidbody.h" #include "api/Transform.h" #include "enemy/BattleScript.h" @@ -16,23 +16,23 @@ void ObjectsScheduler::preset_0() { trigger_event(MissileSpawnEvent {}); trigger_event(MissileSpawnEvent {}); this->trigger_event(BattleStartEvent { - .num_enemies = Random::i(3,1), + .num_enemies = Random::i(3, 1), .battle = false, }); } -void ObjectsScheduler::preset_1() { - trigger_event(MissileSpawnEvent {}); +void ObjectsScheduler::preset_1() { + trigger_event(MissileSpawnEvent {}); this->trigger_event(BattleStartEvent { - .num_enemies = Random::i(4,1), + .num_enemies = Random::i(4, 1), .battle = false, - }); + }); } -void ObjectsScheduler::preset_2() { +void ObjectsScheduler::preset_2() { trigger_event(CreateZapperEvent {}); this->trigger_event(BattleStartEvent { - .num_enemies = Random::i(2,1), + .num_enemies = Random::i(2, 1), .battle = false, - }); + }); } void ObjectsScheduler::preset_3() { trigger_event(CreateZapperEvent {}); } void ObjectsScheduler::preset_4() {} @@ -42,7 +42,7 @@ void ObjectsScheduler::boss_fight_1() { this->trigger_event(BattleStartEvent { .num_enemies = 7, .battle = true, - }); + }); RefVector rb_back_forest = this->get_components_by_tag("forest_background"); -- cgit v1.2.3 From dc8140877c1ae638285d812035473591a1814ce7 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 9 Jan 2025 16:06:45 +0100 Subject: enemy death working --- game/enemy/BattleScript.cpp | 30 +++++++++------ game/enemy/EnemyPool.h | 2 +- game/enemy/EnemyScript.cpp | 88 ++++++++++++++++++++++++++++++++++---------- game/enemy/EnemyScript.h | 2 + game/enemy/EnemySubScene.cpp | 29 ++------------- 5 files changed, 93 insertions(+), 58 deletions(-) (limited to 'game/enemy/EnemyScript.cpp') diff --git a/game/enemy/BattleScript.cpp b/game/enemy/BattleScript.cpp index cfffcb3..f482d5a 100644 --- a/game/enemy/BattleScript.cpp +++ b/game/enemy/BattleScript.cpp @@ -1,5 +1,7 @@ #include "BattleScript.h" #include "EnemyScript.h" +#include "../enemy/EnemyConfig.h" +#include "api/Transform.h" #include #include #include @@ -18,11 +20,11 @@ void BattleScript::init() { void BattleScript::fixed_update(duration_t dt) { if (!battle_active) return; bool enemies_alive = false; - RefVector enemy_scripts - = this->get_components_by_tag("enemy"); + RefVector enemy_ai + = this->get_components_by_tag("enemy"); - for (BehaviorScript & script : enemy_scripts) { - if (script.active) { + for (AI & ai : enemy_ai) { + if (ai.active) { enemies_alive = true; } } @@ -37,20 +39,24 @@ bool BattleScript::create_battle(const BattleStartEvent & e) { return false; } void BattleScript::spawn_enemies(int amount) { - RefVector enemy_scripts - = this->get_components_by_tag("enemy"); + RefVector enemy_ai + = this->get_components_by_tag("enemy"); std::uniform_real_distribution dist(70, 150); - - for (int i = 0; i < amount; i++) { - BehaviorScript & script = enemy_scripts[i]; - if (script.active == true) continue; - script.active = true; + int spawned = 0; + for (int i = 0; i < 7; i++) { + AI& ai = enemy_ai[i]; + Transform& enemy_transform = this->get_components_by_id(ai.game_object_id).front(); + if (ai.active == true || enemy_transform.position != ENEMY_POOL_LOCATION) continue; this->queue_event( SpawnEnemyEvent { .speed = dist(engine), .column = i, }, - script.game_object_id + ai.game_object_id ); + spawned++; + if(spawned >= amount){ + return; + } } } diff --git a/game/enemy/EnemyPool.h b/game/enemy/EnemyPool.h index f4d6765..ec96ac4 100644 --- a/game/enemy/EnemyPool.h +++ b/game/enemy/EnemyPool.h @@ -7,5 +7,5 @@ public: void create_enemies(crepe::Scene & scn); private: - static constexpr int MAXIMUM_AMOUNT = 10; + static constexpr int MAXIMUM_AMOUNT = 7; }; diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index 8804f50..c9603ce 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -1,7 +1,7 @@ #include "EnemyScript.h" #include "../Config.h" #include "../Random.h" -#include "EnemyConfig.h" +#include "../enemy/EnemyConfig.h" #include "api/Color.h" #include "api/Sprite.h" #include @@ -32,10 +32,25 @@ void EnemyScript::init() { }); }; void EnemyScript::fixed_update(duration_t dt) { - if (this->alive) { - return; + if(!spawned) return; + auto now = std::chrono::steady_clock::now(); + std::chrono::duration elapsed_hit = now - last_hit; + //hit blink timer + if (elapsed_hit > blink_time) { + set_hit_blink(false); } Transform & transform = this->get_component(); + if (!this->alive) { + Camera & camera = this->get_components_by_name("camera").front(); + Transform & cam_transform = this->get_components_by_name("camera").front(); + vec2 half_screen = camera.viewport_size / 2; + float x_value = cam_transform.position.x - half_screen.x - 100; + if(transform.position.x < x_value){ + this->despawn_enemy(); + } + return; + } + Transform & player_transform = this->get_components_by_name("player").front(); Rigidbody & enemy_body = this->get_component(); AI & ai_component = this->get_component(); @@ -52,29 +67,41 @@ void EnemyScript::fixed_update(duration_t dt) { path_node.x += player_body.data.linear_velocity.x * dt.count(); } //bullet fire logic: - auto now = std::chrono::steady_clock::now(); + std::chrono::duration elapsed = now - last_fired; if (elapsed > shot_delay) { this->shoot(transform.position); last_fired = now; this->shot_delay = std::chrono::duration(Random::f(4, 1)); } - std::chrono::duration elapsed_hit = now - last_hit; - //hit blink timer - if (elapsed_hit > blink_time) { - set_hit_blink(false); - } + } bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { + this->speed = e.speed; + this->alive = true; + this->spawned = true; + RefVector animators = this->get_components(); + for (Animator & anim : animators) { + anim.active = false; + anim.set_anim(0); + } + RefVector sprites = this->get_components(); + for (Sprite & sprite : sprites) { + sprite.data.position_offset.x = 0; + } + Sprite& jetpack = sprites[2]; + jetpack.data.position_offset.x = 20; + Sprite& gun = sprites[3]; + gun.data.position_offset.x = -20; AI & ai_component = this->get_component(); Transform & transform = this->get_component(); Camera & camera = this->get_components_by_name("camera").front(); Transform & cam_transform = this->get_components_by_name("camera").front(); vec2 half_screen = camera.viewport_size / 2; - float x_value = cam_transform.position.x + half_screen.x - 70 * (1 + e.column); + float x_value = cam_transform.position.x + half_screen.x - 60 * (1 + e.column); uniform_real_distribution dist( cam_transform.position.y - half_screen.y + 100, cam_transform.position.y + half_screen.y - 100 @@ -87,6 +114,7 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { ai_component.make_oval_path(10, 30, vec2 {x_value, random_height}, 1.5708, true); ai_component.active = true; this->last_fired = std::chrono::steady_clock::now(); + return false; } @@ -102,6 +130,7 @@ void EnemyScript::set_hit_blink(bool status) { } bool EnemyScript::on_collide(const CollisionEvent & e) { + if(!this->alive)return false; if (e.info.other.metadata.tag == "player_bullet") { this->health--; last_hit = std::chrono::steady_clock::now(); @@ -109,23 +138,44 @@ bool EnemyScript::on_collide(const CollisionEvent & e) { set_hit_blink(true); } if (health <= 0) { - this->despawn_enemy(); + this->death(); } //body_animator.play(); return false; } - +void EnemyScript::death(){ + + Rigidbody& rb = this->get_component(); + Transform& tr = this->get_component(); + RefVector animators = this->get_components(); + for (Animator & anim : animators) { + anim.active = false; + anim.set_anim(3); + } + RefVector sprites = this->get_components(); + for (Sprite & sprite : sprites) { + sprite.data.position_offset.x = 15; + } + rb.data.linear_velocity_coefficient = {0.5, 1}; + //rb.add_force_linear(vec2{0,20}); + rb.data.gravity_scale = 20; + tr.rotation = 90; + AI& ai = this->get_component(); + ai.active = false; + this->alive = false; + AI& ai_component = this->get_component(); + ai_component.active = false; +} void EnemyScript::despawn_enemy() { Transform & transform = this->get_component(); - BehaviorScript & enemy_script = this->get_component(); - enemy_script.active = false; - Animator & body_animator = this->get_components().front(); - body_animator.data.col = 2; + Rigidbody& rb = this->get_component(); + rb.data.gravity_scale = 0; + rb.data.linear_velocity = {0,0}; + transform.rotation = 0; transform.position = ENEMY_POOL_LOCATION; - AI & ai_component = this->get_component(); - // Rigidbody& enemy_body - ai_component.active = false; + + this->spawned = false; } void EnemyScript::shoot(const vec2 & location) { diff --git a/game/enemy/EnemyScript.h b/game/enemy/EnemyScript.h index 2bd9742..03343f6 100644 --- a/game/enemy/EnemyScript.h +++ b/game/enemy/EnemyScript.h @@ -17,6 +17,7 @@ public: bool on_collide(const crepe::CollisionEvent & collisionData); void despawn_enemy(); bool spawn_enemy(const SpawnEnemyEvent & e); + void death(); void create_tank(); void create_soldier(); void set_hit_blink(bool status); @@ -25,6 +26,7 @@ private: std::random_device rd; std::default_random_engine engine; bool alive = false; + bool spawned = false; float speed = 50; int health = 2; const float MIN_SPEED = 20; diff --git a/game/enemy/EnemySubScene.cpp b/game/enemy/EnemySubScene.cpp index fe9fd63..8224e2f 100644 --- a/game/enemy/EnemySubScene.cpp +++ b/game/enemy/EnemySubScene.cpp @@ -52,7 +52,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { .looping = false, } ); - enemy_body_sprite.active = false; + enemy_body_sprite.active = true; body_animator.pause(); body_animator.active = true; enemy.add_component(vec2(40, 60), vec2(-20, 0)); @@ -74,30 +74,6 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { .looping = true, } ); - // tanky body - Asset tank_body_asset {"asset/workers/workerFatBody.png"}; - enemy.add_component(vec2(50, 50)); - Sprite & tank_body_sprite = enemy.add_component( - tank_body_asset, - Sprite::Data { - .flip = {true, false}, - .sorting_in_layer = SORT_IN_LAY_WORKERS_FRONT, - .order_in_layer = 0, - .size = vec2(0, 50), - } - ); - tank_body_sprite.active = true; - Animator & tank_animator = enemy.add_component( - tank_body_sprite, ivec2(32, 32), uvec2(4, 8), - Animator::Data { - .fps = 5, - .col = 1, - .row = 0, - .looping = false, - } - ); - tank_animator.pause(); - tank_animator.active = true; //jetpack enemy.add_component(25, vec2(0, -20)); @@ -135,8 +111,9 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { enemy.add_component(Asset("asset/sfx/bike_gun_2.ogg")).volume = 0.1; AI & ai_component = enemy.add_component(3000); ai_component.path_follow_on(); + ai_component.active = false; BehaviorScript & enemy_script = enemy.add_component().set_script(); - enemy_script.active = false; + //enemy_script.active = false; return enemy_counter; } -- cgit v1.2.3 From 75cbcb0442bd8849ed109a34e7529b400eecbb30 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 9 Jan 2025 16:08:57 +0100 Subject: cleanup --- game/enemy/EnemyScript.cpp | 6 ------ game/enemy/EnemyScript.h | 2 -- game/enemy/EnemySubScene.cpp | 2 -- game/player/PlayerScript.h | 2 -- 4 files changed, 12 deletions(-) (limited to 'game/enemy/EnemyScript.cpp') diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index c9603ce..0b1a8b7 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -199,9 +199,3 @@ void EnemyScript::shoot(const vec2 & location) { } } } - -void EnemyScript::create_tank() { - RefVector sprites = this->get_components(); - Sprite & tank_body = sprites[2]; - tank_body.active = true; -} diff --git a/game/enemy/EnemyScript.h b/game/enemy/EnemyScript.h index 03343f6..be71a78 100644 --- a/game/enemy/EnemyScript.h +++ b/game/enemy/EnemyScript.h @@ -18,8 +18,6 @@ public: void despawn_enemy(); bool spawn_enemy(const SpawnEnemyEvent & e); void death(); - void create_tank(); - void create_soldier(); void set_hit_blink(bool status); private: diff --git a/game/enemy/EnemySubScene.cpp b/game/enemy/EnemySubScene.cpp index 8224e2f..ed3e555 100644 --- a/game/enemy/EnemySubScene.cpp +++ b/game/enemy/EnemySubScene.cpp @@ -52,9 +52,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { .looping = false, } ); - enemy_body_sprite.active = true; body_animator.pause(); - body_animator.active = true; enemy.add_component(vec2(40, 60), vec2(-20, 0)); Asset enemy_head_asset {"asset/workers/worker2Head.png"}; Sprite & enemy_head_sprite = enemy.add_component( diff --git a/game/player/PlayerScript.h b/game/player/PlayerScript.h index 0fe21d1..0b77caa 100644 --- a/game/player/PlayerScript.h +++ b/game/player/PlayerScript.h @@ -15,8 +15,6 @@ private: private: int prev_anim = 0; - bool gravity_mode = true; - bool fall_direction = false; std::chrono::time_point last_fired; std::chrono::time_point last_switched; std::chrono::duration shot_delay = std::chrono::duration(0.5); -- cgit v1.2.3 From e09e5d3b22f551ef462ba028530dddb6bc578257 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 9 Jan 2025 16:09:08 +0100 Subject: make format --- game/enemy/BattleScript.cpp | 15 +++++++------ game/enemy/EnemyScript.cpp | 51 ++++++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 34 deletions(-) (limited to 'game/enemy/EnemyScript.cpp') diff --git a/game/enemy/BattleScript.cpp b/game/enemy/BattleScript.cpp index f482d5a..7bea79a 100644 --- a/game/enemy/BattleScript.cpp +++ b/game/enemy/BattleScript.cpp @@ -1,6 +1,6 @@ #include "BattleScript.h" -#include "EnemyScript.h" #include "../enemy/EnemyConfig.h" +#include "EnemyScript.h" #include "api/Transform.h" #include #include @@ -20,8 +20,7 @@ void BattleScript::init() { void BattleScript::fixed_update(duration_t dt) { if (!battle_active) return; bool enemies_alive = false; - RefVector enemy_ai - = this->get_components_by_tag("enemy"); + RefVector enemy_ai = this->get_components_by_tag("enemy"); for (AI & ai : enemy_ai) { if (ai.active) { @@ -39,13 +38,13 @@ bool BattleScript::create_battle(const BattleStartEvent & e) { return false; } void BattleScript::spawn_enemies(int amount) { - RefVector enemy_ai - = this->get_components_by_tag("enemy"); + RefVector enemy_ai = this->get_components_by_tag("enemy"); std::uniform_real_distribution dist(70, 150); int spawned = 0; for (int i = 0; i < 7; i++) { - AI& ai = enemy_ai[i]; - Transform& enemy_transform = this->get_components_by_id(ai.game_object_id).front(); + AI & ai = enemy_ai[i]; + Transform & enemy_transform + = this->get_components_by_id(ai.game_object_id).front(); if (ai.active == true || enemy_transform.position != ENEMY_POOL_LOCATION) continue; this->queue_event( SpawnEnemyEvent { @@ -55,7 +54,7 @@ void BattleScript::spawn_enemies(int amount) { ai.game_object_id ); spawned++; - if(spawned >= amount){ + if (spawned >= amount) { return; } } diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index 0b1a8b7..c677dac 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -32,7 +32,7 @@ void EnemyScript::init() { }); }; void EnemyScript::fixed_update(duration_t dt) { - if(!spawned) return; + if (!spawned) return; auto now = std::chrono::steady_clock::now(); std::chrono::duration elapsed_hit = now - last_hit; //hit blink timer @@ -45,12 +45,12 @@ void EnemyScript::fixed_update(duration_t dt) { Transform & cam_transform = this->get_components_by_name("camera").front(); vec2 half_screen = camera.viewport_size / 2; float x_value = cam_transform.position.x - half_screen.x - 100; - if(transform.position.x < x_value){ + if (transform.position.x < x_value) { this->despawn_enemy(); } return; } - + Transform & player_transform = this->get_components_by_name("player").front(); Rigidbody & enemy_body = this->get_component(); AI & ai_component = this->get_component(); @@ -67,33 +67,32 @@ void EnemyScript::fixed_update(duration_t dt) { path_node.x += player_body.data.linear_velocity.x * dt.count(); } //bullet fire logic: - + std::chrono::duration elapsed = now - last_fired; if (elapsed > shot_delay) { this->shoot(transform.position); last_fired = now; this->shot_delay = std::chrono::duration(Random::f(4, 1)); } - } bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { - + this->speed = e.speed; this->alive = true; this->spawned = true; RefVector animators = this->get_components(); - for (Animator & anim : animators) { - anim.active = false; - anim.set_anim(0); - } + for (Animator & anim : animators) { + anim.active = false; + anim.set_anim(0); + } RefVector sprites = this->get_components(); for (Sprite & sprite : sprites) { - sprite.data.position_offset.x = 0; + sprite.data.position_offset.x = 0; } - Sprite& jetpack = sprites[2]; + Sprite & jetpack = sprites[2]; jetpack.data.position_offset.x = 20; - Sprite& gun = sprites[3]; + Sprite & gun = sprites[3]; gun.data.position_offset.x = -20; AI & ai_component = this->get_component(); Transform & transform = this->get_component(); @@ -114,7 +113,7 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { ai_component.make_oval_path(10, 30, vec2 {x_value, random_height}, 1.5708, true); ai_component.active = true; this->last_fired = std::chrono::steady_clock::now(); - + return false; } @@ -130,7 +129,7 @@ void EnemyScript::set_hit_blink(bool status) { } bool EnemyScript::on_collide(const CollisionEvent & e) { - if(!this->alive)return false; + if (!this->alive) return false; if (e.info.other.metadata.tag == "player_bullet") { this->health--; last_hit = std::chrono::steady_clock::now(); @@ -144,10 +143,10 @@ bool EnemyScript::on_collide(const CollisionEvent & e) { return false; } -void EnemyScript::death(){ - - Rigidbody& rb = this->get_component(); - Transform& tr = this->get_component(); +void EnemyScript::death() { + + Rigidbody & rb = this->get_component(); + Transform & tr = this->get_component(); RefVector animators = this->get_components(); for (Animator & anim : animators) { anim.active = false; @@ -155,26 +154,26 @@ void EnemyScript::death(){ } RefVector sprites = this->get_components(); for (Sprite & sprite : sprites) { - sprite.data.position_offset.x = 15; - } + sprite.data.position_offset.x = 15; + } rb.data.linear_velocity_coefficient = {0.5, 1}; //rb.add_force_linear(vec2{0,20}); rb.data.gravity_scale = 20; tr.rotation = 90; - AI& ai = this->get_component(); + AI & ai = this->get_component(); ai.active = false; this->alive = false; - AI& ai_component = this->get_component(); + AI & ai_component = this->get_component(); ai_component.active = false; } void EnemyScript::despawn_enemy() { Transform & transform = this->get_component(); - Rigidbody& rb = this->get_component(); + Rigidbody & rb = this->get_component(); rb.data.gravity_scale = 0; - rb.data.linear_velocity = {0,0}; + rb.data.linear_velocity = {0, 0}; transform.rotation = 0; transform.position = ENEMY_POOL_LOCATION; - + this->spawned = false; } -- cgit v1.2.3 From c1325d3e979e294fced8f80ce43dd1eb86d7f5df Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Fri, 10 Jan 2025 10:12:41 +0100 Subject: balance changes --- game/enemy/EnemyBulletSubScene.cpp | 2 +- game/enemy/EnemyScript.cpp | 11 +++++++---- game/player/PlayerBulletSubScene.cpp | 2 +- game/scheduler/ObjectsScheduler.cpp | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) (limited to 'game/enemy/EnemyScript.cpp') diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp index fb3a4cd..1406660 100644 --- a/game/enemy/EnemyBulletSubScene.cpp +++ b/game/enemy/EnemyBulletSubScene.cpp @@ -28,7 +28,7 @@ int EnemyBulletSubScene::create(Scene & scn, int counter) { Rigidbody & bullet_body = bullet.add_component(Rigidbody::Data { .gravity_scale = 0, .body_type = Rigidbody::BodyType::KINEMATIC, - .linear_velocity = vec2 {-350, 0}, + .linear_velocity = vec2 {-300, 0}, .kinematic_collision = false, .collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_MISSILE, COLL_LAY_ZAPPER}, .collision_layer = COLL_LAY_BULLET diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index c677dac..e3c8e9f 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -14,6 +14,7 @@ #include #include #include +#include using namespace crepe; using namespace std; EnemyScript::EnemyScript() { @@ -72,7 +73,7 @@ void EnemyScript::fixed_update(duration_t dt) { if (elapsed > shot_delay) { this->shoot(transform.position); last_fired = now; - this->shot_delay = std::chrono::duration(Random::f(4, 1)); + this->shot_delay = std::chrono::duration(Random::f(4, 1.5)); } } @@ -100,7 +101,7 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { Transform & cam_transform = this->get_components_by_name("camera").front(); vec2 half_screen = camera.viewport_size / 2; - float x_value = cam_transform.position.x + half_screen.x - 60 * (1 + e.column); + float x_value = cam_transform.position.x + half_screen.x - 40 * (1 + e.column); uniform_real_distribution dist( cam_transform.position.y - half_screen.y + 100, cam_transform.position.y + half_screen.y - 100 @@ -131,14 +132,16 @@ void EnemyScript::set_hit_blink(bool status) { bool EnemyScript::on_collide(const CollisionEvent & e) { if (!this->alive) return false; if (e.info.other.metadata.tag == "player_bullet") { + cout << "health: " << health << endl; this->health--; last_hit = std::chrono::steady_clock::now(); //Sprite& sprite; set_hit_blink(true); - } - if (health <= 0) { + if (health <= 0) { this->death(); } + } + //body_animator.play(); return false; diff --git a/game/player/PlayerBulletSubScene.cpp b/game/player/PlayerBulletSubScene.cpp index 5e1c66e..82ce4a9 100644 --- a/game/player/PlayerBulletSubScene.cpp +++ b/game/player/PlayerBulletSubScene.cpp @@ -24,7 +24,7 @@ int PlayerBulletSubScene::create(Scene & scn, int counter) { Rigidbody & player_bullet_body = player_bullet.add_component(Rigidbody::Data { .gravity_scale = 0, .body_type = Rigidbody::BodyType::KINEMATIC, - .linear_velocity = vec2 {400, 0}, + .linear_velocity = vec2 {450, 0}, .angular_velocity = 300, .kinematic_collision = false, .collision_layers = {COLL_LAY_ENEMY, COLL_LAY_ZAPPER}, diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index 8415ef8..816e1ee 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -16,14 +16,14 @@ void ObjectsScheduler::preset_0() { trigger_event(MissileSpawnEvent {}); trigger_event(MissileSpawnEvent {}); this->trigger_event(BattleStartEvent { - .num_enemies = Random::i(3, 1), + .num_enemies = Random::i(2, 1), .battle = false, }); } void ObjectsScheduler::preset_1() { trigger_event(MissileSpawnEvent {}); this->trigger_event(BattleStartEvent { - .num_enemies = Random::i(4, 1), + .num_enemies = Random::i(2, 1), .battle = false, }); } -- cgit v1.2.3 From a9c6e86e4d95f4f4986be9016779dcc26a925862 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Fri, 10 Jan 2025 11:10:05 +0100 Subject: animation working + removed bullet colliding with dead enemies --- game/enemy/EnemyBulletSubScene.cpp | 2 +- game/enemy/EnemyScript.cpp | 12 ++++++++---- game/enemy/EnemySubScene.cpp | 6 +++--- game/player/PlayerScript.cpp | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) (limited to 'game/enemy/EnemyScript.cpp') diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp index 1406660..bc31ba8 100644 --- a/game/enemy/EnemyBulletSubScene.cpp +++ b/game/enemy/EnemyBulletSubScene.cpp @@ -30,7 +30,7 @@ int EnemyBulletSubScene::create(Scene & scn, int counter) { .body_type = Rigidbody::BodyType::KINEMATIC, .linear_velocity = vec2 {-300, 0}, .kinematic_collision = false, - .collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_MISSILE, COLL_LAY_ZAPPER}, + .collision_layers = {COLL_LAY_MISSILE, COLL_LAY_ZAPPER}, .collision_layer = COLL_LAY_BULLET }); bullet_body.active = false; diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index e3c8e9f..22431fd 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -82,6 +82,7 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { this->speed = e.speed; this->alive = true; this->spawned = true; + this->health = 2; RefVector animators = this->get_components(); for (Animator & anim : animators) { anim.active = false; @@ -99,7 +100,9 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { Transform & transform = this->get_component(); Camera & camera = this->get_components_by_name("camera").front(); Transform & cam_transform = this->get_components_by_name("camera").front(); - + Rigidbody& rb = this->get_component(); + rb.data.collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_PLAYER_BULLET}; + rb.data.collision_layer = COLL_LAY_ENEMY; vec2 half_screen = camera.viewport_size / 2; float x_value = cam_transform.position.x + half_screen.x - 40 * (1 + e.column); uniform_real_distribution dist( @@ -132,7 +135,6 @@ void EnemyScript::set_hit_blink(bool status) { bool EnemyScript::on_collide(const CollisionEvent & e) { if (!this->alive) return false; if (e.info.other.metadata.tag == "player_bullet") { - cout << "health: " << health << endl; this->health--; last_hit = std::chrono::steady_clock::now(); //Sprite& sprite; @@ -160,8 +162,10 @@ void EnemyScript::death() { sprite.data.position_offset.x = 15; } rb.data.linear_velocity_coefficient = {0.5, 1}; - //rb.add_force_linear(vec2{0,20}); - rb.data.gravity_scale = 20; + rb.data.collision_layers = {COLL_LAY_BOT_TOP}; + rb.data.collision_layer = 0; + + rb.data.gravity_scale = 1; tr.rotation = 90; AI & ai = this->get_component(); ai.active = false; diff --git a/game/enemy/EnemySubScene.cpp b/game/enemy/EnemySubScene.cpp index ed3e555..d1117d8 100644 --- a/game/enemy/EnemySubScene.cpp +++ b/game/enemy/EnemySubScene.cpp @@ -33,7 +33,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { }); // normal body Asset enemy_body_asset {"asset/workers/worker2Body.png"}; - enemy.add_component(vec2(50, 50)); + enemy.add_component(vec2(40, 60)); Sprite & enemy_body_sprite = enemy.add_component( enemy_body_asset, Sprite::Data { @@ -53,7 +53,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { } ); body_animator.pause(); - enemy.add_component(vec2(40, 60), vec2(-20, 0)); + Asset enemy_head_asset {"asset/workers/worker2Head.png"}; Sprite & enemy_head_sprite = enemy.add_component( enemy_head_asset, @@ -74,7 +74,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { ); //jetpack - enemy.add_component(25, vec2(0, -20)); + //enemy.add_component(25, vec2(0, -20)); Asset enemy_jetpack_asset {"asset/barry/jetpackDefault.png"}; Sprite & enemy_jetpack_sprite = enemy.add_component( enemy_jetpack_asset, diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index c3843ca..0fadade 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -159,7 +159,7 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { if (current_jetpack_sound > 7) { current_jetpack_sound = 0; } - } else if (transform.position.y == 195) { + } else if (transform.position.y == 200) { Rigidbody & rb = this->body; if (prev_anim != 0 && rb.data.linear_velocity.x != 0) { for (Animator & anim : animators) { -- cgit v1.2.3 From 9246924d2885cdf236a08d20945a4526000cfe39 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Fri, 10 Jan 2025 11:10:38 +0100 Subject: removed iostream --- game/enemy/EnemyScript.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'game/enemy/EnemyScript.cpp') diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index 22431fd..77c9bd2 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -14,7 +14,6 @@ #include #include #include -#include using namespace crepe; using namespace std; EnemyScript::EnemyScript() { -- cgit v1.2.3 From 22d77b99d700e6317a7432e475330e4bb3c9745d Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Fri, 10 Jan 2025 11:11:53 +0100 Subject: make format --- game/enemy/EnemyPool.h | 3 +-- game/enemy/EnemyScript.cpp | 8 ++++---- game/enemy/EnemySubScene.cpp | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'game/enemy/EnemyScript.cpp') diff --git a/game/enemy/EnemyPool.h b/game/enemy/EnemyPool.h index 25f7fb8..cfd0b1c 100644 --- a/game/enemy/EnemyPool.h +++ b/game/enemy/EnemyPool.h @@ -1,9 +1,8 @@ #pragma once -#include #include "EnemyConfig.h" +#include class EnemyPool { public: void create_enemies(crepe::Scene & scn); - }; diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index 77c9bd2..24583c0 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -99,7 +99,7 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { Transform & transform = this->get_component(); Camera & camera = this->get_components_by_name("camera").front(); Transform & cam_transform = this->get_components_by_name("camera").front(); - Rigidbody& rb = this->get_component(); + Rigidbody & rb = this->get_component(); rb.data.collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_PLAYER_BULLET}; rb.data.collision_layer = COLL_LAY_ENEMY; vec2 half_screen = camera.viewport_size / 2; @@ -139,10 +139,10 @@ bool EnemyScript::on_collide(const CollisionEvent & e) { //Sprite& sprite; set_hit_blink(true); if (health <= 0) { - this->death(); - } + this->death(); + } } - + //body_animator.play(); return false; diff --git a/game/enemy/EnemySubScene.cpp b/game/enemy/EnemySubScene.cpp index d1117d8..c6aecec 100644 --- a/game/enemy/EnemySubScene.cpp +++ b/game/enemy/EnemySubScene.cpp @@ -53,7 +53,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { } ); body_animator.pause(); - + Asset enemy_head_asset {"asset/workers/worker2Head.png"}; Sprite & enemy_head_sprite = enemy.add_component( enemy_head_asset, -- cgit v1.2.3 From d7c8cc30e1d37526cf142f950038500b96760514 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Fri, 10 Jan 2025 14:07:30 +0100 Subject: balance changes --- game/enemy/EnemyScript.cpp | 4 ++-- game/scheduler/ObjectsScheduler.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'game/enemy/EnemyScript.cpp') diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index 24583c0..0822c29 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -19,7 +19,7 @@ using namespace std; EnemyScript::EnemyScript() { engine.seed(rd()); this->last_fired = std::chrono::steady_clock::now(); - this->shot_delay = std::chrono::duration(3 + Random::f(1, 0)); + this->shot_delay = std::chrono::duration(1.5 + Random::f(2, 0)); } void EnemyScript::init() { Metadata & meta = this->get_component(); @@ -72,7 +72,7 @@ void EnemyScript::fixed_update(duration_t dt) { if (elapsed > shot_delay) { this->shoot(transform.position); last_fired = now; - this->shot_delay = std::chrono::duration(Random::f(4, 1.5)); + this->shot_delay = std::chrono::duration(Random::f(3, 1.5)); } } diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index 816e1ee..c33c707 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -16,7 +16,7 @@ void ObjectsScheduler::preset_0() { trigger_event(MissileSpawnEvent {}); trigger_event(MissileSpawnEvent {}); this->trigger_event(BattleStartEvent { - .num_enemies = Random::i(2, 1), + .num_enemies = Random::i(2, 0), .battle = false, }); } @@ -40,7 +40,7 @@ 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 = 7, + .num_enemies = 5, .battle = true, }); -- cgit v1.2.3