|
|
@ -2,6 +2,7 @@ |
|
|
|
|
|
|
|
#include <stddef.h> |
|
|
|
|
|
|
|
#include "game.h" |
|
|
|
#include "player.h" |
|
|
|
#include "sdk/oam.h" |
|
|
|
#include "util.h" |
|
|
@ -16,8 +17,7 @@ |
|
|
|
static actor_anim_state_t ANIM_TOTAL_FRAMES[] = {2}; |
|
|
|
|
|
|
|
static uint8_t mob_ids[MAX_UNIQUE_MOBS]; |
|
|
|
static sprite16_mob mob_anim_data[MAX_UNIQUE_MOBS]; |
|
|
|
static sprite16_player player_anim_data; |
|
|
|
static uint8_t *mob_anim_data[MAX_UNIQUE_MOBS]; |
|
|
|
static actor_t all_actors[MAX_ACTORS]; |
|
|
|
|
|
|
|
static uint8_t actor_load_mob_anim_data(uint8_t mob_id); |
|
|
@ -28,6 +28,9 @@ void actor_init(void) { |
|
|
|
actor_reset(); |
|
|
|
|
|
|
|
PLAYER_ACTOR->active = 1; |
|
|
|
PLAYER_ACTOR->anim = ANIM_STAND; |
|
|
|
PLAYER_ACTOR->frame_idx = 0; |
|
|
|
PLAYER_ACTOR->frame_counter = 0; |
|
|
|
PLAYER_ACTOR->x = PLAYER.x; |
|
|
|
PLAYER_ACTOR->y = PLAYER.y; |
|
|
|
} |
|
|
@ -70,10 +73,12 @@ actor_t *actor_create_mob(uint8_t id) { |
|
|
|
void actor_remove(actor_t *a) { a->active = 0; } |
|
|
|
|
|
|
|
void actor_update(void) { |
|
|
|
struct oam_entry *oam_ptr = &shadow_oam[0]; |
|
|
|
actor_t *a = &all_actors[0]; |
|
|
|
|
|
|
|
for (uint8_t i = 0; i < ARRSIZE(all_actors); ++i) { |
|
|
|
if (!a->active) { |
|
|
|
a++; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
@ -83,44 +88,35 @@ void actor_update(void) { |
|
|
|
a->frame_idx = (a->frame_idx + 1) % ANIM_TOTAL_FRAMES[a->anim]; |
|
|
|
} |
|
|
|
|
|
|
|
a++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void actor_flush_oam(void) { |
|
|
|
struct oam_entry *oam_ptr = &shadow_oam[0]; |
|
|
|
actor_t *a = &all_actors[0]; |
|
|
|
|
|
|
|
for (uint8_t i = 0; i < ARRSIZE(all_actors); ++i) { |
|
|
|
if (!a->active) { |
|
|
|
a++; |
|
|
|
continue; |
|
|
|
const uint8_t *anim_ptr; |
|
|
|
if (i == 0) { |
|
|
|
anim_ptr = &player_map[0]; |
|
|
|
} else { |
|
|
|
anim_ptr = mob_anim_data[a->mob_anim_idx]; |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t *anim_ptr = mob_anim_data[a->mob_anim_idx].anims[a->anim]; |
|
|
|
anim_ptr += a->frame_idx * 4; |
|
|
|
|
|
|
|
oam_ptr->y = a->y; |
|
|
|
oam_ptr->x = a->x; |
|
|
|
oam_ptr->tile = *anim_ptr++; |
|
|
|
oam_ptr->y = a->y + 16; |
|
|
|
oam_ptr->x = a->x + 8; |
|
|
|
oam_ptr->tile = *anim_ptr++ + TILE_INDEX_PLAYER; |
|
|
|
oam_ptr->attr = 0; |
|
|
|
oam_ptr++; |
|
|
|
|
|
|
|
oam_ptr->y = a->y; |
|
|
|
oam_ptr->x = a->x + TILE_WIDTH; |
|
|
|
oam_ptr->tile = *anim_ptr++; |
|
|
|
oam_ptr->y = a->y + 16; |
|
|
|
oam_ptr->x = a->x + TILE_WIDTH + 8; |
|
|
|
oam_ptr->tile = *anim_ptr++ + TILE_INDEX_PLAYER; |
|
|
|
oam_ptr->attr = 0; |
|
|
|
oam_ptr++; |
|
|
|
|
|
|
|
oam_ptr->y = a->y + TILE_WIDTH; |
|
|
|
oam_ptr->x = a->x; |
|
|
|
oam_ptr->tile = *anim_ptr++; |
|
|
|
oam_ptr->y = a->y + TILE_WIDTH + 16; |
|
|
|
oam_ptr->x = a->x + 8; |
|
|
|
oam_ptr->tile = *anim_ptr++ + TILE_INDEX_PLAYER; |
|
|
|
oam_ptr->attr = 0; |
|
|
|
oam_ptr++; |
|
|
|
|
|
|
|
oam_ptr->y = a->y + TILE_WIDTH; |
|
|
|
oam_ptr->x = a->x + TILE_WIDTH; |
|
|
|
oam_ptr->tile = *anim_ptr++; |
|
|
|
oam_ptr->y = a->y + TILE_WIDTH + 16; |
|
|
|
oam_ptr->x = a->x + TILE_WIDTH + 8; |
|
|
|
oam_ptr->tile = *anim_ptr++ + TILE_INDEX_PLAYER; |
|
|
|
oam_ptr->attr = 0; |
|
|
|
oam_ptr++; |
|
|
|
|
|
|
|