Change range indicator display behaviors.
This commit is contained in:
parent
40238e67a6
commit
fd5e6048ac
@ -64,7 +64,7 @@ BitRestorer::BitRestorer(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IM
|
|||||||
{ATKSPD,1},
|
{ATKSPD,1},
|
||||||
{MOVESPD,1},
|
{MOVESPD,1},
|
||||||
{HEALTH,2},
|
{HEALTH,2},
|
||||||
},pos,12,*IMAGES[BIT_RESTORER],friendly,moveable){}
|
},pos,12,*IMAGES[BIT_RESTORER],friendly,moveable,true,false){}
|
||||||
|
|
||||||
void BitRestorer::Attack(Unit&victim){
|
void BitRestorer::Attack(Unit&victim){
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ MemorySwapper::MemorySwapper(vf2d pos,std::map<Image,std::unique_ptr<Renderable>
|
|||||||
{HEALTH,3},
|
{HEALTH,3},
|
||||||
{PROCEDURE,3},
|
{PROCEDURE,3},
|
||||||
{MOVESPD,2},
|
{MOVESPD,2},
|
||||||
},pos,12,*IMAGES[MEMORY_SWAPPER],friendly,moveable){}
|
},pos,12,*IMAGES[MEMORY_SWAPPER],friendly,moveable,true){}
|
||||||
|
|
||||||
void MemorySwapper::Attack(Unit&victim){
|
void MemorySwapper::Attack(Unit&victim){
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ MemoryAllocator::MemoryAllocator(vf2d pos,std::map<Image,std::unique_ptr<Rendera
|
|||||||
{MOVESPD,1},
|
{MOVESPD,1},
|
||||||
{PROCEDURE,1},
|
{PROCEDURE,1},
|
||||||
{HEALTH,1},
|
{HEALTH,1},
|
||||||
},pos,12,*IMAGES[UNIT_ALLOCATOR],friendly){}
|
},pos,12,*IMAGES[UNIT_ALLOCATOR],friendly,false,false){}
|
||||||
|
|
||||||
void MemoryAllocator::Attack(Unit&victim){
|
void MemoryAllocator::Attack(Unit&victim){
|
||||||
|
|
||||||
@ -116,7 +116,9 @@ 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,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]){
|
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 +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)
|
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){
|
:pos(pos),radius(radius),ghostPos(pos),img(img),friendly(friendly),moveable(moveable),friendlyInteractable(friendlyInteractable),enemyInteractable(enemyInteractable){
|
||||||
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++){
|
||||||
@ -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){
|
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 dist=geom2d::line<float>(game.ScreenToWorld(pge->GetMousePos()),GetGhostPos()).length();
|
||||||
float range=12*(GetRange()+1);
|
float range=12*(GetRange()+1);
|
||||||
float totalRange=GetUnitSize().x/2+range;
|
float totalRange=GetUnitSize().x/2+range;
|
||||||
if(IsSelected()){
|
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
|
}else
|
||||||
if(dist<range*2){
|
if(dist<range*2){
|
||||||
Pixel col;
|
Pixel col;
|
||||||
if(IsFriendly()){
|
if(IsFriendly()){
|
||||||
col={0,196,0};
|
if(CanInteractWithAllies()&&!CanInteractWithEnemies()){
|
||||||
|
col={40,127,173};
|
||||||
|
} else {
|
||||||
|
col={0,196,0};
|
||||||
|
}
|
||||||
}else{
|
}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)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -447,3 +464,11 @@ vf2d Unit::GetGhostPos(){
|
|||||||
bool Unit::IsMoveable(){
|
bool Unit::IsMoveable(){
|
||||||
return moveable;
|
return moveable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Unit::CanInteractWithAllies(){
|
||||||
|
return friendlyInteractable;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Unit::CanInteractWithEnemies(){
|
||||||
|
return enemyInteractable;
|
||||||
|
}
|
@ -25,7 +25,7 @@ struct Memory{
|
|||||||
|
|
||||||
struct Unit{
|
struct Unit{
|
||||||
public:
|
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 GetHealth();
|
||||||
int GetRange();
|
int GetRange();
|
||||||
int GetAtkSpd();
|
int GetAtkSpd();
|
||||||
@ -56,6 +56,8 @@ public:
|
|||||||
void _Update(PixelGameEngine*pge);
|
void _Update(PixelGameEngine*pge);
|
||||||
bool IsMoveable();
|
bool IsMoveable();
|
||||||
void DrawRangeIndicator(PixelGameEngine*pge,TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES);
|
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){
|
std::vector<bool>& operator <<=(const int n){
|
||||||
for(int i=0;i<GetMemorySize()-1;i++){
|
for(int i=0;i<GetMemorySize()-1;i++){
|
||||||
@ -103,6 +105,8 @@ private:
|
|||||||
vf2d movementVel={0,0};
|
vf2d movementVel={0,0};
|
||||||
float changeDirTimer=0;
|
float changeDirTimer=0;
|
||||||
bool moveable=true;
|
bool moveable=true;
|
||||||
|
bool friendlyInteractable=false;
|
||||||
|
bool enemyInteractable=true;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BasicUnit:Unit{
|
struct BasicUnit:Unit{
|
||||||
|
@ -341,6 +341,11 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
|||||||
|
|
||||||
DrawMinimap();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 736 B After Width: | Height: | Size: 8.8 KiB |
Loading…
x
Reference in New Issue
Block a user