2023-09-10 14:43:20 +02:00
|
|
|
/**
|
|
|
|
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
|
|
|
|
will handle each platform's hardware details and I/O).
|
|
|
|
*/
|
|
|
|
|
2023-07-21 21:17:49 +02:00
|
|
|
#ifndef _LCR_GAME_H
|
|
|
|
#define _LCR_GAME_H
|
|
|
|
|
2023-09-10 14:43:20 +02:00
|
|
|
#define LCR_KEY_UP 0x00
|
|
|
|
#define LCR_KEY_RIGHT 0x01
|
|
|
|
#define LCR_KEY_DOWN 0x02
|
|
|
|
#define LCR_KEY_LEFT 0x03
|
|
|
|
#define LCR_KEY_A 0x04 ///< confirm, restart race
|
|
|
|
#define LCR_KEY_B 0x05 ///< cancel, open menu
|
|
|
|
|
|
|
|
#define LCR_KEYS_TOTAL 6
|
|
|
|
|
|
|
|
/*
|
|
|
|
FOR FRONTENDS:
|
|
|
|
- Implement the below described functions according to their description.
|
|
|
|
- Implement the main program and game loop.
|
|
|
|
- Call the below described functions as described.
|
|
|
|
*/
|
2023-08-08 20:34:21 +02:00
|
|
|
|
2023-09-10 14:43:20 +02:00
|
|
|
/**
|
|
|
|
Implement this in your frontend. Returns 1 if given key is pressed or 0
|
|
|
|
otherwise.
|
|
|
|
*/
|
2023-08-08 20:34:21 +02:00
|
|
|
uint8_t LCR_keyPressed(uint8_t key);
|
|
|
|
|
2023-09-10 14:43:20 +02:00
|
|
|
/**
|
|
|
|
Implement this in your frontend. This function pauses program execution for
|
|
|
|
given amount of milliseconds and relieves the CPU usage. On platforms that
|
|
|
|
don't support this the function may simply do nothing.
|
|
|
|
*/
|
2023-08-08 20:34:21 +02:00
|
|
|
void LCR_sleep(uint16_t timeMs);
|
|
|
|
|
2023-09-10 14:43:20 +02:00
|
|
|
/**
|
|
|
|
Implement this in your frontend. This function draws a pixel of given color
|
|
|
|
to the screen back buffer (i.e. NOT directly to screen, back buffer shall
|
|
|
|
only be copied to front buffer once the LCR_gameStep function finishes all
|
|
|
|
rendering). This function should NOT check for out-of-screen coordinates, this
|
|
|
|
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.
|
|
|
|
*/
|
2023-08-08 20:34:21 +02:00
|
|
|
void LCR_drawPixel(unsigned int x, unsigned int y, uint_fast16_t color);
|
|
|
|
|
|
|
|
/**
|
2023-09-10 14:43:20 +02:00
|
|
|
Call this function in your frontend at the start of the program.
|
2023-08-08 20:34:21 +02:00
|
|
|
*/
|
|
|
|
void LCR_gameInit(void);
|
|
|
|
|
|
|
|
/**
|
2023-09-10 14:43:20 +02:00
|
|
|
Call this function in your frontend right before program end.
|
2023-08-08 20:34:21 +02:00
|
|
|
*/
|
|
|
|
void LCR_gameEnd(void);
|
|
|
|
|
|
|
|
/**
|
2023-09-10 14:43:20 +02:00
|
|
|
Call this function in your frontend repeatedly inside the main loop, pass the
|
|
|
|
current time as the number of milliseconds since program start. This function
|
|
|
|
will perform the game step AND other things such as checking the input states,
|
|
|
|
rendering or sleeping (all using the above functions you should implement).
|
|
|
|
Returns 0 if program should end, otherwise 1.
|
2023-08-08 20:34:21 +02:00
|
|
|
*/
|
|
|
|
uint8_t LCR_gameStep(uint32_t timeMs);
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2023-09-13 20:51:07 +02:00
|
|
|
void LCR_drawPixelUnsafe(unsigned int x, unsigned int y,
|
|
|
|
uint_fast16_t color);
|
2023-09-10 14:43:20 +02:00
|
|
|
|
|
|
|
/**
|
2023-09-13 20:51:07 +02:00
|
|
|
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).
|
2023-09-10 14:43:20 +02:00
|
|
|
*/
|
2023-09-13 20:51:07 +02:00
|
|
|
static inline void LCR_drawPixelSafe(unsigned int x, unsigned int y,
|
|
|
|
uint_fast16_t color);
|
|
|
|
|
|
|
|
#include "map.h"
|
|
|
|
#include "assets.h"
|
|
|
|
#include "renderer.h"
|
|
|
|
|
|
|
|
uint8_t _LCR_keyStates[LCR_KEYS_TOTAL]; /**< Assures unchanging key states
|
|
|
|
during a single frame. */
|
|
|
|
|
2023-09-11 20:56:04 +02:00
|
|
|
void LCR_drawPixelUnsafe(unsigned int x, unsigned int y,
|
2023-09-10 14:43:20 +02:00
|
|
|
uint_fast16_t color)
|
|
|
|
{
|
2023-09-11 20:56:04 +02:00
|
|
|
#if LCR_SETTING_RESOLUTION_SUBDIVIDE == 1
|
|
|
|
LCR_drawPixel(x,y,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);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void LCR_drawPixelSafe(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);
|
2023-09-10 14:43:20 +02:00
|
|
|
}
|
|
|
|
|
2023-08-08 20:34:21 +02:00
|
|
|
void LCR_gameInit(void)
|
|
|
|
{
|
2023-09-10 14:43:20 +02:00
|
|
|
for (int i = 0; i < LCR_KEYS_TOTAL; ++i)
|
|
|
|
_LCR_keyStates[i] = 0;
|
2023-09-16 20:35:01 +02:00
|
|
|
|
|
|
|
LCR_rendererInit();
|
2023-08-08 20:34:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LCR_gameEnd(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-09-12 17:39:55 +02:00
|
|
|
int aaa = 0;
|
|
|
|
|
2023-08-08 20:34:21 +02:00
|
|
|
uint8_t LCR_gameStep(uint32_t time)
|
|
|
|
{
|
2023-09-12 17:39:55 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-09-10 14:43:20 +02:00
|
|
|
for (int i = 0; i < LCR_KEYS_TOTAL; ++i)
|
|
|
|
_LCR_keyStates[i] = LCR_keyPressed(i);
|
|
|
|
|
2023-09-13 20:51:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
LCR_drawBackground(200 + aaa / 10);
|
|
|
|
LCR_drawSkyStrip(200 + aaa / 10,aaa / 30);
|
2023-09-12 17:39:55 +02:00
|
|
|
|
2023-09-16 20:35:01 +02:00
|
|
|
LCR_render();
|
|
|
|
|
2023-09-12 17:39:55 +02:00
|
|
|
|
|
|
|
aaa = (aaa + 1) % 10000;
|
2023-09-10 14:43:20 +02:00
|
|
|
|
|
|
|
return 1;
|
2023-08-08 20:34:21 +02:00
|
|
|
}
|
|
|
|
|
2023-07-21 21:17:49 +02:00
|
|
|
#endif // guard
|