From 8639a3feed9ae54a68a3d1b7e6baf04d61f84561 Mon Sep 17 00:00:00 2001 From: SlyVTT Date: Sat, 19 Aug 2023 14:18:41 +0200 Subject: [PATCH] added representation of NPCs + finalized path importation for NPCs - data alignement issue to be solved --- CMakeLists.txt | 3 +- assets/converters.py | 41 ++++++++++++++++++++------ assets/level0.tmx | 18 ++++++++++-- src/game.c | 2 ++ src/npc.c | 68 ++++++++++++++++++++++++++++++++++++++++++++ src/npc.h | 18 ++++++++++++ 6 files changed, 138 insertions(+), 12 deletions(-) create mode 100644 src/npc.c create mode 100644 src/npc.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c66b518..65291bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ find_package(LibProf 2.4 REQUIRED) #set the color mode either to 1b or 2b set(COLORMODE_fx 2b) #set the color mode either to 1b, 2b or EGA64 -set(COLORMODE_cg 1b) +set(COLORMODE_cg EGA64) fxconv_declare_converters(assets/converters.py) @@ -25,6 +25,7 @@ set(SOURCES src/memory.c src/game.c src/dialogs.c + src/npc.c # ... ) # Shared assets, fx-9860G-only assets and fx-CG-50-only assets diff --git a/assets/converters.py b/assets/converters.py index e12b782..a942fa6 100644 --- a/assets/converters.py +++ b/assets/converters.py @@ -230,7 +230,6 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): #create the structure of the map structData = fxconv.Structure() - nbExtraData = 0 layer = data["layers"][layer_extradata] for i in layer["objects"]: @@ -257,7 +256,6 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): xdata = None ydata = None - #we now fill all the properties of this item for j in i["properties"]: #property "dialog" @@ -276,9 +274,30 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): #Extra properties for NPCs (path) if tpe=="NPC": if j["name"]=="hasPath": + pathID = None path = j[ "value" ] - if path==1: print( "PNJ has path" ) - else: print( "PNJ has no Path" ) + if path==1: + print( "PNJ has path - NOW LOOKING FOR RELEVANT DATA" ) + + # we start looking for path data with first the ID of the path Object + for u in i["properties"]: + if u["name"]=="path": + pathID = u[ "value" ] + print( "path ID is identified : ID= ", pathID ) + + for v in layer["objects"]: + if v[ "id" ] == pathID: + print( "path data found : " ) + xdata = bytes() + ydata = bytes() + for w in v[ "polyline" ]: + path_length = path_length + 1 + print( "X= ", w[ "x" ], " Y= ", w[ "y" ] ) + xdata += fxconv.u16( int( w[ "x" ] ) ) + ydata += fxconv.u16( int( w[ "y" ] ) ) + + else: + print( "PNJ has no Path" ) else: print( "UNIDENTIFIED PROPERTY : ", j["name"]) @@ -297,10 +316,16 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax): structData += fxconv.string( choi ) structData += fxconv.string( conc1 ) structData += fxconv.string( conc2 ) - structData += fxconv.u32(0) - structData += fxconv.u32(0) - structData += fxconv.u32(0) - structData += fxconv.u32(0) + if path==0: + structData += fxconv.u32(0) + structData += fxconv.u32(0) + structData += fxconv.u32(0) + structData += fxconv.u32(0) + else: + structData += fxconv.u32(path) + structData += fxconv.u32(path_length) + structData += fxconv.ptr( xdata ) + structData += fxconv.ptr( ydata ) #else we do nothing (yet) else: diff --git a/assets/level0.tmx b/assets/level0.tmx index a7f1590..e4aa782 100644 --- a/assets/level0.tmx +++ b/assets/level0.tmx @@ -1,5 +1,5 @@ - + @@ -120,7 +120,19 @@ - + + + + + + + + + + + + + @@ -152,7 +164,7 @@ - + diff --git a/src/game.c b/src/game.c index e04fea4..587e746 100644 --- a/src/game.c +++ b/src/game.c @@ -8,6 +8,7 @@ #include #include +#include "npc.h" #include "stdlib.h" extern bopti_image_t SignAction_img; @@ -58,6 +59,7 @@ void render_indicator(Game *game) void draw(Game *game) { /* Draw everything. */ render_map_by_layer(game, BACKGROUND); + npc_draw( game ); player_draw(game); render_map_by_layer(game, FOREGROUND); render_indicator( game ); diff --git a/src/npc.c b/src/npc.c new file mode 100644 index 0000000..ca7b4a7 --- /dev/null +++ b/src/npc.c @@ -0,0 +1,68 @@ +#include "npc.h" +#include "dialogs.h" +#include "game.h" +#include "map.h" +#include "config.h" +#include +#include + + +extern bopti_image_t demo_PNJ_img; + + +/* the color of the text to go to the next dialog phase */ +/* it improves readability to have somathing lighter */ +#if defined(FXCG50) + #define PATH_COLOR C_RED +#else + #define PATH_COLOR C_BLACK +#endif + + +void npc_draw(Game *game) { + Player *player = &game->player; + + for (int u=0; umap_level->nbextradata; u++) + { + ExtraData *Data = &game->map_level->extradata[u]; + + if (strcmp(Data->type, "NPC")==0) /* the current data is a NPC */ + { + + /* TODO : This is for debugging purpose, JUste to render the path */ + /* to be followed by the NPC when this will be implemented */ + if (Data->hasPath==1) /* this NPC has a trajectory */ + { + int NbPoints = Data->path_length; + for(int v=0; vxpath[v % NbPoints] * PXSIZE))-(int16_t) player->wx; + int16_t deltaY1=((int16_t) (Data->ypath[v % NbPoints] * PXSIZE))-(int16_t) player->wy; + + int16_t deltaX2=((int16_t) (Data->xpath[(v+1) % NbPoints] * PXSIZE))-(int16_t) player->wx; + int16_t deltaY2=((int16_t) (Data->ypath[(v+1) % NbPoints] * PXSIZE))-(int16_t) player->wy; + + dline( player->px + deltaX1, player->py + deltaY1, + player->px + deltaX2, player->py + deltaY2, + PATH_COLOR); + */ + + } + + + } + + int16_t deltaX=((int16_t) (Data->x * PXSIZE))-(int16_t) player->wx; + int16_t deltaY=((int16_t) (Data->y * PXSIZE))-(int16_t) player->wy; + dimage( player->px-P_WIDTH/2+deltaX, + player->py-P_HEIGHT/2+deltaY, + &demo_PNJ_img); + + } + } + + +} + diff --git a/src/npc.h b/src/npc.h new file mode 100644 index 0000000..0293824 --- /dev/null +++ b/src/npc.h @@ -0,0 +1,18 @@ +#ifndef NPC_H +#define NPC_H + + +#include + +#include "game.h" +#include "memory.h" + + + +/* Draws the player player. This function should be called after drawing the + * map! */ +void npc_draw(Game *game); + + +#endif +