From 192aea3112af0b36f6f26670e66c7e24926c579a Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 12:10:28 +0100 Subject: Added collision animations --- game/Config.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'game/Config.h') diff --git a/game/Config.h b/game/Config.h index ec753df..796ad6c 100644 --- a/game/Config.h +++ b/game/Config.h @@ -13,6 +13,9 @@ static constexpr int COLL_LAY_BOT_LOW = 2; // Only for GameScene static constexpr int COLL_LAY_BOT_HIGH = 3; // Only for GameScene static constexpr int COLL_LAY_PLAYER = 4; // Only for GameScene static constexpr int COLL_LAY_WALL_FRAGS = 5; // Only for GameScene +static constexpr int COLL_LAY_ZAPPER = 6; // Only for GameScene +static constexpr int COLL_LAY_LASER = 7; // Only for GameScene +static constexpr int COLL_LAY_MISSILE = 8; // Only for GameScene static constexpr int GAME_HEIGHT = 800; // In game units -- cgit v1.2.3 From e7cebc43f567b0fa1701d953a9f25d5f527e89bb Mon Sep 17 00:00:00 2001 From: Max-001 Date: Sun, 29 Dec 2024 12:29:40 +0100 Subject: Added Player params to Config --- game/Config.h | 3 +++ game/StartGameScript.cpp | 3 ++- game/player/PlayerEndScript.cpp | 4 +++- game/player/PlayerScript.cpp | 5 +++-- game/player/PlayerSubScene.cpp | 4 ++-- 5 files changed, 13 insertions(+), 6 deletions(-) (limited to 'game/Config.h') diff --git a/game/Config.h b/game/Config.h index 796ad6c..973944e 100644 --- a/game/Config.h +++ b/game/Config.h @@ -22,3 +22,6 @@ static constexpr int GAME_HEIGHT = 800; // In game units static constexpr int VIEWPORT_X = 1100; // In game units // 'GAME_HEIGHT' (below) should be replaced by '500' when game development is finished static constexpr int VIEWPORT_Y = GAME_HEIGHT; // In game units + +static constexpr int PLAYER_SPEED = 100; // In game units +static constexpr int PLAYER_GRAVITY_SCALE = 40; // In game units diff --git a/game/StartGameScript.cpp b/game/StartGameScript.cpp index 50ba86c..72bdcd5 100644 --- a/game/StartGameScript.cpp +++ b/game/StartGameScript.cpp @@ -1,4 +1,5 @@ #include "StartGameScript.h" +#include "Config.h" #include #include @@ -50,7 +51,7 @@ void StartGameScript::fixed_update(crepe::duration_t dt) { // Start camera movement, enable player jumping and disable this script if (player_transform.position.x > 500) { Rigidbody & rb = this->get_components_by_name("camera").front(); - rb.data.linear_velocity = vec2(100, 0); + rb.data.linear_velocity = vec2(PLAYER_SPEED, 0); BehaviorScript & player_script = this->get_components_by_name("player").front(); player_script.active = true; diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp index 80d3011..8833c28 100644 --- a/game/player/PlayerEndScript.cpp +++ b/game/player/PlayerEndScript.cpp @@ -1,5 +1,7 @@ #include "PlayerEndScript.h" +#include "../Config.h" + #include #include #include @@ -50,7 +52,7 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { } else if (jump == 2) { rb_player.data.angular_velocity = 0; rb_player.data.elasticity_coefficient = 0; - rb_player.data.linear_velocity = vec2(100, 0); + rb_player.data.linear_velocity = vec2(PLAYER_SPEED, 0); rb_player.data.linear_velocity_coefficient = vec2(0.5, 0.5); rb_camera.data.linear_velocity_coefficient = vec2(0.5, 0.5); for (Animator & anim : anim_player) { diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index 7f5d0c4..3b4cc5e 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -1,5 +1,6 @@ #include "PlayerScript.h" -#include "api/BehaviorScript.h" + +#include "../Config.h" #include #include @@ -79,7 +80,7 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { Rigidbody & rb = this->get_components_by_name("player").front(); if (this->get_key_state(Keycode::SPACE)) { - rb.add_force_linear(vec2(0, -10)); + rb.add_force_linear(vec2(0, -PLAYER_GRAVITY_SCALE / 3)); if (prev_anim != 1) { for (Animator & anim : animators) { anim.active = true; diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index 91ae882..7e78e82 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -141,9 +141,9 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { ); player.add_component(vec2(40, 60), vec2(-20, 0)); player.add_component(Rigidbody::Data { - .gravity_scale = 20, + .gravity_scale = PLAYER_GRAVITY_SCALE, .body_type = Rigidbody::BodyType::DYNAMIC, - .linear_velocity = vec2(100, 0), + .linear_velocity = vec2(PLAYER_SPEED, 0), .collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_ZAPPER, COLL_LAY_LASER, COLL_LAY_MISSILE}, .collision_layer = COLL_LAY_PLAYER, -- cgit v1.2.3 From a4576c3bab0901074c53209c141b2a767c60d38a Mon Sep 17 00:00:00 2001 From: Max-001 Date: Mon, 6 Jan 2025 09:56:37 +0100 Subject: Improved Player speed and velocity --- game/Config.h | 4 ++-- game/player/PlayerScript.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'game/Config.h') diff --git a/game/Config.h b/game/Config.h index 973944e..1e51141 100644 --- a/game/Config.h +++ b/game/Config.h @@ -23,5 +23,5 @@ static constexpr int VIEWPORT_X = 1100; // In game units // 'GAME_HEIGHT' (below) should be replaced by '500' when game development is finished static constexpr int VIEWPORT_Y = GAME_HEIGHT; // In game units -static constexpr int PLAYER_SPEED = 100; // In game units -static constexpr int PLAYER_GRAVITY_SCALE = 40; // In game units +static constexpr int PLAYER_SPEED = 150; // In game units +static constexpr int PLAYER_GRAVITY_SCALE = 60; // In game units diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index 3b4cc5e..c4ed6a0 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -80,7 +80,7 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { Rigidbody & rb = this->get_components_by_name("player").front(); if (this->get_key_state(Keycode::SPACE)) { - rb.add_force_linear(vec2(0, -PLAYER_GRAVITY_SCALE / 3)); + rb.add_force_linear(vec2(0, -PLAYER_GRAVITY_SCALE / 2.5)); if (prev_anim != 1) { for (Animator & anim : animators) { anim.active = true; -- cgit v1.2.3 From 20ae1e9dc2043ef3c190f77dd5f9de74bcd533de Mon Sep 17 00:00:00 2001 From: Max-001 Date: Mon, 6 Jan 2025 11:11:25 +0100 Subject: Added dt --- game/Config.h | 2 +- game/StartGameScript.cpp | 2 +- game/player/PlayerEndScript.cpp | 7 +++++-- game/player/PlayerSubScene.cpp | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) (limited to 'game/Config.h') diff --git a/game/Config.h b/game/Config.h index 1e51141..d6f8349 100644 --- a/game/Config.h +++ b/game/Config.h @@ -23,5 +23,5 @@ static constexpr int VIEWPORT_X = 1100; // In game units // 'GAME_HEIGHT' (below) should be replaced by '500' when game development is finished static constexpr int VIEWPORT_Y = GAME_HEIGHT; // In game units -static constexpr int PLAYER_SPEED = 150; // In game units +static constexpr int PLAYER_SPEED = 7500; // In game units static constexpr int PLAYER_GRAVITY_SCALE = 60; // In game units diff --git a/game/StartGameScript.cpp b/game/StartGameScript.cpp index 72bdcd5..c786eb4 100644 --- a/game/StartGameScript.cpp +++ b/game/StartGameScript.cpp @@ -51,7 +51,7 @@ void StartGameScript::fixed_update(crepe::duration_t dt) { // Start camera movement, enable player jumping and disable this script if (player_transform.position.x > 500) { Rigidbody & rb = this->get_components_by_name("camera").front(); - rb.data.linear_velocity = vec2(PLAYER_SPEED, 0); + rb.data.linear_velocity = vec2(PLAYER_SPEED * dt.count(), 0); BehaviorScript & player_script = this->get_components_by_name("player").front(); player_script.active = true; diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp index 4cd2cd0..e04fb9d 100644 --- a/game/player/PlayerEndScript.cpp +++ b/game/player/PlayerEndScript.cpp @@ -1,6 +1,7 @@ #include "PlayerEndScript.h" #include "../Config.h" +#include "manager/LoopTimerManager.h" #include #include @@ -28,6 +29,8 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { Rigidbody & rb_player = this->get_components_by_name("player").front(); Rigidbody & rb_camera = this->get_components_by_name("camera").front(); + float dt = this->get_loop_timer().get_fixed_delta_time().count(); + if (jump == 0) { int random_number = rand() % 4; for (Animator & anim : anim_player) { @@ -44,7 +47,7 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { } if (jump == 0) { - rb_player.data.angular_velocity = 320; + rb_player.data.angular_velocity = 16000 * dt; rb_player.data.angular_velocity_coefficient = 0.7; jump++; } else if (jump == 1) { @@ -58,7 +61,7 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { rb_player.data.angular_velocity = 0; rb_player.data.elasticity_coefficient = 0; - rb_player.data.linear_velocity = vec2(PLAYER_SPEED, 0); + rb_player.data.linear_velocity = vec2(PLAYER_SPEED * dt, 0); rb_player.data.linear_velocity_coefficient = vec2(0.5, 0.5); rb_camera.data.linear_velocity_coefficient = vec2(0.5, 0.5); for (Animator & anim : anim_player) { diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index 7e78e82..c1e5e2f 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -143,7 +143,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { player.add_component(Rigidbody::Data { .gravity_scale = PLAYER_GRAVITY_SCALE, .body_type = Rigidbody::BodyType::DYNAMIC, - .linear_velocity = vec2(PLAYER_SPEED, 0), + .linear_velocity = vec2(PLAYER_SPEED * 0.02, 0), .collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_ZAPPER, COLL_LAY_LASER, COLL_LAY_MISSILE}, .collision_layer = COLL_LAY_PLAYER, -- cgit v1.2.3