RAMBAnk is immoveable.

CorrectiveAction
sigonasr2 1 year ago
parent 3126621645
commit d233afe975
  1. 40
      olcCodeJam2023Entry/Unit.cpp
  2. 20
      olcCodeJam2023Entry/Unit.h
  3. 4
      olcCodeJam2023Entry/VirusAttack.cpp

@ -4,99 +4,99 @@
#include "TileManager.h" #include "TileManager.h"
#include "util.h" #include "util.h"
BasicUnit::BasicUnit(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly) BasicUnit::BasicUnit(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit({ :Unit({
{HEALTH,4}, {HEALTH,4},
{RANGE,2}, {RANGE,2},
{ATKSPD,2}, {ATKSPD,2},
{MOVESPD,3}, {MOVESPD,3},
{PROCEDURE,1}, {PROCEDURE,1},
},pos,*IMAGES[VIRUS_IMG1],friendly){} },pos,*IMAGES[VIRUS_IMG1],friendly,moveable){}
void BasicUnit::Attack(Unit&victim){ void BasicUnit::Attack(Unit&victim){
victim<<=1; victim<<=1;
} }
BasicUnit2::BasicUnit2(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly) BasicUnit2::BasicUnit2(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit({ :Unit({
{RANGE,2}, {RANGE,2},
{ATKSPD,2}, {ATKSPD,2},
{MOVESPD,3}, {MOVESPD,3},
{PROCEDURE,1}, {PROCEDURE,1},
{HEALTH,4}, {HEALTH,4},
},pos,*IMAGES[VIRUS_IMG1],friendly){} },pos,*IMAGES[VIRUS_IMG1],friendly,moveable){}
void BasicUnit2::Attack(Unit&victim){ void BasicUnit2::Attack(Unit&victim){
} }
LeftShifter::LeftShifter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly) LeftShifter::LeftShifter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit({ :Unit({
{RANGE,2}, {RANGE,2},
{ATKSPD,2}, {ATKSPD,2},
{MOVESPD,3}, {MOVESPD,3},
{PROCEDURE,1}, {PROCEDURE,1},
{HEALTH,4}, {HEALTH,4},
},pos,*IMAGES[LEFT_SHIFTER],friendly){} },pos,*IMAGES[LEFT_SHIFTER],friendly,moveable){}
void LeftShifter::Attack(Unit&victim){ void LeftShifter::Attack(Unit&victim){
} }
RightShifter::RightShifter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly) RightShifter::RightShifter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit({ :Unit({
{HEALTH,4}, {HEALTH,4},
{RANGE,2}, {RANGE,2},
{ATKSPD,2}, {ATKSPD,2},
{MOVESPD,3}, {MOVESPD,3},
{PROCEDURE,1}, {PROCEDURE,1},
},pos,*IMAGES[RIGHT_SHIFTER],friendly){} },pos,*IMAGES[RIGHT_SHIFTER],friendly,moveable){}
void RightShifter::Attack(Unit&victim){ void RightShifter::Attack(Unit&victim){
} }
BitRestorer::BitRestorer(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly) BitRestorer::BitRestorer(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit({ :Unit({
{PROCEDURE,6}, {PROCEDURE,6},
{RANGE,1}, {RANGE,1},
{ATKSPD,1}, {ATKSPD,1},
{MOVESPD,1}, {MOVESPD,1},
{HEALTH,2}, {HEALTH,2},
},pos,*IMAGES[BIT_RESTORER],friendly){} },pos,*IMAGES[BIT_RESTORER],friendly,moveable){}
void BitRestorer::Attack(Unit&victim){ void BitRestorer::Attack(Unit&victim){
} }
MemorySwapper::MemorySwapper(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly) MemorySwapper::MemorySwapper(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit({ :Unit({
{RANGE,3}, {RANGE,3},
{ATKSPD,1}, {ATKSPD,1},
{HEALTH,3}, {HEALTH,3},
{PROCEDURE,3}, {PROCEDURE,3},
{MOVESPD,2}, {MOVESPD,2},
},pos,*IMAGES[MEMORY_SWAPPER],friendly){} },pos,*IMAGES[MEMORY_SWAPPER],friendly,moveable){}
void MemorySwapper::Attack(Unit&victim){ void MemorySwapper::Attack(Unit&victim){
} }
Corrupter::Corrupter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly) Corrupter::Corrupter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit({ :Unit({
{ATKSPD,3}, {ATKSPD,3},
{RANGE,1}, {RANGE,1},
{PROCEDURE,8}, {PROCEDURE,8},
{MOVESPD,4}, {MOVESPD,4},
{HEALTH,4}, {HEALTH,4},
},pos,*IMAGES[CORRUPTER],friendly){} },pos,*IMAGES[CORRUPTER],friendly,moveable){}
void Corrupter::Attack(Unit&victim){ void Corrupter::Attack(Unit&victim){
} }
MemoryAllocator::MemoryAllocator(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly) MemoryAllocator::MemoryAllocator(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable)
:Unit({ :Unit({
{RANGE,1}, {RANGE,1},
{ATKSPD,1}, {ATKSPD,1},
@ -116,7 +116,7 @@ RAMBank::RAMBank(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Ren
{MOVESPD,0}, {MOVESPD,0},
{PROCEDURE,25}, {PROCEDURE,25},
{HEALTH,16}, {HEALTH,16},
},pos,*IMAGES[RAM_BANK],friendly),randomOffset({util::random(128),util::random(128)}),matrixImg(*IMAGES[MATRIX]), },pos,*IMAGES[RAM_BANK],friendly,false),randomOffset({util::random(128),util::random(128)}),matrixImg(*IMAGES[MATRIX]),
originalImg(*IMAGES[RAM_BANK]){ originalImg(*IMAGES[RAM_BANK]){
img.Create(IMAGES[RAM_BANK]->Sprite()->width,IMAGES[RAM_BANK]->Sprite()->height); img.Create(IMAGES[RAM_BANK]->Sprite()->width,IMAGES[RAM_BANK]->Sprite()->height);
pge->SetDrawTarget(img.Sprite()); pge->SetDrawTarget(img.Sprite());
@ -150,8 +150,8 @@ void RAMBank::Draw(TileTransformedView&game,std::map<Image,std::unique_ptr<Rende
} }
} }
Unit::Unit(std::vector<Memory>memory,vf2d pos,Renderable&img,bool friendly) Unit::Unit(std::vector<Memory>memory,vf2d pos,Renderable&img,bool friendly,bool moveable)
:pos(pos),ghostPos(pos),img(img),friendly(friendly){ :pos(pos),ghostPos(pos),img(img),friendly(friendly),moveable(moveable){
int marker=0; int marker=0;
for(Memory&mem:memory){ for(Memory&mem:memory){
for(int i=0;i<mem.size;i++){ for(int i=0;i<mem.size;i++){
@ -423,3 +423,7 @@ void Unit::HideGhost(){
vf2d Unit::GetGhostPos(){ vf2d Unit::GetGhostPos(){
return ghostPos; return ghostPos;
} }
bool Unit::IsMoveable(){
return moveable;
}

@ -25,7 +25,7 @@ struct Memory{
struct Unit{ struct Unit{
public: public:
Unit(std::vector<Memory>memory,vf2d pos,Renderable&img,bool friendly=false); Unit(std::vector<Memory>memory,vf2d pos,Renderable&img,bool friendly=false,bool moveable=true);
int GetHealth(); int GetHealth();
int GetRange(); int GetRange();
int GetAtkSpd(); int GetAtkSpd();
@ -54,6 +54,7 @@ public:
void HideGhost(); void HideGhost();
vf2d GetGhostPos(); vf2d GetGhostPos();
void _Update(PixelGameEngine*pge); void _Update(PixelGameEngine*pge);
bool IsMoveable();
std::vector<bool>& operator <<=(const int n){ std::vector<bool>& operator <<=(const int n){
for(int i=0;i<GetMemorySize()-1;i++){ for(int i=0;i<GetMemorySize()-1;i++){
@ -98,45 +99,46 @@ private:
void _Attack(Unit*finalTarget); void _Attack(Unit*finalTarget);
vf2d movementVel={0,0}; vf2d movementVel={0,0};
float changeDirTimer=0; float changeDirTimer=0;
bool moveable=true;
}; };
struct BasicUnit:Unit{ struct BasicUnit:Unit{
BasicUnit(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false); BasicUnit(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim)override; void Attack(Unit&victim)override;
}; };
struct BasicUnit2:Unit{ struct BasicUnit2:Unit{
BasicUnit2(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false); BasicUnit2(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim)override; void Attack(Unit&victim)override;
}; };
struct LeftShifter:Unit{ struct LeftShifter:Unit{
LeftShifter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false); LeftShifter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim)override; void Attack(Unit&victim)override;
}; };
struct RightShifter:Unit{ struct RightShifter:Unit{
RightShifter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false); RightShifter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim)override; void Attack(Unit&victim)override;
}; };
struct BitRestorer:Unit{ struct BitRestorer:Unit{
BitRestorer(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false); BitRestorer(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim)override; void Attack(Unit&victim)override;
}; };
struct MemorySwapper:Unit{ struct MemorySwapper:Unit{
MemorySwapper(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false); MemorySwapper(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim)override; void Attack(Unit&victim)override;
}; };
struct Corrupter:Unit{ struct Corrupter:Unit{
Corrupter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false); Corrupter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim)override; void Attack(Unit&victim)override;
}; };
struct MemoryAllocator:Unit{ struct MemoryAllocator:Unit{
MemoryAllocator(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false); MemoryAllocator(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly=false,bool moveable=true);
void Attack(Unit&victim)override; void Attack(Unit&victim)override;
}; };

@ -135,9 +135,13 @@ void VirusAttack::CollisionChecking(std::shared_ptr<Unit>u,std::shared_ptr<Unit>
float maxDist=u->GetUnitSize().x/2+u2->GetUnitSize().x/2; float maxDist=u->GetUnitSize().x/2+u2->GetUnitSize().x/2;
float dist=maxDist-collisionLine.length(); float dist=maxDist-collisionLine.length();
vf2d dir=collisionLine.vector().norm(); vf2d dir=collisionLine.vector().norm();
if(u->IsMoveable()){
u->SetPos(u->GetPos()-dir*dist/2); u->SetPos(u->GetPos()-dir*dist/2);
}
if(u2->IsMoveable()){
u2->SetPos(u2->GetPos()+dir*dist/2); u2->SetPos(u2->GetPos()+dir*dist/2);
} }
}
} }
void VirusAttack::IdentifyClosestTarget(Unit*&closestUnit,float&closestDist,std::shared_ptr<Unit>u,std::shared_ptr<Unit>u2){ void VirusAttack::IdentifyClosestTarget(Unit*&closestUnit,float&closestDist,std::shared_ptr<Unit>u,std::shared_ptr<Unit>u2){

Loading…
Cancel
Save