interaction with items of the map (NPC, INFO, SIGNS, ...)

This commit is contained in:
SlyVTT 2023-08-18 20:56:44 +02:00
parent 74f0e3844d
commit f56b6432f2
9 changed files with 147 additions and 30 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View file

@ -123,10 +123,10 @@ def get_tile_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
#create the structure of the map #create the structure of the map
structMap = fxconv.Structure() structMap = fxconv.Structure()
structMap += fxconv.u16(w) + fxconv.u16(h) + fxconv.u16(nbTilelayer) structMap += fxconv.u32(w) + fxconv.u32(h) + fxconv.u32(nbTilelayer)
structMap += fxconv.u16(tileset_size) structMap += fxconv.u32(tileset_size)
structMap += fxconv.u16(xmin) + fxconv.u16(ymin) + fxconv.u16(xmax) + fxconv.u16(ymax) structMap += fxconv.u32(xmin) + fxconv.u32(ymin) + fxconv.u32(xmax) + fxconv.u32(ymax)
structMap += fxconv.ref(f"img_{nameTilesetFree}") structMap += fxconv.ref(f"img_{nameTilesetFree}")
@ -239,15 +239,42 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
y = i["y"] + ymin y = i["y"] + ymin
nme = i["name"] nme = i["name"]
tpe = i["type"] tpe = i["type"]
stg = None
quest = 0
choi = None
conc1 = None
conc2 = None
for j in i["properties"]: for j in i["properties"]:
stg = j[ "value" ] #property "dialog"
if j["name"]=="dialog": stg = j[ "value" ]
#property "isQuestion"
elif j["name"]=="isQuestion": quest = j[ "value" ]
#property "choices"
elif j["name"]=="choices":
choi = j[ "value" ]
choi = choi.replace( '$', chr(0) )
#property "conclusion1"
elif j["name"]=="conclusion1": conc1 = j[ "value" ]
#property "conclusion2"
elif j["name"]=="conclusion2": conc2 = j[ "value" ]
else: print( "UNIDENTIFIED PROPERTY : ", j["name"])
print( "OBJECT X= ", x, " Y= ", y, "STR= ", stg ) print( "OBJECT X= ", x, " Y= ", y, "STR= ", stg )
print( " Type= ", tpe, " Name= ", nme ) print( " Type= ", tpe, " Name= ", nme )
print( " Q?= ", quest, " Choi= ", choi )
print( " c1= ", conc1, " c2=", conc2)
structData += fxconv.u16( int(x) ) structData += fxconv.u32( int(x) )
structData += fxconv.u16( int(y) ) structData += fxconv.u32( int(y) )
structData += fxconv.string( nme ) structData += fxconv.string( nme )
structData += fxconv.string( tpe ) structData += fxconv.string( tpe )
structData += fxconv.string( stg ) structData += fxconv.string( stg )
structData += fxconv.u32( int(quest) )
structData += fxconv.string( choi )
structData += fxconv.string( conc1 )
structData += fxconv.string( conc2 )
return nbExtraData, structData return nbExtraData, structData

View file

