diff --git a/src/main.c b/src/main.c index 882cfd4..3a6fae8 100644 --- a/src/main.c +++ b/src/main.c @@ -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 diff --git a/src/map.c b/src/map.c index da9f948..0f184d1 100644 --- a/src/map.c +++ b/src/map.c @@ -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 ); } } diff --git a/src/map.h b/src/map.h index 0667bc2..2a0332e 100644 --- a/src/map.h +++ b/src/map.h @@ -9,6 +9,7 @@ void RenderMap(void); struct Map { + /*width, height and the number of layer of the map*/ int w, h, nblayers; diff --git a/src/player.h b/src/player.h index 094cc99..a9a3f49 100644 --- a/src/player.h +++ b/src/player.h @@ -4,7 +4,7 @@ #include - +/* Struct that define player parameters */ struct Player { uint16_t x, y;