Add map fog

This commit is contained in:
Miloslav Číž 2020-02-21 21:21:09 +01:00
parent fbac1e486b
commit 54c2233e95

27
main.c
View File

@ -335,6 +335,9 @@ struct
uint8_t backgroundImage; uint8_t backgroundImage;
uint8_t teleportCount; uint8_t teleportCount;
uint16_t mapRevealMask; /**< Bits say which parts of the map have been
revealed. */
} SFG_currentLevel; } SFG_currentLevel;
#if SFG_DITHERED_SHADOW #if SFG_DITHERED_SHADOW
@ -1080,12 +1083,10 @@ void SFG_setAndInitLevel(const SFG_Level *level)
SFG_LOG("initializing doors"); SFG_LOG("initializing doors");
SFG_currentLevel.checkedDoorIndex = 0; SFG_currentLevel.checkedDoorIndex = 0;
SFG_currentLevel.doorRecordCount = 0; SFG_currentLevel.doorRecordCount = 0;
SFG_currentLevel.projectileRecordCount = 0; SFG_currentLevel.projectileRecordCount = 0;
SFG_currentLevel.teleportCount = 0; SFG_currentLevel.teleportCount = 0;
SFG_currentLevel.mapRevealMask = 0;
for (uint8_t j = 0; j < SFG_MAP_SIZE; ++j) for (uint8_t j = 0; j < SFG_MAP_SIZE; ++j)
{ {
@ -2280,6 +2281,14 @@ void SFG_updateLevel()
} }
} }
/**
Maps square position on the map to a bit in map reveal mask.
*/
static inline uint16_t SFG_getMapRevealBit(uint8_t squareX, uint8_t squareY)
{
return 1 << ((squareY / 16) * 4 + squareX / 16);
}
/** /**
Part of SFG_gameStep() for SFG_GAME_STATE_PLAYING. Part of SFG_gameStep() for SFG_GAME_STATE_PLAYING.
*/ */
@ -2822,6 +2831,11 @@ void SFG_gameStepPlaying()
SFG_player.squarePosition[1] = SFG_player.squarePosition[1] =
SFG_player.camera.position.y / RCL_UNITS_PER_SQUARE; SFG_player.camera.position.y / RCL_UNITS_PER_SQUARE;
SFG_currentLevel.mapRevealMask |=
SFG_getMapRevealBit(
SFG_player.squarePosition[0],
SFG_player.squarePosition[1]);
SFG_updateLevel(); SFG_updateLevel();
#if SFG_IMMORTAL == 0 #if SFG_IMMORTAL == 0
@ -3014,13 +3028,17 @@ void SFG_drawMap()
x = topLeftX; x = topLeftX;
for (uint16_t i = 0; i < maxI; ++i) for (uint16_t i = 0; i < maxI; ++i)
{
uint8_t color = 0; // init with non-revealed color
if (SFG_currentLevel.mapRevealMask & SFG_getMapRevealBit(i,j))
{ {
uint8_t properties; uint8_t properties;
SFG_TileDefinition tile = SFG_TileDefinition tile =
SFG_getMapTile(SFG_currentLevel.levelPointer,i,j,&properties); SFG_getMapTile(SFG_currentLevel.levelPointer,i,j,&properties);
uint8_t color = 94; // init with player color color = 94; // start with player color
if (i != SFG_player.squarePosition[0] || if (i != SFG_player.squarePosition[0] ||
j != SFG_player.squarePosition[1]) j != SFG_player.squarePosition[1])
@ -3037,6 +3055,7 @@ void SFG_drawMap()
color += 8; color += 8;
} }
} }
}
for (uint16_t k = 0; k < SFG_MAP_PIXEL_SIZE; ++k) for (uint16_t k = 0; k < SFG_MAP_PIXEL_SIZE; ++k)
for (uint16_t l = 0; l < SFG_MAP_PIXEL_SIZE; ++l) for (uint16_t l = 0; l < SFG_MAP_PIXEL_SIZE; ++l)