@ -92,37 +92,61 @@
<objectgroup id="4" name="ExtraData"> <objectgroup id="4" name="ExtraData">
<object id="1" name="INFO3" type="INFO" x="232" y="79.75"> <object id="1" name="INFO3" type="INFO" x="232" y="79.75">
<properties> <properties>
<property name="dialog" value="Etrange ce coffre ouvert ..."/> <property name="choices" value="Oui$Non"/>
<property name="conclusion1" value="Trop cool, du stuff `$life+5``$mana+5``$power+2`"/>
<property name="conclusion2" value="Je ferai mieux de partir loin ..."/>
<property name="dialog" value="Etrange ce coffre ouvert ... Fouiller dedans ?"/>
<property name="isQuestion" type="int" value="1"/>
</properties> </properties>
<point/> <point/>
</object> </object>
<object id="8" name="INFO2" type="INFO" x="119.75" y="47.25"> <object id="8" name="INFO2" type="INFO" x="119.75" y="47.25">
<properties> <properties>
<property name="choices" value="_"/>
<property name="conclusion1" value="_"/>
<property name="conclusion2" value="_"/>
<property name="dialog" value="Et sa tombe est en train d'etre creusee ...^"/> <property name="dialog" value="Et sa tombe est en train d'etre creusee ...^"/>
<property name="isQuestion" type="int" value="0"/>
</properties> </properties>
<point/> <point/>
</object> </object>
<object id="7" name="INFO2" type="INFO" x="52" y="44"> <object id="7" name="INFO1" type="INFO" x="52" y="44">
<properties> <properties>
<property name="dialog" value="Quelqu'un est mort ici ..."/> <property name="choices" value="Oui$Non"/>
<property name="conclusion1" value="C'est triste mon Ami`$life-2``$power-5`"/>
<property name="conclusion2" value="Dommage quand meme pour Lui."/>
<property name="dialog" value="Quelqu'un est mort ici ... Tu le connais ?"/>
<property name="isQuestion" type="int" value="1"/>
</properties> </properties>
<point/> <point/>
</object> </object>
<object id="2" name="PNJ1" type="NPC" x="252" y="164"> <object id="2" name="PNJ1" type="NPC" x="252" y="164">
<properties> <properties>
<property name="dialog" value="Salut, je suis un PNJ"/> <property name="choices" value="Oui$Non"/>
<property name="conclusion1" value="Voici donc pour toi`$life+5``$mana+5``$power+2`"/>
<property name="conclusion2" value="Bon bah casse toi ..."/>
<property name="dialog" value="Salut Hero, je suis le cremier. Veux tu me delester un peu ?"/>
<property name="isQuestion" type="int" value="1"/>
</properties> </properties>
<point/> <point/>
</object> </object>
<object id="4" name="SGN1" type="SGN" x="96" y="136"> <object id="4" name="SGN1" type="SGN" x="96" y="136">
<properties> <properties>
<property name="choices" value="_"/>
<property name="conclusion1" value="_"/>
<property name="conclusion2" value="_"/>
<property name="dialog" value="Indication sur le panneau. Bienvenue dans la maison du Tondu ..."/> <property name="dialog" value="Indication sur le panneau. Bienvenue dans la maison du Tondu ..."/>
<property name="isQuestion" type="int" value="0"/>
</properties> </properties>
<point/> <point/>
</object> </object>
<object id="5" name="SGN2" type="SGN" x="288" y="128"> <object id="5" name="SGN2" type="SGN" x="288" y="128">
<properties> <properties>
<property name="choices" value="_"/>
<property name="conclusion1" value="_"/>
<property name="conclusion2" value="_"/>
<property name="dialog" value="Indication sur le panneau. Entree dans le Sanctuaire Maudit ..."/> <property name="dialog" value="Indication sur le panneau. Entree dans le Sanctuaire Maudit ..."/>
<property name="isQuestion" type="int" value="0"/>
</properties> </properties>
<point/> <point/>
</object> </object>

View file

@ -89,7 +89,11 @@
<objectgroup id="4" name="ExtraData"> <objectgroup id="4" name="ExtraData">
<object id="1" name="INFO1" type="INFO" x="303.75" y="143.25"> <object id="1" name="INFO1" type="INFO" x="303.75" y="143.25">
<properties> <properties>
<property name="choices" value="_"/>
<property name="conclusion1" value="_"/>
<property name="conclusion2" value="_"/>
<property name="dialog" value="Le tombeau du Chevalier Legendaire"/> <property name="dialog" value="Le tombeau du Chevalier Legendaire"/>
<property name="isQuestion" type="int" value="0"/>
</properties> </properties>
<point/> <point/>
</object> </object>

View file

@ -89,19 +89,31 @@
<objectgroup id="4" name="ExtraData"> <objectgroup id="4" name="ExtraData">
<object id="1" name="INFO1" type="INFO" x="128" y="87.5"> <object id="1" name="INFO1" type="INFO" x="128" y="87.5">
<properties> <properties>
<property name="choices" value="_"/>
<property name="conclusion1" value="_"/>
<property name="conclusion2" value="_"/>
<property name="dialog" value="Encore une tombe ..."/> <property name="dialog" value="Encore une tombe ..."/>
<property name="isQuestion" type="int" value="0"/>
</properties> </properties>
<point/> <point/>
</object> </object>
<object id="2" name="INFO2" type="INFO" x="262.75" y="49"> <object id="2" name="INFO2" type="INFO" x="262.75" y="49">
<properties> <properties>
<property name="choices" value="_"/>
<property name="conclusion1" value="_"/>
<property name="conclusion2" value="_"/>
<property name="dialog" value="Un passage souterrain ..."/> <property name="dialog" value="Un passage souterrain ..."/>
<property name="isQuestion" type="int" value="0"/>
</properties> </properties>
<point/> <point/>
</object> </object>
<object id="3" name="SGN1" type="SGN" x="296" y="143.75"> <object id="3" name="SGN1" type="SGN" x="296" y="143.75">
<properties> <properties>
<property name="choices" value="_"/>
<property name="conclusion1" value="_"/>
<property name="conclusion2" value="_"/>
<property name="dialog" value="C'est la maison du gardien du cimetiere"/> <property name="dialog" value="C'est la maison du gardien du cimetiere"/>
<property name="isQuestion" type="int" value="0"/>
</properties> </properties>
<point/> <point/>
</object> </object>

