Make finish work

This commit is contained in:
Miloslav Ciz 2025-01-07 23:21:08 +01:00
parent 4cc592b0f5
commit b1c2041d84
3 changed files with 38 additions and 19 deletions

View file

@ -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:

49
game.h
View file

@ -204,13 +204,16 @@ struct
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];
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;
}

View file

@ -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");