Count CPs
This commit is contained in:
parent
f0c2977002
commit
a388a915f9
4 changed files with 69 additions and 8 deletions
20
map.h
20
map.h
|
@ -130,7 +130,7 @@ struct
|
|||
uint8_t startPos[4]; ///< Initial position and rotation.
|
||||
|
||||
uint8_t environment;
|
||||
|
||||
uint8_t checkpointCount;
|
||||
// TODO: name, desc? possibly as a single '\n' separated string?
|
||||
} LCR_currentMap;
|
||||
|
||||
|
@ -309,6 +309,18 @@ uint8_t _LCR_mapAddBlock(const uint8_t block[LCR_BLOCK_SIZE])
|
|||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
Resets the map to start a run (including e.g. unmarking checkpoints etc.).
|
||||
*/
|
||||
void LCR_mapReset(void)
|
||||
{
|
||||
LCR_LOG0("resetting map");
|
||||
|
||||
for (int i = 0; i < LCR_currentMap.blockCount; ++i)
|
||||
if (LCR_currentMap.blocks[i * LCR_BLOCK_SIZE] == LCR_BLOCK_CHECKPOINT_1)
|
||||
LCR_currentMap.blocks[i * LCR_BLOCK_SIZE] = LCR_BLOCK_CHECKPOINT_0;
|
||||
}
|
||||
|
||||
/**
|
||||
Loads and preprocesses given map. Returns 1 on success, otherwise 0.
|
||||
*/
|
||||
|
@ -319,6 +331,7 @@ uint8_t LCR_mapLoad(const uint8_t *map)
|
|||
for (int i = 0; i < 4; ++i)
|
||||
LCR_currentMap.startPos[i] = 0;
|
||||
|
||||
LCR_currentMap.checkpointCount = 0;
|
||||
LCR_currentMap.blockCount = 0;
|
||||
|
||||
if (map[0] != LCR_MAP_MAGIC_NUMBER1 || map[1] != LCR_MAP_MAGIC_NUMBER2)
|
||||
|
@ -392,6 +405,9 @@ uint8_t LCR_mapLoad(const uint8_t *map)
|
|||
LCR_currentMap.startPos[3] = LCR_mapBlockGetTransform(map) & 0x60;
|
||||
break;
|
||||
|
||||
case LCR_BLOCK_CHECKPOINT_0:
|
||||
LCR_currentMap.checkpointCount++;
|
||||
// fall through
|
||||
default:
|
||||
if (!_LCR_mapAddBlock(map)) // normal block
|
||||
return 0;
|
||||
|
@ -409,6 +425,8 @@ uint8_t LCR_mapLoad(const uint8_t *map)
|
|||
|
||||
LCR_LOG2("map loaded")
|
||||
|
||||
LCR_mapReset();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue