From a86462fdb215d2f24844b188b8b87ef03c709fd4 Mon Sep 17 00:00:00 2001 From: attilavs2 Date: Thu, 1 Aug 2024 17:37:42 +0200 Subject: [PATCH] npc : Functional npc_stack --- src/game.c | 10 ++++------ src/game.h | 3 ++- src/npc.c | 10 +++++----- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/game.c b/src/game.c index 744223d..276764a 100644 --- a/src/game.c +++ b/src/game.c @@ -175,16 +175,14 @@ void game_get_inputs(Game *game) { if(keydown(KEY_F1)) { NPC *mynpc = npc_create(); if(mynpc) { - mynpc->curx = player->x; - mynpc->cury = player->y; - mynpc->x = 0; - mynpc->y = 0; + mynpc->curx = (player->x << PRECISION)/PXSIZE; + mynpc->cury = (player->y << PRECISION)/PXSIZE; + mynpc->x = player->x; + mynpc->y = player->x; mynpc->hasPath = 0; mynpc->face = 0; mynpc->paused = 0; mynpc->has_dialog = 0; - dprint(0, 50, 0, "succes"); - dupdate(); } } diff --git a/src/game.h b/src/game.h index 7a20c1c..ac815f2 100644 --- a/src/game.h +++ b/src/game.h @@ -70,7 +70,8 @@ typedef struct { } Sign; typedef struct { - /* current coordinates of the NPC */ + /* current coordinates of the NPC + * In 24:8 fixed point */ uint32_t curx; uint32_t cury; diff --git a/src/npc.c b/src/npc.c index 32dbc53..7adf076 100644 --- a/src/npc.c +++ b/src/npc.c @@ -60,9 +60,9 @@ int npc_append_path(uint16_t x, uint16_t y, NPC *npc) { npc->ypath = realloc(npc->ypath, npc->path_length * 2 + 2); if(npc->xpath == NULL || npc->ypath == NULL) return 1; + npc->xpath[npc->path_length] = x - npc->x; + npc->ypath[npc->path_length] = y - npc->y; npc->path_length++; - npc->xpath[npc->path_length - 1] = x - npc->x; - npc->ypath[npc->path_length - 1] = y - npc->y; return 0; } @@ -297,12 +297,12 @@ void npc_draw(Game *game) { Player *pl = &game->player; uint32_t u; - for(u = 0; u < game->map_level->nbNPC; u++) { - npc_draw_single(&game->map_level->npcs[u], pl); - } for(u = 0; u < npc_count; u++) { npc_draw_single(&npc_stack[u], pl); } + for(u = 0; u < game->map_level->nbNPC; u++) { + npc_draw_single(&game->map_level->npcs[u], pl); + } } void npc_reload(GUNUSED Game *game) { npc_count = 0; }