From d15de7503f2f7320e23863a11e97fcd401bc2eeb Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 09:45:44 +0100 Subject: Moved Player files to seperate folder --- game/player/PlayerSubScene.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 game/player/PlayerSubScene.cpp (limited to 'game/player/PlayerSubScene.cpp') diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp new file mode 100644 index 0000000..00b7810 --- /dev/null +++ b/game/player/PlayerSubScene.cpp @@ -0,0 +1,76 @@ +#include "PlayerSubScene.h" +#include "Config.h" +#include "PlayerScript.h" + +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +PlayerSubScene::PlayerSubScene(Scene & scn) { + GameObject player = scn.new_object("player", "player", vec2(-100, 200)); + Asset player_body_asset {"asset/barry/defaultBody.png"}; + Sprite & player_body_sprite = player.add_component( + player_body_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 0, + .size = vec2(0, 50), + } + ); + player.add_component( + player_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = 5, + .looping = true, + } + ); + Asset player_head_asset {"asset/barry/defaultHead.png"}; + Sprite & player_head_sprite = player.add_component( + player_head_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 1, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + player.add_component( + player_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = 5, + .looping = true, + } + ); + Asset player_jetpack_asset {"asset/barry/jetpackDefault.png"}; + Sprite & player_jetpack_sprite = player.add_component( + player_jetpack_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 2, + .size = vec2(0, 60), + .position_offset = vec2(-20, 0), + } + ); + player_jetpack_sprite.active = false; + player.add_component( + player_jetpack_sprite, ivec2(32, 44), uvec2(4, 4), + Animator::Data { + .fps = 5, + .looping = true, + } + ); + player.add_component(Rigidbody::Data { + .gravity_scale = 20, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2(100, 0), + .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layer = COLL_LAY_PLAYER, + }); + player.add_component(vec2(50, 50)); + player.add_component().set_script().active = false; +} -- cgit v1.2.3 From a5d68e4ea0a858235aee47339af0b223c87817c5 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 09:46:45 +0100 Subject: Moved Player files to seperate folder --- game/player/PlayerSubScene.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'game/player/PlayerSubScene.cpp') diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index 00b7810..42b969c 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -1,7 +1,8 @@ #include "PlayerSubScene.h" -#include "Config.h" #include "PlayerScript.h" +#include "../Config.h" + #include #include #include -- cgit v1.2.3 From 2691f8ef665d38f04d6aa8f38681b68ca0c852ea Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 09:54:33 +0100 Subject: Added correct colliders --- game/player/PlayerSubScene.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'game/player/PlayerSubScene.cpp') diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index 42b969c..2e73546 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -2,8 +2,11 @@ #include "PlayerScript.h" #include "../Config.h" +#include "api/BoxCollider.h" +#include "types.h" #include +#include #include #include #include @@ -30,6 +33,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .looping = true, } ); + player.add_component(vec2(50, 50)); Asset player_head_asset {"asset/barry/defaultHead.png"}; Sprite & player_head_sprite = player.add_component( player_head_asset, @@ -47,6 +51,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .looping = true, } ); + player.add_component(25, vec2(0, -20)); Asset player_jetpack_asset {"asset/barry/jetpackDefault.png"}; Sprite & player_jetpack_sprite = player.add_component( player_jetpack_asset, @@ -65,6 +70,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .looping = true, } ); + player.add_component(vec2(40, 60), vec2(-20, 0)); player.add_component(Rigidbody::Data { .gravity_scale = 20, .body_type = Rigidbody::BodyType::DYNAMIC, @@ -72,6 +78,5 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .collision_layers = {COLL_LAY_BOT_TOP}, .collision_layer = COLL_LAY_PLAYER, }); - player.add_component(vec2(50, 50)); player.add_component().set_script().active = false; } -- cgit v1.2.3 From 7a6658510ba48c2fbe77e50f36452b0407f7d840 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 11:36:19 +0100 Subject: Implemented particle emmitters --- game/player/PlayerScript.cpp | 16 ++++++++++ game/player/PlayerSubScene.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) (limited to 'game/player/PlayerSubScene.cpp') diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index 874324e..04e7264 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -1,6 +1,7 @@ #include "PlayerScript.h" #include +#include #include #include #include @@ -10,8 +11,14 @@ using namespace std; void PlayerScript::fixed_update(crepe::duration_t dt) { RefVector animators = this->get_components_by_name("player"); + RefVector emitters + = this->get_components_by_name("player"); Transform & transform = this->get_components_by_name("player").front(); + for (ParticleEmitter & emitter : emitters) { + emitter.data.boundary.offset = vec2(0, -transform.position.y); + } + Rigidbody & rb = this->get_components_by_name("player").front(); if (this->get_key_state(Keycode::SPACE)) { rb.add_force_linear(vec2(0, -10)); @@ -22,6 +29,9 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { anim.data.looping = true; prev_anim = 1; } + for (ParticleEmitter & emitter : emitters) { + emitter.data.emission_rate = 30; + } } } else if (transform.position.y == 195) { if (prev_anim != 0) { @@ -31,6 +41,9 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { anim.data.looping = true; prev_anim = 0; } + for (ParticleEmitter & emitter : emitters) { + emitter.data.emission_rate = 0; + } } } else { if (prev_anim != 2) { @@ -39,6 +52,9 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { anim.data.looping = false; prev_anim = 2; } + for (ParticleEmitter & emitter : emitters) { + emitter.data.emission_rate = 0; + } } } } diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index 2e73546..166d54b 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -3,6 +3,7 @@ #include "../Config.h" #include "api/BoxCollider.h" +#include "api/ParticleEmitter.h" #include "types.h" #include @@ -17,6 +18,73 @@ using namespace std; PlayerSubScene::PlayerSubScene(Scene & scn) { 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( + player_bullet, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 3, + .size = vec2(0, 6), + } + ); + player.add_component(player_bullet_sprite, ParticleEmitter::Data{ + .offset = vec2(-15, 15), + .emission_rate = 0, + .min_speed = 300, + .max_speed = 500, + .min_angle = 85, + .max_angle = 100, + .boundary = ParticleEmitter::Boundary { + .height = 400, + .reset_on_exit = true, + }, + }); + Asset player_bullet_x2 {"asset/other_effects/effect_smgbullet_x2.png"}; + Sprite & player_bullet_x2_sprite = player.add_component( + player_bullet_x2, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 3, + .size = vec2(0, 12), + } + ); + player.add_component(player_bullet_x2_sprite, ParticleEmitter::Data{ + .offset = vec2(-15, 15), + .emission_rate = 0, + .min_speed = 300, + .max_speed = 500, + .min_angle = 85, + .max_angle = 100, + .boundary = ParticleEmitter::Boundary { + .height = 400, + .reset_on_exit = true, + }, + }); + Asset player_shell {"asset/other_effects/effect_rocketmgshell_TVOS.png"}; + Sprite & player_shell_sprite = player.add_component( + player_shell, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 3, + .size = vec2(0, 12), + .angle_offset = 90, + } + ); + player.add_component(player_shell_sprite, ParticleEmitter::Data{ + .offset = vec2(-15, 15), + .emission_rate = 0, + .min_speed = 200, + .max_speed = 500, + .min_angle = 110, + .max_angle = 120, + .force_over_time = vec2(0, 1000), + .boundary = ParticleEmitter::Boundary { + .height = 400, + .reset_on_exit = true, + }, + }); + Asset player_body_asset {"asset/barry/defaultBody.png"}; Sprite & player_body_sprite = player.add_component( player_body_asset, -- cgit v1.2.3 From 46cc8767338578cbacb5a61bf50bbca71ea8e538 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 11:37:40 +0100 Subject: Make format --- game/player/PlayerSubScene.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'game/player/PlayerSubScene.cpp') diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index 166d54b..ccf3d42 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -2,16 +2,16 @@ #include "PlayerScript.h" #include "../Config.h" -#include "api/BoxCollider.h" -#include "api/ParticleEmitter.h" -#include "types.h" #include +#include #include #include +#include #include #include #include +#include using namespace crepe; using namespace std; -- cgit v1.2.3 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 +++ game/GameScene.cpp | 50 +++++++++++++++++++++++++++++++++++++++ game/player/PlayerScript.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++ game/player/PlayerScript.h | 5 ++++ game/player/PlayerSubScene.cpp | 3 ++- 5 files changed, 113 insertions(+), 1 deletion(-) (limited to 'game/player/PlayerSubScene.cpp') 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 diff --git a/game/GameScene.cpp b/game/GameScene.cpp index ee9b7dd..821191d 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -66,6 +66,56 @@ void GameScene::load_scene() { GameObject start_game_script = new_object("start_game_script", "script", vec2(0, 0)); start_game_script.add_component().set_script(); + + // zapper, laser and missile (below) for testing purpose only!!! + GameObject zapper = new_object("zapper", "zapper", vec2(1000, 0)); + Asset zapper_asset {"asset/obstacles/zapper/regular_zappers/zapEffect.png"}; + Sprite & zapper_sprite = zapper.add_component( + zapper_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_OBSTACLES, + .order_in_layer = 0, + .size = vec2(100, 100), + } + ); + zapper.add_component(Rigidbody::Data { + .body_type = Rigidbody::BodyType::KINEMATIC, + .kinematic_collision = false, + .collision_layer = COLL_LAY_ZAPPER, + }); + zapper.add_component(vec2(100, 100)); + GameObject laser = new_object("laser", "laser", vec2(2000, 0)); + Asset laser_asset {"asset/obstacles/laser/laserPower.png"}; + Sprite & laser_sprite = laser.add_component( + laser_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_OBSTACLES, + .order_in_layer = 0, + .size = vec2(100, 100), + } + ); + laser.add_component(Rigidbody::Data { + .body_type = Rigidbody::BodyType::KINEMATIC, + .kinematic_collision = false, + .collision_layer = COLL_LAY_LASER, + }); + laser.add_component(vec2(100, 100)); + GameObject missile = new_object("missile", "missile", vec2(3000, 0)); + Asset missile_asset {"asset/obstacles/missile/missile.png"}; + Sprite & missile_sprite = missile.add_component( + missile_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_OBSTACLES, + .order_in_layer = 0, + .size = vec2(100, 100), + } + ); + missile.add_component(Rigidbody::Data { + .body_type = Rigidbody::BodyType::KINEMATIC, + .kinematic_collision = false, + .collision_layer = COLL_LAY_MISSILE, + }); + missile.add_component(vec2(100, 100)); } string GameScene::get_name() const { return "scene1"; } diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index 04e7264..1a5d497 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -9,6 +9,59 @@ using namespace crepe; using namespace std; +void PlayerScript::init() { + subscribe([this](const CollisionEvent & ev) -> bool { + return this->on_collision(ev); + }); +} + +bool PlayerScript::on_collision(const CollisionEvent & ev) { + BehaviorScript & play_scr = this->get_components_by_name("player").front(); + RefVector animators = this->get_components_by_name("player"); + RefVector emitters + = this->get_components_by_name("player"); + + if (ev.info.other.metadata.tag == "zapper") { + for (Animator & anim : animators) { + anim.active = true; + anim.set_anim(4); + anim.data.looping = true; + prev_anim = 0; + } + for (ParticleEmitter & emitter : emitters) { + emitter.data.emission_rate = 0; + } + play_scr.active = false; + return true; + } else if (ev.info.other.metadata.tag == "laser") { + for (Animator & anim : animators) { + anim.active = true; + anim.set_anim(4); + anim.data.looping = true; + prev_anim = 0; + } + for (ParticleEmitter & emitter : emitters) { + emitter.data.emission_rate = 0; + } + play_scr.active = false; + return true; + } else if (ev.info.other.metadata.tag == "missile") { + for (Animator & anim : animators) { + anim.active = true; + anim.set_anim(5); + anim.data.looping = true; + prev_anim = 0; + } + for (ParticleEmitter & emitter : emitters) { + emitter.data.emission_rate = 0; + } + play_scr.active = false; + return true; + } + + return false; +} + void PlayerScript::fixed_update(crepe::duration_t dt) { RefVector animators = this->get_components_by_name("player"); RefVector emitters diff --git a/game/player/PlayerScript.h b/game/player/PlayerScript.h index dfd02eb..d8eb098 100644 --- a/game/player/PlayerScript.h +++ b/game/player/PlayerScript.h @@ -1,11 +1,16 @@ #pragma once +#include #include class PlayerScript : public crepe::Script { public: + void init(); void fixed_update(crepe::duration_t dt); +private: + bool on_collision(const crepe::CollisionEvent & ev); + private: int prev_anim = 0; }; diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index ccf3d42..812d99a 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -143,7 +143,8 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .gravity_scale = 20, .body_type = Rigidbody::BodyType::DYNAMIC, .linear_velocity = vec2(100, 0), - .collision_layers = {COLL_LAY_BOT_TOP}, + .collision_layers + = {COLL_LAY_BOT_TOP, COLL_LAY_ZAPPER, COLL_LAY_LASER, COLL_LAY_MISSILE}, .collision_layer = COLL_LAY_PLAYER, }); player.add_component().set_script().active = false; -- cgit v1.2.3 From abbfe5d06697b93de485dcfe975812befc018a00 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 16:31:58 +0100 Subject: Moved EndGameScript to Player --- game/CMakeLists.txt | 2 +- game/EndGameScript.cpp | 60 ----------------------------------------- game/EndGameScript.h | 12 --------- game/GameScene.cpp | 3 --- game/player/PlayerEndScript.cpp | 60 +++++++++++++++++++++++++++++++++++++++++ game/player/PlayerEndScript.h | 12 +++++++++ game/player/PlayerScript.cpp | 3 +-- game/player/PlayerSubScene.cpp | 2 ++ 8 files changed, 76 insertions(+), 78 deletions(-) delete mode 100644 game/EndGameScript.cpp delete mode 100644 game/EndGameScript.h create mode 100644 game/player/PlayerEndScript.cpp create mode 100644 game/player/PlayerEndScript.h (limited to 'game/player/PlayerSubScene.cpp') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 33ceaf4..8e3692b 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -19,7 +19,7 @@ add_executable(main player/PlayerScript.cpp player/PlayerSubScene.cpp StartGameScript.cpp - EndGameScript.cpp + player/PlayerEndScript.cpp background/StartSubScene.cpp main.cpp ) diff --git a/game/EndGameScript.cpp b/game/EndGameScript.cpp deleted file mode 100644 index a18f18c..0000000 --- a/game/EndGameScript.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "EndGameScript.h" - -#include -#include -#include -#include -#include - -using namespace crepe; -using namespace std; - -void EndGameScript::init() { - BoxCollider jetpack_coll = this->get_components_by_name("player").back(); - CircleCollider head_coll = this->get_components_by_name("player").back(); - jetpack_coll.active = false; - head_coll.active = false; -} - -void EndGameScript::fixed_update(crepe::duration_t dt) { - Transform & transform_player = this->get_components_by_name("player").front(); - RefVector anim_player = this->get_components_by_name("player"); - Rigidbody & rb_player = this->get_components_by_name("player").front(); - Rigidbody & rb_camera = this->get_components_by_name("camera").front(); - - if (transform_player.position.y >= 194) { - if (jump == 0 || jump == 1) { - int random_number = rand() % 4; - for (Animator & anim : anim_player) { - anim.active = false; - anim.set_anim(6); - for (int i = 0; i < random_number; i++) { - anim.next_anim(); - } - } - } else if (jump == 2) { - for (Animator & anim : anim_player) { - anim.active = false; - anim.set_anim(7); - } - rb_player.data.angular_velocity = 0; - transform_player.rotation = 90; - } - if (jump == 0) { - rb_player.data.linear_velocity = vec2(100, -150); - rb_player.data.angular_velocity = 320; - rb_player.data.angular_velocity_coefficient = 0.8; - jump++; - } else if (jump == 1) { - rb_player.data.linear_velocity = vec2(100, -125); - rb_player.data.angular_velocity = 300; - rb_player.data.angular_velocity_coefficient = 0.8; - jump++; - } else if (jump == 2) { - rb_player.data.linear_velocity = vec2(100, 0); - rb_player.data.linear_velocity_coefficient = vec2(0.5, 0.5); - rb_camera.data.linear_velocity_coefficient = vec2(0.5, 0.5); - jump++; - } - } -} diff --git a/game/EndGameScript.h b/game/EndGameScript.h deleted file mode 100644 index 980dff5..0000000 --- a/game/EndGameScript.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -class EndGameScript : public crepe::Script { -public: - void init(); - void fixed_update(crepe::duration_t dt); - -private: - int jump = 0; -}; diff --git a/game/GameScene.cpp b/game/GameScene.cpp index b471484..821191d 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -1,6 +1,5 @@ #include "GameScene.h" #include "Config.h" -#include "EndGameScript.h" #include "MoveCameraManualyScript.h" #include "StartGameScript.h" @@ -67,8 +66,6 @@ void GameScene::load_scene() { GameObject start_game_script = new_object("start_game_script", "script", vec2(0, 0)); start_game_script.add_component().set_script(); - GameObject end_game_script = new_object("end_game_script", "script", vec2(0, 0)); - end_game_script.add_component().set_script().active = false; // zapper, laser and missile (below) for testing purpose only!!! GameObject zapper = new_object("zapper", "zapper", vec2(1000, 0)); diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp new file mode 100644 index 0000000..c0b4e74 --- /dev/null +++ b/game/player/PlayerEndScript.cpp @@ -0,0 +1,60 @@ +#include "PlayerEndScript.h" + +#include +#include +#include +#include +#include + +using namespace crepe; +using namespace std; + +void PlayerEndScript::init() { + BoxCollider jetpack_coll = this->get_components_by_name("player").back(); + CircleCollider head_coll = this->get_components_by_name("player").back(); + jetpack_coll.active = false; + head_coll.active = false; +} + +void PlayerEndScript::fixed_update(crepe::duration_t dt) { + Transform & transform_player = this->get_components_by_name("player").front(); + RefVector anim_player = this->get_components_by_name("player"); + Rigidbody & rb_player = this->get_components_by_name("player").front(); + Rigidbody & rb_camera = this->get_components_by_name("camera").front(); + + if (transform_player.position.y >= 194) { + if (jump == 0 || jump == 1) { + int random_number = rand() % 4; + for (Animator & anim : anim_player) { + anim.active = false; + anim.set_anim(6); + for (int i = 0; i < random_number; i++) { + anim.next_anim(); + } + } + } else if (jump == 2) { + for (Animator & anim : anim_player) { + anim.active = false; + anim.set_anim(7); + } + rb_player.data.angular_velocity = 0; + transform_player.rotation = 90; + } + if (jump == 0) { + rb_player.data.linear_velocity = vec2(100, -150); + rb_player.data.angular_velocity = 320; + rb_player.data.angular_velocity_coefficient = 0.8; + jump++; + } else if (jump == 1) { + rb_player.data.linear_velocity = vec2(100, -125); + rb_player.data.angular_velocity = 300; + rb_player.data.angular_velocity_coefficient = 0.8; + jump++; + } else if (jump == 2) { + rb_player.data.linear_velocity = vec2(100, 0); + rb_player.data.linear_velocity_coefficient = vec2(0.5, 0.5); + rb_camera.data.linear_velocity_coefficient = vec2(0.5, 0.5); + jump++; + } + } +} diff --git a/game/player/PlayerEndScript.h b/game/player/PlayerEndScript.h new file mode 100644 index 0000000..240ab7c --- /dev/null +++ b/game/player/PlayerEndScript.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +class PlayerEndScript : public crepe::Script { +public: + void init(); + void fixed_update(crepe::duration_t dt); + +private: + int jump = 0; +}; diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index de53fc7..7f5d0c4 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -18,8 +18,7 @@ void PlayerScript::init() { bool PlayerScript::on_collision(const CollisionEvent & ev) { BehaviorScript & play_scr = this->get_components_by_name("player").front(); - BehaviorScript & end_scr - = this->get_components_by_name("end_game_script").front(); + BehaviorScript & end_scr = this->get_components_by_name("player").back(); RefVector animators = this->get_components_by_name("player"); RefVector emitters = this->get_components_by_name("player"); diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index 812d99a..91ae882 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -1,4 +1,5 @@ #include "PlayerSubScene.h" +#include "PlayerEndScript.h" #include "PlayerScript.h" #include "../Config.h" @@ -148,4 +149,5 @@ PlayerSubScene::PlayerSubScene(Scene & scn) { .collision_layer = COLL_LAY_PLAYER, }); player.add_component().set_script().active = false; + player.add_component().set_script().active = false; } -- 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/player/PlayerSubScene.cpp') 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 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/player/PlayerSubScene.cpp') 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