From 88d9dea027237101dd2ae3973bce38be43d750f2 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 27 Aug 2023 02:33:30 -0500 Subject: [PATCH] Fixed Range indicator issues and reduced attack range stat to be 2 per point. --- olcCodeJam2023Entry/Info.txt | 9 +++++++++ olcCodeJam2023Entry/Unit.cpp | 24 ++++++++++++++---------- olcCodeJam2023Entry/Unit.h | 1 + olcCodeJam2023Entry/VirusAttack.cpp | 7 ++++++- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/olcCodeJam2023Entry/Info.txt b/olcCodeJam2023Entry/Info.txt index f6c70d3..a1cc2c7 100644 --- a/olcCodeJam2023Entry/Info.txt +++ b/olcCodeJam2023Entry/Info.txt @@ -14,6 +14,15 @@ Attack Speed: 1/(AtkSpd/2) attacks per second Range/Attack indicators System has limited resources, both sides fight for resources. +Add Bar +Quantify Resource Limits + +Start off w/5 of each resource. + +Player build Memory Allocators using Resources. +(HEALTH,RANGE,ATKSPD,MOVESPD,PROCEDURE) +Memory Allocator costs 1/1/1/1/1. + Tutorial diff --git a/olcCodeJam2023Entry/Unit.cpp b/olcCodeJam2023Entry/Unit.cpp index 1dd1892..9aeae8c 100644 --- a/olcCodeJam2023Entry/Unit.cpp +++ b/olcCodeJam2023Entry/Unit.cpp @@ -28,7 +28,7 @@ BasicUnit2::BasicUnit2(vf2d pos,std::map>&IMAG },pos,*IMAGES[VIRUS_IMG1],friendly,moveable){} void BasicUnit2::Attack(Unit&victim){ - + victim>>=1; } LeftShifter::LeftShifter(vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) @@ -41,7 +41,7 @@ LeftShifter::LeftShifter(vf2d pos,std::map>&IM },pos,*IMAGES[LEFT_SHIFTER],friendly,moveable){} void LeftShifter::Attack(Unit&victim){ - + victim<<=1; } RightShifter::RightShifter(vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) @@ -54,7 +54,7 @@ RightShifter::RightShifter(vf2d pos,std::map>& },pos,*IMAGES[RIGHT_SHIFTER],friendly,moveable){} void RightShifter::Attack(Unit&victim){ - + victim>>=1; } BitRestorer::BitRestorer(vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) @@ -266,8 +266,6 @@ void Unit::_Update(PixelGameEngine*pge){ auto ptrTarget=target.lock(); if(!InRange(ptrTarget)){ SetPos(GetPos()+(ptrTarget->GetPos()-pos).norm()*GetMoveSpd()*24*pge->GetElapsedTime()); - } else { - //TODO Attack here. } } else if(targetLoc!=CONSTANT::UNSELECTED){ @@ -366,13 +364,19 @@ void Unit::SetTargetLocation(vf2d targetLoc){ } bool Unit::InRange(std::shared_ptrtarget){ - float dist=geom2d::line(GetPos(),target->GetPos()).length(); - return dist<24*(GetRange()+1); + return InRange(target.get()); +} + +bool Unit::InRange(Unit*target){ + float range=12*(GetRange()+1); + float totalRange=GetUnitSize().x/2+range; + return geom2d::overlaps(geom2d::circle{GetPos(),totalRange},geom2d::circle{target->GetPos(),target->GetUnitSize().x/2}); } bool Unit::InRange(vf2d pos){ - float dist=geom2d::line(GetPos(),pos).length(); - return dist<24*(GetRange()+1); + float range=12*(GetRange()+1); + float totalRange=GetUnitSize().x/2+range; + return geom2d::overlaps(geom2d::circle{GetPos(),totalRange},geom2d::circle{pos,0.1}); } void Unit::SetPos(vf2d newPos){ @@ -395,7 +399,7 @@ void Unit::AttemptAttack(Unit*unit){ } } if(finalTarget!=nullptr){ - if(InRange(finalTarget->GetPos())){ + if(InRange(finalTarget)){ _Attack(finalTarget); //Call the parent function first, followed by the child. } } diff --git a/olcCodeJam2023Entry/Unit.h b/olcCodeJam2023Entry/Unit.h index 4cbf81a..4376203 100644 --- a/olcCodeJam2023Entry/Unit.h +++ b/olcCodeJam2023Entry/Unit.h @@ -94,6 +94,7 @@ private: bool selected=false; bool dead=false; bool InRange(std::shared_ptrtarget); + bool InRange(Unit*target); bool InRange(vf2d pos); float reloadTimer=0; void _Attack(Unit*finalTarget); diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index e2eac14..d8493bd 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -61,6 +61,8 @@ bool VirusAttack::OnUserCreate(){ collectionPoints.push_back(std::make_unique(this,vf2d{32.f,32.f+48*i},-PI/2,*IMAGES[MEMORY_COLLECTION_POINT],MemoryType(i))); } + units.push_back(std::make_unique(this,vf2d{320,320},IMAGES,false)); + return true; } @@ -163,7 +165,10 @@ void VirusAttack::DrawMinimap(){ Clear(BLANK); DrawRect((game.GetWorldOffset()/worldPixelSize*64),viewingTilesPct*64/game.GetWorldScale()); for(auto&u:units){ - FillRect(u->GetGhostPos()/worldPixelSize*64,vf2d{2,2}*u->GetUnitSize()/24,u->IsFriendly()?GREEN:RED); + vf2d squareSize=u->GetUnitSize()/vf2d(CONSTANT::WORLD_SIZE); + squareSize.x=std::round(std::max(1.f,squareSize.x)); + squareSize.y=std::round(std::max(1.f,squareSize.y)); + FillRect(u->GetGhostPos()/worldPixelSize*64-squareSize,squareSize*2,u->IsFriendly()?GREEN:RED); } IMAGES[MINIMAP_OUTLINE]->Decal()->Update(); SetDrawTarget(nullptr);