|
|
|
@ -80,6 +80,12 @@ void HamsterGame::LoadLevel(const std::string_view mapName){ |
|
|
|
|
Hamster::LoadHamsters(levelSpawnLoc); |
|
|
|
|
camera.SetTarget(Hamster::GetPlayer().GetPos()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapImage.Create(currentMap.value().GetData().GetMapData().width*16,currentMap.value().GetData().GetMapData().height*16); |
|
|
|
|
SetDrawTarget(mapImage.Sprite()); |
|
|
|
|
Clear(BLANK); |
|
|
|
|
SetPixelMode(Pixel::MASK); |
|
|
|
|
|
|
|
|
|
#pragma region Detect powerup tiles |
|
|
|
|
std::vector<Powerup>mapPowerups; |
|
|
|
|
for(const LayerTag&layer:currentMap.value().GetData().GetLayers()){ |
|
|
|
@ -87,11 +93,23 @@ void HamsterGame::LoadLevel(const std::string_view mapName){ |
|
|
|
|
for(size_t x:std::ranges::iota_view(0U,layer.tiles[y].size())){ |
|
|
|
|
const int tileID{layer.tiles[y][x]-1}; |
|
|
|
|
if(Powerup::TileIDIsUpperLeftPowerupTile(tileID))mapPowerups.emplace_back(vf2d{float(x),float(y)}*16+vf2d{16,16},Powerup::TileIDPowerupType(tileID)); |
|
|
|
|
|
|
|
|
|
const int numTilesWide{GetGFX("gametiles.png").Sprite()->width/16}; |
|
|
|
|
const int numTilesTall{GetGFX("gametiles.png").Sprite()->height/16}; |
|
|
|
|
|
|
|
|
|
int imgTileX{tileID%numTilesWide}; |
|
|
|
|
int imgTileY{tileID/numTilesWide}; |
|
|
|
|
if(tileID==-1||Powerup::TileIDIsPowerupTile(tileID))continue; |
|
|
|
|
DrawPartialSprite(vf2d{float(x),float(y)}*16,GetGFX("gametiles.png").Sprite(),vf2d{float(imgTileX),float(imgTileY)}*16.f,vf2d{16.f,16.f}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Powerup::Initialize(mapPowerups); |
|
|
|
|
#pragma endregion |
|
|
|
|
|
|
|
|
|
mapImage.Decal()->Update(); |
|
|
|
|
SetPixelMode(Pixel::NORMAL); |
|
|
|
|
SetDrawTarget(nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HamsterGame::UpdateGame(const float fElapsedTime){ |
|
|
|
@ -158,27 +176,19 @@ const Terrain::TerrainType HamsterGame::GetTerrainTypeAtPos(const vf2d pos)const |
|
|
|
|
void HamsterGame::DrawLevelTiles(){ |
|
|
|
|
float extendedBounds{SCREEN_FRAME.pos.x}; |
|
|
|
|
extendedBounds*=1/tv.GetWorldScale().x; |
|
|
|
|
tv.DrawDecal({},mapImage.Decal()); |
|
|
|
|
for(const LayerTag&layer:currentMap.value().GetData().GetLayers()){ |
|
|
|
|
for(float y=tv.GetWorldTL().y-17;y<=tv.GetWorldBR().y+16;y+=16){ |
|
|
|
|
for(float x=tv.GetWorldTL().x-17+extendedBounds;x<=tv.GetWorldBR().x+16+extendedBounds;x+=16){ |
|
|
|
|
if(x<=0.f||y<=0.f||x>=currentMap.value().GetData().GetMapData().width*16||y>=currentMap.value().GetData().GetMapData().height*16)continue; |
|
|
|
|
const int numTilesWide{GetGFX("gametiles.png").Sprite()->width/16}; |
|
|
|
|
const int numTilesTall{GetGFX("gametiles.png").Sprite()->height/16}; |
|
|
|
|
|
|
|
|
|
int tileX{int(floor(x)/16)}; |
|
|
|
|
int tileY{int(floor(y)/16)}; |
|
|
|
|
int tileID{layer.tiles[tileY][tileX]-1}; |
|
|
|
|
if(tileID==-1||Powerup::TileIDIsPowerupTile(tileID))continue; |
|
|
|
|
|
|
|
|
|
int imgTileX{tileID%numTilesWide}; |
|
|
|
|
int imgTileY{tileID/numTilesWide}; |
|
|
|
|
if(ANIMATED_TILE_IDS.count(tileID)){ |
|
|
|
|
Animate2D::FrameSequence&animatedTile{ANIMATED_TILE_IDS[tileID]}; |
|
|
|
|
const Animate2D::Frame¤tFrame{animatedTile.GetFrame(runTime)}; |
|
|
|
|
tv.DrawPartialDecal(vf2d{float(tileX),float(tileY)}*16,currentFrame.GetSourceImage()->Decal(),currentFrame.GetSourceRect().pos,currentFrame.GetSourceRect().size); |
|
|
|
|
}else{ |
|
|
|
|
tv.DrawPartialDecal(vf2d{float(tileX),float(tileY)}*16,GetGFX("gametiles.png").Decal(),vf2d{float(imgTileX),float(imgTileY)}*16,{16,16}); |
|
|
|
|
} |
|
|
|
|
}else continue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|