From 6bed39f178c6c32d1a1f0a953cfe47482b92ec38 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 29 Aug 2023 06:17:39 -0500 Subject: [PATCH] Added debuff disable indicators. --- olcCodeJam2023Entry/Constant.cpp | 4 +++- olcCodeJam2023Entry/Constant.h | 2 ++ olcCodeJam2023Entry/DebuffIcon.cpp | 11 +++++++++++ olcCodeJam2023Entry/DebuffIcon.h | 13 +++++++++++++ olcCodeJam2023Entry/Image.h | 4 ++++ olcCodeJam2023Entry/Unit.cpp | 19 ++++++++++++++++++- olcCodeJam2023Entry/Unit.h | 3 ++- olcCodeJam2023Entry/VirusAttack.cpp | 13 ++++++++++++- olcCodeJam2023Entry/VirusAttack.h | 2 ++ .../olcCodeJam2023Entry.vcxproj | 2 ++ .../olcCodeJam2023Entry.vcxproj.filters | 6 ++++++ 11 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 olcCodeJam2023Entry/DebuffIcon.cpp create mode 100644 olcCodeJam2023Entry/DebuffIcon.h diff --git a/olcCodeJam2023Entry/Constant.cpp b/olcCodeJam2023Entry/Constant.cpp index ae6a951..0a3f694 100644 --- a/olcCodeJam2023Entry/Constant.cpp +++ b/olcCodeJam2023Entry/Constant.cpp @@ -20,4 +20,6 @@ Pixel CONSTANT::ATTACKER_TARGET_COL={196, 101, 0, 196}; Pixel CONSTANT::ATTACKER_ATTACK_COL={171, 0, 0, 220}; Pixel CONSTANT::HEALER_TARGET_COL={0, 134, 230, 196}; -Pixel CONSTANT::HEALER_ATTACK_COL={91, 222, 104, 220}; \ No newline at end of file +Pixel CONSTANT::HEALER_ATTACK_COL={91, 222, 104, 220}; + +float CONSTANT::DEBUFFICON_LIFETIME=0.8; \ No newline at end of file diff --git a/olcCodeJam2023Entry/Constant.h b/olcCodeJam2023Entry/Constant.h index 26d54ea..e45e8df 100644 --- a/olcCodeJam2023Entry/Constant.h +++ b/olcCodeJam2023Entry/Constant.h @@ -25,4 +25,6 @@ public: static Pixel ATTACKER_ATTACK_COL; static Pixel HEALER_TARGET_COL; static Pixel HEALER_ATTACK_COL; + + static float DEBUFFICON_LIFETIME; }; \ No newline at end of file diff --git a/olcCodeJam2023Entry/DebuffIcon.cpp b/olcCodeJam2023Entry/DebuffIcon.cpp new file mode 100644 index 0000000..5e2a4ea --- /dev/null +++ b/olcCodeJam2023Entry/DebuffIcon.cpp @@ -0,0 +1,11 @@ +#include "DebuffIcon.h" + +void DebuffIcon::Update(float fElapsedTime){ + pos.y-=6*fElapsedTime; + lifetime-=fElapsedTime; +} + +void DebuffIcon::Draw(TileTransformedView&game){ + game.DrawRotatedDecal(pos,icon->Decal(),0,icon->Sprite()->Size()/2,{1,1},{255,255,255,uint8_t((lifetime/CONSTANT::DEBUFFICON_LIFETIME)*255)}); + game.DrawRotatedDecal(pos+vf2d{4,-4},redXIcon->Decal(),0,icon->Sprite()->Size()/2,{1,1},{255,255,255,uint8_t((lifetime/CONSTANT::DEBUFFICON_LIFETIME)*255)}); +} \ No newline at end of file diff --git a/olcCodeJam2023Entry/DebuffIcon.h b/olcCodeJam2023Entry/DebuffIcon.h new file mode 100644 index 0000000..2c25ac4 --- /dev/null +++ b/olcCodeJam2023Entry/DebuffIcon.h @@ -0,0 +1,13 @@ +#pragma once +#include "olcPixelGameEngine.h" +#include "olcPGEX_TransformedView.h" +#include "Constant.h" + +struct DebuffIcon{ + Renderable*icon; + Renderable*redXIcon; + vf2d pos; + float lifetime=CONSTANT::DEBUFFICON_LIFETIME; + void Update(float fElapsedTime); + void Draw(TileTransformedView&game); +}; \ No newline at end of file diff --git a/olcCodeJam2023Entry/Image.h b/olcCodeJam2023Entry/Image.h index df8c36d..8577b43 100644 --- a/olcCodeJam2023Entry/Image.h +++ b/olcCodeJam2023Entry/Image.h @@ -26,5 +26,9 @@ enum Image{ SPD, TARGETING_LINE, ATTACKING_LINE, + RLD_ICON, + PRC_ICON, + RNG_ICON, + SPD_ICON, }; diff --git a/olcCodeJam2023Entry/Unit.cpp b/olcCodeJam2023Entry/Unit.cpp index 7ee4257..4c2d488 100644 --- a/olcCodeJam2023Entry/Unit.cpp +++ b/olcCodeJam2023Entry/Unit.cpp @@ -2,6 +2,7 @@ #include "olcUTIL_Geometry2D.h" #include "TileManager.h" #include "util.h" +#include "DebuffIcon.h" BasicUnit::BasicUnit(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) :Unit(pge,{ @@ -532,7 +533,7 @@ void Unit::SetPos(vf2d newPos){ } } -void Unit::AttemptAttack(std::weak_ptrattacker,std::weak_ptrunit,std::vector>&otherUnits){ +void Unit::AttemptAttack(std::weak_ptrattacker,std::weak_ptrunit,std::vector>&otherUnits,std::vector&debuffIcons,std::map>&IMAGES){ if(reloadTimer>0)return; std::weak_ptrfinalTarget; if(!unit.expired()){ @@ -547,7 +548,23 @@ void Unit::AttemptAttack(std::weak_ptrattacker,std::weak_ptrunit,std if(!finalTarget.expired()){ if(InRange(finalTarget.lock())){ appliedTarget=finalTarget; + bool hadAtkSpd=finalTarget.lock()->GetAtkSpd()>0; + bool hadMoveSpd=finalTarget.lock()->GetMoveSpd()>0; + bool hadRange=finalTarget.lock()->GetRange()>0; + bool hadProcedure=finalTarget.lock()->GetProcedure()>0; _Attack(attacker,finalTarget,otherUnits); //Call the parent function first, followed by the child. + if(hadAtkSpd&&finalTarget.lock()->GetAtkSpd()==0){ + debuffIcons.emplace_back(IMAGES[RLD_ICON].get(),IMAGES[RED_X].get(),finalTarget.lock()->GetPos()-vf2d{util::random(12)-6,4}); + } + if(hadMoveSpd&&finalTarget.lock()->GetMoveSpd()==0){ + debuffIcons.emplace_back(IMAGES[SPD_ICON].get(),IMAGES[RED_X].get(),finalTarget.lock()->GetPos()-vf2d{util::random(12)-6,4}); + } + if(hadRange&&finalTarget.lock()->GetRange()==0){ + debuffIcons.emplace_back(IMAGES[RNG_ICON].get(),IMAGES[RED_X].get(),finalTarget.lock()->GetPos()-vf2d{util::random(12)-6,4}); + } + if(hadProcedure&&finalTarget.lock()->GetProcedure()==0){ + debuffIcons.emplace_back(IMAGES[PRC_ICON].get(),IMAGES[RED_X].get(),finalTarget.lock()->GetPos()-vf2d{util::random(12)-6,4}); + } } } } diff --git a/olcCodeJam2023Entry/Unit.h b/olcCodeJam2023Entry/Unit.h index 69d26c7..1dc18e0 100644 --- a/olcCodeJam2023Entry/Unit.h +++ b/olcCodeJam2023Entry/Unit.h @@ -7,6 +7,7 @@ #include "Sound.h" #include "olcPGEX_AudioSource.h" #include "util.h" +#include "DebuffIcon.h" struct Marker{ size_t index; @@ -52,7 +53,7 @@ public: void SetTargetUnit(std::weak_ptrtarget); void SetTargetLocation(vf2d targetLoc); void SetPos(vf2d newPos); - void AttemptAttack(std::weak_ptrattacker,std::weak_ptrunit,std::vector>&otherUnits); + void AttemptAttack(std::weak_ptrattacker,std::weak_ptrunit,std::vector>&otherUnits,std::vector&debuffIcons,std::map>&IMAGES); bool InFogOfWar(); bool GhostInFogOfWar(); void HideGhost(); diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 010da65..a2f6816 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -42,6 +42,10 @@ void VirusAttack::InitializeImages(){ LoadImage(SPD,"assets/spd.png"); LoadImage(TARGETING_LINE,"assets/targetLine.png"); LoadImage(ATTACKING_LINE,"assets/attackLine.png"); + LoadImage(RLD_ICON,"assets/rld_icon.png"); + LoadImage(PRC_ICON,"assets/prc_icon.png"); + LoadImage(RNG_ICON,"assets/rng_icon.png"); + LoadImage(SPD_ICON,"assets/spd_icon.png"); } bool VirusAttack::OnUserCreate(){ @@ -358,7 +362,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ } } } - u->AttemptAttack(u,closestUnit,units); + u->AttemptAttack(u,closestUnit,units,debuffIcons,IMAGES); u->_Update(this,SOUNDS); } @@ -398,6 +402,13 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ u->DrawUnitDamageStats(this,game,IMAGES); } + for(DebuffIcon&icon:debuffIcons){ + icon.Update(fElapsedTime); + icon.Draw(game); + } + + std::erase_if(debuffIcons,[](DebuffIcon&icon){return icon.lifetime<=0;}); + for(auto&u:units){ u->DrawHud(game,IMAGES); } diff --git a/olcCodeJam2023Entry/VirusAttack.h b/olcCodeJam2023Entry/VirusAttack.h index df4d3af..4b5e317 100644 --- a/olcCodeJam2023Entry/VirusAttack.h +++ b/olcCodeJam2023Entry/VirusAttack.h @@ -8,6 +8,7 @@ #include "olcPGEX_AudioListener.h" #include "olcPGEX_AudioSource.h" #include "Sound.h" +#include "DebuffIcon.h" struct Letter{ vf2d pos; @@ -32,6 +33,7 @@ private: std::vector>units; std::vector>collectionPoints; std::vector>deathAnimations; + std::vectordebuffIcons; std::map>IMAGES; std::map>SOUNDS; diff --git a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj index 943f9b4..f66b16b 100644 --- a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj +++ b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj @@ -141,6 +141,7 @@ + @@ -163,6 +164,7 @@ + diff --git a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters index fcb4814..f637f6d 100644 --- a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters +++ b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters @@ -78,6 +78,9 @@ Header Files + + Header Files + @@ -98,6 +101,9 @@ Source Files + + Source Files +