View file

@ -89,31 +89,51 @@
<objectgroup id="4" name="ExtraData"> <objectgroup id="4" name="ExtraData">
<object id="1" name="SGN5" type="SGN" x="224" y="183.25"> <object id="1" name="SGN5" type="SGN" x="224" y="183.25">
<properties> <properties>
<property name="choices" value="_"/>
<property name="conclusion1" value="_"/>
<property name="conclusion2" value="_"/>
<property name="dialog" value="Maison du Maire"/> <property name="dialog" value="Maison du Maire"/>
<property name="isQuestion" type="int" value="0"/>
</properties> </properties>
<point/> <point/>
</object> </object>
<object id="5" name="SGN4" type="SGN" x="320.5" y="159.25"> <object id="5" name="SGN4" type="SGN" x="320.5" y="159.25">
<properties> <properties>
<property name="choices" value="_"/>
<property name="conclusion1" value="_"/>
<property name="conclusion2" value="_"/>
<property name="dialog" value="Maison du Boulanger"/> <property name="dialog" value="Maison du Boulanger"/>
<property name="isQuestion" type="int" value="0"/>
</properties> </properties>
<point/> <point/>
</object> </object>
<object id="3" name="SGN3" type="SGN" x="184.25" y="95.75"> <object id="3" name="SGN3" type="SGN" x="184.25" y="95.75">
<properties> <properties>
<property name="dialog" value="Maison du Boucher"/> <property name="choices" value="Oui$Non"/>
<property name="conclusion1" value="Super te voila requinque."/>
<property name="conclusion2" value="J'aime pas la viande."/>
<property name="dialog" value="Maison du Boucher. Tu veux un steak ?"/>
<property name="isQuestion" type="int" value="1"/>
</properties> </properties>
<point/> <point/>
</object> </object>
<object id="4" name="SGN2" type="SGN" x="343.75" y="80"> <object id="4" name="SGN2" type="SGN" x="343.75" y="80">
<properties> <properties>
<property name="choices" value="_"/>
<property name="conclusion1" value="_"/>
<property name="conclusion2" value="_"/>
<property name="dialog" value="Maison du Marechal Ferrand"/> <property name="dialog" value="Maison du Marechal Ferrand"/>
<property name="isQuestion" type="int" value="0"/>
</properties> </properties>
<point/> <point/>
</object> </object>
<object id="2" name="SGN1" type="SGN" x="71.75" y="143.25"> <object id="2" name="SGN1" type="SGN" x="71.75" y="143.25">
<properties> <properties>
<property name="choices" value="_"/>
<property name="conclusion1" value="_"/>
<property name="conclusion2" value="_"/>
<property name="dialog" value="Maison du Fermier"/> <property name="dialog" value="Maison du Fermier"/>
<property name="isQuestion" type="int" value="0"/>
</properties> </properties>
<point/> <point/>
</object> </object>

View file

