diff --git a/CMakeLists.txt b/CMakeLists.txt index df83849..6a7f080 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,10 @@ set(ASSETS set(ASSETS_cg assets-cg/demo_player.png assets-cg/demo_PNJ.png + assets-cg/SignAction.png + assets-cg/NPC_Icon.png + assets-cg/SGN_Icon.png + assets-cg/INFO_Icon.png assets-cg/player_face.png assets-cg/font.png ) @@ -55,6 +59,10 @@ set(ASSETS_cg_EGA64 set(ASSETS_fx assets-fx/demo_player.png assets-fx/demo_PNJ.png + assets-fx/SignAction.png + assets-fx/NPC_Icon.png + assets-fx/SGN_Icon.png + assets-fx/INFO_Icon.png assets-fx/player_face.png assets-fx/font.png # ... diff --git a/assets-cg/INFO_Icon.png b/assets-cg/INFO_Icon.png new file mode 100644 index 0000000..f07aa4e Binary files /dev/null and b/assets-cg/INFO_Icon.png differ diff --git a/assets-cg/NPC_Icon.png b/assets-cg/NPC_Icon.png new file mode 100644 index 0000000..60597e5 Binary files /dev/null and b/assets-cg/NPC_Icon.png differ diff --git a/assets-cg/SGN_Icon.png b/assets-cg/SGN_Icon.png new file mode 100644 index 0000000..2659532 Binary files /dev/null and b/assets-cg/SGN_Icon.png differ diff --git a/assets-cg/SignAction.png b/assets-cg/SignAction.png new file mode 100644 index 0000000..891b824 Binary files /dev/null and b/assets-cg/SignAction.png differ diff --git a/assets-cg/fxconv-metadata.txt b/assets-cg/fxconv-metadata.txt index a631b2a..9b21fe9 100644 --- a/assets-cg/fxconv-metadata.txt +++ b/assets-cg/fxconv-metadata.txt @@ -10,6 +10,22 @@ player_face.png: type: bopti-image name: player_face_img +SignAction.png: + type: bopti-image + name: SignAction_img + +INFO_Icon.png: + type: bopti-image + name: INFO_Icon_img + +NPC_Icon.png: + type: bopti-image + name: NPC_Icon_img + +SGN_Icon.png: + type: bopti-image + name: SGN_Icon_img + font.png: name: fontRPG type: font diff --git a/assets-fx/INFO_Icon.png b/assets-fx/INFO_Icon.png new file mode 100644 index 0000000..b204c4b Binary files /dev/null and b/assets-fx/INFO_Icon.png differ diff --git a/assets-fx/NPC_Icon.png b/assets-fx/NPC_Icon.png new file mode 100644 index 0000000..dd61d33 Binary files /dev/null and b/assets-fx/NPC_Icon.png differ diff --git a/assets-fx/SGN_Icon.png b/assets-fx/SGN_Icon.png new file mode 100644 index 0000000..dc041e3 Binary files /dev/null and b/assets-fx/SGN_Icon.png differ diff --git a/assets-fx/SignAction.png b/assets-fx/SignAction.png new file mode 100644 index 0000000..ced6850 Binary files /dev/null and b/assets-fx/SignAction.png differ diff --git a/assets-fx/fxconv-metadata.txt b/assets-fx/fxconv-metadata.txt index 0ca3da4..499f659 100644 --- a/assets-fx/fxconv-metadata.txt +++ b/assets-fx/fxconv-metadata.txt @@ -10,6 +10,21 @@ player_face.png: type: bopti-image name: player_face_img +SignAction.png: + type: bopti-image + name: SignAction_img + +INFO_Icon.png: + type: bopti-image + name: INFO_Icon_img + +NPC_Icon.png: + type: bopti-image + name: NPC_Icon_img + +SGN_Icon.png: + type: bopti-image + name: SGN_Icon_img font.png: name: fontRPG diff --git a/src/game.c b/src/game.c index 284ce7c..2a6439a 100644 --- a/src/game.c +++ b/src/game.c @@ -6,13 +6,40 @@ #include #include +#include +#include "stdlib.h" + +extern bopti_image_t SignAction_img; void game_logic(Game *game) { + for( int i=0; imap_level->nbextradata; i++ ) + { + if ( (abs((int) game->player.x - (int) game->map_level->extradata[i].x*PXSIZE) < 8*PXSIZE) + && (abs((int) game->player.y - (int) game->map_level->extradata[i].y*PXSIZE) < 8*PXSIZE)) + { + game->player.canDoSomething = true; + game->player.whichAction = i; + return; + } + } + + game->player.canDoSomething = false; + game->player.whichAction = -1; + return; +} +void render_indicator(Game *game) +{ + if (game->player.canDoSomething==false) + return; + + dimage(5, 5, &SignAction_img); + //dprint( 20, 20, C_RED, "X= %d - Y= %d / Xp= %d - Yp= %d", game->player.x, game->player.y, game->map_level->extradata[0].x*PXSIZE, game->map_level->extradata[0].y*PXSIZE ); + //dprint( 20, 40, C_RED, "ABS1= %d - ABS2= %d", abs((int) game->player.x - (int) game->map_level->extradata[0].x*PXSIZE), abs((int) game->player.y - (int) game->map_level->extradata[0].y*PXSIZE) ); } void draw(Game *game) { @@ -20,6 +47,7 @@ void draw(Game *game) { render_map_by_layer(game, BACKGROUND); player_draw(game); render_map_by_layer(game, FOREGROUND); + render_indicator( game ); } /* Key management */ @@ -51,6 +79,9 @@ void get_inputs(Game *game) { if(keydown(KEY_F2)) { game->debug_player = !game->debug_player; } + if(keydown(KEY_F3)) { + game->debug_extra = !game->debug_extra; + } #endif diff --git a/src/game.h b/src/game.h index af724b5..76c6a38 100644 --- a/src/game.h +++ b/src/game.h @@ -1,6 +1,7 @@ #ifndef GAME_H #define GAME_H + #include #include @@ -24,12 +25,16 @@ typedef enum { /* Struct that define player parameters */ typedef struct { - int x, y; /* The position of the player int the current map */ - unsigned int px, py; /* The position of the player on screen */ - int wx, wy; /* position of the player in the world */ - unsigned short int life; /* How many lives the player still has between 0 + int16_t x, y; /* The position of the player int the current map */ + uint16_t px, py; /* The position of the player on screen */ + int16_t wx, wy; /* position of the player in the world */ + int16_t life; /* How many lives the player still has between 0 * and 100. */ - char speed; /* The speed of the movement of the player. */ + int8_t speed; /* The speed of the movement of the player. */ + + bool canDoSomething; /* set to true if a action can be done in the current position of the map */ + int32_t whichAction; /* indicates which data are relevant to the current action in the extradata layer of the map */ + bool isDoingAction; } Player; @@ -103,6 +108,10 @@ void game_logic(Game *game); /* Draws everything on screen. */ void draw(Game *game); +/* This render a small sign on the upper lecft corner of the screen */ +/* if the player can do an action */ +void render_indicator(Game *game); + /* Handle key presses. */ void get_inputs(Game *game); diff --git a/src/main.c b/src/main.c index 07d98d8..f7893c9 100644 --- a/src/main.c +++ b/src/main.c @@ -32,11 +32,11 @@ extern Map *worldRPG[]; /* Game data (defined in "game.h")*/ Game game = { NULL, - {12*PXSIZE, 36*PXSIZE, 0, 0, 10*PXSIZE, 48*PXSIZE, 100, SPEED}, + {12*PXSIZE, 36*PXSIZE, 0, 0, 10*PXSIZE, 48*PXSIZE, 100, SPEED, false, 0, false}, false, false, false, 0 /* debug variables*/ - , false, false, true + , false, false, false }; /* screen capture management code */ @@ -142,7 +142,6 @@ int main(void) { if (game.debug_extra) { dfont( NULL ); - //drect( 155, 80, 390, 150, C_WHITE ); for (int i=0; inbextradata; i++ ) dprint( 10, 90+i*15, C_RED, "X= %d - Y= %d - T: %s", game.map_level->extradata[i].x, game.map_level->extradata[i].y, game.map_level->extradata[i].dialog ); } diff --git a/src/player.c b/src/player.c index 3cb1efc..777a6b4 100644 --- a/src/player.c +++ b/src/player.c @@ -1,4 +1,5 @@ #include "player.h" +#include "dialogs.h" #include "map.h" #include "config.h" #include @@ -25,6 +26,9 @@ const char damage_taken_walkable[WALKABLE_TILE_MAX] = { }; extern bopti_image_t demo_player_img; +extern bopti_image_t NPC_Icon_img; +extern bopti_image_t SGN_Icon_img; +extern bopti_image_t INFO_Icon_img; void player_draw(Game *game) { @@ -77,8 +81,30 @@ void player_move(Game *game, Direction direction) { player->wy = game->map_level->ymin * PXSIZE + player->y; } + void player_action(Game *game) { - /* TODO */ + if( game->player.isDoingAction ) return; /* alreday doing something */ + + if( game->player.canDoSomething ) /* we can do something */ + { + game->player.isDoingAction = true; + + char *text = game->map_level->extradata[game->player.whichAction].dialog; + bopti_image_t *face; + + if (strcmp("PST", game->map_level->extradata[game->player.whichAction].type)==0) + face = &INFO_Icon_img; + else if (strcmp("NPC", game->map_level->extradata[game->player.whichAction].type)==0) + face = &NPC_Icon_img; + else if (strcmp("SGN", game->map_level->extradata[game->player.whichAction].type)==0) + face = &NPC_Icon_img; + else face = &demo_player_img; + + showtext_dialog( game, + face, + text, + true, true ); + } } bool player_collision(Game *game, Direction direction,