From d233afe97574a3fbf3b7eb792b9c2ba22f2efc04 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sat, 26 Aug 2023 16:18:38 -0500 Subject: [PATCH] RAMBAnk is immoveable. --- olcCodeJam2023Entry/Unit.cpp | 44 ++++++++++++++++------------- olcCodeJam2023Entry/Unit.h | 20 +++++++------ olcCodeJam2023Entry/VirusAttack.cpp | 8 ++++-- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/olcCodeJam2023Entry/Unit.cpp b/olcCodeJam2023Entry/Unit.cpp index 20a258d..1dd1892 100644 --- a/olcCodeJam2023Entry/Unit.cpp +++ b/olcCodeJam2023Entry/Unit.cpp @@ -4,99 +4,99 @@ #include "TileManager.h" #include "util.h" -BasicUnit::BasicUnit(vf2d pos,std::map>&IMAGES,bool friendly) +BasicUnit::BasicUnit(vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) :Unit({ {HEALTH,4}, {RANGE,2}, {ATKSPD,2}, {MOVESPD,3}, {PROCEDURE,1}, - },pos,*IMAGES[VIRUS_IMG1],friendly){} + },pos,*IMAGES[VIRUS_IMG1],friendly,moveable){} void BasicUnit::Attack(Unit&victim){ victim<<=1; } -BasicUnit2::BasicUnit2(vf2d pos,std::map>&IMAGES,bool friendly) +BasicUnit2::BasicUnit2(vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) :Unit({ {RANGE,2}, {ATKSPD,2}, {MOVESPD,3}, {PROCEDURE,1}, {HEALTH,4}, - },pos,*IMAGES[VIRUS_IMG1],friendly){} + },pos,*IMAGES[VIRUS_IMG1],friendly,moveable){} void BasicUnit2::Attack(Unit&victim){ - + } -LeftShifter::LeftShifter(vf2d pos,std::map>&IMAGES,bool friendly) +LeftShifter::LeftShifter(vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) :Unit({ {RANGE,2}, {ATKSPD,2}, {MOVESPD,3}, {PROCEDURE,1}, {HEALTH,4}, - },pos,*IMAGES[LEFT_SHIFTER],friendly){} + },pos,*IMAGES[LEFT_SHIFTER],friendly,moveable){} void LeftShifter::Attack(Unit&victim){ - + } -RightShifter::RightShifter(vf2d pos,std::map>&IMAGES,bool friendly) +RightShifter::RightShifter(vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) :Unit({ {HEALTH,4}, {RANGE,2}, {ATKSPD,2}, {MOVESPD,3}, {PROCEDURE,1}, - },pos,*IMAGES[RIGHT_SHIFTER],friendly){} + },pos,*IMAGES[RIGHT_SHIFTER],friendly,moveable){} void RightShifter::Attack(Unit&victim){ } -BitRestorer::BitRestorer(vf2d pos,std::map>&IMAGES,bool friendly) +BitRestorer::BitRestorer(vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) :Unit({ {PROCEDURE,6}, {RANGE,1}, {ATKSPD,1}, {MOVESPD,1}, {HEALTH,2}, - },pos,*IMAGES[BIT_RESTORER],friendly){} + },pos,*IMAGES[BIT_RESTORER],friendly,moveable){} void BitRestorer::Attack(Unit&victim){ } -MemorySwapper::MemorySwapper(vf2d pos,std::map>&IMAGES,bool friendly) +MemorySwapper::MemorySwapper(vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) :Unit({ {RANGE,3}, {ATKSPD,1}, {HEALTH,3}, {PROCEDURE,3}, {MOVESPD,2}, - },pos,*IMAGES[MEMORY_SWAPPER],friendly){} + },pos,*IMAGES[MEMORY_SWAPPER],friendly,moveable){} void MemorySwapper::Attack(Unit&victim){ } -Corrupter::Corrupter(vf2d pos,std::map>&IMAGES,bool friendly) +Corrupter::Corrupter(vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) :Unit({ {ATKSPD,3}, {RANGE,1}, {PROCEDURE,8}, {MOVESPD,4}, {HEALTH,4}, - },pos,*IMAGES[CORRUPTER],friendly){} + },pos,*IMAGES[CORRUPTER],friendly,moveable){} void Corrupter::Attack(Unit&victim){ } -MemoryAllocator::MemoryAllocator(vf2d pos,std::map>&IMAGES,bool friendly) +MemoryAllocator::MemoryAllocator(vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) :Unit({ {RANGE,1}, {ATKSPD,1}, @@ -116,7 +116,7 @@ RAMBank::RAMBank(PixelGameEngine*pge,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) -:pos(pos),ghostPos(pos),img(img),friendly(friendly){ +Unit::Unit(std::vectormemory,vf2d pos,Renderable&img,bool friendly,bool moveable) +:pos(pos),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=false); + Unit(std::vectormemory,vf2d pos,Renderable&img,bool friendly=false,bool moveable=true); int GetHealth(); int GetRange(); int GetAtkSpd(); @@ -54,6 +54,7 @@ public: void HideGhost(); vf2d GetGhostPos(); void _Update(PixelGameEngine*pge); + bool IsMoveable(); std::vector& operator <<=(const int n){ for(int i=0;i>&IMAGES,bool friendly=false); + BasicUnit(vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim)override; }; struct BasicUnit2:Unit{ - BasicUnit2(vf2d pos,std::map>&IMAGES,bool friendly=false); + BasicUnit2(vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim)override; }; struct LeftShifter:Unit{ - LeftShifter(vf2d pos,std::map>&IMAGES,bool friendly=false); + LeftShifter(vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim)override; }; struct RightShifter:Unit{ - RightShifter(vf2d pos,std::map>&IMAGES,bool friendly=false); + RightShifter(vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim)override; }; struct BitRestorer:Unit{ - BitRestorer(vf2d pos,std::map>&IMAGES,bool friendly=false); + BitRestorer(vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim)override; }; struct MemorySwapper:Unit{ - MemorySwapper(vf2d pos,std::map>&IMAGES,bool friendly=false); + MemorySwapper(vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim)override; }; struct Corrupter:Unit{ - Corrupter(vf2d pos,std::map>&IMAGES,bool friendly=false); + Corrupter(vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim)override; }; struct MemoryAllocator:Unit{ - MemoryAllocator(vf2d pos,std::map>&IMAGES,bool friendly=false); + MemoryAllocator(vf2d pos,std::map>&IMAGES,bool friendly=false,bool moveable=true); void Attack(Unit&victim)override; }; diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 46d1e95..e2eac14 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -135,8 +135,12 @@ void VirusAttack::CollisionChecking(std::shared_ptru,std::shared_ptr float maxDist=u->GetUnitSize().x/2+u2->GetUnitSize().x/2; float dist=maxDist-collisionLine.length(); vf2d dir=collisionLine.vector().norm(); - u->SetPos(u->GetPos()-dir*dist/2); - u2->SetPos(u2->GetPos()+dir*dist/2); + if(u->IsMoveable()){ + u->SetPos(u->GetPos()-dir*dist/2); + } + if(u2->IsMoveable()){ + u2->SetPos(u2->GetPos()+dir*dist/2); + } } }