From b1c2041d84cbe2118a6205efcf15da4203fbc796 Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Tue, 7 Jan 2025 23:21:08 +0100 Subject: [PATCH] Make finish work --- TODO.txt | 2 +- game.h | 53 ++++++++++++++++++++++++++++++++++++----------------- racing.h | 2 +- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/TODO.txt b/TODO.txt index bfed44d..bd01f01 100644 --- a/TODO.txt +++ b/TODO.txt @@ -7,7 +7,6 @@ - player name (modifyable via resource file) - popup messages? would be useful for several things: showing checkpoint times, showing changes in menu etc. -- prevent time overflow! stop incrementing level frame once it's at maximum - make the racing module usable by itself, e.g. to allow making tools for verifying replays etc., i.e. make the module measure time, count checkpoints etc. @@ -26,6 +25,7 @@ =========== HANDLED ============== - allow stopping car rotation in air like in Trackmania +- prevent time overflow! stop incrementing level frame once it's at maximum - car shadow? probably would have to be done as screen space effect with z-buffer (shadow as 3D model would require collision detection and would make renderer depend on physics engine). Maybe like this: diff --git a/game.h b/game.h index bf98ccc..f4e61bf 100644 --- a/game.h +++ b/game.h @@ -203,14 +203,17 @@ struct during a single frame, hold number of frames for which the key has been continuously held. */ + + uint32_t runTimeMS; + + // TODO: make menu struct? uint8_t menuSelectedTab; uint8_t menuSelectedItem; -char menuItemNames[LCR_MENU_MAX_ITEMS][LCR_MENU_STRING_SIZE]; -uint8_t menuItemCount; - -const char *menuItemNamePointers[LCR_MENU_MAX_ITEMS]; + char menuItemNames[LCR_MENU_MAX_ITEMS][LCR_MENU_STRING_SIZE]; + uint8_t menuItemCount; + const char *menuItemNamePointers[LCR_MENU_MAX_ITEMS]; ///< helper array struct { @@ -290,6 +293,7 @@ void LCR_gameResetRun(void) LCR_rendererSetCarTransform(carTransform,carTransform + 3); LCR_rendererCameraReset(); LCR_gameSetState(LCR_GAME_STATE_RUN_STARTING); + LCR_game.runTimeMS = 0; } void LCR_gameRewindResourceFile(void) @@ -547,7 +551,8 @@ void LCR_gameDraw3DView(void) LCR_rendererSetCarTransform(carTransform,carTransform + 3); - if (LCR_game.cameraMode != LCR_CAMERA_MODE_FREE) + if (LCR_game.cameraMode != LCR_CAMERA_MODE_FREE && + LCR_game.state != LCR_GAME_STATE_RUN_FINISHED) LCR_rendererCameraFollow( (LCR_game.cameraMode != LCR_CAMERA_MODE_INSIDE) + (LCR_game.cameraMode == LCR_CAMERA_MODE_DRIVE2)); @@ -567,7 +572,7 @@ void LCR_gameDraw3DView(void) // GUI/HUD: - char str[6]; + char str[10]; switch (LCR_game.state) { @@ -599,17 +604,26 @@ void LCR_gameDraw3DView(void) LCR_EFFECTIVE_RESOLUTION_Y - LCR_rendererComputeTextHeight(2) - 20,0,2); - val = LCR_racingGetRunTimeMS() / 1000; // seconds + val = LCR_game.runTimeMS; - str[3] = '0' + (val % 60) / 10; + str[9] = 0; + + str[6] = '0' + val % 10; // milliseconds + val /= 10; + str[7] = '0' + val % 10; + val /= 10; + str[8] = '0' + val % 10; + val /= 10; + + str[3] = '0' + (val % 60) / 10; // seconds str[4] = '0' + val % 10; + str[5] = '\''; val = (val / 60) % 100; // minutes str[0] = '0' + val / 10; str[1] = '0' + val % 10; str[2] = '\''; - str[5] = 0; LCR_rendererDrawText(str,20,LCR_EFFECTIVE_RESOLUTION_Y - LCR_rendererComputeTextHeight(2) - 20,0,2); @@ -738,6 +752,12 @@ void LCR_gameHandleInput(void) break; + case LCR_GAME_STATE_RUN_FINISHED: + if (LCR_game.keyStates[LCR_KEY_A] == 1) + LCR_gameResetRun(); + + break; + case LCR_GAME_STATE_RUN_STARTING: if (LCR_game.time - LCR_game.stateStartTime >= 1000 * LCR_SETTING_COUNTDOWN_SECONDS) @@ -823,19 +843,14 @@ uint8_t LCR_gameStep(uint32_t time) LCR_gameHandleInput(); -/* - LCR_GameUnit offsets[5]; - - for (int i = 0; i < 5; ++i) - offsets[i] = 0; -*/ - // handle simulation: while (time >= LCR_game.nextRacingTickTime) { LCR_LOG2("gonna step racing engine"); - unsigned int input = LCR_game.cameraMode == LCR_CAMERA_MODE_FREE ? 0 : + unsigned int input = + (LCR_game.cameraMode == LCR_CAMERA_MODE_FREE || + LCR_game.state == LCR_GAME_STATE_RUN_FINISHED) ? 0 : ((LCR_game.keyStates[LCR_KEY_UP] ? LCR_RACING_INPUT_FORW : 0) | (LCR_game.keyStates[LCR_KEY_RIGHT] ? LCR_RACING_INPUT_RIGHT : 0) | (LCR_game.keyStates[LCR_KEY_DOWN] ? LCR_RACING_INPUT_BACK : 0) | @@ -856,6 +871,7 @@ uint8_t LCR_gameStep(uint32_t time) { LCR_LOG1("finished"); LCR_audioPlaySound(LCR_SOUND_CLICK); + LCR_gameSetState(LCR_GAME_STATE_RUN_FINISHED); } if (events & LCR_RACING_EVENT_CRASH_SMALL) @@ -873,6 +889,9 @@ uint8_t LCR_gameStep(uint32_t time) LCR_audioSetEngineIntensity(paused ? 0 : (engineIntensity < 256 ? engineIntensity : 255)); + if (LCR_game.state != LCR_GAME_STATE_RUN_FINISHED) + LCR_game.runTimeMS = LCR_racingGetRunTimeMS(); + LCR_game.nextRacingTickTime += LCR_RACING_TICK_MS; } diff --git a/racing.h b/racing.h index afff05b..278afd5 100644 --- a/racing.h +++ b/racing.h @@ -1202,7 +1202,7 @@ uint32_t LCR_racingStep(unsigned int input) } } - LCR_racing.tick++; + LCR_racing.tick += LCR_racing.tick < 0xffffffff; // disallow overflow LCR_LOG2("racing step end");