From a32a99806168c5dba45821007d605a9dd9a4b154 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 30 Aug 2023 01:38:11 -0500 Subject: [PATCH] Add resouce bar, move collection points into its own class. --- olcCodeJam2023Entry/CollectionPoint.cpp | 26 +++++++++ olcCodeJam2023Entry/CollectionPoint.h | 15 +++++ olcCodeJam2023Entry/Image.h | 1 + olcCodeJam2023Entry/MemoryType.h | 9 +++ olcCodeJam2023Entry/Unit.h | 11 +--- olcCodeJam2023Entry/VirusAttack.cpp | 36 ++++-------- olcCodeJam2023Entry/VirusAttack.h | 22 ++++---- olcCodeJam2023Entry/assets/material.png | Bin 0 -> 695 bytes .../olcCodeJam2023Entry.vcxproj | 3 + .../olcCodeJam2023Entry.vcxproj.filters | 9 +++ olcCodeJam2023Entry/olcPixelGameEngine.h | 52 ++++++++++++++++++ 11 files changed, 141 insertions(+), 43 deletions(-) create mode 100644 olcCodeJam2023Entry/CollectionPoint.cpp create mode 100644 olcCodeJam2023Entry/CollectionPoint.h create mode 100644 olcCodeJam2023Entry/MemoryType.h create mode 100644 olcCodeJam2023Entry/assets/material.png diff --git a/olcCodeJam2023Entry/CollectionPoint.cpp b/olcCodeJam2023Entry/CollectionPoint.cpp new file mode 100644 index 0000000..9b6ba0b --- /dev/null +++ b/olcCodeJam2023Entry/CollectionPoint.cpp @@ -0,0 +1,26 @@ +#include "CollectionPoint.h" +#include "util.h" + +CollectionPoint::CollectionPoint(PixelGameEngine*pge,vf2d pos,float rot,Renderable&collectionPointImg,MemoryType type) + :pos(pos),rot(rot),type(type),originalCollectionPointImg(collectionPointImg.Sprite()),randomOffset({util::random(128),util::random(128)}){ + img.Create(collectionPointImg.Sprite()->width,collectionPointImg.Sprite()->height); + pge->SetDrawTarget(img.Sprite()); + pge->Clear(BLANK); + pge->DrawSprite({0,0},collectionPointImg.Sprite()); + pge->SetDrawTarget(nullptr); + img.Decal()->Update(); +} + +void CollectionPoint::Update(PixelGameEngine*pge,Renderable&matrixImg){ + pge->SetDrawTarget(img.Sprite()); + for(int y=0;yheight;y++){ + for(int x=0;xwidth;x++){ + Pixel col=originalCollectionPointImg->GetPixel(x,y); + if(col==WHITE){ + pge->Draw(x,y,matrixImg.Sprite()->GetPixel(int(x+randomOffset.x),int(y+randomOffset.y))); + } + } + } + img.Decal()->Update(); + pge->SetDrawTarget(nullptr); +} \ No newline at end of file diff --git a/olcCodeJam2023Entry/CollectionPoint.h b/olcCodeJam2023Entry/CollectionPoint.h new file mode 100644 index 0000000..891143e --- /dev/null +++ b/olcCodeJam2023Entry/CollectionPoint.h @@ -0,0 +1,15 @@ +#pragma once +#include "olcPixelGameEngine.h" +#include "MemoryType.h" + +class CollectionPoint{ +public: + vf2d pos; + Renderable img; + Sprite*originalCollectionPointImg; + MemoryType type; + vf2d randomOffset; + float rot; + CollectionPoint(PixelGameEngine*pge,vf2d pos,float rot,Renderable&collectionPointImg,MemoryType type); + void Update(PixelGameEngine*pge,Renderable&matrixImg); +}; \ No newline at end of file diff --git a/olcCodeJam2023Entry/Image.h b/olcCodeJam2023Entry/Image.h index 8577b43..5979da0 100644 --- a/olcCodeJam2023Entry/Image.h +++ b/olcCodeJam2023Entry/Image.h @@ -30,5 +30,6 @@ enum Image{ PRC_ICON, RNG_ICON, SPD_ICON, + RESOURCE, }; diff --git a/olcCodeJam2023Entry/MemoryType.h b/olcCodeJam2023Entry/MemoryType.h new file mode 100644 index 0000000..dcdbd36 --- /dev/null +++ b/olcCodeJam2023Entry/MemoryType.h @@ -0,0 +1,9 @@ +#pragma once + +enum MemoryType{ + HEALTH, + RANGE, + ATKSPD, + MOVESPD, + PROCEDURE +}; \ No newline at end of file diff --git a/olcCodeJam2023Entry/Unit.h b/olcCodeJam2023Entry/Unit.h index 1dc18e0..0f67593 100644 --- a/olcCodeJam2023Entry/Unit.h +++ b/olcCodeJam2023Entry/Unit.h @@ -8,20 +8,14 @@ #include "olcPGEX_AudioSource.h" #include "util.h" #include "DebuffIcon.h" +#include "CollectionPoint.h" +#include "MemoryType.h" struct Marker{ size_t index; size_t size; }; -enum MemoryType{ - HEALTH, - RANGE, - ATKSPD, - MOVESPD, - PROCEDURE -}; - struct Memory{ MemoryType type; int size; @@ -126,6 +120,7 @@ private: bool enemyInteractable=true; float lineShift=0; void ApplyMatrixEffect(Renderable&r); + std::weak_ptrattachedPoint; }; struct BasicUnit:Unit{ diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index a2f6816..407d2b9 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -46,6 +46,7 @@ void VirusAttack::InitializeImages(){ LoadImage(PRC_ICON,"assets/prc_icon.png"); LoadImage(RNG_ICON,"assets/rng_icon.png"); LoadImage(SPD_ICON,"assets/spd_icon.png"); + LoadImage(RESOURCE,"assets/material.png"); } bool VirusAttack::OnUserCreate(){ @@ -415,6 +416,17 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ DrawSelectionRectangle(); RenderFogOfWar(); + GradientFillRectDecal({0,0},{float(ScreenWidth()),12.f},BLACK,{VERY_DARK_BLUE.r,VERY_DARK_BLUE.g,VERY_DARK_BLUE.b,128},{VERY_DARK_BLUE.r,VERY_DARK_BLUE.g,VERY_DARK_BLUE.b,128},BLACK); + DrawRectDecal({0,0},{float(ScreenWidth()),12.f},{3, 194, 252}); + auto DrawResourceDisplay=[&](int index,int resourceValue,Pixel col){ + DrawDecal({6.f+index*42,1.f},IMAGES[RESOURCE]->Decal(),{1,1},col); + DrawShadowStringDecal({6.f+index*42+20,2.f},std::to_string(resourceValue),col,BLACK); + }; + DrawResourceDisplay(0,player_resources.health,CONSTANT::HEALTH_COLOR); + DrawResourceDisplay(1,player_resources.atkSpd,CONSTANT::ATKSPD_COLOR); + DrawResourceDisplay(2,player_resources.moveSpd,CONSTANT::MOVESPD_COLOR); + DrawResourceDisplay(3,player_resources.range,CONSTANT::RANGE_COLOR); + DrawResourceDisplay(4,player_resources.procedure,CONSTANT::PROCEDURE_COLOR); DrawMinimap(); @@ -438,30 +450,6 @@ void VirusAttack::RenderFogOfWar(){ } } -VirusAttack::CollectionPoint::CollectionPoint(PixelGameEngine*pge,vf2d pos,float rot,Renderable&collectionPointImg,MemoryType type) - :pos(pos),rot(rot),type(type),originalCollectionPointImg(collectionPointImg.Sprite()),randomOffset({util::random(128),util::random(128)}){ - img.Create(collectionPointImg.Sprite()->width,collectionPointImg.Sprite()->height); - pge->SetDrawTarget(img.Sprite()); - pge->Clear(BLANK); - pge->DrawSprite({0,0},collectionPointImg.Sprite()); - pge->SetDrawTarget(nullptr); - img.Decal()->Update(); -} - -void VirusAttack::CollectionPoint::Update(PixelGameEngine*pge,Renderable&matrixImg){ - pge->SetDrawTarget(img.Sprite()); - for(int y=0;yheight;y++){ - for(int x=0;xwidth;x++){ - Pixel col=originalCollectionPointImg->GetPixel(x,y); - if(col==WHITE){ - pge->Draw(x,y,matrixImg.Sprite()->GetPixel(int(x+randomOffset.x),int(y+randomOffset.y))); - } - } - } - img.Decal()->Update(); - pge->SetDrawTarget(nullptr); -} - int main() { VirusAttack app; diff --git a/olcCodeJam2023Entry/VirusAttack.h b/olcCodeJam2023Entry/VirusAttack.h index 4b5e317..3eca249 100644 --- a/olcCodeJam2023Entry/VirusAttack.h +++ b/olcCodeJam2023Entry/VirusAttack.h @@ -9,6 +9,7 @@ #include "olcPGEX_AudioSource.h" #include "Sound.h" #include "DebuffIcon.h" +#include "CollectionPoint.h" struct Letter{ vf2d pos; @@ -16,19 +17,16 @@ struct Letter{ char c; }; +struct Resources{ + int health=0; + int atkSpd=0; + int moveSpd=0; + int range=0; + int procedure=0; +}; + class VirusAttack : public olc::PixelGameEngine { - class CollectionPoint{ - public: - vf2d pos; - Renderable img; - Sprite*originalCollectionPointImg; - MemoryType type; - vf2d randomOffset; - float rot; - CollectionPoint(PixelGameEngine*pge,vf2d pos,float rot,Renderable&collectionPointImg,MemoryType type); - void Update(PixelGameEngine*pge,Renderable&matrixImg); - }; private: std::vector>units; std::vector>collectionPoints; @@ -41,6 +39,8 @@ private: olcPGEX_AudioListener AL; Audio*bgm; + Resources player_resources,enemy_resources; + TileTransformedView game; float matrixTimer=0; diff --git a/olcCodeJam2023Entry/assets/material.png b/olcCodeJam2023Entry/assets/material.png new file mode 100644 index 0000000000000000000000000000000000000000..c3746a8232a00b810c0dff62ecf686cc343c1951 GIT binary patch literal 695 zcmV;o0!aOdP)EX>4Tx04R}tkv&MmKpe$iQ?*4Z4t5X`$xxl_Qbio4ibb$c+6t{Ym|Xe=O&XFE z7e~Rh;NZt%)xpJCR|i)?5c~jfb#YR3krMxx6k5c1aNLh~_a1le0HIlBs@XFKsG4P@ z6LB$@Uljwd2x1I<2p}dgQ%`0Vv+x{W_we!cF3PjK&;2e3JS*_Mt`=0!Tp@O!O;X2JxB(Q`eQV=1djtZ)<5T#Wk#YCF+;~xGI$DbmXOs)zT zITlcZ3d!+<|H1EW&EizdO$x<<-WS{c7zYBoK&xTf-^aGyIsyF8z?IhV*P6iWC+Urj z7C8b2w}Ff6jwbH`mpj1llP(#OBl&3x#Uk*2M&FbNhHioWHMh6+K29HiEOoVf0~{Oz z6D7)C_jq@(ySIPOwEO!3x1e&u@PZ5300006VoOIv00#i;008dPSS|nn010qNS#tmY zE+YT{E+YYWr9XB6000McNliru=LjAK2q!LmsU`pb02y>eSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{0056kL_t(2&y|uf4#Xe~1lLk3UP0}z@Lqq#Exf`l*Bpss zLhe`z2?;Y^F93J-@7fZ1fT{ujnE9=43F&4A0BEgEMZcgF?GHCmwbpZAN|}hK3jjzd z;SK6x19-%aW_BAXjv^wHBl3X)K+buYO@xZbhf|N&%+L%G&BDd^49x5eY^)J dMA%o4CO&L%La)G>&2j($002ovPDHLkV1lA0Bpv_& literal 0 HcmV?d00001 diff --git a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj index f66b16b..d4f0a74 100644 --- a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj +++ b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj @@ -139,10 +139,12 @@ + + @@ -162,6 +164,7 @@ + diff --git a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters index f637f6d..afd5b60 100644 --- a/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters +++ b/olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters @@ -81,6 +81,12 @@ Header Files + + Header Files + + + Header Files + @@ -104,6 +110,9 @@ Source Files + + Source Files + diff --git a/olcCodeJam2023Entry/olcPixelGameEngine.h b/olcCodeJam2023Entry/olcPixelGameEngine.h index 174d8c9..a240e6a 100644 --- a/olcCodeJam2023Entry/olcPixelGameEngine.h +++ b/olcCodeJam2023Entry/olcPixelGameEngine.h @@ -1128,6 +1128,8 @@ namespace olc // Draws a multiline string as a decal, with tiniting and scaling void DrawStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f }); void DrawStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f }); + void DrawShadowStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1); + void DrawShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1); // Draws a single shaded filled rectangle as a decal void DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE); void FillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE); @@ -1142,6 +1144,8 @@ namespace olc void DrawLineDecal(const olc::vf2d& pos1, const olc::vf2d& pos2, Pixel p = olc::WHITE); void DrawRotatedStringDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f }); void DrawRotatedStringPropDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f }); + void DrawRotatedShadowStringDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1); + void DrawRotatedShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1); // Clears entire draw target to Pixel void Clear(Pixel p); // Clears the rendering back buffer @@ -3261,6 +3265,54 @@ namespace olc } } } + + + + void PixelGameEngine::DrawShadowStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){ + for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){ + for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){ + if(x!=0||y!=0){ + DrawStringDecal(pos+vf2d{x,y}, sText, shadowCol,scale); + } + } + } + DrawStringDecal(pos, sText, col,scale); + } + + void PixelGameEngine::DrawShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){ + for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){ + for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){ + if(x!=0||y!=0){ + DrawStringPropDecal(pos+vf2d{x,y}, sText, shadowCol,scale); + } + } + } + DrawStringPropDecal(pos, sText, col,scale); + } + + + + void PixelGameEngine::DrawRotatedShadowStringDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){ + for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){ + for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){ + if(x!=0||y!=0){ + DrawRotatedStringDecal(pos+vf2d{x,y}, sText,fAngle,center,shadowCol,scale); + } + } + } + DrawRotatedStringDecal(pos, sText,fAngle,center,col,scale); + } + void PixelGameEngine::DrawRotatedShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){ + for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){ + for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){ + if(x!=0||y!=0){ + DrawRotatedStringPropDecal(pos+vf2d{x,y}, sText,fAngle,center,shadowCol,scale); + } + } + } + DrawRotatedStringPropDecal(pos, sText,fAngle,center,col,scale); + } + // Thanks Oso-Grande/Sopadeoso For these awesom and stupidly clever Text Rotation routines... duh XD void PixelGameEngine::DrawRotatedStringDecal(const olc::vf2d& pos, const std::string& sText, const float fAngle, const olc::vf2d& center, const Pixel col, const olc::vf2d& scale) {