From e8d2ec9e9d43928482b24747109a309a3cc0fa40 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sat, 13 Jan 2024 17:20:13 -0600 Subject: [PATCH] Frog behavior implemented. --- Adventures in Lestoria/BulletTypes.h | 3 +- Adventures in Lestoria/Frog.cpp | 49 ++++++++++++------ Adventures in Lestoria/FrogTongue.cpp | 16 ++++-- Adventures in Lestoria/Monster.cpp | 4 ++ Adventures in Lestoria/Monster.h | 2 + .../MonsterStrategyHelpers.h | 1 + Adventures in Lestoria/Player.cpp | 4 -- Adventures in Lestoria/RUN_STRATEGY.cpp | 7 +++ Adventures in Lestoria/Version.h | 2 +- .../assets/config/MonsterStrategies.txt | 15 ++++++ Adventures in Lestoria/assets/tongue.png | Bin 513 -> 4180 bytes Adventures in Lestoria/assets/tongue_end.png | Bin 550 -> 4214 bytes 12 files changed, 76 insertions(+), 27 deletions(-) diff --git a/Adventures in Lestoria/BulletTypes.h b/Adventures in Lestoria/BulletTypes.h index ba0764af..db878230 100644 --- a/Adventures in Lestoria/BulletTypes.h +++ b/Adventures in Lestoria/BulletTypes.h @@ -85,7 +85,8 @@ struct FrogTongue:public Bullet{ float tongueLength; float tongueSpd; float duration; - FrogTongue(vf2d pos,vf2d targetPos,float lifetime,int damage,bool upperLevel,bool friendly=false,Pixel col=WHITE); + float knockbackStrength; + FrogTongue(vf2d pos,vf2d targetPos,float lifetime,int damage,bool upperLevel,float knockbackStrength=1.0f,bool friendly=false,Pixel col=WHITE); void Update(float fElapsedTime)override; bool PlayerHit(Player*player)override; bool MonsterHit(Monster&monster)override; diff --git a/Adventures in Lestoria/Frog.cpp b/Adventures in Lestoria/Frog.cpp index 009e9e2c..607ee79d 100644 --- a/Adventures in Lestoria/Frog.cpp +++ b/Adventures in Lestoria/Frog.cpp @@ -40,12 +40,15 @@ All rights reserved. #include "AdventuresInLestoria.h" #include "MonsterStrategyHelpers.h" #include "util.h" +#include "BulletTypes.h" INCLUDE_game +INCLUDE_BULLET_LIST using A=Attribute; void Monster::STRATEGY::FROG(Monster&m,float fElapsedTime,std::string strategy){ + m.F(A::LOCKON_WAITTIME)=std::max(0.0f,m.F(A::LOCKON_WAITTIME)-fElapsedTime); phase: switch(m.I(A::PHASE)){ case 0:{ //Move towards phase. @@ -55,6 +58,23 @@ void Monster::STRATEGY::FROG(Monster&m,float fElapsedTime,std::string strategy){ m.F(A::LOCKON_WAITTIME)=ConfigFloat("Lockon Wait Time"); m.V(A::LOCKON_POS)=game->GetPlayer()->GetPos(); float dirToPlayer=util::angleTo(m.GetPos(),m.V(A::LOCKON_POS)); + #pragma region Face towards lockon direction + if(abs(dirToPlayer)<0.5f*PI){ //This sprite is supposed to be facing right (flipped) + m.facingDirection=RIGHT; + m.spriteRot=dirToPlayer; + }else{ + m.facingDirection=LEFT; + if(dirToPlayer>0){ + m.spriteRot=-PI+dirToPlayer; + }else{ + m.spriteRot=PI+dirToPlayer; + } + } + #pragma endregion + goto phase; + } + float dirToPlayer=util::angleTo(m.GetPos(),m.target); + #pragma region Face towards target direction if(abs(dirToPlayer)<0.5f*PI){ //This sprite is supposed to be facing right (flipped) m.facingDirection=RIGHT; m.spriteRot=dirToPlayer; @@ -66,30 +86,27 @@ void Monster::STRATEGY::FROG(Monster&m,float fElapsedTime,std::string strategy){ m.spriteRot=PI+dirToPlayer; } } - goto phase; - } - float dirToPlayer=util::angleTo(m.GetPos(),m.target); - if(abs(dirToPlayer)<0.5f*PI){ //This sprite is supposed to be facing right (flipped) - m.facingDirection=RIGHT; - m.spriteRot=dirToPlayer; - }else{ - m.facingDirection=LEFT; - if(dirToPlayer>0){ - m.spriteRot=-PI+dirToPlayer; - }else{ - m.spriteRot=PI+dirToPlayer; - } - } + #pragma endregion RUN_TOWARDS(m,fElapsedTime,"Run Towards"); m.PerformJumpAnimation(); }break; case 1:{ - m.F(A::LOCKON_WAITTIME)=std::max(0.0f,m.F(A::LOCKON_WAITTIME)-fElapsedTime); if(m.F(A::LOCKON_WAITTIME)==0.0f){ - m.I(A::PHASE)=0; + m.F(A::LOCKON_WAITTIME)=ConfigFloat("Attack Duration"); + vf2d tongueMaxRangePos=geom2d::line(m.GetPos(),m.V(A::LOCKON_POS)).upoint(ConfigFloat("Tongue Max Range")/ConfigFloat("Range")); + + CreateBullet(FrogTongue)(m.pos,tongueMaxRangePos,ConfigFloat("Attack Duration"),m.GetAttack(),m.OnUpperLevel(),ConfigFloat("Tongue Knockback Strength"),false,ConfigPixel("Tongue Color"))EndBullet; + m.PerformShootAnimation(); + m.I(A::PHASE)=2; } m.PerformIdleAnimation(); }break; + case 2:{ + if(m.F(A::LOCKON_WAITTIME)==0.0f){ + m.F(A::LOCKON_WAITTIME)=ConfigFloat("Attack Recovery Time"); + m.I(A::PHASE)=0; + } + }break; default:{ ERR(std::format("Unhandled phase {} for {} strategy!",m.I(A::PHASE),strategy)); } diff --git a/Adventures in Lestoria/FrogTongue.cpp b/Adventures in Lestoria/FrogTongue.cpp index a91285ad..c4ec3b19 100644 --- a/Adventures in Lestoria/FrogTongue.cpp +++ b/Adventures in Lestoria/FrogTongue.cpp @@ -44,8 +44,8 @@ INCLUDE_game INCLUDE_MONSTER_LIST INCLUDE_GFX -FrogTongue::FrogTongue(vf2d pos,vf2d targetPos,float lifetime,int damage,bool upperLevel,bool friendly,Pixel col) - :Bullet(pos,{},0,damage,upperLevel,friendly,col),targetPos(targetPos),tongueSpd(tongueSpd),tongueLength(0.f){ +FrogTongue::FrogTongue(vf2d pos,vf2d targetPos,float lifetime,int damage,bool upperLevel,float knockbackStrength,bool friendly,Pixel col) + :Bullet(pos,{},0,damage,upperLevel,friendly,col),targetPos(targetPos),tongueSpd(tongueSpd),tongueLength(0.f),knockbackStrength(knockbackStrength){ this->lifetime=lifetime; duration=lifetime; } @@ -53,9 +53,9 @@ void FrogTongue::Update(float fElapsedTime){ geom2d::linelineToTarget(pos,targetPos); vf2d drawVec=lineToTarget.vector().norm()*3; - tongueLength=util::lerp(0,lineToTarget.length(),sin((lifetime*PI)/duration)); + tongueLength=util::lerp(0,lineToTarget.length(),pow(sin((lifetime*PI)/duration),20.f)); - vf2d tongueEndPos=geom2d::line(pos+drawVec,targetPos).upoint(sin((lifetime*PI)/duration)); + vf2d tongueEndPos=geom2d::line(pos+drawVec,targetPos).upoint(pow(sin((lifetime*PI)/duration),20.f)); geom2d::linetongueLine(pos+drawVec,tongueEndPos); if(!friendly&&geom2d::overlaps(game->GetPlayer()->Hitbox(),tongueLine)){ @@ -73,19 +73,25 @@ void FrogTongue::Update(float fElapsedTime){ bool FrogTongue::PlayerHit(Player*player){ if(!deactivated){ player->Hurt(damage,OnUpperLevel(),0); + geom2d::linelineToTarget(pos,targetPos); + vf2d drawVec=lineToTarget.vector().norm()*3; + player->Knockback(geom2d::line(pos+drawVec,targetPos).vector()*knockbackStrength); deactivated=true; } return false; } bool FrogTongue::MonsterHit(Monster&monster){ monster.Hurt(damage,OnUpperLevel(),0); + geom2d::linelineToTarget(pos,targetPos); + vf2d drawVec=lineToTarget.vector().norm()*3; + monster.Knockback(geom2d::line(pos+drawVec,targetPos).vector()*knockbackStrength); return false; } void FrogTongue::Draw(){ geom2d::linelineToTarget(pos,targetPos); vf2d drawVec=lineToTarget.vector().norm()*3; - vf2d tongueEndPos=geom2d::line(pos+drawVec,targetPos).upoint(sin((lifetime*PI)/duration)); + vf2d tongueEndPos=geom2d::line(pos+drawVec,targetPos).upoint(pow(sin((lifetime*PI)/duration),20.f)); game->view.DrawRotatedDecal(pos+drawVec,GFX["tongue.png"].Decal(),drawVec.polar().y,{0.f,1.f},{tongueLength,1.0f},col); game->view.DrawRotatedDecal(tongueEndPos,GFX["tongue_end.png"].Decal(),drawVec.polar().y,{2.f,2.f},{1.f,1.f},col); diff --git a/Adventures in Lestoria/Monster.cpp b/Adventures in Lestoria/Monster.cpp index 068bcad2..abc93539 100644 --- a/Adventures in Lestoria/Monster.cpp +++ b/Adventures in Lestoria/Monster.cpp @@ -577,4 +577,8 @@ const EventName&Monster::GetWalkSound(){ geom2d::circleMonster::Hitbox(){ return {GetPos(),12*GetSizeMult()}; +} + +void Monster::Knockback(const vf2d&vel){ + this->vel+=vel; } \ No newline at end of file diff --git a/Adventures in Lestoria/Monster.h b/Adventures in Lestoria/Monster.h index 62da87ad..1e04c4a1 100644 --- a/Adventures in Lestoria/Monster.h +++ b/Adventures in Lestoria/Monster.h @@ -170,6 +170,7 @@ public: const EventName&GetHurtSound(); const EventName&GetDeathSound(); const EventName&GetWalkSound(); + void Knockback(const vf2d&vel); private: std::string name; vf2d pos; @@ -225,6 +226,7 @@ private: struct STRATEGY{ static int _GetInt(Monster&m,std::string param,std::string strategy,int index=0); static float _GetFloat(Monster&m,std::string param,std::string strategy,int index=0); + static Pixel _GetPixel(Monster&m,std::string param,std::string strategy,int index=0); static std::string _GetString(Monster&m,std::string param,std::string strategy,int index=0); static void RUN_STRATEGY(Monster&m,float fElapsedTime); static void RUN_TOWARDS(Monster&m,float fElapsedTime,std::string strategy); diff --git a/Adventures in Lestoria/MonsterStrategyHelpers.h b/Adventures in Lestoria/MonsterStrategyHelpers.h index 402cdfee..d11c75f7 100644 --- a/Adventures in Lestoria/MonsterStrategyHelpers.h +++ b/Adventures in Lestoria/MonsterStrategyHelpers.h @@ -38,6 +38,7 @@ All rights reserved. #pragma once #define ConfigInt(param) _GetInt(m,param,strategy) #define ConfigFloat(param) _GetFloat(m,param,strategy) +#define ConfigPixel(param) _GetPixel(m,param,strategy) #define ConfigString(param) _GetString(m,param,strategy) #define ConfigIntArr(param,ind) _GetInt(m,param,strategy,ind) #define ConfigFloatArr(param,ind) _GetFloat(m,param,strategy,ind) diff --git a/Adventures in Lestoria/Player.cpp b/Adventures in Lestoria/Player.cpp index afe62b95..07cc7144 100644 --- a/Adventures in Lestoria/Player.cpp +++ b/Adventures in Lestoria/Player.cpp @@ -537,10 +537,6 @@ void Player::Update(float fElapsedTime){ } } - if(game->GetKey(G).bPressed){ - CreateBullet(FrogTongue)(GetPos(),game->GetWorldMousePos(),1.f,10,OnUpperLevel(),true,RED)EndBullet; - } - #pragma region Warrior switch(GetState()){ case State::SWING_SWORD:{ diff --git a/Adventures in Lestoria/RUN_STRATEGY.cpp b/Adventures in Lestoria/RUN_STRATEGY.cpp index 6c8f54aa..1707023d 100644 --- a/Adventures in Lestoria/RUN_STRATEGY.cpp +++ b/Adventures in Lestoria/RUN_STRATEGY.cpp @@ -63,6 +63,13 @@ std::string Monster::STRATEGY::_GetString(Monster&m,std::string param,std::strin return DATA["MonsterStrategy"][strategy].GetProperty(param).GetString(index); } } +Pixel Monster::STRATEGY::_GetPixel(Monster&m,std::string param,std::string strategy,int index){ + if(DATA["Monsters"][m.name].HasProperty(param)){ + return DATA["Monsters"][m.name].GetProperty(param).GetPixel(index); + } else { + return DATA["MonsterStrategy"][strategy].GetProperty(param).GetPixel(index); + } +} void Monster::STRATEGY::RUN_STRATEGY(Monster&m,float fElapsedTime){ m.GetStrategy()(m,fElapsedTime,m.strategy); diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index 060d7958..5123e947 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 5750 +#define VERSION_BUILD 5760 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Adventures in Lestoria/assets/config/MonsterStrategies.txt b/Adventures in Lestoria/assets/config/MonsterStrategies.txt index 5c1780da..224f460e 100644 --- a/Adventures in Lestoria/assets/config/MonsterStrategies.txt +++ b/Adventures in Lestoria/assets/config/MonsterStrategies.txt @@ -174,5 +174,20 @@ MonsterStrategy # How long to wait after getting in range and locking on to the player, before firing tongue. Lockon Wait Time = 1.5s + + # How long the tongue attack lasts for. + Attack Duration = 1.0s + + # Max range of the tongue attack. + Tongue Max Range = 450 + + # How long to wait before starting its seeking phase over again. + Attack Recovery Time = 0.5s + + # The color of the tongue RGBA + Tongue Color = 95,23,31,255 + + # A multiplier for the knockback strength of the tongue. (1 is quite small) + Tongue Knockback Strength = 2 } } \ No newline at end of file diff --git a/Adventures in Lestoria/assets/tongue.png b/Adventures in Lestoria/assets/tongue.png index 521738f924ebf9ee728b03d8cfe8a2e2eec0d06d..f2ecbd1387b2ccb5d1bc8137bbb34f18b7e7fac6 100644 GIT binary patch literal 4180 zcmeHKd2AF_7~j$YwcLk=Aj)*=fynIK+nJ%;Qg?f-xMgW8w!xCl&b-|Y-Q8Jcr`>G< z1*J&~Xaqc}Qap)@M@Yax0}7_fr3eullNLmaF^Ebfpwy&L-^}(RnwTc?UpLvEneX_0 z@ArG(_p;OIDa@acGAqSmu}p9kIE&yl0e(j%kAlCc=hMRQ@>yL;sa_;Tk+7!vlmI~V z+Au&sOz~MPvG$-RXJTSn@_{QGvJyt${;IUUEnG#mA#LDceUxL z%e82Cdlgu?|If_HGZ!5GwDFIMX98zuG;{fBj;Uul-))N>y!y(LSq;aJ9bLX8wtQT9 z>$y8LyCf^;N%8dT7Vcd52ny1&-_jH^db=}f_pls4RZ?sw=zk0>t@VFd~em;=J zwl$mW1+AXx^^1#lpxDIJDJze9n%i@8KXdIYO&Yi3gHt=7I<~0yHJ4*cXXo5~sk3{^ z-WT?9zg+x&UhCcGn;SN^ z^z57&tDlrMK5au;<4bka?xuSGnzO|jZRMN%wb!nfrR}Jo4&68PBzbmMLq@~f8Cdg` ztd&jA-&5bcjazYQbmN>B>;9g@EkEu$M7QSI?2BjLo4Tlcew2LRj(L}-uXHY9kI&Go z4{Y1Zz1JpGo!felC_S~5dhBg>L(&V+I#W>jn6O-S%a>IsS)xN1tEVwK4d_ri69nueI&^txM_%HCt}@zkleL?kac1 zPg}3%k$)0AZ|*mB4aiN)3f(r68G_ z>=TNdd3_M@$&Oa)dRV~mXf$e#(pFXT<0Q}XI6>hQg~13cQXA667#5188xU~}Cx}Rz z64n(pgcz8jSFP6VC<^^Z|N4Sqw|f9S6zNj|>Ve0^Fiu(tJQ&1>W<>Pd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