From 40238e67a6794f5edfa2efc1e9adccdca1d782e7 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 27 Aug 2023 11:22:44 -0500 Subject: [PATCH] Fix range display issues, make right click holding a thing for smoother movement. --- olcCodeJam2023Entry/Unit.cpp | 37 +++++++++++++++++------------ olcCodeJam2023Entry/Unit.h | 3 ++- olcCodeJam2023Entry/VirusAttack.cpp | 2 +- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/olcCodeJam2023Entry/Unit.cpp b/olcCodeJam2023Entry/Unit.cpp index 8f0e411..2807243 100644 --- a/olcCodeJam2023Entry/Unit.cpp +++ b/olcCodeJam2023Entry/Unit.cpp @@ -11,7 +11,7 @@ BasicUnit::BasicUnit(vf2d pos,std::map>&IMAGES {ATKSPD,2}, {MOVESPD,3}, {PROCEDURE,1}, - },pos,*IMAGES[VIRUS_IMG1],friendly,moveable){} + },pos,12,*IMAGES[VIRUS_IMG1],friendly,moveable){} void BasicUnit::Attack(Unit&victim){ @@ -25,7 +25,7 @@ BasicUnit2::BasicUnit2(vf2d pos,std::map>&IMAG {MOVESPD,3}, {PROCEDURE,1}, {HEALTH,4}, - },pos,*IMAGES[VIRUS_IMG1],friendly,moveable){} + },pos,12,*IMAGES[VIRUS_IMG1],friendly,moveable){} void BasicUnit2::Attack(Unit&victim){ victim>>=1; @@ -38,7 +38,7 @@ LeftShifter::LeftShifter(vf2d pos,std::map>&IM {MOVESPD,3}, {PROCEDURE,1}, {HEALTH,4}, - },pos,*IMAGES[LEFT_SHIFTER],friendly,moveable){} + },pos,12,*IMAGES[LEFT_SHIFTER],friendly,moveable){} void LeftShifter::Attack(Unit&victim){ victim<<=1; @@ -51,7 +51,7 @@ RightShifter::RightShifter(vf2d pos,std::map>& {ATKSPD,2}, {MOVESPD,3}, {PROCEDURE,1}, - },pos,*IMAGES[RIGHT_SHIFTER],friendly,moveable){} + },pos,12,*IMAGES[RIGHT_SHIFTER],friendly,moveable){} void RightShifter::Attack(Unit&victim){ victim>>=1; @@ -64,7 +64,7 @@ BitRestorer::BitRestorer(vf2d pos,std::map>&IM {ATKSPD,1}, {MOVESPD,1}, {HEALTH,2}, - },pos,*IMAGES[BIT_RESTORER],friendly,moveable){} + },pos,12,*IMAGES[BIT_RESTORER],friendly,moveable){} void BitRestorer::Attack(Unit&victim){ @@ -77,7 +77,7 @@ MemorySwapper::MemorySwapper(vf2d pos,std::map {HEALTH,3}, {PROCEDURE,3}, {MOVESPD,2}, - },pos,*IMAGES[MEMORY_SWAPPER],friendly,moveable){} + },pos,12,*IMAGES[MEMORY_SWAPPER],friendly,moveable){} void MemorySwapper::Attack(Unit&victim){ @@ -90,7 +90,7 @@ Corrupter::Corrupter(vf2d pos,std::map>&IMAGES {PROCEDURE,8}, {MOVESPD,4}, {HEALTH,4}, - },pos,*IMAGES[CORRUPTER],friendly,moveable){} + },pos,12,*IMAGES[CORRUPTER],friendly,moveable){} void Corrupter::Attack(Unit&victim){ @@ -103,7 +103,7 @@ MemoryAllocator::MemoryAllocator(vf2d pos,std::mapSprite()->width,IMAGES[RAM_BANK]->Sprite()->height); pge->SetDrawTarget(img.Sprite()); @@ -150,8 +150,8 @@ void RAMBank::Draw(TileTransformedView&game,std::mapmemory,vf2d pos,Renderable&img,bool friendly,bool moveable) -:pos(pos),ghostPos(pos),img(img),friendly(friendly),moveable(moveable){ +Unit::Unit(std::vectormemory,vf2d pos,float radius,Renderable&img,bool friendly,bool moveable) +:pos(pos),radius(radius),ghostPos(pos),img(img),friendly(friendly),moveable(moveable){ int marker=0; for(Memory&mem:memory){ for(int i=0;imemory,vf2d pos,Renderable&img,bool friendly,bool } void Unit::DrawRangeIndicator(PixelGameEngine*pge,TileTransformedView&game,std::map>&IMAGES){ - float dist=geom2d::line(game.ScreenToWorld(pge->GetMousePos()),GetPos()).length(); + float dist=geom2d::line(game.ScreenToWorld(pge->GetMousePos()),GetGhostPos()).length(); float range=12*(GetRange()+1); + float totalRange=GetUnitSize().x/2+range; if(IsSelected()){ - game.DrawRotatedDecal(GetPos(),IMAGES[RANGE_INDICATOR]->Decal(),0,IMAGES[RANGE_INDICATOR]->Sprite()->Size()/2,{range/12,range/12},{0,196,0,128}); + game.DrawRotatedDecal(GetGhostPos(),IMAGES[RANGE_INDICATOR]->Decal(),0,IMAGES[RANGE_INDICATOR]->Sprite()->Size()/2,{totalRange/12,totalRange/12},{0,196,0,128}); }else if(distDecal(),0,IMAGES[RANGE_INDICATOR]->Sprite()->Size()/2,{range/12,range/12},{0,196,0,uint8_t((1.f-(dist/(range*2)))*128)}); + Pixel col; + if(IsFriendly()){ + col={0,196,0}; + }else{ + col={196,130,0}; + } + game.DrawRotatedDecal(GetGhostPos(),IMAGES[RANGE_INDICATOR]->Decal(),0,IMAGES[RANGE_INDICATOR]->Sprite()->Size()/2,{totalRange/12,totalRange/12},{col.r,col.g,col.b,uint8_t((1.f-(dist/(range*2)))*128)}); } } @@ -359,7 +366,7 @@ bool Unit::IsDead(){ } vf2d Unit::GetUnitSize(){ - return img.Sprite()->Size(); + return vf2d{radius,radius}*2; } void Unit::SetTargetUnit(std::weak_ptrtarget){ diff --git a/olcCodeJam2023Entry/Unit.h b/olcCodeJam2023Entry/Unit.h index 0b5d11c..380381f 100644 --- a/olcCodeJam2023Entry/Unit.h +++ b/olcCodeJam2023Entry/Unit.h @@ -25,7 +25,7 @@ struct Memory{ struct Unit{ public: - Unit(std::vectormemory,vf2d pos,Renderable&img,bool friendly=false,bool moveable=true); + Unit(std::vectormemory,vf2d pos,float radius,Renderable&img,bool friendly=false,bool moveable=true); int GetHealth(); int GetRange(); int GetAtkSpd(); @@ -91,6 +91,7 @@ protected: private: vf2d pos; vf2d ghostPos; + float radius; int GetBits(Marker&m); bool selected=false; bool dead=false; diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index f3dbe51..16e3944 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -106,7 +106,7 @@ void VirusAttack::DrawSelectionRectangle(){ } void VirusAttack::HandleRightClickMove(){ - if (GetMouse(1).bPressed){ + if (GetMouse(1).bHeld){ bool selectedTarget=false; for(auto&u:units){ if(!u->IsFriendly()){