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/player/PlayerScript.cpp | 6 ++++++ game/player/PlayerScript.h | 5 ++++- game/player/PlayerSubScene.cpp | 7 ++++--- 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'game/player') diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index fadca9c..c072e06 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -104,6 +104,12 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { last_fired = now; } } + if (this->get_key_state(Keycode::P)) { + this->trigger_event(BattleStartEvent{ + .num_enemies = 4, + .battle = true, + }); + } if (this->get_key_state(Keycode::SPACE)) { rb.add_force_linear(vec2(0, -PLAYER_GRAVITY_SCALE / 2.5) * dt.count() / 0.02); if (prev_anim != 1) { diff --git a/game/player/PlayerScript.h b/game/player/PlayerScript.h index e7d860a..0fe21d1 100644 --- a/game/player/PlayerScript.h +++ b/game/player/PlayerScript.h @@ -15,8 +15,11 @@ 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); - + std::chrono::duration switch_delay = std::chrono::duration(0.01); int current_jetpack_sound = 0; }; diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index c4d689a..245f19c 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -22,7 +22,7 @@ using namespace crepe; using namespace std; PlayerSubScene::PlayerSubScene(Scene & scn) { - GameObject player = scn.new_object("player", "player", vec2(-100, 200)); + GameObject player = scn.new_object("player", "player", vec2(200, 200)); Asset player_bullet {"asset/other_effects/effect_smgbullet.png"}; Sprite & player_bullet_sprite = player.add_component( @@ -106,7 +106,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .looping = true, } ); - player.add_component(vec2(50, 50)); + player.add_component(vec2(35, 35)); Asset player_head_asset {"asset/barry/defaultHead.png"}; Sprite & player_head_sprite = player.add_component( player_head_asset, @@ -143,7 +143,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .looping = true, } ); - player.add_component(vec2(40, 60), vec2(-20, 0)); + player.add_component(vec2(40, 50), vec2(-20, 0)); player.add_component(Rigidbody::Data { .gravity_scale = PLAYER_GRAVITY_SCALE, .body_type = Rigidbody::BodyType::DYNAMIC, @@ -153,6 +153,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { }, .collision_layer = COLL_LAY_PLAYER, }); + player.add_component().set_script().active = false; player.add_component().set_script(); player.add_component().set_script().active = false; -- cgit v1.2.3 From 8bd94b7a0a1eb7c2f6ca003fac95bea858671218 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 9 Jan 2025 14:51:48 +0100 Subject: removed player spawn battle --- game/player/PlayerScript.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'game/player') diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index c072e06..1283d0a 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -104,12 +104,7 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { last_fired = now; } } - if (this->get_key_state(Keycode::P)) { - this->trigger_event(BattleStartEvent{ - .num_enemies = 4, - .battle = true, - }); - } + if (this->get_key_state(Keycode::SPACE)) { rb.add_force_linear(vec2(0, -PLAYER_GRAVITY_SCALE / 2.5) * dt.count() / 0.02); if (prev_anim != 1) { -- cgit v1.2.3 From 843d27e8f68bf3d3d39baedb7a5c53154160afd7 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 9 Jan 2025 14:54:40 +0100 Subject: fixed some player features --- game/player/PlayerScript.cpp | 1 - game/player/PlayerSubScene.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'game/player') diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index 1283d0a..fadca9c 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -104,7 +104,6 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { last_fired = now; } } - if (this->get_key_state(Keycode::SPACE)) { rb.add_force_linear(vec2(0, -PLAYER_GRAVITY_SCALE / 2.5) * dt.count() / 0.02); if (prev_anim != 1) { diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index 245f19c..dfcd763 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -22,7 +22,7 @@ using namespace crepe; using namespace std; PlayerSubScene::PlayerSubScene(Scene & scn) { - GameObject player = scn.new_object("player", "player", vec2(200, 200)); + GameObject player = scn.new_object("player", "player", vec2(-100, 200)); Asset player_bullet {"asset/other_effects/effect_smgbullet.png"}; Sprite & player_bullet_sprite = player.add_component( @@ -106,7 +106,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .looping = true, } ); - player.add_component(vec2(35, 35)); + player.add_component(vec2(50, 35)); Asset player_head_asset {"asset/barry/defaultHead.png"}; Sprite & player_head_sprite = player.add_component( player_head_asset, -- 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/player') 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 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/player') 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/player') 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