Death animation on skeleton deaed

main
Cameron Murphy Reikes 2 years ago
parent 1a69aedb9d
commit 1834f99b3c

@ -195,7 +195,7 @@ int main(int argc, char **argv) {
if(MD_S8Match(type, MD_S8Lit("objectgroup"), 0)) { if(MD_S8Match(type, MD_S8Lit("objectgroup"), 0)) {
fprintf(output, ".initial_entities = {\n"); fprintf(output, ".initial_entities = {\n");
for(MD_EachNode(object, MD_ChildFromString(lay, MD_S8Lit("objects"), 0)->first_child)) { for(MD_EachNode(object, MD_ChildFromString(lay, MD_S8Lit("objects"), 0)->first_child)) {
dump(object); //dump(object);
// negative numbers for object position aren't supported here // negative numbers for object position aren't supported here
MD_String8 name = MD_ChildFromString(object, MD_S8Lit("name"), 0)->first_child->string; MD_String8 name = MD_ChildFromString(object, MD_S8Lit("name"), 0)->first_child->string;
MD_String8 x_string = MD_ChildFromString(object, MD_S8Lit("x"), 0)->first_child->string; MD_String8 x_string = MD_ChildFromString(object, MD_S8Lit("x"), 0)->first_child->string;

@ -167,6 +167,8 @@ typedef struct Entity
Vec2 vel; // only used sometimes, like in old man and bullet Vec2 vel; // only used sometimes, like in old man and bullet
float damage; // at 1.0, dead! zero initialized float damage; // at 1.0, dead! zero initialized
bool facing_left; bool facing_left;
double dead_time;
bool dead;
// multiple entities have a sword swing // multiple entities have a sword swing
BUFF(struct Entity*, 8) done_damage_to_this_swing; // only do damage once, but hitbox stays around BUFF(struct Entity*, 8) done_damage_to_this_swing; // only do damage once, but hitbox stays around
@ -818,6 +820,17 @@ AnimatedSprite skeleton_run =
.offset = {0.0f, 20.0f}, .offset = {0.0f, 20.0f},
.region_size = {80.0f, 80.0f}, .region_size = {80.0f, 80.0f},
}; };
AnimatedSprite skeleton_die =
{
.img = &image_skeleton,
.time_per_frame = 0.10,
.num_frames = 13,
.start = {0.0f, 400.0f},
.horizontal_diff_btwn_frames = 80.0,
.offset = {0.0f, 20.0f},
.region_size = {80.0f, 80.0f},
.no_wrap = true,
};
AnimatedSprite merchant_idle = AnimatedSprite merchant_idle =
{ {
.img = &image_merchant, .img = &image_merchant,
@ -886,6 +899,8 @@ void reset_level()
void init(void) void init(void)
{ {
Log("Size of entity struct: %zu\n", sizeof(Entity));
Log("Size of %lld entities: %zu kb\n", ARRLEN(entities), sizeof(entities)/1024);
sg_setup(&(sg_desc){ sg_setup(&(sg_desc){
.context = sapp_sgcontext(), .context = sapp_sgcontext(),
}); });
@ -1682,7 +1697,7 @@ Vec2 move_and_slide(Entity *from, Vec2 position, Vec2 movement_this_frame)
{ {
ENTITIES_ITER(entities) ENTITIES_ITER(entities)
{ {
if(!(it->is_character && it->is_rolling) && it != from) if(!(it->is_character && it->is_rolling) && it != from && !(it->is_npc && it->dead))
{ {
to_check[to_check_index++] = centered_aabb(it->pos, entity_aabb_size(it)); to_check[to_check_index++] = centered_aabb(it->pos, entity_aabb_size(it));
assert(to_check_index < ARRLEN(to_check)); assert(to_check_index < ARRLEN(to_check));
@ -2085,6 +2100,11 @@ void frame(void)
it->facing_left = it->vel.x < 0.0f; it->facing_left = it->vel.x < 0.0f;
if(it->dead)
{
it->dead_time += dt;
}
// draw drop shadow // draw drop shadow
if(it->is_character || it->is_npc) if(it->is_character || it->is_npc)
{ {
@ -2163,11 +2183,17 @@ void frame(void)
draw_animated_sprite(&old_man_idle, elapsed_time, face_left, it->pos, col); draw_animated_sprite(&old_man_idle, elapsed_time, face_left, it->pos, col);
} }
else if(it->npc_kind == SKELETON) else if(it->npc_kind == SKELETON)
{
Color col = WHITE;
if(it->dead)
{
draw_animated_sprite(&skeleton_die, it->dead_time, it->facing_left, it->pos, col);
}
else
{ {
if(fabsf(it->vel.x) > 0.01f) if(fabsf(it->vel.x) > 0.01f)
it->facing_left = it->vel.x < 0.0f; it->facing_left = it->vel.x < 0.0f;
Color col = WHITE;
it->pos = move_and_slide(it, it->pos, MulV2F(it->vel, pixels_per_meter * dt)); it->pos = move_and_slide(it, it->pos, MulV2F(it->vel, pixels_per_meter * dt));
AABB weapon_aabb = entity_sword_aabb(it, 30.0f, 18.0f); AABB weapon_aabb = entity_sword_aabb(it, 30.0f, 18.0f);
dbgrect(weapon_aabb); dbgrect(weapon_aabb);
@ -2217,6 +2243,7 @@ void frame(void)
} }
it->vel = LerpV2(it->vel, dt*8.0f, target_vel); it->vel = LerpV2(it->vel, dt*8.0f, target_vel);
} }
}
else if(it->npc_kind == DEATH) else if(it->npc_kind == DEATH)
{ {
draw_animated_sprite(&death_idle, elapsed_time, true, AddV2(it->pos, V2(0, 30.0f)), col); draw_animated_sprite(&death_idle, elapsed_time, true, AddV2(it->pos, V2(0, 30.0f)), col);
@ -2230,10 +2257,17 @@ void frame(void)
assert(false); assert(false);
} }
if(it->damage >= 1.0) if(it->damage >= 1.0)
{
if(it->npc_kind == SKELETON)
{
it->dead = true;
}
else
{ {
*it = (Entity){0}; *it = (Entity){0};
} }
} }
}
else if (it->is_bullet) else if (it->is_bullet)
{ {
it->pos = AddV2(it->pos, MulV2F(it->vel, pixels_per_meter * dt)); it->pos = AddV2(it->pos, MulV2F(it->vel, pixels_per_meter * dt));

Loading…
Cancel
Save