From b7ef0c8712c194c4cfc67284bce7349f752c212c Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 14 Jan 2024 23:13:00 -0600 Subject: [PATCH] Added knockup status for players/monsters. --- .../Chapter_1_Creatures_Part_2.txt | 2 +- Adventures in Lestoria/Monster.cpp | 20 ++++++++++++++++ Adventures in Lestoria/Monster.h | 5 ++++ Adventures in Lestoria/Player.cpp | 23 +++++++++++++++++-- Adventures in Lestoria/Player.h | 5 ++++ Adventures in Lestoria/Version.h | 2 +- 6 files changed, 53 insertions(+), 4 deletions(-) diff --git a/Adventures in Lestoria/Chapter_1_Creatures_Part_2.txt b/Adventures in Lestoria/Chapter_1_Creatures_Part_2.txt index 098a10e9..d3d4ef1d 100644 --- a/Adventures in Lestoria/Chapter_1_Creatures_Part_2.txt +++ b/Adventures in Lestoria/Chapter_1_Creatures_Part_2.txt @@ -12,7 +12,7 @@ HP: 210 Atk: 45 Move-Spd: 60% Size: 200% -Strategie: Moves towards player. Once next to the Player character builds itself up and smashes the ground infront of him. 2 seconds time to dodge attack once it locks the area its attacking. +Strategie: Moves towards player. Once next to the Player character builds itself up and smashes the ground infront of him. 2 seconds time to dodge attack once it locks the area its attacking. Knockup? Frog HP: 60 diff --git a/Adventures in Lestoria/Monster.cpp b/Adventures in Lestoria/Monster.cpp index 841b84f5..74811222 100644 --- a/Adventures in Lestoria/Monster.cpp +++ b/Adventures in Lestoria/Monster.cpp @@ -202,6 +202,20 @@ bool Monster::Update(float fElapsedTime){ size=std::min(targetSize,size+AiL::SIZE_CHANGE_SPEED*fElapsedTime); } } + + #pragma region Handle knockup timers + if(knockUpTimer>0.f){ + knockUpTimer=std::max(0.f,knockUpTimer-fElapsedTime); + if(knockUpTimer==0.f){ + totalKnockupTime=0.f; + knockUpZAmt=0.f; + SetZ(0.f); + }else{ + SetZ(util::lerp(0.f,1.f,-(pow((knockUpTimer-totalKnockupTime/2)/(totalKnockupTime/2),2))+1)*knockUpZAmt); + } + } + #pragma endregion + if(IsAlive()){ for(std::vector::iterator it=buffList.begin();it!=buffList.end();++it){ Buff&b=*it; @@ -598,4 +612,10 @@ geom2d::circleMonster::Hitbox(){ void Monster::Knockback(const vf2d&vel){ this->vel+=vel; +} + +void Monster::Knockup(float duration){ + knockUpTimer+=duration; + totalKnockupTime+=duration; + knockUpZAmt+=32*pow(duration,2); } \ No newline at end of file diff --git a/Adventures in Lestoria/Monster.h b/Adventures in Lestoria/Monster.h index 5b544090..68ece8be 100644 --- a/Adventures in Lestoria/Monster.h +++ b/Adventures in Lestoria/Monster.h @@ -175,6 +175,8 @@ public: const EventName&GetDeathSound(); const EventName&GetWalkSound(); void Knockback(const vf2d&vel); + //Knockup the player for duration amount of seconds, and Zamt pixels. + void Knockup(float duration); private: std::string name; vf2d pos; @@ -225,6 +227,9 @@ private: //Set monsterInvoked to false when you don't want a movement loop due to collisions. //Typical usage is monsterInvoked is true on first call, and monsterInvoked is false on all subsequent chained calls. bool _SetY(float y,const bool monsterInvoked=true); + float knockUpTimer=0.f; + float totalKnockupTime=0.f; + float knockUpZAmt=0.f; private: struct STRATEGY{ diff --git a/Adventures in Lestoria/Player.cpp b/Adventures in Lestoria/Player.cpp index e1c68587..5639d834 100644 --- a/Adventures in Lestoria/Player.cpp +++ b/Adventures in Lestoria/Player.cpp @@ -621,6 +621,19 @@ void Player::Update(float fElapsedTime){ } } #pragma endregion + + #pragma region Handle knockup timers + if(knockUpTimer>0.f){ + knockUpTimer=std::max(0.f,knockUpTimer-fElapsedTime); + if(knockUpTimer==0.f){ + totalKnockupTime=0.f; + knockUpZAmt=0.f; + SetZ(0.f); + }else{ + SetZ(util::lerp(0.f,1.f,-(pow((knockUpTimer-totalKnockupTime/2)/(totalKnockupTime/2),2))+1)*knockUpZAmt); + } + } + #pragma endregion } float Player::GetSwordSwingTimer(){ @@ -643,7 +656,7 @@ vf2d Player::GetVelocity(){ } bool Player::CanMove(){ - return state!=State::ANIMATION_LOCK&&(state!=State::CASTING||(castInfo.castTotalTime-castInfo.castTimer>0.2f)); + return knockUpTimer==0.f&&state!=State::ANIMATION_LOCK&&(state!=State::CASTING||(castInfo.castTotalTime-castInfo.castTimer>0.2f)); } bool Player::CanAct(){ @@ -652,7 +665,7 @@ bool Player::CanAct(){ } bool Player::CanAct(Ability&ability){ - return !ability.waitForRelease&&(ability.canCancelCast||state!=State::CASTING)&&state!=State::ANIMATION_LOCK&&GameState::STATE==GameState::states[States::GAME_RUN]; + return knockUpTimer==0&&!ability.waitForRelease&&(ability.canCancelCast||state!=State::CASTING)&&state!=State::ANIMATION_LOCK&&GameState::STATE==GameState::states[States::GAME_RUN]; } bool Player::HasIframes(){ @@ -1226,4 +1239,10 @@ void EntityStats::Reset(){ geom2d::circlePlayer::Hitbox(){ return {GetPos(),12*GetSizeMult()/2}; +} + +void Player::Knockup(float duration){ + knockUpTimer+=duration; + totalKnockupTime+=duration; + knockUpZAmt+=32*pow(duration,2); } \ No newline at end of file diff --git a/Adventures in Lestoria/Player.h b/Adventures in Lestoria/Player.h index b03d90e9..f7616f3a 100644 --- a/Adventures in Lestoria/Player.h +++ b/Adventures in Lestoria/Player.h @@ -236,6 +236,8 @@ public: void ResetAccumulatedXP(); const uint32_t GetAccumulatedXP()const; void AddAccumulatedXP(const uint32_t xpGain); + //Knockup the player for duration amount of seconds, and Zamt pixels. + void Knockup(float duration); private: int hp="Warrior.BaseHealth"_I; int mana="Player.BaseMana"_I; @@ -257,6 +259,9 @@ private: float hpRecoveryTimer=0; float hp6RecoveryTimer=0; float hp4RecoveryTimer=0; + float knockUpTimer=0.f; + float totalKnockupTime=0.f; + float knockUpZAmt=0.f; std::pair notEnoughManaDisplay={"",0.f}; float teleportAttemptWaitTime=0; //If a teleport fails, we wait awhile before trying again, it's expensive. State::State state=State::NORMAL; diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index df05af58..15c2b56b 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 5794 +#define VERSION_BUILD 5799 #define stringify(a) stringify_(a) #define stringify_(a) #a