Placeholder for GameLogic() loop + some comments in the code

This commit is contained in:
SlyVTT 2023-07-06 22:49:29 +02:00
parent 25bc00e311
commit e6867a37ac
4 changed files with 45 additions and 11 deletions

View file

@ -26,17 +26,20 @@
/* Player data (defined in "player.h")*/
struct Player MyPlayer = { 10, 5, 100 };
bool exittoOS = false;
/* some global variables */
bool exittoOS = false; // set to true when asked for exit
bool screenshot = false;
bool record = false;
bool screenshot = false; // set to true when screenshot is required
bool record = false; // set to true when
/* Key management */
static void get_inputs( void )
{
key_event_t ev;
@ -51,13 +54,14 @@ static void get_inputs( void )
if(keydown(KEY_EXIT)) exittoOS = true;
/* Player actions - Prototypes in player.h and implementation in player.c */
if(keydown(KEY_LEFT)) PlayerLeft();
if(keydown(KEY_RIGHT)) PlayerRight();
if(keydown(KEY_UP)) PlayerUp();
if(keydown(KEY_DOWN)) PlayerDown();
if(keydown(KEY_SHIFT)) PlayerAction();
/* if USB is enabled - keybinding for screencapture */
#if USB_FEATURE==1
@ -68,6 +72,8 @@ static void get_inputs( void )
}
/* screen capture management code */
#if USB_FEATURE==1
void USB_feature( void )
@ -91,6 +97,11 @@ static void get_inputs( void )
#endif
void GameLogic( void )
{
}
int main(void)
@ -102,8 +113,8 @@ int main(void)
#endif
dclear(C_WHITE);
/* start grayscale engine */
#ifdef COLOR2BIT
dgray( DGRAY_ON );
#endif
@ -111,27 +122,38 @@ int main(void)
do
{
/* clear screen */
dclear(C_WHITE);
/* render the map */
RenderMap();
/* start the logic of the game */
GameLogic();
/* Screen blit */
dupdate();
/* Screen capture feature if enabled */
#if USB_FEATURE==1
USB_feature();
#endif
/* Management of the inputs */
get_inputs();
}
while (exittoOS == false);
while (exittoOS == false); // want to exit ?
/* shutdown grayengine*/
#ifdef COLOR2BIT
dgray( DGRAY_OFF );
#endif
/* close USB */
#if USB_FEATURE==1
usb_close();
#endif

View file

@ -7,18 +7,29 @@ struct Map *map_level = &map_level0;
void RenderMap( void )
{
/* for all Layer (2 in the current configuration: Background is layer 0 and foreground is layer 1 ) */
for (int u = 0; u < map_level->nblayers; u++)
{
/* for each colum */
for (int i = 0; i < map_level->w; i++)
{
/* and each line */
for (int j = 0; j < map_level->h; j++)
{
/* compute the index */
uint16_t index = j * map_level->w + i;
/* get the tile index from the map*/
int16_t currentTile = map_level->layers[u][index];
/* currentTile == -1 means nothing to be draw */
if (currentTile != -1)
{
/* get x and y position in the tileset image */
uint16_t xtile = (currentTile % map_level->tileset_size) * 8;
uint16_t ytile = (currentTile / map_level->tileset_size) * 8;
/* render */
dsubimage(i * 8, j * 8, map_level->tileset, xtile, ytile, 8, 8, DIMAGE_NONE );
}
}

View file

@ -9,6 +9,7 @@ void RenderMap(void);
struct Map {
/*width, height and the number of layer of the map*/
int w, h, nblayers;

View file

@ -4,7 +4,7 @@
#include <stdint.h>
/* Struct that define player parameters */
struct Player
{
uint16_t x, y;