Continue physics
This commit is contained in:
parent
1c6666b377
commit
46c8a4eade
4 changed files with 122 additions and 23 deletions
36
game.h
36
game.h
|
@ -74,7 +74,11 @@ uint8_t LCR_gameStep(uint32_t timeMs);
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
uint32_t LCR_nextRenderFrameTime;
|
||||
struct
|
||||
{
|
||||
uint32_t nextRenderFrameTime;
|
||||
uint32_t nextRacingTickTime;
|
||||
} LCR_game;
|
||||
|
||||
void LCR_drawPixelXYUnsafe(unsigned int x, unsigned int y,
|
||||
uint16_t color);
|
||||
|
@ -92,7 +96,7 @@ static inline void LCR_drawPixelXYSafe(unsigned int x, unsigned int y,
|
|||
#include "renderer.h"
|
||||
|
||||
uint8_t LCR_keyStates[LCR_KEYS_TOTAL]; /**< Assures unchanging key states
|
||||
during a single frame. */
|
||||
during a single frame. */
|
||||
|
||||
void LCR_drawPixelXYUnsafe(unsigned int x, unsigned int y,
|
||||
uint16_t color)
|
||||
|
@ -121,6 +125,9 @@ void LCR_gameInit(void)
|
|||
LCR_mapLoad(map1);
|
||||
LCR_rendererInit();
|
||||
LCR_racingInit();
|
||||
|
||||
LCR_game.nextRenderFrameTime = 0;
|
||||
LCR_game.nextRacingTickTime = 0;
|
||||
}
|
||||
|
||||
void LCR_gameEnd(void)
|
||||
|
@ -134,10 +141,27 @@ uint8_t LCR_gameStep(uint32_t time)
|
|||
|
||||
uint32_t sleep = 0;
|
||||
|
||||
if (time >= LCR_nextRenderFrameTime)
|
||||
while (time >= LCR_game.nextRacingTickTime)
|
||||
{
|
||||
unsigned int input = 0;
|
||||
|
||||
if (LCR_keyStates[LCR_KEY_B])
|
||||
input =
|
||||
(LCR_keyStates[LCR_KEY_UP] ? LCR_RACING_INPUT_FORW : 0) |
|
||||
(LCR_keyStates[LCR_KEY_RIGHT] ? LCR_RACING_INPUT_RIGHT : 0) |
|
||||
(LCR_keyStates[LCR_KEY_DOWN] ? LCR_RACING_INPUT_BACK : 0) |
|
||||
(LCR_keyStates[LCR_KEY_LEFT] ? LCR_RACING_INPUT_LEFT : 0);
|
||||
|
||||
LCR_racingStep(input);
|
||||
LCR_game.nextRacingTickTime += LCR_RACING_TICK_MS;
|
||||
}
|
||||
|
||||
|
||||
if (time >= LCR_game.nextRenderFrameTime)
|
||||
{
|
||||
LCR_GameUnit carTransform[6];
|
||||
LCR_racingGetCarTransform(carTransform,carTransform + 3);
|
||||
LCR_rendererSetCarTransform(carTransform,carTransform + 3);
|
||||
|
||||
|
||||
|
||||
|
@ -149,7 +173,7 @@ LCR_rendererGetCameraTransform(sss,sss + 3,sss + 6);
|
|||
LCR_physicsDebugDraw(sss,sss + 3,sss[6]);
|
||||
|
||||
|
||||
LCR_nextRenderFrameTime += 1000 / LCR_SETTING_FPS;
|
||||
LCR_game.nextRenderFrameTime += 1000 / LCR_SETTING_FPS;
|
||||
|
||||
LCR_GameUnit offsets[5];
|
||||
|
||||
|
@ -168,7 +192,7 @@ LCR_physicsDebugDraw(sss,sss + 3,sss[6]);
|
|||
else if (LCR_keyStates[LCR_KEY_LEFT])
|
||||
offsets[3] = LCR_FREE_CAMERA_TURN_STEP;
|
||||
}
|
||||
else
|
||||
else if (!LCR_keyStates[LCR_KEY_B])
|
||||
{
|
||||
if (LCR_keyStates[LCR_KEY_UP])
|
||||
offsets[0] = LCR_FREE_CAMERA_STEP;
|
||||
|
@ -184,7 +208,7 @@ LCR_physicsDebugDraw(sss,sss + 3,sss[6]);
|
|||
LCR_rendererMoveCamera(offsets,offsets + 3);
|
||||
}
|
||||
else
|
||||
sleep = LCR_nextRenderFrameTime - time;
|
||||
sleep = LCR_game.nextRenderFrameTime - time;
|
||||
|
||||
if (sleep)
|
||||
LCR_sleep(sleep);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue