Change range indicator display behaviors.

CorrectiveAction
sigonasr2 1 year ago
parent 40238e67a6
commit fd5e6048ac
  1. 45
      olcCodeJam2023Entry/Unit.cpp
  2. 6
      olcCodeJam2023Entry/Unit.h
  3. 5
      olcCodeJam2023Entry/VirusAttack.cpp
  4. BIN
      olcCodeJam2023Entry/assets/range_indicator.png

@ -64,7 +64,7 @@ BitRestorer::BitRestorer(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IM
{ATKSPD,1},
{MOVESPD,1},
{HEALTH,2},
},pos,12,*IMAGES[BIT_RESTORER],friendly,moveable){}
},pos,12,*IMAGES[BIT_RESTORER],friendly,moveable,true,false){}
void BitRestorer::Attack(Unit&victim){
@ -77,7 +77,7 @@ MemorySwapper::MemorySwapper(vf2d pos,std::map<Image,std::unique_ptr<Renderable>
{HEALTH,3},
{PROCEDURE,3},
{MOVESPD,2},
},pos,12,*IMAGES[MEMORY_SWAPPER],friendly,moveable){}
},pos,12,*IMAGES[MEMORY_SWAPPER],friendly,moveable,true){}
void MemorySwapper::Attack(Unit&victim){
@ -103,7 +103,7 @@ MemoryAllocator::MemoryAllocator(vf2d pos,std::map<Image,std::unique_ptr<Rendera
{MOVESPD,1},
{PROCEDURE,1},
{HEALTH,1},
},pos,12,*IMAGES[UNIT_ALLOCATOR],friendly){}
},pos,12,*IMAGES[UNIT_ALLOCATOR],friendly,false,false){}
void MemoryAllocator::Attack(Unit&victim){
@ -116,7 +116,9 @@ RAMBank::RAMBank(PixelGameEngine*pge,vf2d pos,std::map<Image,std::unique_ptr<Ren
{MOVESPD,0},
{PROCEDURE,25},
{HEALTH,16},
},pos,41,*IMAGES[RAM_BANK],friendly,false),randomOffset({util::random(128),util::random(128)}),matrixImg(*IMAGES[MATRIX]),
},pos,41,*IMAGES[RAM_BANK],friendly,false
,false,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 +152,8 @@ void RAMBank::Draw(TileTransformedView&game,std::map<Image,std::unique_ptr<Rende
}
}
Unit::Unit(std::vector<Memory>memory,vf2d pos,float radius,Renderable&img,bool friendly,bool moveable)
:pos(pos),radius(radius),ghostPos(pos),img(img),friendly(friendly),moveable(moveable){
Unit::Unit(std::vector<Memory>memory,vf2d pos,float radius,Renderable&img,bool friendly,bool moveable,bool friendlyInteractable,bool enemyInteractable)
:pos(pos),radius(radius),ghostPos(pos),img(img),friendly(friendly),moveable(moveable),friendlyInteractable(friendlyInteractable),enemyInteractable(enemyInteractable){
int marker=0;
for(Memory&mem:memory){
for(int i=0;i<mem.size;i++){
@ -185,20 +187,35 @@ Unit::Unit(std::vector<Memory>memory,vf2d pos,float radius,Renderable&img,bool f
}
void Unit::DrawRangeIndicator(PixelGameEngine*pge,TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES){
if(!CanInteractWithAllies()&&!CanInteractWithEnemies())return;
float dist=geom2d::line<float>(game.ScreenToWorld(pge->GetMousePos()),GetGhostPos()).length();
float range=12*(GetRange()+1);
float totalRange=GetUnitSize().x/2+range;
if(IsSelected()){
game.DrawRotatedDecal(GetGhostPos(),IMAGES[RANGE_INDICATOR]->Decal(),0,IMAGES[RANGE_INDICATOR]->Sprite()->Size()/2,{totalRange/12,totalRange/12},{0,196,0,128});
Pixel col;
if(CanInteractWithAllies()&&!CanInteractWithEnemies()){
col={40,127,173};
} else {
col={0,196,0};
}
game.DrawRotatedDecal(GetGhostPos(),IMAGES[RANGE_INDICATOR]->Decal(),0,IMAGES[RANGE_INDICATOR]->Sprite()->Size()/2,{totalRange/12,totalRange/12},col);
}else
if(dist<range*2){
Pixel col;
if(IsFriendly()){
col={0,196,0};
if(CanInteractWithAllies()&&!CanInteractWithEnemies()){
col={40,127,173};
} else {
col={0,196,0};
}
}else{
col={196,130,0};
if(CanInteractWithAllies()&&!CanInteractWithEnemies()){
col={194, 37, 168};
} 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)});
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)))*255)});
}
}
@ -446,4 +463,12 @@ vf2d Unit::GetGhostPos(){
bool Unit::IsMoveable(){
return moveable;
}
bool Unit::CanInteractWithAllies(){
return friendlyInteractable;
}
bool Unit::CanInteractWithEnemies(){
return enemyInteractable;
}

@ -25,7 +25,7 @@ struct Memory{
struct Unit{
public:
Unit(std::vector<Memory>memory,vf2d pos,float radius,Renderable&img,bool friendly=false,bool moveable=true);
Unit(std::vector<Memory>memory,vf2d pos,float radius,Renderable&img,bool friendly=false,bool moveable=true,bool friendlyInteractable=false,bool enemyInteractable=true);
int GetHealth();
int GetRange();
int GetAtkSpd();
@ -56,6 +56,8 @@ public:
void _Update(PixelGameEngine*pge);
bool IsMoveable();
void DrawRangeIndicator(PixelGameEngine*pge,TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES);
bool CanInteractWithEnemies();
bool CanInteractWithAllies();
std::vector<bool>& operator <<=(const int n){
for(int i=0;i<GetMemorySize()-1;i++){
@ -103,6 +105,8 @@ private:
vf2d movementVel={0,0};
float changeDirTimer=0;
bool moveable=true;
bool friendlyInteractable=false;
bool enemyInteractable=true;
};
struct BasicUnit:Unit{

@ -341,6 +341,11 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
DrawMinimap();
std::sort(units.begin(),units.end(),[&](auto&u1,auto&u2){
float dist1=geom2d::line<float>(u1->GetGhostPos(),GetWorldMousePos()).length();
float dist2=geom2d::line<float>(u2->GetGhostPos(),GetWorldMousePos()).length();
return dist1>dist2;});
return true;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 736 B

After

Width:  |  Height:  |  Size: 8.8 KiB

Loading…
Cancel
Save