diff --git a/assets-cg/npc/char/npc_female.png b/assets-cg/npc/char/npc_female.png index 041e951..7c83737 100644 Binary files a/assets-cg/npc/char/npc_female.png and b/assets-cg/npc/char/npc_female.png differ diff --git a/assets-cg/npc/char/npc_male.png b/assets-cg/npc/char/npc_male.png index 9734b02..e241c9f 100644 Binary files a/assets-cg/npc/char/npc_male.png and b/assets-cg/npc/char/npc_male.png differ diff --git a/assets-cg/npc/char/npc_milkman.png b/assets-cg/npc/char/npc_milkman.png index 92ead4b..63ea993 100644 Binary files a/assets-cg/npc/char/npc_milkman.png and b/assets-cg/npc/char/npc_milkman.png differ diff --git a/assets-cg/npc/char/npc_police.png b/assets-cg/npc/char/npc_police.png index e590a72..f033d02 100644 Binary files a/assets-cg/npc/char/npc_police.png and b/assets-cg/npc/char/npc_police.png differ diff --git a/src/animation.h b/src/animation.h index 62830f7..7c274a7 100644 --- a/src/animation.h +++ b/src/animation.h @@ -4,14 +4,14 @@ #include "config.h" typedef struct { - unsigned char frame; + unsigned char frame : 8; bopti_image_t *image; - unsigned char len; - unsigned short frame_ms; - int current_ms; - unsigned short width; - unsigned short height; - unsigned short wrap_dest; + unsigned char len : 8; + unsigned short frame_ms : 16; + int current_ms : 32; + unsigned short width : 16; + unsigned short height : 16; + unsigned char wrap_dest : 8; } Animation; /* TODO: Doc! */ diff --git a/src/game.c b/src/game.c index df3ab8a..5158002 100644 --- a/src/game.c +++ b/src/game.c @@ -213,5 +213,6 @@ void game_get_inputs(Game *game) { } void game_update_animations(Game *game, unsigned char ms) { + animation_update(&game->npc_animation, ms); animation_update(&game->player.animation, ms); } diff --git a/src/game.h b/src/game.h index e52e768..8f94392 100644 --- a/src/game.h +++ b/src/game.h @@ -175,6 +175,8 @@ typedef struct { bool debug_player; bool debug_extra; + Animation npc_animation; + int mana; /* Only for testing events TODO: Remove this! */ } Game; diff --git a/src/main.c b/src/main.c index 3e3e959..b9dce89 100644 --- a/src/main.c +++ b/src/main.c @@ -29,6 +29,7 @@ extern bopti_image_t player_face_img; extern bopti_image_t player_male_img; +extern bopti_image_t tiny_npc_male; extern Map *worldRPG[]; @@ -47,6 +48,7 @@ Game game = { false, false, false, + {}, 100}; /* screen capture management code. TODO: Clean this up! */ @@ -109,6 +111,9 @@ int main(void) { timer_start(timer); game.map_level = worldRPG[0]; + /* NPC animation */ + animation_new(&game.npc_animation, &tiny_npc_male, 3, 250); + /* Player animation */ animation_new(&game.player.animation, &player_male_img, 3, 250); /* Wrapping back to 1 to skip the idle frame. */ game.player.animation.wrap_dest = 1; diff --git a/src/npc.c b/src/npc.c index 32dbc53..38bd991 100644 --- a/src/npc.c +++ b/src/npc.c @@ -260,8 +260,9 @@ void update_npc(NPC *npc) { bopti_image_t *npc_sprites[FACES] = {&tiny_npc_male, &tiny_npc_female, &tiny_npc_milkman, &tiny_npc_police}; -void npc_draw_single(NPC *npc, Player *pl) { +void npc_draw_single(NPC *npc, Game *game) { + Player *pl = &game->player; /* Render the path if in debug and it has one*/ #if DEBUGMODE if(npc->hasPath) { @@ -270,16 +271,16 @@ void npc_draw_single(NPC *npc, Player *pl) { int16_t deltaX1 = ((int16_t)(npc->x + npc->xpath[v % NbPoints]) * PXSIZE) - - (int16_t)pl->wx; + (int16_t)pl->x; int16_t deltaY1 = ((int16_t)(npc->y + npc->ypath[v % NbPoints]) * PXSIZE) - - (int16_t)pl->wy; + (int16_t)pl->y; int16_t deltaX2 = ((int16_t)(npc->x + npc->xpath[(v + 1) % NbPoints]) * PXSIZE) - - (int16_t)pl->wx; + (int16_t)pl->x; int16_t deltaY2 = ((int16_t)(npc->y + npc->ypath[(v + 1) % NbPoints]) * PXSIZE) - - (int16_t)pl->wy; + (int16_t)pl->y; dline(pl->px + deltaX1, pl->py + deltaY1, pl->px + deltaX2, pl->py + deltaY2, PATH_COLOR); @@ -289,19 +290,21 @@ void npc_draw_single(NPC *npc, Player *pl) { int16_t delX = ((npc->curx * PXSIZE) >> PRECISION) - (int16_t)pl->x; int16_t delY = ((npc->cury * PXSIZE) >> PRECISION) - (int16_t)pl->y; - bopti_image_t *face = npc_sprites[npc->face]; - dimage(pl->px - P_WIDTH / 2 + delX, pl->py - P_HEIGHT / 2 + delY, face); + game->npc_animation.image = npc_sprites[npc->face]; + unsigned char frame = game->npc_animation.frame; + if(npc->paused || !npc->hasPath) game->npc_animation.frame = 0; + animation_draw(&game->npc_animation, pl->px - P_WIDTH / 2 + delX, + pl->py - P_HEIGHT / 2 + delY); + game->npc_animation.frame = frame; } 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); + npc_draw_single(&game->map_level->npcs[u], game); } for(u = 0; u < npc_count; u++) { - npc_draw_single(&npc_stack[u], pl); + npc_draw_single(&npc_stack[u], game); } }