From 9d8464e0d5a523f3b1cb0c7d29d77c739307e0e3 Mon Sep 17 00:00:00 2001 From: SlyVTT Date: Wed, 16 Aug 2023 23:12:16 +0200 Subject: [PATCH] added items on all maps - one bug to be corrected with coodinates --- CMakeLists.txt | 4 ++-- TODO.txt | 8 ++++---- assets/level0.tmx | 16 ++++++++++++++-- assets/level1.tmx | 42 +++++++++++++++++++++++++----------------- assets/level2.tmx | 22 +++++++++++++++++++++- assets/level3.tmx | 36 ++++++++++++++++++++++++++++++++++-- src/game.c | 11 ++++++++--- src/game.h | 27 ++++++++++++++++++--------- src/player.c | 13 +++++++------ 9 files changed, 133 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a7f080..d8c8bba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,9 +12,9 @@ find_package(Gint 2.9 REQUIRED) find_package(LibProf 2.4 REQUIRED) #set the color mode either to 1b or 2b -set(COLORMODE_fx 2b) +set(COLORMODE_fx 1b) #set the color mode either to 1b, 2b or EGA64 -set(COLORMODE_cg 2b) +set(COLORMODE_cg EGA64) fxconv_declare_converters(assets/converters.py) diff --git a/TODO.txt b/TODO.txt index e9f2bcf..46d445e 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,6 +1,6 @@ -- Jeu de tuile 1bit pour CG pour avoir la version 1bit vérifiable en fonctionnement dans l'émulateur de Heath -- corriger les tuiles 1bit pour les rivières (tiles 1 2 3 et 4) avec niveaux de diphering pour tiles 1 et 3 (gris 33% et 66%) -- ajouter face pour dialogue pour PNJ -- ajouter indicateur visuel pour action joueur quand on est proche d'un PNJ ou d'un panneau +[OK] - Jeu de tuile 1bit pour CG pour avoir la version 1bit vérifiable en fonctionnement dans l'émulateur de Heath +[OK] - corriger les tuiles 1bit pour les rivières (tiles 1 2 3 et 4) avec niveaux de diphering pour tiles 1 et 3 (gris 33% et 66%) +[OK] - ajouter face pour dialogue pour PNJ +[OK] - ajouter indicateur visuel pour action joueur quand on est proche d'un PNJ ou d'un panneau - faire des fonts lisibles avec le set `print` disponible intégralement \ No newline at end of file diff --git a/assets/level0.tmx b/assets/level0.tmx index d01c166..e6fd8eb 100644 --- a/assets/level0.tmx +++ b/assets/level0.tmx @@ -1,5 +1,5 @@ - + @@ -90,7 +90,19 @@ - + + + + + + + + + + + + + diff --git a/assets/level1.tmx b/assets/level1.tmx index 300ef70..20e3824 100644 --- a/assets/level1.tmx +++ b/assets/level1.tmx @@ -1,5 +1,5 @@ - + @@ -16,16 +16,16 @@ 2,293,1,1,1,1,1,1,1,1,1,1,1,1,272,2,2,2,2,270,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,267,268,269,1,1,1,1,1,1,1,1,1,1, 2,2,269,1,1,1,1,1,1,319,319,269,1,1,1,316,271,316,271,317,1,1,1,1,319,319,319,268,268,319,319,319,268,319,320,2,2,318,319,320,268,269,1,1,1,1,1,1, 2,2,2,269,1,1,1,1,320,2,2,2,269,1,1,1,1,1,1,1,1,1,267,2,2,2,2,2,2,2,2,2,2,2,2,2,2,219,2,2,2,318,319,320,269,1,1,1, -2,2,2,2,319,268,319,320,2,2,2,2,318,319,269,1,1,1,1,1,1,267,2,2,2,2,313,265,242,266,241,219,314,313,242,241,289,314,219,2,2,2,2,2,2,269,1,1, -27,26,27,26,27,28,2,2,2,2,2,2,2,2,318,319,319,268,268,319,319,320,2,2,2,219,2,2,2,2,266,241,289,290,266,265,290,313,266,297,298,299,300,2,2,318,319,320, +2,2,2,2,319,268,319,320,2,2,2,2,318,319,269,1,1,1,1,1,1,267,2,2,2,2,313,265,242,266,241,219,314,313,242,241,2,2,219,2,2,2,2,2,2,269,1,1, +27,26,27,26,27,28,2,2,2,2,2,2,2,2,318,319,319,268,268,319,319,320,2,2,2,219,2,2,2,2,266,241,289,290,266,265,2,2,2,297,298,299,300,2,2,318,319,320, 2,50,51,51,99,100,132,2,2,2,2,2,2,2,2,2,2,2,2,314,265,2,2,2,2,313,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,74,75,76,16,17,133,2,2,2,2,2,2,2,2,2,2,2,241,219,290,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 98,98,99,100,40,41,290,314,297,298,299,300,2,2,2,2,2,219,219,289,2,297,298,299,300,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,297,298,299,300,2, -121,122,123,124,64,65,265,289,313,289,241,265,219,2,2,2,2,290,314,2,2,2,2,2,2,2,297,298,299,300,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, -145,146,147,148,132,2,2,2,2,2,2,314,314,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,297,298,299,300,2,2,2,2,2,2,2,2,2, +121,122,123,124,64,65,265,289,313,289,241,265,219,2,2,2,2,290,314,2,2,2,2,2,2,2,297,298,299,300,2,2,2,2,402,403,2,374,375,2,404,405,2,2,2,2,2,2, +145,146,147,148,132,2,2,2,2,2,2,314,314,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 169,170,171,172,133,2,2,2,2,2,2,2,2,297,298,299,300,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,385,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,385,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,345,346,347,348,2,2,2,2,2,2,2,2,2, -2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,385,2,2,2,297,298,299,300,2,2,2,2,2,2,2,2,2,2,369,370,371,372,297,298,299,300,2,2,2,2,2, +2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,385,2,2,2,297,298,299,300,2,2,2,2,2,2,2,2,2,2,369,370,371,372,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,297,298,299,300,2,2,2,2,2,2,2,2,2,2,385,2,2,2,2,2,2,2,2,2,2,2,2,2,393,394,395,396,2,2,2,2,2,297,298,299,300, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,297,298,299,300,297,298,299,300,2,2,2,2,2,2,2,2,2,2,2,2,2,2 @@ -46,19 +46,19 @@ 251,252,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,250,251,252,0,0,0,0,0, 275,276,0,0,0,0,0,0,201,202,203,204,0,0,0,0,0,0,0,0,0,201,202,203,204,0,0,0,0,0,0,0,0,0,0,0,0,0,0,273,274,275,276,201,202,203,204,0, 0,0,0,0,0,0,0,0,225,226,227,228,0,0,0,0,0,0,0,0,0,225,226,227,228,0,201,202,203,204,0,0,0,0,0,0,0,0,0,0,0,0,0,225,226,227,228,0, -0,0,0,0,0,0,0,0,249,250,251,252,0,0,0,0,0,0,0,0,0,249,250,251,252,0,225,226,227,228,0,0,0,0,0,201,202,203,204,0,0,0,0,249,250,251,252,0, -0,0,0,0,0,0,0,0,273,274,275,276,0,201,202,203,204,0,0,0,0,273,274,275,276,0,249,250,251,252,201,202,203,204,0,225,226,227,228,0,0,0,0,273,274,275,276,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,225,226,227,228,0,0,0,0,0,0,0,0,0,273,274,275,276,225,226,227,228,0,249,250,251,252,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,249,250,251,252,0,0,0,0,201,202,203,204,0,0,0,0,0,249,250,251,252,0,273,274,275,276,201,202,203,204,0,0,0,0,0, -0,0,0,0,0,0,0,201,202,203,204,0,0,273,274,275,276,0,0,0,0,225,226,227,228,0,0,0,0,0,273,274,275,276,0,0,0,0,0,225,226,227,228,0,201,202,203,204, -0,0,0,0,0,0,0,225,226,227,228,0,0,0,0,0,0,0,0,0,0,249,250,251,252,0,201,202,203,204,201,202,203,204,0,0,0,0,0,249,250,251,252,0,225,226,227,228, -204,0,0,201,202,203,204,249,250,251,252,201,202,203,204,0,0,0,0,0,0,273,274,275,276,0,225,226,227,228,225,226,227,228,0,0,0,0,0,273,274,275,276,0,249,250,251,252, +0,0,0,0,0,0,0,0,249,250,251,252,0,0,0,0,0,0,0,0,0,249,250,251,252,0,225,226,227,228,0,0,0,0,0,0,0,0,0,0,0,0,0,249,250,251,252,0, +0,0,0,0,0,0,0,0,273,274,275,276,0,201,202,203,204,0,0,0,0,273,274,275,276,0,249,250,251,252,201,202,203,204,354,355,0,0,0,0,356,357,0,273,274,275,276,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,225,226,227,228,0,0,0,0,0,0,0,0,0,273,274,275,276,225,226,227,228,378,379,0,350,351,0,380,381,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,249,250,251,252,0,0,0,0,201,202,203,204,0,0,0,0,0,249,250,251,252,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,201,202,203,204,0,0,273,274,275,276,0,0,0,0,225,226,227,228,0,0,0,0,0,273,274,275,276,0,0,0,0,0,0,0,0,0,0,201,202,203,204, +0,0,0,0,0,0,0,225,226,227,228,0,0,0,0,0,0,0,0,0,0,249,250,251,252,0,201,202,203,204,201,202,203,204,0,0,0,0,0,0,0,0,0,0,225,226,227,228, +204,0,0,201,202,203,204,249,250,251,252,201,202,203,204,0,0,0,0,0,0,273,274,275,276,0,225,226,227,228,225,226,227,228,0,0,0,0,0,0,0,0,0,0,249,250,251,252, 228,0,0,225,226,227,228,273,274,275,276,225,226,227,228,0,0,0,0,0,0,0,0,0,0,0,249,250,251,252,249,250,251,252,0,0,0,0,0,0,0,0,0,0,273,274,275,276, 252,0,0,249,250,251,252,0,0,0,0,249,250,251,252,0,0,0,0,0,0,0,0,0,0,0,273,274,275,276,273,274,275,276,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 276,0,0,273,274,275,276,0,0,0,0,273,274,275,276,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,0,410,410,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,0,0,0,0,0,0,410,410,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + + + + + + + diff --git a/assets/level2.tmx b/assets/level2.tmx index 35d297c..6d1fb52 100644 --- a/assets/level2.tmx +++ b/assets/level2.tmx @@ -1,5 +1,5 @@ - + @@ -86,4 +86,24 @@ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + + + + + + + + + + + + + + + + + + + diff --git a/assets/level3.tmx b/assets/level3.tmx index ea2adeb..d756a70 100644 --- a/assets/level3.tmx +++ b/assets/level3.tmx @@ -1,5 +1,5 @@ - + @@ -58,7 +58,7 @@ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - + 0,0,0,0,410,410,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,0,0,0,0,410,0,0,0,0,0,0,0,410,410,410,410,410,410,410,410,410,410,0,410,410, @@ -86,4 +86,36 @@ 0,0,0,0,0,0,0,410,410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,410,410,410,410,0,0,0,0,0,0,0,410,0,0,0,0,0,0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/game.c b/src/game.c index 2a6439a..8052712 100644 --- a/src/game.c +++ b/src/game.c @@ -15,17 +15,21 @@ extern bopti_image_t SignAction_img; void game_logic(Game *game) { + /* we check if interactions are possible close to the player */ for( int i=0; imap_level->nbextradata; i++ ) { + /* simple distance check along X and Y axis */ 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)) { + /* the player can do something */ game->player.canDoSomething = true; + /* we mark the action for futur treatment in player_action() */ game->player.whichAction = i; return; } } - + /* else nothing to be done here */ game->player.canDoSomething = false; game->player.whichAction = -1; return; @@ -34,14 +38,15 @@ void game_logic(Game *game) { void render_indicator(Game *game) { + /* nothing to do for the player so we quit */ if (game->player.canDoSomething==false) return; + /* else we draw a small indicator on the screen */ 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) { /* Draw everything. */ render_map_by_layer(game, BACKGROUND); diff --git a/src/game.h b/src/game.h index 76c6a38..d6237e6 100644 --- a/src/game.h +++ b/src/game.h @@ -28,22 +28,31 @@ typedef struct { 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. */ + int8_t life; /* How many lives the player still has between 0 and 100. */ 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; + + /* set to true if a action can be done in the current position of the map */ + bool canDoSomething; + /* indicates which data are relevant to the current action in the */ + /* extradata layer of the map */ + int32_t whichAction; + /* the player is doing something */ + bool isDoingAction; } Player; typedef struct { + /* position of the item */ uint16_t x; uint16_t y; + /* its name */ char *name; + /* its class (NPC, SGN, INFO, ... )*/ char *type; + /* data to be shown in the dialog*/ char *dialog; + /* ... this can be extended as per needs ... */ } ExtraData; @@ -66,16 +75,16 @@ typedef struct { /* contain the properties of the tiles */ /* this is given by the layer Walkable of the map in Tiled */ - uint8_t *walkable; + /* structure that contains all the items on the map to interract with */ + /* each portion of the map has its own list to avoid scrutinizing too much */ + /* data when lloking for proximity of items */ uint32_t nbextradata; ExtraData *extradata; - /* list of all the tiles */ + /* list of all the tiles to draw the background and the foreground layers */ uint16_t *layers[]; - - } Map; diff --git a/src/player.c b/src/player.c index db0c28d..ed7067f 100644 --- a/src/player.c +++ b/src/player.c @@ -87,12 +87,14 @@ void player_action(Game *game) { if( game->player.canDoSomething ) /* we can do something */ { + /* we indicate that the player is occupied */ game->player.isDoingAction = true; + /* we collect the information */ char *text = game->map_level->extradata[game->player.whichAction].dialog; + /* we use the correct image as per the class of the item */ bopti_image_t *face; - - if (strcmp("PST", game->map_level->extradata[game->player.whichAction].type)==0) + if (strcmp("INFO", 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; @@ -100,11 +102,10 @@ void player_action(Game *game) { face = &SGN_Icon_img; else face = &demo_player_img; - showtext_dialog( game, - face, - text, - true, true ); + /* we treat the action - i.e. we show a dialog */ + showtext_dialog( game, face, text, true, true ); + /* when done we release the occupied status of the player */ game->player.isDoingAction = false; } }