|
|
|
@ -43,20 +43,30 @@ All rights reserved. |
|
|
|
|
INCLUDE_game |
|
|
|
|
|
|
|
|
|
void Minimap::Initialize(){ |
|
|
|
|
loadedChunks.clear(); |
|
|
|
|
|
|
|
|
|
if(minimap.Sprite()==nullptr)minimap.Create(1,1); |
|
|
|
|
if(cover.Sprite()==nullptr)cover.Create(1,1); |
|
|
|
|
|
|
|
|
|
Sprite baseMinimap; |
|
|
|
|
|
|
|
|
|
#pragma region Cleanup minimap and cover images |
|
|
|
|
minimap.Sprite()->Resize(game->GetCurrentMapData().width,game->GetCurrentMapData().height); |
|
|
|
|
cover.Sprite()->Resize(game->GetCurrentMapData().width,game->GetCurrentMapData().height); |
|
|
|
|
baseMinimap.Resize(game->GetCurrentMapData().width,game->GetCurrentMapData().height); |
|
|
|
|
game->SetDrawTarget(minimap.Sprite()); |
|
|
|
|
game->Clear(WHITE); |
|
|
|
|
game->SetPixelMode(Pixel::ALPHA); |
|
|
|
|
game->Clear(BLANK); |
|
|
|
|
game->SetDrawTarget(&baseMinimap); |
|
|
|
|
game->Clear(BLANK); |
|
|
|
|
game->SetDrawTarget(cover.Sprite()); |
|
|
|
|
game->Clear(BLANK); |
|
|
|
|
game->SetPixelMode(Pixel::NORMAL); |
|
|
|
|
//Will update the minimap decal at the end, since we are about to change it anyways.
|
|
|
|
|
cover.Decal()->Update(); |
|
|
|
|
#pragma endregion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(int x=0;x<game->GetCurrentMapData().width;x++){ |
|
|
|
|
for(int y=0;y<game->GetCurrentMapData().height;y++){ |
|
|
|
|
bool tileFound=false; |
|
|
|
@ -68,9 +78,7 @@ void Minimap::Initialize(){ |
|
|
|
|
if(tileID!=-1){ |
|
|
|
|
tileFound=true; |
|
|
|
|
if(game->GetTileCollision(game->GetCurrentMapName(),vf2d{float(x),float(y)}*game->GetCurrentMapData().tilewidth)!=game->NO_COLLISION){ |
|
|
|
|
game->SetPixelMode(Pixel::ALPHA); |
|
|
|
|
minimap.Sprite()->SetPixel({x,y},BLANK); |
|
|
|
|
game->SetPixelMode(Pixel::NORMAL); |
|
|
|
|
baseMinimap.SetPixel({x,y},BLANK); |
|
|
|
|
collision=true; |
|
|
|
|
} |
|
|
|
|
tileCol=game->GetTileColor(game->GetCurrentMapName(),vf2d{float(x),float(y)}*game->GetCurrentMapData().tilewidth); |
|
|
|
@ -78,29 +86,50 @@ void Minimap::Initialize(){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(tileFound&&!collision){ |
|
|
|
|
minimap.Sprite()->SetPixel({x,y},{uint8_t(std::min(255.f,tileCol.r*1.5f)),uint8_t(std::min(255.f,tileCol.g*1.5f)),uint8_t(std::min(255.f,tileCol.b*1.5f))}); |
|
|
|
|
baseMinimap.SetPixel({x,y},{uint8_t(std::min(255.f,tileCol.r*1.5f)),uint8_t(std::min(255.f,tileCol.g*1.5f)),uint8_t(std::min(255.f,tileCol.b*1.5f))}); |
|
|
|
|
}else |
|
|
|
|
if(!tileFound){ |
|
|
|
|
game->SetPixelMode(Pixel::ALPHA); |
|
|
|
|
minimap.Sprite()->SetPixel({x,y},BLANK); |
|
|
|
|
game->SetPixelMode(Pixel::NORMAL); |
|
|
|
|
baseMinimap.SetPixel({x,y},BLANK); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for(int sy=0;sy<baseMinimap.height;sy++){ |
|
|
|
|
for(int sx=0;sx<baseMinimap.width;sx++){ |
|
|
|
|
if(baseMinimap.GetPixel(sx,sy).a>0){ |
|
|
|
|
for(int y=-1;y<=1;y++){ |
|
|
|
|
for(int x=-1;x<=1;x++){ |
|
|
|
|
if(x==0&&y==0)continue; |
|
|
|
|
minimap.Sprite()->SetPixel(sx+x,sy+y,BLACK); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for(int sy=0;sy<baseMinimap.height;sy++){ |
|
|
|
|
for(int sx=0;sx<baseMinimap.width;sx++){ |
|
|
|
|
if(baseMinimap.GetPixel(sx,sy).a>0){ |
|
|
|
|
minimap.Sprite()->SetPixel(sx,sy,baseMinimap.GetPixel(sx,sy)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
game->SetDrawTarget(nullptr); |
|
|
|
|
|
|
|
|
|
minimap.Decal()->Update(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Minimap::Update(){ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Minimap::UpdateChunk(const vi2d chunkPos){ |
|
|
|
|
if(!loadedChunks.count(std::format("{}_{}",chunkPos.x,chunkPos.y))){ |
|
|
|
|
loadedChunks.insert(std::format("{}_{}",chunkPos.x,chunkPos.y)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Minimap::Draw(){ |
|
|
|
|
for(int y=-1;y<=1;y++){ |
|
|
|
|
for(int x=-1;x<=1;x++){ |
|
|
|
|
if(x==0&&y==0)continue; |
|
|
|
|
else game->DrawDecal(vf2d{float(game->ScreenWidth()-minimap.Sprite()->width),0}+vf2d{float(x),float(y)},minimap.Decal(),{1.f,1.f},BLACK); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
game->DrawDecal(vf2d{float(game->ScreenWidth()-minimap.Sprite()->width),0},minimap.Decal()); |
|
|
|
|
} |