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/GameScene.cpp | 2 +- game/PlayerScript.cpp | 11 ------ game/PlayerScript.h | 8 ----- game/PlayerSubScene.cpp | 76 ------------------------------------------ game/PlayerSubScene.h | 10 ------ game/player/PlayerScript.cpp | 11 ++++++ game/player/PlayerScript.h | 8 +++++ game/player/PlayerSubScene.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++ game/player/PlayerSubScene.h | 10 ++++++ 9 files changed, 106 insertions(+), 106 deletions(-) delete mode 100644 game/PlayerScript.cpp delete mode 100644 game/PlayerScript.h delete mode 100644 game/PlayerSubScene.cpp delete mode 100644 game/PlayerSubScene.h create mode 100644 game/player/PlayerScript.cpp create mode 100644 game/player/PlayerScript.h create mode 100644 game/player/PlayerSubScene.cpp create mode 100644 game/player/PlayerSubScene.h diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 2511567..ee9b7dd 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -1,10 +1,10 @@ #include "GameScene.h" #include "Config.h" #include "MoveCameraManualyScript.h" -#include "PlayerSubScene.h" #include "StartGameScript.h" #include "background/BackgroundSubScene.h" +#include "player/PlayerSubScene.h" #include #include diff --git a/game/PlayerScript.cpp b/game/PlayerScript.cpp deleted file mode 100644 index 1c388f5..0000000 --- a/game/PlayerScript.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "PlayerScript.h" - -#include - -using namespace crepe; -using namespace std; - -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)); -} diff --git a/game/PlayerScript.h b/game/PlayerScript.h deleted file mode 100644 index 84c4f7f..0000000 --- a/game/PlayerScript.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include - -class PlayerScript : public crepe::Script { -public: - void fixed_update(crepe::duration_t dt); -}; diff --git a/game/PlayerSubScene.cpp b/game/PlayerSubScene.cpp deleted file mode 100644 index 00b7810..0000000 --- a/game/PlayerSubScene.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#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; -} diff --git a/game/PlayerSubScene.h b/game/PlayerSubScene.h deleted file mode 100644 index bf94c32..0000000 --- a/game/PlayerSubScene.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -namespace crepe { -class Scene; -} - -class PlayerSubScene { -public: - PlayerSubScene(crepe::Scene & scn); -}; diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp new file mode 100644 index 0000000..1c388f5 --- /dev/null +++ b/game/player/PlayerScript.cpp @@ -0,0 +1,11 @@ +#include "PlayerScript.h" + +#include + +using namespace crepe; +using namespace std; + +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)); +} diff --git a/game/player/PlayerScript.h b/game/player/PlayerScript.h new file mode 100644 index 0000000..84c4f7f --- /dev/null +++ b/game/player/PlayerScript.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +class PlayerScript : public crepe::Script { +public: + void fixed_update(crepe::duration_t dt); +}; 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; +} diff --git a/game/player/PlayerSubScene.h b/game/player/PlayerSubScene.h new file mode 100644 index 0000000..bf94c32 --- /dev/null +++ b/game/player/PlayerSubScene.h @@ -0,0 +1,10 @@ +#pragma once + +namespace crepe { +class Scene; +} + +class PlayerSubScene { +public: + PlayerSubScene(crepe::Scene & scn); +}; -- 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(-) 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 f663aa291713be3e9e7cf70707d6a23b128d1ab4 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 09:52:50 +0100 Subject: Moved Player files to seperate folder --- game/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 937b5e6..c3a2d52 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -16,8 +16,8 @@ add_executable(main GameScene.cpp background/HallwaySubScene.cpp MoveCameraManualyScript.cpp - PlayerScript.cpp - PlayerSubScene.cpp + player/PlayerScript.cpp + player/PlayerSubScene.cpp StartGameScript.cpp background/StartSubScene.cpp main.cpp -- 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(-) 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 0bfc194d2c31d111ad438c040d4b0b74238d4ef6 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 10:51:26 +0100 Subject: Stop looping at last frame instead of start frame --- src/crepe/system/AnimatorSystem.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/crepe/system/AnimatorSystem.cpp b/src/crepe/system/AnimatorSystem.cpp index e5ab2fa..0a5a417 100644 --- a/src/crepe/system/AnimatorSystem.cpp +++ b/src/crepe/system/AnimatorSystem.cpp @@ -1,6 +1,7 @@ #include "../api/Animator.h" #include "../manager/ComponentManager.h" #include "../manager/LoopTimerManager.h" +#include "util/Log.h" #include #include "AnimatorSystem.h" @@ -29,12 +30,13 @@ void AnimatorSystem::frame_update() { int curr_frame = static_cast(elapsed_time / frame_duration) % total_frames; - ctx.row = ctx.cycle_start + curr_frame; - a.spritesheet.mask.x = ctx.row * a.spritesheet.mask.w; - a.spritesheet.mask.y = (ctx.col * a.spritesheet.mask.h); - if (!ctx.looping && curr_frame == ctx.cycle_start && last_frame == total_frames - 1) { a.active = false; + continue; } + + ctx.row = ctx.cycle_start + curr_frame; + a.spritesheet.mask.x = ctx.row * a.spritesheet.mask.w; + a.spritesheet.mask.y = (ctx.col * a.spritesheet.mask.h); } } -- cgit v1.2.3 From 8f8d579389303184038addc77c1acffdb2081f91 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 10:52:36 +0100 Subject: Added correct animations --- game/player/PlayerScript.cpp | 35 ++++++++++++++++++++++++++++++++++- game/player/PlayerScript.h | 3 +++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index 1c388f5..874324e 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -1,11 +1,44 @@ #include "PlayerScript.h" +#include #include +#include +#include using namespace crepe; using namespace std; void PlayerScript::fixed_update(crepe::duration_t dt) { + RefVector animators = this->get_components_by_name("player"); + Transform & transform = this->get_components_by_name("player").front(); + Rigidbody & rb = this->get_components_by_name("player").front(); - if (this->get_key_state(Keycode::SPACE)) rb.add_force_linear(vec2(0, -10)); + if (this->get_key_state(Keycode::SPACE)) { + rb.add_force_linear(vec2(0, -10)); + if (prev_anim != 1) { + for (Animator & anim : animators) { + anim.active = true; + anim.set_anim(1); + anim.data.looping = true; + prev_anim = 1; + } + } + } else if (transform.position.y == 195) { + if (prev_anim != 0) { + for (Animator & anim : animators) { + anim.active = true; + anim.set_anim(0); + anim.data.looping = true; + prev_anim = 0; + } + } + } else { + if (prev_anim != 2) { + for (Animator & anim : animators) { + anim.set_anim(2); + anim.data.looping = false; + prev_anim = 2; + } + } + } } diff --git a/game/player/PlayerScript.h b/game/player/PlayerScript.h index 84c4f7f..dfd02eb 100644 --- a/game/player/PlayerScript.h +++ b/game/player/PlayerScript.h @@ -5,4 +5,7 @@ class PlayerScript : public crepe::Script { public: void fixed_update(crepe::duration_t dt); + +private: + int prev_anim = 0; }; -- 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(+) 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(-) 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(-) 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 a0a3e7e2d12d3acb7bf4073cb5a10c08047cd08e Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 12:14:51 +0100 Subject: Added EndGameScript --- game/CMakeLists.txt | 1 + game/EndGameScript.cpp | 6 ++++++ game/EndGameScript.h | 8 ++++++++ game/GameScene.cpp | 3 +++ game/player/PlayerScript.cpp | 6 ++++++ 5 files changed, 24 insertions(+) create mode 100644 game/EndGameScript.cpp create mode 100644 game/EndGameScript.h diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index c3a2d52..33ceaf4 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -19,6 +19,7 @@ add_executable(main player/PlayerScript.cpp player/PlayerSubScene.cpp StartGameScript.cpp + EndGameScript.cpp background/StartSubScene.cpp main.cpp ) diff --git a/game/EndGameScript.cpp b/game/EndGameScript.cpp new file mode 100644 index 0000000..4d7b5fd --- /dev/null +++ b/game/EndGameScript.cpp @@ -0,0 +1,6 @@ +#include "EndGameScript.h" + +void EndGameScript::fixed_update(crepe::duration_t dt) { + logf("EndGameScript::fixed_update"); + // ... +} diff --git a/game/EndGameScript.h b/game/EndGameScript.h new file mode 100644 index 0000000..b63ac9d --- /dev/null +++ b/game/EndGameScript.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +class EndGameScript : public crepe::Script { +public: + void fixed_update(crepe::duration_t dt); +}; diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 821191d..b471484 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -1,5 +1,6 @@ #include "GameScene.h" #include "Config.h" +#include "EndGameScript.h" #include "MoveCameraManualyScript.h" #include "StartGameScript.h" @@ -66,6 +67,8 @@ 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/PlayerScript.cpp b/game/player/PlayerScript.cpp index 1a5d497..de53fc7 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -1,4 +1,5 @@ #include "PlayerScript.h" +#include "api/BehaviorScript.h" #include #include @@ -17,6 +18,8 @@ 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(); RefVector animators = this->get_components_by_name("player"); RefVector emitters = this->get_components_by_name("player"); @@ -32,6 +35,7 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) { emitter.data.emission_rate = 0; } play_scr.active = false; + end_scr.active = true; return true; } else if (ev.info.other.metadata.tag == "laser") { for (Animator & anim : animators) { @@ -44,6 +48,7 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) { emitter.data.emission_rate = 0; } play_scr.active = false; + end_scr.active = true; return true; } else if (ev.info.other.metadata.tag == "missile") { for (Animator & anim : animators) { @@ -56,6 +61,7 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) { emitter.data.emission_rate = 0; } play_scr.active = false; + end_scr.active = true; return true; } -- cgit v1.2.3 From 9cdc0a89d9b6f504eeef888f845751977b1bc769 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 12:17:32 +0100 Subject: Added init --- game/EndGameScript.cpp | 5 +++++ game/EndGameScript.h | 1 + 2 files changed, 6 insertions(+) diff --git a/game/EndGameScript.cpp b/game/EndGameScript.cpp index 4d7b5fd..6b9c47f 100644 --- a/game/EndGameScript.cpp +++ b/game/EndGameScript.cpp @@ -1,5 +1,10 @@ #include "EndGameScript.h" +void EndGameScript::init() { + logf("EndGameScript::init"); + // ... +} + void EndGameScript::fixed_update(crepe::duration_t dt) { logf("EndGameScript::fixed_update"); // ... diff --git a/game/EndGameScript.h b/game/EndGameScript.h index b63ac9d..3b1970a 100644 --- a/game/EndGameScript.h +++ b/game/EndGameScript.h @@ -4,5 +4,6 @@ class EndGameScript : public crepe::Script { public: + void init(); void fixed_update(crepe::duration_t dt); }; -- cgit v1.2.3 From 81c25a7aa3722e2a65ccae29d22aa37bc5d1bc70 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 12:23:15 +0100 Subject: Slowed down at end --- game/EndGameScript.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/game/EndGameScript.cpp b/game/EndGameScript.cpp index 6b9c47f..55f08cd 100644 --- a/game/EndGameScript.cpp +++ b/game/EndGameScript.cpp @@ -1,11 +1,20 @@ #include "EndGameScript.h" +#include +#include + +using namespace crepe; +using namespace std; + void EndGameScript::init() { - logf("EndGameScript::init"); - // ... + Rigidbody & rb_player = this->get_components_by_name("player").front(); + Rigidbody & rb_camera = this->get_components_by_name("camera").front(); + + rb_player.data.linear_velocity_coefficient = vec2(0.8, 0.8); + rb_camera.data.linear_velocity_coefficient = vec2(0.8, 0.8); } void EndGameScript::fixed_update(crepe::duration_t dt) { - logf("EndGameScript::fixed_update"); + //logf("EndGameScript::fixed_update"); // ... } -- cgit v1.2.3 From a764ef0f1f6b7c5d18155163d63db1a6dd47093a Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 14:38:01 +0100 Subject: Added end script --- game/EndGameScript.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++------- game/EndGameScript.h | 3 +++ 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/game/EndGameScript.cpp b/game/EndGameScript.cpp index 55f08cd..a18f18c 100644 --- a/game/EndGameScript.cpp +++ b/game/EndGameScript.cpp @@ -1,5 +1,8 @@ #include "EndGameScript.h" +#include +#include +#include #include #include @@ -7,14 +10,51 @@ using namespace crepe; using namespace std; void EndGameScript::init() { - Rigidbody & rb_player = this->get_components_by_name("player").front(); - Rigidbody & rb_camera = this->get_components_by_name("camera").front(); - - rb_player.data.linear_velocity_coefficient = vec2(0.8, 0.8); - rb_camera.data.linear_velocity_coefficient = vec2(0.8, 0.8); + 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) { - //logf("EndGameScript::fixed_update"); - // ... + 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 index 3b1970a..980dff5 100644 --- a/game/EndGameScript.h +++ b/game/EndGameScript.h @@ -6,4 +6,7 @@ class EndGameScript : public crepe::Script { public: void init(); void fixed_update(crepe::duration_t dt); + +private: + int jump = 0; }; -- 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 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 493f7bd2f8f74a418fb06ddbd419e5d010ec5808 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Tue, 24 Dec 2024 17:28:10 +0100 Subject: Re-implemented player end --- game/player/PlayerEndScript.cpp | 52 +++++++++++++++++++++-------------------- game/player/PlayerEndScript.h | 4 +++- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp index c0b4e74..37b870c 100644 --- a/game/player/PlayerEndScript.cpp +++ b/game/player/PlayerEndScript.cpp @@ -10,19 +10,22 @@ 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; + Rigidbody & rb_player = this->get_components_by_name("player").front(); + rb_player.data.elasticity_coefficient = 0.7; + + subscribe([this](const CollisionEvent & ev) -> bool { + return this->on_collision(ev); + }); } -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(); +bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { + if (ev.info.other.metadata.name == "floor") { + 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) { @@ -32,29 +35,28 @@ void PlayerEndScript::fixed_update(crepe::duration_t dt) { 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; + rb_player.data.angular_velocity_coefficient = 0.7; 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) { + } else if (jump == 1 && transform_player.rotation > 65 + && transform_player.rotation < 115) { + 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_coefficient = vec2(0.5, 0.5); rb_camera.data.linear_velocity_coefficient = vec2(0.5, 0.5); + for (Animator & anim : anim_player) { + anim.active = false; + anim.set_anim(7); + } jump++; } + + return true; } + + return false; } diff --git a/game/player/PlayerEndScript.h b/game/player/PlayerEndScript.h index 240ab7c..03ea8a9 100644 --- a/game/player/PlayerEndScript.h +++ b/game/player/PlayerEndScript.h @@ -5,7 +5,9 @@ class PlayerEndScript : public crepe::Script { public: void init(); - void fixed_update(crepe::duration_t dt); + +private: + bool on_collision(const crepe::CollisionEvent & ev); private: int jump = 0; -- cgit v1.2.3 From bc66ba7754dec9d6f907bc69730f211ae2215906 Mon Sep 17 00:00:00 2001 From: Max-001 Date: Sun, 29 Dec 2024 12:15:10 +0100 Subject: Improved stop sprite --- game/player/PlayerEndScript.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp index 37b870c..80d3011 100644 --- a/game/player/PlayerEndScript.cpp +++ b/game/player/PlayerEndScript.cpp @@ -26,7 +26,7 @@ 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(); - if (jump == 0 || jump == 1) { + if (jump == 0) { int random_number = rand() % 4; for (Animator & anim : anim_player) { anim.active = false; @@ -35,14 +35,19 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { anim.next_anim(); } } + } else if (jump == 1) { + for (Animator & anim : anim_player) { + anim.next_anim(); + } } if (jump == 0) { rb_player.data.angular_velocity = 320; rb_player.data.angular_velocity_coefficient = 0.7; jump++; - } else if (jump == 1 && transform_player.rotation > 65 - && transform_player.rotation < 115) { + } else if (jump == 1) { + jump++; + } else if (jump == 2) { rb_player.data.angular_velocity = 0; rb_player.data.elasticity_coefficient = 0; rb_player.data.linear_velocity = vec2(100, 0); @@ -52,6 +57,24 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { anim.active = false; anim.set_anim(7); } + if (transform_player.rotation > 0 && transform_player.rotation < 90) { + // Do not call next_anim() + } else if (transform_player.rotation > 90 && transform_player.rotation < 180) { + for (Animator & anim : anim_player) { + anim.next_anim(); + } + } else if (transform_player.rotation > 180 && transform_player.rotation < 270) { + for (Animator & anim : anim_player) { + anim.next_anim(); + anim.next_anim(); + } + } else { + for (Animator & anim : anim_player) { + anim.next_anim(); + anim.next_anim(); + anim.next_anim(); + } + } jump++; } -- 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(-) 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(-) 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 b31934cc6867be10e986a4bd4d0ab81dc91d56ec Mon Sep 17 00:00:00 2001 From: Max-001 Date: Mon, 6 Jan 2025 10:14:58 +0100 Subject: Paralax stops when player stops --- game/GameScene.cpp | 2 +- game/player/PlayerEndScript.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 821191d..a8fcb47 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -100,7 +100,7 @@ void GameScene::load_scene() { .collision_layer = COLL_LAY_LASER, }); laser.add_component(vec2(100, 100)); - GameObject missile = new_object("missile", "missile", vec2(3000, 0)); + GameObject missile = new_object("missile", "missile", vec2(4000, 0)); Asset missile_asset {"asset/obstacles/missile/missile.png"}; Sprite & missile_sprite = missile.add_component( missile_asset, diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp index 8833c28..4cd2cd0 100644 --- a/game/player/PlayerEndScript.cpp +++ b/game/player/PlayerEndScript.cpp @@ -50,6 +50,12 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) { } else if (jump == 1) { jump++; } else if (jump == 2) { + RefVector rb_back_forest + = this->get_components_by_tag("forest_background"); + for (Rigidbody & rb : rb_back_forest) { + rb.data.linear_velocity_coefficient = vec2(0.5, 0.5); + } + rb_player.data.angular_velocity = 0; rb_player.data.elasticity_coefficient = 0; rb_player.data.linear_velocity = vec2(PLAYER_SPEED, 0); -- 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(-) 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