mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2024-12-29 13:03:43 +01:00
Placeholder for GameLogic() loop + some comments in the code
This commit is contained in:
parent
25bc00e311
commit
e6867a37ac
4 changed files with 45 additions and 11 deletions
38
src/main.c
38
src/main.c
|
@ -26,17 +26,20 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Player data (defined in "player.h")*/
|
||||||
struct Player MyPlayer = { 10, 5, 100 };
|
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 screenshot = false; // set to true when screenshot is required
|
||||||
bool record = false;
|
bool record = false; // set to true when
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Key management */
|
||||||
|
|
||||||
static void get_inputs( void )
|
static void get_inputs( void )
|
||||||
{
|
{
|
||||||
key_event_t ev;
|
key_event_t ev;
|
||||||
|
@ -51,13 +54,14 @@ static void get_inputs( void )
|
||||||
|
|
||||||
if(keydown(KEY_EXIT)) exittoOS = true;
|
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_LEFT)) PlayerLeft();
|
||||||
if(keydown(KEY_RIGHT)) PlayerRight();
|
if(keydown(KEY_RIGHT)) PlayerRight();
|
||||||
if(keydown(KEY_UP)) PlayerUp();
|
if(keydown(KEY_UP)) PlayerUp();
|
||||||
if(keydown(KEY_DOWN)) PlayerDown();
|
if(keydown(KEY_DOWN)) PlayerDown();
|
||||||
if(keydown(KEY_SHIFT)) PlayerAction();
|
if(keydown(KEY_SHIFT)) PlayerAction();
|
||||||
|
|
||||||
|
/* if USB is enabled - keybinding for screencapture */
|
||||||
|
|
||||||
#if USB_FEATURE==1
|
#if USB_FEATURE==1
|
||||||
|
|
||||||
|
@ -68,6 +72,8 @@ static void get_inputs( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* screen capture management code */
|
||||||
|
|
||||||
#if USB_FEATURE==1
|
#if USB_FEATURE==1
|
||||||
|
|
||||||
void USB_feature( void )
|
void USB_feature( void )
|
||||||
|
@ -91,6 +97,11 @@ static void get_inputs( void )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void GameLogic( void )
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
@ -102,7 +113,7 @@ int main(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
dclear(C_WHITE);
|
/* start grayscale engine */
|
||||||
|
|
||||||
#ifdef COLOR2BIT
|
#ifdef COLOR2BIT
|
||||||
dgray( DGRAY_ON );
|
dgray( DGRAY_ON );
|
||||||
|
@ -111,27 +122,38 @@ int main(void)
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
/* clear screen */
|
||||||
|
dclear(C_WHITE);
|
||||||
|
|
||||||
|
/* render the map */
|
||||||
RenderMap();
|
RenderMap();
|
||||||
|
|
||||||
|
/* start the logic of the game */
|
||||||
|
GameLogic();
|
||||||
|
|
||||||
|
/* Screen blit */
|
||||||
dupdate();
|
dupdate();
|
||||||
|
|
||||||
|
/* Screen capture feature if enabled */
|
||||||
#if USB_FEATURE==1
|
#if USB_FEATURE==1
|
||||||
USB_feature();
|
USB_feature();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Management of the inputs */
|
||||||
get_inputs();
|
get_inputs();
|
||||||
|
|
||||||
}
|
}
|
||||||
while (exittoOS == false);
|
while (exittoOS == false); // want to exit ?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* shutdown grayengine*/
|
||||||
#ifdef COLOR2BIT
|
#ifdef COLOR2BIT
|
||||||
dgray( DGRAY_OFF );
|
dgray( DGRAY_OFF );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* close USB */
|
||||||
#if USB_FEATURE==1
|
#if USB_FEATURE==1
|
||||||
usb_close();
|
usb_close();
|
||||||
#endif
|
#endif
|
||||||
|
|
11
src/map.c
11
src/map.c
|
@ -7,18 +7,29 @@ struct Map *map_level = &map_level0;
|
||||||
|
|
||||||
void RenderMap( void )
|
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 (int u = 0; u < map_level->nblayers; u++)
|
||||||
{
|
{
|
||||||
|
/* for each colum */
|
||||||
for (int i = 0; i < map_level->w; i++)
|
for (int i = 0; i < map_level->w; i++)
|
||||||
{
|
{
|
||||||
|
/* and each line */
|
||||||
for (int j = 0; j < map_level->h; j++)
|
for (int j = 0; j < map_level->h; j++)
|
||||||
{
|
{
|
||||||
|
/* compute the index */
|
||||||
uint16_t index = j * map_level->w + i;
|
uint16_t index = j * map_level->w + i;
|
||||||
|
|
||||||
|
/* get the tile index from the map*/
|
||||||
int16_t currentTile = map_level->layers[u][index];
|
int16_t currentTile = map_level->layers[u][index];
|
||||||
|
|
||||||
|
/* currentTile == -1 means nothing to be draw */
|
||||||
if (currentTile != -1)
|
if (currentTile != -1)
|
||||||
{
|
{
|
||||||
|
/* get x and y position in the tileset image */
|
||||||
uint16_t xtile = (currentTile % map_level->tileset_size) * 8;
|
uint16_t xtile = (currentTile % map_level->tileset_size) * 8;
|
||||||
uint16_t ytile = (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 );
|
dsubimage(i * 8, j * 8, map_level->tileset, xtile, ytile, 8, 8, DIMAGE_NONE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ void RenderMap(void);
|
||||||
|
|
||||||
|
|
||||||
struct Map {
|
struct Map {
|
||||||
|
|
||||||
/*width, height and the number of layer of the map*/
|
/*width, height and the number of layer of the map*/
|
||||||
int w, h, nblayers;
|
int w, h, nblayers;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* Struct that define player parameters */
|
||||||
struct Player
|
struct Player
|
||||||
{
|
{
|
||||||
uint16_t x, y;
|
uint16_t x, y;
|
||||||
|
|
Loading…
Reference in a new issue