diff --git a/olcCodeJam2023Entry/Image.h b/olcCodeJam2023Entry/Image.h index c36ec41..5fbecc7 100644 --- a/olcCodeJam2023Entry/Image.h +++ b/olcCodeJam2023Entry/Image.h @@ -17,5 +17,6 @@ enum Image{ CORRUPTER, UNIT_ALLOCATOR, RAM_BANK, + RANGE_INDICATOR }; diff --git a/olcCodeJam2023Entry/Unit.cpp b/olcCodeJam2023Entry/Unit.cpp index 9aeae8c..8f0e411 100644 --- a/olcCodeJam2023Entry/Unit.cpp +++ b/olcCodeJam2023Entry/Unit.cpp @@ -184,7 +184,16 @@ Unit::Unit(std::vectormemory,vf2d pos,Renderable&img,bool friendly,bool } } - +void Unit::DrawRangeIndicator(PixelGameEngine*pge,TileTransformedView&game,std::map>&IMAGES){ + float dist=geom2d::line(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(distDecal(),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>&IMAGES){ game.DrawRotatedDecal(ghostPos,img.Decal(),0,img.Sprite()->Size()/2,{1,1},friendly?Pixel{192,192,255}:Pixel{255,192,192}); diff --git a/olcCodeJam2023Entry/Unit.h b/olcCodeJam2023Entry/Unit.h index 4376203..0b5d11c 100644 --- a/olcCodeJam2023Entry/Unit.h +++ b/olcCodeJam2023Entry/Unit.h @@ -55,6 +55,7 @@ public: vf2d GetGhostPos(); void _Update(PixelGameEngine*pge); bool IsMoveable(); + void DrawRangeIndicator(PixelGameEngine*pge,TileTransformedView&game,std::map>&IMAGES); std::vector& operator <<=(const int n){ for(int i=0;iDecal(),{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); } diff --git a/olcCodeJam2023Entry/assets/range_indicator.png b/olcCodeJam2023Entry/assets/range_indicator.png new file mode 100644 index 0000000..a959b65 Binary files /dev/null and b/olcCodeJam2023Entry/assets/range_indicator.png differ