Added NPC animation.
Before Width: | Height: | Size: 221 B After Width: | Height: | Size: 382 B |
Before Width: | Height: | Size: 206 B After Width: | Height: | Size: 327 B |
Before Width: | Height: | Size: 222 B After Width: | Height: | Size: 343 B |
Before Width: | Height: | Size: 220 B After Width: | Height: | Size: 344 B |
|
@ -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! */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
25
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|