|
|
|
@ -39,6 +39,7 @@ All rights reserved. |
|
|
|
|
#include "AdventuresInLestoria.h" |
|
|
|
|
#include "DEFINES.h" |
|
|
|
|
#include "Unlock.h" |
|
|
|
|
#include "util.h" |
|
|
|
|
|
|
|
|
|
INCLUDE_game |
|
|
|
|
|
|
|
|
@ -126,10 +127,40 @@ void Minimap::UpdateChunk(const vi2d chunkPos){ |
|
|
|
|
if(!loadedChunks.count(std::format("{}_{}",chunkPos.x,chunkPos.y))){ |
|
|
|
|
loadedChunks.insert(std::format("{}_{}",chunkPos.x,chunkPos.y)); |
|
|
|
|
|
|
|
|
|
vi2d centerChunkPos=chunkPos*"Minimap.Chunk Size"_I; |
|
|
|
|
|
|
|
|
|
vi2d pixelPos=centerChunkPos-"Minimap.Chunk Size"_I*2; |
|
|
|
|
vi2d chunkEndPixelPos=centerChunkPos+"Minimap.Chunk Size"_I*4; |
|
|
|
|
|
|
|
|
|
//We start twice the distance we are supposed to outwards.
|
|
|
|
|
for(int y=pixelPos.y;y<chunkEndPixelPos.y;y++){ |
|
|
|
|
for(int x=pixelPos.x;x<chunkEndPixelPos.x;x++){ |
|
|
|
|
if(cover.Sprite()->GetPixel(x,y).a==255||minimap.Sprite()->GetPixel(x,y).a==0)continue; //Already revealed or invisible anyways.
|
|
|
|
|
|
|
|
|
|
vi2d chunk=vi2d{x,y}/"Minimap.Chunk Size"_I; |
|
|
|
|
if(chunk==chunkPos){ |
|
|
|
|
cover.Sprite()->SetPixel(x,y,minimap.Sprite()->GetPixel(x,y)); |
|
|
|
|
}else{ |
|
|
|
|
const vi2d chunkOffset={"Minimap.Chunk Size"_I/2,"Minimap.Chunk Size"_I/2}; |
|
|
|
|
|
|
|
|
|
const float distance=geom2d::line<float>(centerChunkPos+chunkOffset,vf2d{float(x),float(y)}).length(); |
|
|
|
|
const int alpha=std::clamp(util::lerp(255,0,(distance-"Minimap.Chunk Size"_I)/"Minimap.Chunk Size"_I),0.f,255.f); |
|
|
|
|
|
|
|
|
|
if(cover.Sprite()->GetPixel(x,y).a>alpha)continue; //The distance was uncovered by another closer chunk, don't need to reveal it here.
|
|
|
|
|
|
|
|
|
|
Pixel sourceCol=minimap.Sprite()->GetPixel(x,y); |
|
|
|
|
sourceCol.a=alpha; |
|
|
|
|
cover.Sprite()->SetPixel(x,y,sourceCol); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cover.Decal()->Update(); |
|
|
|
|
|
|
|
|
|
LOG(std::format("Chunk {}_{} Revealed",chunkPos.x,chunkPos.y)<<std::endl); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Minimap::Draw(){ |
|
|
|
|
game->DrawDecal(vf2d{float(game->ScreenWidth()-minimap.Sprite()->width),0},minimap.Decal()); |
|
|
|
|
game->DrawDecal(vf2d{float(game->ScreenWidth()-cover.Sprite()->width),0},cover.Decal()); |
|
|
|
|
} |