@ -44,31 +44,39 @@ typedef struct {
typedef struct { typedef struct {
/* position of the item */ /* position of the item */
uint16_t x; uint32_t x;
uint16_t y; uint32_t y;
/* its name */ /* its name */
char *name; char *name;
/* its class (NPC, SGN, INFO, ... )*/ /* its class (NPC, SGN, INFO, ... )*/
char *type; char *type;
/* data to be shown in the dialog*/ /* data to be shown in the dialog*/
char *dialog; char *dialog;
/* is it a question or a simple dialog ? */
uint32_t isQuestion;
/* if it is a question, then the choices for answering */
char *choices;
/* the conclusion of the dialog for answer 1 and 2 respectively */
/* Note : it may contain a set of event with a dedicated syntax */
char *conclusion1;
char *conclusion2;
/* ... this can be extended as per needs ... */ /* ... this can be extended as per needs ... */
} ExtraData; } ExtraData;
typedef struct { typedef struct {
/* width, height and the number of layer of the map */ /* width, height and the number of layer of the map */
uint16_t w; uint32_t w;
uint16_t h; uint32_t h;
uint16_t nblayers; uint32_t nblayers;
uint16_t tileset_size; uint32_t tileset_size;
/* world coordinates of the upper left and bootom right*/ /* world coordinates of the upper left and bootom right*/
/* corners of the current map to be multiplied in game by PXSIZE */ /* corners of the current map to be multiplied in game by PXSIZE */
uint16_t xmin; uint32_t xmin;
uint16_t ymin; uint32_t ymin;
uint16_t xmax; uint32_t xmax;
uint16_t ymax; uint32_t ymax;
/* the tileset to use */ /* the tileset to use */
bopti_image_t *tileset; bopti_image_t *tileset;

View file

@ -108,11 +108,13 @@ int main(void) {
dgray(DGRAY_ON); dgray(DGRAY_ON);
#endif #endif
/*
showtext_dialog(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet.", true, true); showtext_dialog(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet.", true, true);
int in = showtext_dialog_ask(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet.", true, false, "Lorem\0Ipsum\0Dolor", 3, 0); int in = showtext_dialog_ask(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet.", true, false, "Lorem\0Ipsum\0Dolor", 3, 0);
if(in==2) showtext_dialog(&game, &player_face_img, "You choosed Dolor", false, true); if(in==2) showtext_dialog(&game, &player_face_img, "You choosed Dolor", false, true);
else if(in==1) showtext_dialog(&game, &player_face_img, "You choosed Ipsum", false, true); else if(in==1) showtext_dialog(&game, &player_face_img, "You choosed Ipsum", false, true);
else showtext_dialog(&game, &player_face_img, "You choosed Lorem", false, true); else showtext_dialog(&game, &player_face_img, "You choosed Lorem", false, true);
*/
do{ do{
/* clear screen */ /* clear screen */

View file

@ -1,5 +1,6 @@
#include "player.h" #include "player.h"
#include "dialogs.h" #include "dialogs.h"
#include "game.h"
#include "map.h" #include "map.h"
#include "config.h" #include "config.h"
#include <gint/display.h> #include <gint/display.h>
@ -90,20 +91,39 @@ void player_action(Game *game) {
/* we indicate that the player is occupied */ /* we indicate that the player is occupied */
game->player.isDoingAction = true; game->player.isDoingAction = true;
ExtraData *currentData = &game->map_level->extradata[game->player.whichAction];
/* we collect the information */ /* we collect the information */
char *text = game->map_level->extradata[game->player.whichAction].dialog; char *text = currentData->dialog;
/* we use the correct image as per the class of the item */ /* we use the correct image as per the class of the item */
bopti_image_t *face; bopti_image_t *face;
if (strcmp("INFO", game->map_level->extradata[game->player.whichAction].type)==0) if (strcmp("INFO", currentData->type)==0)
face = &INFO_Icon_img; face = &INFO_Icon_img;
else if (strcmp("NPC", game->map_level->extradata[game->player.whichAction].type)==0) else if (strcmp("NPC", currentData->type)==0)
face = &NPC_Icon_img; face = &NPC_Icon_img;
else if (strcmp("SGN", game->map_level->extradata[game->player.whichAction].type)==0) else if (strcmp("SGN", currentData->type)==0)
face = &SGN_Icon_img; face = &SGN_Icon_img;
else face = &demo_player_img; else face = &demo_player_img;
/* we treat the action - i.e. we show a dialog */ /* we treat the action - i.e. we show a dialog */
if (currentData->isQuestion==1) /* we have to manage a question */
{
char *choices = currentData->choices;
char *conclusion1 = currentData->conclusion1;
char *conclusion2 = currentData->conclusion2;
int answer = showtext_dialog_ask( game, face, text, true, true, choices, 2, 0 );
/* TO DO we need to split the strings conclusion1 and conclusion2 */
/* to extract the "gift" part */
if (answer==0) showtext_dialog( game, face, conclusion1, true, true );
else showtext_dialog( game, face, conclusion2, true, true );
}
else
{
showtext_dialog( game, face, text, true, true ); showtext_dialog( game, face, text, true, true );
}
/* when done we release the occupied status of the player */ /* when done we release the occupied status of the player */
game->player.isDoingAction = false; game->player.isDoingAction = false;