RAMBAnk is immoveable.

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

@ -4,99 +4,99 @@
#include "TileManager.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({
{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<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({
{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<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({
{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<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({
{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<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({
{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<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({
{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<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({
{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<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({
{RANGE,1},
{ATKSPD,1},
@ -116,7 +116,7 @@ RAMBank::RAMBank(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Ren
{MOVESPD,0},
{PROCEDURE,25},
{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]){
img.Create(IMAGES[RAM_BANK]->Sprite()->width,IMAGES[RAM_BANK]->Sprite()->height);
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)
:pos(pos),ghostPos(pos),img(img),friendly(friendly){
Unit::Unit(std::vector<Memory>memory,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;i<mem.size;i++){
@ -422,4 +422,8 @@ void Unit::HideGhost(){
vf2d Unit::GetGhostPos(){
return ghostPos;
}
bool Unit::IsMoveable(){
return moveable;
}

@ -25,7 +25,7 @@ struct Memory{
struct Unit{
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 GetRange();
int GetAtkSpd();
@ -54,6 +54,7 @@ public:
void HideGhost();
vf2d GetGhostPos();
void _Update(PixelGameEngine*pge);
bool IsMoveable();
std::vector<bool>& operator <<=(const int n){
for(int i=0;i<GetMemorySize()-1;i++){
@ -98,45 +99,46 @@ private:
void _Attack(Unit*finalTarget);
vf2d movementVel={0,0};
float changeDirTimer=0;
bool moveable=true;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};

@ -135,8 +135,12 @@ void VirusAttack::CollisionChecking(std::shared_ptr<Unit>u,std::shared_ptr<Unit>
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);
}
}
}

Loading…
Cancel
Save