From 1daba611880b2970f69080c87bcc61dae1dc8d33 Mon Sep 17 00:00:00 2001 From: mibi88 <76903855+mibi88@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:01:51 +0200 Subject: [PATCH] NPC face property --- CMakeLists.txt | 6 ++ assets-cg/npc/face/fxconv-metadata.txt | 11 ++- .../npc/face/{milkman.png => npc_milkman.png} | Bin .../npc/face/{police.png => npc_police.png} | Bin assets-fx/npc/face/fxconv-metadata.txt | 11 ++- .../npc/face/{milkman.png => npc_milkman.png} | Bin .../npc/face/{police.png => npc_police.png} | Bin assets/converters.py | 11 +-- assets/level0.tmx | 5 +- assets/level1.tmx | 3 +- src/game.h | 1 + src/npc.c | 1 + src/npc.h | 2 + src/player.c | 66 ++++++++++++++---- 14 files changed, 96 insertions(+), 21 deletions(-) rename assets-cg/npc/face/{milkman.png => npc_milkman.png} (100%) rename assets-cg/npc/face/{police.png => npc_police.png} (100%) rename assets-fx/npc/face/{milkman.png => npc_milkman.png} (100%) rename assets-fx/npc/face/{police.png => npc_police.png} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 897d71d..eaca920 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,9 @@ set(ASSETS_cg assets-cg/npc/char/npc_male.png assets-cg/SignAction.png assets-cg/npc/face/npc_male.png + assets-cg/npc/face/npc_female.png + assets-cg/npc/face/npc_milkman.png + assets-cg/npc/face/npc_police.png assets-cg/SGN_Icon.png assets-cg/INFO_Icon.png assets-cg/player_face.png @@ -64,6 +67,9 @@ set(ASSETS_fx assets-fx/npc/char/npc_male.png assets-fx/SignAction.png assets-fx/npc/face/npc_male.png + assets-fx/npc/face/npc_female.png + assets-fx/npc/face/npc_milkman.png + assets-fx/npc/face/npc_police.png assets-fx/SGN_Icon.png assets-fx/INFO_Icon.png assets-fx/player_face.png diff --git a/assets-cg/npc/face/fxconv-metadata.txt b/assets-cg/npc/face/fxconv-metadata.txt index 1ac7f6f..664ce84 100644 --- a/assets-cg/npc/face/fxconv-metadata.txt +++ b/assets-cg/npc/face/fxconv-metadata.txt @@ -1,3 +1,12 @@ npc_male.png: type: bopti-image - name: NPC_Icon_img + name: npc_male +npc_female.png: + type: bopti-image + name: npc_female +npc_milkman.png: + type: bopti-image + name: npc_milkman +npc_police.png: + type: bopti-image + name: npc_police diff --git a/assets-cg/npc/face/milkman.png b/assets-cg/npc/face/npc_milkman.png similarity index 100% rename from assets-cg/npc/face/milkman.png rename to assets-cg/npc/face/npc_milkman.png diff --git a/assets-cg/npc/face/police.png b/assets-cg/npc/face/npc_police.png similarity index 100% rename from assets-cg/npc/face/police.png rename to assets-cg/npc/face/npc_police.png diff --git a/assets-fx/npc/face/fxconv-metadata.txt b/assets-fx/npc/face/fxconv-metadata.txt index 1ac7f6f..664ce84 100644 --- a/assets-fx/npc/face/fxconv-metadata.txt +++ b/assets-fx/npc/face/fxconv-metadata.txt @@ -1,3 +1,12 @@ npc_male.png: type: bopti-image - name: NPC_Icon_img + name: npc_male +npc_female.png: + type: bopti-image + name: npc_female +npc_milkman.png: + type: bopti-image + name: npc_milkman +npc_police.png: + type: bopti-image + name: npc_police diff --git a/assets-fx/npc/face/milkman.png b/assets-fx/npc/face/npc_milkman.png similarity index 100% rename from assets-fx/npc/face/milkman.png rename to assets-fx/npc/face/npc_milkman.png diff --git a/assets-fx/npc/face/police.png b/assets-fx/npc/face/npc_police.png similarity index 100% rename from assets-fx/npc/face/police.png rename to assets-fx/npc/face/npc_police.png diff --git a/assets/converters.py b/assets/converters.py index fc7dcad..7143aba 100644 --- a/assets/converters.py +++ b/assets/converters.py @@ -273,6 +273,7 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): path_length = 0 xdata = None ydata = None + face_type = "MALE" #we now fill all the properties of this item for j in i["properties"]: @@ -282,9 +283,11 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): elif j["name"]=="needAction": needAction = j[ "value" ] else: - #Extra properties for NPCs (path) + #Extra properties for NPCs (path and face) if tpe=="NPC": - if j["name"]=="hasPath": + if j["name"]=="face": + face_type = j["value"] + elif j["name"]=="hasPath": pathID = None path = j[ "value" ] if path==1: @@ -317,7 +320,7 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): if DEBUG: print( "OBJECT X= ", x, " Y= ", y, "STR= ", dialogID ) - print( " Type= ", tpe, " Name= ", nme ) + print( " Type= ", tpe, " Name= ", nme, "Face =", face_type) print( " Action?= ", needAction ) @@ -326,6 +329,7 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): structData += fxconv.u32( int(y) ) structData += fxconv.string( nme ) structData += fxconv.string( tpe ) + structData += fxconv.string(face_type) structData += fxconv.u32( int(dialogID) ) structData += fxconv.u32( int(needAction) ) @@ -349,7 +353,6 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): else: if DEBUG: print( "Skip this object" ) - return nbExtraData, structData diff --git a/assets/level0.tmx b/assets/level0.tmx index 4cf2838..553ed3b 100644 --- a/assets/level0.tmx +++ b/assets/level0.tmx @@ -1,5 +1,5 @@ - + @@ -117,6 +117,7 @@ + @@ -126,6 +127,7 @@ + @@ -135,6 +137,7 @@ + diff --git a/assets/level1.tmx b/assets/level1.tmx index c3af03c..b635cb5 100644 --- a/assets/level1.tmx +++ b/assets/level1.tmx @@ -1,5 +1,5 @@ - + @@ -100,6 +100,7 @@ + diff --git a/src/game.h b/src/game.h index 1802bbd..07df01a 100644 --- a/src/game.h +++ b/src/game.h @@ -72,6 +72,7 @@ typedef struct { char *name; /* its class (NPC, SGN, INFO, ... )*/ char *type; + char *face; /* the ID of the first element of the dialog */ /* (to be aligned with "dialogs.json" IDs)*/ diff --git a/src/npc.c b/src/npc.c index d92894c..3f87086 100644 --- a/src/npc.c +++ b/src/npc.c @@ -97,6 +97,7 @@ void reload_npc(Game *game) npcRPG[currentNPC].xpath = Data->xpath; npcRPG[currentNPC].ypath = Data->ypath; npcRPG[currentNPC].paused = false; + npcRPG[currentNPC].face = Data->face; currentNPC++; } } diff --git a/src/npc.h b/src/npc.h index e7e1e12..a7dd906 100644 --- a/src/npc.h +++ b/src/npc.h @@ -31,6 +31,8 @@ typedef struct /* is the current NPC in pause (during dialog) */ bool paused; + + char *face; } NPC; diff --git a/src/player.c b/src/player.c index 4506b75..58d8e37 100644 --- a/src/player.c +++ b/src/player.c @@ -6,6 +6,28 @@ #include "npc.h" #include +#define FACES 4 + +struct Face { + const char *name; + bopti_image_t *face; +}; + +extern bopti_image_t demo_player_img; +extern bopti_image_t npc_male; +extern bopti_image_t npc_female; +extern bopti_image_t npc_milkman; +extern bopti_image_t npc_police; +extern bopti_image_t SGN_Icon_img; +extern bopti_image_t INFO_Icon_img; + +const struct Face faces[FACES] = { + {"MALE", &npc_male}, + {"FEMALE", &npc_female}, + {"MILKMAN", &npc_milkman}, + {"POLICE", &npc_police} +}; + const char one_px_mov[8] = { 0, -1, /* Up */ 0, 1, /* Down */ @@ -83,14 +105,8 @@ void player_move(Game *game, Direction direction) { player->wy = game->map_level->ymin * PXSIZE + player->y; } - -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_action(Game *game) { + register size_t i; /* already doing something (action IS NOT with an NPC) */ if(game->player.isDoingAction) return; @@ -107,13 +123,24 @@ void player_action(Game *game) { /* we use the correct image as per the class of the item */ - if (strcmp("INFO", currentData->type)==0) + if (strcmp("INFO", currentData->type)==0){ face = &INFO_Icon_img; - //else if (strcmp("NPC", currentData->type)==0) - // face = &NPC_Icon_img; - else if (strcmp("SGN", currentData->type)==0) + }else if (strcmp("SGN", currentData->type)==0){ face = &SGN_Icon_img; - else face = &demo_player_img; + }else{ + /* It's a NPC */ + /* (Mibi88) TODO: Use string hash + strcmp if the hashes match for + * fast string comparison. */ + face = NULL; + for(i=0;iface)){ + face = current_face.face; + } + } + if(!face) face = &npc_male; + + } uint32_t dialogStart = currentData->dialogID; @@ -130,7 +157,20 @@ void player_action(Game *game) { /* we use the correct image as per the class of the item */ - bopti_image_t *face = &NPC_Icon_img; + ExtraData *currentData = &game->map_level->extradata[game->player.whichAction]; + bopti_image_t *face = &npc_male; + /* It's a NPC */ + /* (Mibi88) TODO: Use string hash + strcmp if the hashes match for + * fast string comparison. */ + face = NULL; + for(i=0;iface)){ + face = current_face.face; + } + if(!face) face = &npc_male; + } + dtext(2, 64, C_BLACK, currentData->type); uint32_t dialogStart = currentNPC->dialogID; /* we set this NPC to paused to avoid changing its position while