From f0c29770025265462138836bc3f12c368a84fe3c Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Thu, 21 Nov 2024 21:33:36 +0100 Subject: [PATCH] Take checkpoints --- assets.h | 3 +-- game.h | 25 ++++++++++++++++++++++++- racing.h | 1 - 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/assets.h b/assets.h index 044f215..7a777c8 100644 --- a/assets.h +++ b/assets.h @@ -60,8 +60,7 @@ LCR_MAP_BLOCK(LCR_BLOCK_RAMP_STEEP,4,4,6,LCR_BLOCK_MATERIAL_CONCRETE,LCR_BLOCK_T LCR_MAP_BLOCK(LCR_BLOCK_RAMP_CURVED_PLAT,4,5,6,LCR_BLOCK_MATERIAL_CONCRETE,LCR_BLOCK_TRANSFORM_FLIP_V | LCR_BLOCK_TRANSFORM_ROT_180), LCR_MAP_BLOCK(LCR_BLOCK_RAMP_CURVED_PLAT,3,5,6,LCR_BLOCK_MATERIAL_CONCRETE,LCR_BLOCK_TRANSFORM_FLIP_V | LCR_BLOCK_TRANSFORM_ROT_180), -LCR_MAP_BLOCK(LCR_BLOCK_CHECKPOINT_0,3,2,4,LCR_BLOCK_MATERIAL_CONCRETE,0), -LCR_MAP_BLOCK(LCR_BLOCK_FINISH,3,2,2,LCR_BLOCK_MATERIAL_CONCRETE,0), +LCR_MAP_BLOCK(LCR_BLOCK_CHECKPOINT_0,3,1,4,LCR_BLOCK_MATERIAL_CONCRETE,0), /* LCR_MAP_BLOCK(LCR_BLOCK_FULL,2,1,9,LCR_BLOCK_MATERIAL_CONCRETE,0), diff --git a/game.h b/game.h index 107a6d2..ba5b095 100644 --- a/game.h +++ b/game.h @@ -11,6 +11,7 @@ - LCR_GameUnit: data type, abstract unit of the game (racing module). One map square is LCR_GAME_UNITs long, a full angle is also LCR_GAME_UNITs. - LCR_GAME_UNIT: Size of one game square and full angle in LCR_GameUnits. + Square height is only half of this. - S3L_Unit: data type, small3dlib's unit. May change with renderer change. - S3L_F: small3dlib's value representing 1.0. - LCR_RENDERER_UNIT: for the renderer one map square is this many S3L_Units. @@ -188,6 +189,8 @@ uint8_t LCR_gameStep(uint32_t time) { LCR_LOG2("game step start"); + LCR_GameUnit carTransform[6]; + for (int i = 0; i < LCR_KEYS_TOTAL; ++i) LCR_keyStates[i] = LCR_keyPressed(i) ? (LCR_keyStates[i] < 255 ? LCR_keyStates[i] + 1 : 255) : 0; @@ -221,6 +224,27 @@ if ((LCR_racing.tick % 32) == 0) (LCR_keyStates[LCR_KEY_LEFT] ? LCR_RACING_INPUT_LEFT : 0); LCR_racingStep(input); + + LCR_racingGetCarTransform(carTransform,carTransform + 3,0); + + carTransform[0] = (carTransform[0] + (LCR_GAME_UNIT * LCR_MAP_SIZE_BLOCKS) + / 2) / LCR_GAME_UNIT; + carTransform[1] = (carTransform[1] + (LCR_GAME_UNIT * LCR_MAP_SIZE_BLOCKS) + / 4) / (LCR_GAME_UNIT / 2); + carTransform[2] = (carTransform[2] + (LCR_GAME_UNIT * LCR_MAP_SIZE_BLOCKS) + / 2) / LCR_GAME_UNIT; + + int blockIndex = LCR_mapGetBlockAt(carTransform[0],carTransform[1],carTransform[2]); + + if (blockIndex >= 0 && LCR_currentMap.blocks[blockIndex * LCR_BLOCK_SIZE] == + LCR_BLOCK_CHECKPOINT_0) + { + LCR_currentMap.blocks[blockIndex * LCR_BLOCK_SIZE] = + LCR_BLOCK_CHECKPOINT_1; + LCR_rendererMarkTakenCP( + carTransform[0],carTransform[1],carTransform[2]); + } + LCR_game.nextRacingTickTime += LCR_RACING_TICK_MS; } @@ -234,7 +258,6 @@ LCR_GameUnit physicsInterpolationParam = LCR_GAME_UNIT - ((LCR_game.nextRacingTickTime - time) * LCR_GAME_UNIT) / LCR_RACING_TICK_MS; - LCR_GameUnit carTransform[6]; LCR_racingGetCarTransform(carTransform,carTransform + 3, physicsInterpolationParam); diff --git a/racing.h b/racing.h index 3fd02b5..d95946b 100644 --- a/racing.h +++ b/racing.h @@ -580,7 +580,6 @@ int _LCR_racingCarShapeOK(void) */ uint32_t LCR_racingStep(unsigned int input) { -printf("---------\n"); LCR_LOG2("racing step start"); uint32_t result = 0;