diff --git a/game.h b/game.h index 585d8ef..987e354 100644 --- a/game.h +++ b/game.h @@ -1,6 +1,6 @@ /** - Licar game: this file implements the backend of a complete, actually playable - licar game, and is meant to be included and used by specific frontends (which + game: this file implements the backend of a complete, actually playable + game, and is meant to be included and used by specific frontends (which will handle each platform's hardware details and I/O). */ @@ -78,7 +78,7 @@ void LCR_drawPixelUnsafe(unsigned int x, unsigned int y, static inline void LCR_drawPixelSafe(unsigned int x, unsigned int y, uint_fast16_t color); -#include "map.h" +#include "racing.h" #include "assets.h" #include "renderer.h" @@ -133,6 +133,22 @@ for (int i = 0; i < LCR_EFFECTIVE_RESOLUTION_X; ++i) for (int i = 0; i < LCR_KEYS_TOTAL; ++i) _LCR_keyStates[i] = LCR_keyPressed(i); +LCR_SpaceUnit camPos[3]; + +LCR_getCameraPos(camPos); + +#define N 10 +if (_LCR_keyStates[LCR_KEY_UP]) camPos[2] += N; +else if (_LCR_keyStates[LCR_KEY_DOWN]) camPos[2] -= N; + +if (_LCR_keyStates[LCR_KEY_LEFT]) camPos[0] -= N; +else if (_LCR_keyStates[LCR_KEY_RIGHT]) camPos[0] += N; + +if (_LCR_keyStates[LCR_KEY_A]) camPos[1] -= N; +else if (_LCR_keyStates[LCR_KEY_B]) camPos[1] += N; + +LCR_setCameraPos(camPos); + LCR_drawBackground(200 + aaa / 10); diff --git a/racing.h b/racing.h new file mode 100644 index 0000000..755f834 --- /dev/null +++ b/racing.h @@ -0,0 +1,15 @@ +/** + racing module: implements the racing physics and logic. +*/ + +#ifndef _LCR_RACING_H +#define _LCR_RACING_H + +typedef int32_t LCR_SpaceUnit; ///< game spatial units + +#define LCR_SQUARE_SIDE_LEN 1024 ///< length of map square in LCR_SpaceUnits + +#include "map.h" +#include "tinyphysicsengine.h" + +#endif // guard diff --git a/renderer.h b/renderer.h index 8852669..376543a 100644 --- a/renderer.h +++ b/renderer.h @@ -1,3 +1,7 @@ +/** + 3D renderer: implements 3D rendering. +*/ + #ifndef _LCR_RENDERER_H #define _LCR_RENDERER_H @@ -10,6 +14,8 @@ struct LCR_Renderer { // TODO + + }; S3L_Scene LCR_scene3D; @@ -59,6 +65,26 @@ uint8_t LCR_rendererInit(void) return 1; } +void LCR_getCameraPos(LCR_SpaceUnit pos[3]) +{ + pos[0] = (LCR_scene3D.camera.transform.translation.x * + LCR_SQUARE_SIDE_LEN) / S3L_FRACTIONS_PER_UNIT; + pos[1] = (LCR_scene3D.camera.transform.translation.y * + LCR_SQUARE_SIDE_LEN) / S3L_FRACTIONS_PER_UNIT; + pos[2] = (LCR_scene3D.camera.transform.translation.z * + LCR_SQUARE_SIDE_LEN) / S3L_FRACTIONS_PER_UNIT; +} + +void LCR_setCameraPos(LCR_SpaceUnit pos[3]) +{ + LCR_scene3D.camera.transform.translation.x = + (pos[0] * S3L_FRACTIONS_PER_UNIT) / LCR_SQUARE_SIDE_LEN; + LCR_scene3D.camera.transform.translation.y = + (pos[1] * S3L_FRACTIONS_PER_UNIT) / LCR_SQUARE_SIDE_LEN; + LCR_scene3D.camera.transform.translation.z = + (pos[2] * S3L_FRACTIONS_PER_UNIT) / LCR_SQUARE_SIDE_LEN; +} + void LCR_render(void) { S3L_newFrame();