diff --git a/src/config.h b/src/config.h index ea1b966..d84de0e 100644 --- a/src/config.h +++ b/src/config.h @@ -8,6 +8,7 @@ #define USB_FEATURE 0 +#define DEBUGMODE 1 #ifdef FXCG50 #define T_HEIGHT 16 diff --git a/src/game.h b/src/game.h index aadefb0..e13f3d4 100644 --- a/src/game.h +++ b/src/game.h @@ -1,8 +1,61 @@ #ifndef GAME_H #define GAME_H -#include "mapstruct.h" -#include "player.h" +#include + + + +/* The direction where the player is going to. */ +typedef enum { + D_UP, + D_DOWN, + D_LEFT, + D_RIGHT +} Direction; + +typedef enum { + P_LEFTUP = -1, + P_CENTER = 0, + P_RIGHTDOWN = 1 +} Checkpos; + + + +/* Struct that define player parameters */ +typedef struct { + int x, y; /* The position of the player */ + unsigned int px, py; /* The position of the player on screen */ + unsigned short int life; /* How many lives the player still has between 0 + * and 100. */ + char speed; /* The speed of the movement of the player. */ +} Player; + + + +typedef struct { + /* width, height and the number of layer of the map */ + uint16_t w, h; + uint16_t nblayers; + uint16_t tileset_size; + + uint16_t xmin; + uint16_t ymin; + uint16_t xmax; + uint16_t ymax; + + /* the tileset to use */ + bopti_image_t *tileset; + + /* contain the properties of the tiles */ + /* this is given by the layer Walkable of the map in Tiled */ + + uint8_t *walkable; + + /* list of all the tiles */ + uint16_t *layers[]; +} Map; + + /* This struct will contain all the data of the game. It will make it possible * to pass it to the NPCs to let them interact with the player and the rest of @@ -20,7 +73,6 @@ typedef struct { /* How many ms the frame already took. */ long int frame_duration; - /* variables used for debuging */ bool debug_player; bool debug_map; diff --git a/src/main.c b/src/main.c index b88cbac..6d07010 100644 --- a/src/main.c +++ b/src/main.c @@ -21,13 +21,12 @@ #include "game.h" #include "mapdata.h" -#include "mapstruct.h" #include "dialogs.h" extern bopti_image_t player_face_img; -extern const Map *worldRPG[]; +extern Map *worldRPG[]; /* Game data (defined in "game.h")*/ @@ -124,15 +123,23 @@ int main(void) { /* render the map */ draw(&game); - if (game.debug_map) - { - dfont( NULL ); - drect( 5, 5, 200, 50, C_WHITE ); - dprint( 10, 10, C_RED, "Map[ % d ] : Xmin %d Ymin %d Xmax %d Ymax %d", 0, worldRPG[0]->xmin, worldRPG[0]->ymin, worldRPG[0]->xmax, worldRPG[0]->ymax ); - dprint( 10, 20, C_RED, "Map[ % d ] : Xmin %d Ymin %d Xmax %d Ymax %d", 1, worldRPG[1]->xmin, worldRPG[1]->ymin, worldRPG[1]->xmax, worldRPG[1]->ymax ); - dprint( 10, 30, C_RED, "Map[ % d ] : Xmin %d Ymin %d Xmax %d Ymax %d", 2, worldRPG[2]->xmin, worldRPG[2]->ymin, worldRPG[2]->xmax, worldRPG[2]->ymax ); - dprint( 10, 40, C_RED, "Map[ % d ] : Xmin %d Ymin %d Xmax %d Ymax %d", 3, worldRPG[3]->xmin, worldRPG[3]->ymin, worldRPG[3]->xmax, worldRPG[3]->ymax ); - } + #if DEBUGMODE + if (game.debug_map) + { + dfont( NULL ); + drect( 5, 5,390, 55, C_WHITE ); + dprint( 10, 10, C_RED, "Map[%d] : Xmn %d Ymn %d Xmx %d Ymx %d", 0, worldRPG[0]->xmin, worldRPG[0]->ymin, worldRPG[0]->xmax, worldRPG[0]->ymax ); + dprint( 10, 20, C_RED, "Map[%d] : Xmn %d Ymn %d Xmx %d Ymx %d", 1, worldRPG[1]->xmin, worldRPG[1]->ymin, worldRPG[1]->xmax, worldRPG[1]->ymax ); + dprint( 10, 30, C_RED, "Map[%d] : Xmn %d Ymn %d Xmx %d Ymx %d", 2, worldRPG[2]->xmin, worldRPG[2]->ymin, worldRPG[2]->xmax, worldRPG[2]->ymax ); + dprint( 10, 40, C_RED, "Map[%d] : Xmn %d Ymn %d Xmx %d Ymx %d", 3, worldRPG[3]->xmin, worldRPG[3]->ymin, worldRPG[3]->xmax, worldRPG[3]->ymax ); + } + if (game.debug_player) + { + dfont( NULL ); + drect( 5, 55,390, 75, C_WHITE ); + dprint( 10, 60, C_BLUE, "X= %d - Y= %d", game.player.x, game.player.y ); + } + #endif /* start the logic of the game */ game_logic(&game); diff --git a/src/map.h b/src/map.h index 3b3de33..4c6b173 100644 --- a/src/map.h +++ b/src/map.h @@ -8,7 +8,7 @@ #define MAP_OUTSIDE -2 /* Returned by get_tile_at_pos if the point is outside of * the map. */ -#include "mapstruct.h" +#include "game.h" #include "player.h" /* Draws the map map on the entire screen to be viewed by the player player. */ diff --git a/src/mapdata.h b/src/mapdata.h index 6d1edbb..fb40c12 100644 --- a/src/mapdata.h +++ b/src/mapdata.h @@ -2,9 +2,9 @@ #define MAPDATA_H #include -#include "mapstruct.h" +#include "game.h" -extern const Map *worldRPG[]; +extern Map *worldRPG[]; #endif diff --git a/src/mapstruct.h b/src/mapstruct.h deleted file mode 100644 index e6bc6d4..0000000 --- a/src/mapstruct.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef MAPSTRUCT_H -#define MAPSTRUCT_H - -#include -#include - - - - -typedef struct { - /* width, height and the number of layer of the map */ - uint16_t w, h; - uint16_t nblayers; - uint16_t tileset_size; - - uint16_t xmin; - uint16_t ymin; - uint16_t xmax; - uint16_t ymax; - - /* the tileset to use */ - bopti_image_t *tileset; - - /* contain the properties of the tiles */ - /* this is given by the layer Walkable of the map in Tiled */ - - uint8_t *walkable; - - /* list of all the tiles */ - uint16_t *layers[]; -} Map; - -#endif diff --git a/src/player.c b/src/player.c index 78330fa..253c1f2 100644 --- a/src/player.c +++ b/src/player.c @@ -26,12 +26,13 @@ const char damage_taken_walkable[WALKABLE_TILE_MAX] = { extern bopti_image_t demo_player_img; + void player_draw(Player *player) { dimage(player->px-P_WIDTH/2, player->py-P_HEIGHT/2, &demo_player_img); - //dprint( 10, 10, C_RED, "X= %d - Y= %d", player->x, player->y ); } void player_move(Map *map_level, Player *player, Direction direction) { + /* How this player movement will modify the player x and y. */ char dx, dy; /* If the player will collide with a hard tile or if the will go outside of diff --git a/src/player.h b/src/player.h index 9ac3510..af8d026 100644 --- a/src/player.h +++ b/src/player.h @@ -16,31 +16,9 @@ #include -#include "mapstruct.h" +#include "game.h" #include "memory.h" -/* The direction where the player is going to. */ -typedef enum { - D_UP, - D_DOWN, - D_LEFT, - D_RIGHT -} Direction; - -typedef enum { - P_LEFTUP = -1, - P_CENTER = 0, - P_RIGHTDOWN = 1 -} Checkpos; - -/* Struct that define player parameters */ -typedef struct { - int x, y; /* The position of the player */ - unsigned int px, py; /* The position of the player on screen */ - unsigned short int life; /* How many lives the player still has between 0 - * and 100. */ - char speed; /* The speed of the movement of the player. */ -} Player; /* Draws the player player. This function should be called after drawing the * map! */