Start block shapes

This commit is contained in:
Miloslav Ciz 2024-07-22 01:16:16 +02:00
parent 84163d0d3c
commit 9e3bf000cf
8 changed files with 217 additions and 67 deletions

53
game.h
View file

@ -44,7 +44,7 @@ void LCR_sleep(uint16_t timeMs);
is handled by the game internals and out-of-screen pixels will never be drawn.
The color value depends on game settings but is normally an RGB565 value.
*/
void LCR_drawPixel(unsigned int x, unsigned int y, uint_fast16_t color);
void LCR_drawPixel(unsigned long index, uint16_t color);
/**
Call this function in your frontend at the start of the program.
@ -69,52 +69,47 @@ uint8_t LCR_gameStep(uint32_t timeMs);
uint32_t LCR_nextRenderFrameTime;
void LCR_drawPixelUnsafe(unsigned int x, unsigned int y,
uint_fast16_t color);
void LCR_drawPixelXYUnsafe(unsigned int x, unsigned int y,
uint16_t color);
/**
Internal pixel drawing function that checks for out-of-screen coordinates. Use
this if the pixel can potentially lie of screen (however if you know it won't,
use the normal unsafe function in sake of performance).
*/
static inline void LCR_drawPixelSafe(unsigned int x, unsigned int y,
static inline void LCR_drawPixelXYSafe(unsigned int x, unsigned int y,
uint_fast16_t color);
#include "racing.h"
#include "assets.h"
#include "renderer.h"
uint8_t _LCR_keyStates[LCR_KEYS_TOTAL]; /**< Assures unchanging key states
uint8_t LCR_keyStates[LCR_KEYS_TOTAL]; /**< Assures unchanging key states
during a single frame. */
void LCR_drawPixelUnsafe(unsigned int x, unsigned int y,
uint_fast16_t color)
void LCR_drawPixelXYUnsafe(unsigned int x, unsigned int y,
uint16_t color)
{
#if LCR_SETTING_RESOLUTION_SUBDIVIDE == 1
LCR_drawPixel(x,y,color);
LCR_drawPixel(y * LCR_SETTING_RESOLUTION_X + x,color);
#else
x *= LCR_SETTING_RESOLUTION_SUBDIVIDE;
y *= LCR_SETTING_RESOLUTION_SUBDIVIDE;
unsigned int x2 = x + LCR_SETTING_RESOLUTION_SUBDIVIDE;
for (int yy = y; yy < y + LCR_SETTING_RESOLUTION_SUBDIVIDE; ++yy)
for (int xx = x; xx < x2; ++xx)
LCR_drawPixel(xx,yy,color);
// TODO
#endif
}
static inline void LCR_drawPixelSafe(unsigned int x, unsigned int y,
static inline void LCR_drawPixelXYSafe(unsigned int x, unsigned int y,
uint_fast16_t color)
{
if (x < LCR_EFFECTIVE_RESOLUTION_X && y < LCR_EFFECTIVE_RESOLUTION_Y)
LCR_drawPixelUnsafe(x,y,color);
LCR_drawPixelXYUnsafe(x,y,color);
}
void LCR_gameInit(void)
{
for (int i = 0; i < LCR_KEYS_TOTAL; ++i)
_LCR_keyStates[i] = 0;
LCR_keyStates[i] = 0;
LCR_mapLoad(map1);
LCR_rendererInit();
}
@ -126,7 +121,7 @@ void LCR_gameEnd(void)
uint8_t LCR_gameStep(uint32_t time)
{
for (int i = 0; i < LCR_KEYS_TOTAL; ++i)
_LCR_keyStates[i] = LCR_keyPressed(i);
LCR_keyStates[i] = LCR_keyPressed(i);
uint32_t sleep = 0;
@ -152,28 +147,28 @@ uint8_t LCR_gameStep(uint32_t time)
for (int i = 0; i < 5; ++i)
offsets[i] = 0;
if (_LCR_keyStates[LCR_KEY_A])
if (LCR_keyStates[LCR_KEY_A])
{
if (_LCR_keyStates[LCR_KEY_UP])
if (LCR_keyStates[LCR_KEY_UP])
offsets[4] = LCR_FREE_CAMERA_TURN_STEP;
else if (_LCR_keyStates[LCR_KEY_DOWN])
else if (LCR_keyStates[LCR_KEY_DOWN])
offsets[4] -= LCR_FREE_CAMERA_TURN_STEP;
if (_LCR_keyStates[LCR_KEY_RIGHT])
if (LCR_keyStates[LCR_KEY_RIGHT])
offsets[3] -= LCR_FREE_CAMERA_TURN_STEP;
else if (_LCR_keyStates[LCR_KEY_LEFT])
else if (LCR_keyStates[LCR_KEY_LEFT])
offsets[3] = LCR_FREE_CAMERA_TURN_STEP;
}
else
{
if (_LCR_keyStates[LCR_KEY_UP])
if (LCR_keyStates[LCR_KEY_UP])
offsets[0] = LCR_FREE_CAMERA_STEP;
else if (_LCR_keyStates[LCR_KEY_DOWN])
else if (LCR_keyStates[LCR_KEY_DOWN])
offsets[0] -= LCR_FREE_CAMERA_STEP;
if (_LCR_keyStates[LCR_KEY_RIGHT])
if (LCR_keyStates[LCR_KEY_RIGHT])
offsets[1] = LCR_FREE_CAMERA_STEP;
else if (_LCR_keyStates[LCR_KEY_LEFT])
else if (LCR_keyStates[LCR_KEY_LEFT])
offsets[1] -= LCR_FREE_CAMERA_STEP;
}