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/EnemyBulletSubScene.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'game/enemy/EnemyBulletSubScene.cpp') diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp index ad2ca9d..eb43f0a 100644 --- a/game/enemy/EnemyBulletSubScene.cpp +++ b/game/enemy/EnemyBulletSubScene.cpp @@ -27,14 +27,13 @@ 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 {-250, 0}, + .linear_velocity = vec2 {-400, 0}, .kinematic_collision = false, - .collision_layers = {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; - BoxCollider & bullet_collider = bullet.add_component(vec2(60, 30)); + BoxCollider & bullet_collider = bullet.add_component(vec2(40, 10)); //bullet_collider.active = false; Asset bullet_asset {"asset/other_effects/effect_smgbullet_x2.png"}; Sprite & bullet_sprite = bullet.add_component( -- 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/EnemyBulletSubScene.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 8d4fd0798fcdef1d90b35358f20e5cd636685e5c Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 9 Jan 2025 16:09:39 +0100 Subject: decreased bullet --- game/enemy/EnemyBulletSubScene.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'game/enemy/EnemyBulletSubScene.cpp') diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp index c0e94e0..e726284 100644 --- a/game/enemy/EnemyBulletSubScene.cpp +++ b/game/enemy/EnemyBulletSubScene.cpp @@ -27,7 +27,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 {-400, 0}, + .linear_velocity = vec2 {-350, 0}, .kinematic_collision = false, .collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_MISSILE, COLL_LAY_ZAPPER}, .collision_layer = COLL_LAY_BULLET -- cgit v1.2.3 From cb81d9c3bbb57404dc469dd16cf3bb9c15c1cd5d Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 9 Jan 2025 16:10:54 +0100 Subject: changed bullet color --- game/enemy/EnemyBulletSubScene.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'game/enemy/EnemyBulletSubScene.cpp') diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp index e726284..fb3a4cd 100644 --- a/game/enemy/EnemyBulletSubScene.cpp +++ b/game/enemy/EnemyBulletSubScene.cpp @@ -16,6 +16,7 @@ #include "EnemyBulletScript.h" #include "EnemyBulletSubScene.h" #include "EnemyScript.h" +#include "api/Color.h" using namespace crepe; using namespace std; int EnemyBulletSubScene::create(Scene & scn, int counter) { @@ -39,6 +40,7 @@ int EnemyBulletSubScene::create(Scene & scn, int counter) { Sprite & bullet_sprite = bullet.add_component( bullet_asset, Sprite::Data { + .color = Color::BLUE, .flip = {true, false}, .sorting_in_layer = SORT_IN_LAY_OBSTACLES, .order_in_layer = 1, -- 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/EnemyBulletSubScene.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/EnemyBulletSubScene.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