Added Attack Range indicators

CorrectiveAction
sigonasr2 1 year ago
parent 88d9dea027
commit 15a08e8b9f
  1. 1
      olcCodeJam2023Entry/Image.h
  2. 11
      olcCodeJam2023Entry/Unit.cpp
  3. 1
      olcCodeJam2023Entry/Unit.h
  4. 5
      olcCodeJam2023Entry/VirusAttack.cpp
  5. BIN
      olcCodeJam2023Entry/assets/range_indicator.png

@ -17,5 +17,6 @@ enum Image{
CORRUPTER,
UNIT_ALLOCATOR,
RAM_BANK,
RANGE_INDICATOR
};

@ -184,7 +184,16 @@ Unit::Unit(std::vector<Memory>memory,vf2d pos,Renderable&img,bool friendly,bool
}
}
void Unit::DrawRangeIndicator(PixelGameEngine*pge,TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES){
float dist=geom2d::line<float>(game.ScreenToWorld(pge->GetMousePos()),GetPos()).length();
float range=12*(GetRange()+1);
if(IsSelected()){
game.DrawRotatedDecal(GetPos(),IMAGES[RANGE_INDICATOR]->Decal(),0,IMAGES[RANGE_INDICATOR]->Sprite()->Size()/2,{range/12,range/12},{0,196,0,128});
}else
if(dist<range*2){
game.DrawRotatedDecal(GetPos(),IMAGES[RANGE_INDICATOR]->Decal(),0,IMAGES[RANGE_INDICATOR]->Sprite()->Size()/2,{range/12,range/12},{0,196,0,uint8_t((1.f-(dist/(range*2)))*128)});
}
}
void Unit::Draw(TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES){
game.DrawRotatedDecal(ghostPos,img.Decal(),0,img.Sprite()->Size()/2,{1,1},friendly?Pixel{192,192,255}:Pixel{255,192,192});

@ -55,6 +55,7 @@ public:
vf2d GetGhostPos();
void _Update(PixelGameEngine*pge);
bool IsMoveable();
void DrawRangeIndicator(PixelGameEngine*pge,TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES);
std::vector<bool>& operator <<=(const int n){
for(int i=0;i<GetMemorySize()-1;i++){

@ -31,6 +31,7 @@ void VirusAttack::InitializeImages(){
LoadImage(CORRUPTER,"assets/corrupter.png");
LoadImage(UNIT_ALLOCATOR,"assets/shell.png");
LoadImage(RAM_BANK,"assets/ram_bank.png");
LoadImage(RANGE_INDICATOR,"assets/range_indicator.png");
}
bool VirusAttack::OnUserCreate(){
@ -318,6 +319,10 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
}
game.DrawPartialDecal({0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,IMAGES[TILE]->Decal(),{0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,DARK_GREEN);
for(auto&u:units){
u->DrawRangeIndicator(this,game,IMAGES);
}
for(auto&u:units){
u->Draw(game,IMAGES);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 736 B

Loading…
Cancel
Save