Start main loop

This commit is contained in:
Miloslav Ciz 2023-09-17 13:21:19 +02:00
parent ee15824329
commit e21d5b7825
5 changed files with 86 additions and 24 deletions

63
game.h
View file

@ -67,6 +67,8 @@ uint8_t LCR_gameStep(uint32_t timeMs);
//------------------------------------------------------------------------------
uint32_t LCR_nextRenderFrameTime;
void LCR_drawPixelUnsafe(unsigned int x, unsigned int y,
uint_fast16_t color);
@ -121,43 +123,58 @@ void LCR_gameEnd(void)
{
}
int aaa = 0;
uint8_t LCR_gameStep(uint32_t time)
{
for (int i = 0; i < LCR_EFFECTIVE_RESOLUTION_X; ++i)
for (int j = 0; j < LCR_EFFECTIVE_RESOLUTION_Y; ++j)
LCR_drawPixelUnsafe(i,j,0);
for (int i = 0; i < LCR_KEYS_TOTAL; ++i)
_LCR_keyStates[i] = LCR_keyPressed(i);
LCR_SpaceUnit camPos[3];
uint32_t sleep = 0;
LCR_getCameraPos(camPos);
if (time >= LCR_nextRenderFrameTime)
{
LCR_drawBackground(0);
LCR_drawSkyStrip(0,0); // TODO: do this AFTER 3D rendering
LCR_rendererDraw();
#define N 10
if (_LCR_keyStates[LCR_KEY_UP]) camPos[2] += N;
else if (_LCR_keyStates[LCR_KEY_DOWN]) camPos[2] -= N;
LCR_nextRenderFrameTime += 1000 / LCR_SETTING_FPS;
if (_LCR_keyStates[LCR_KEY_LEFT]) camPos[0] -= N;
else if (_LCR_keyStates[LCR_KEY_RIGHT]) camPos[0] += N;
LCR_SpaceUnit offsets[5];
if (_LCR_keyStates[LCR_KEY_A]) camPos[1] -= N;
else if (_LCR_keyStates[LCR_KEY_B]) camPos[1] += N;
for (int i = 0; i < 5; ++i)
offsets[i] = 0;
LCR_setCameraPos(camPos);
if (_LCR_keyStates[LCR_KEY_A])
{
if (_LCR_keyStates[LCR_KEY_UP])
offsets[4] = 4;
else if (_LCR_keyStates[LCR_KEY_DOWN])
offsets[4] -= 4;
if (_LCR_keyStates[LCR_KEY_RIGHT])
offsets[3] -= 4;
else if (_LCR_keyStates[LCR_KEY_LEFT])
offsets[3] = 4;
}
else
{
if (_LCR_keyStates[LCR_KEY_UP])
offsets[0] = LCR_FREE_CAMERA_STEP;
else if (_LCR_keyStates[LCR_KEY_DOWN])
offsets[0] -= LCR_FREE_CAMERA_STEP;
if (_LCR_keyStates[LCR_KEY_RIGHT])
offsets[1] = LCR_FREE_CAMERA_STEP;
else if (_LCR_keyStates[LCR_KEY_LEFT])
offsets[1] -= LCR_FREE_CAMERA_STEP;
}
LCR_drawBackground(200 + aaa / 10);
LCR_drawSkyStrip(200 + aaa / 10,aaa / 30);
LCR_rendererMoveCamera(offsets,offsets + 3);
}
else
sleep = LCR_nextRenderFrameTime - time;
LCR_render();
aaa = (aaa + 1) % 10000;
if (sleep)
LCR_sleep(sleep);
return 1;
}