Change Animation names, stop input parse on attack
This commit is contained in:
parent
b8b76cecd3
commit
403999b566
@ -414,22 +414,19 @@ const i32 asset_loadTTFont(AssetManager *assetManager, const char *filePath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void asset_addAnimation(AssetManager *assetManager, i32 texId,
|
void asset_addAnimation(AssetManager *assetManager, i32 texId,
|
||||||
i32 animId, i32 *atlasIndexes, i32 numFrames,
|
i32 animId, i32 *frameIndex, i32 numFrames,
|
||||||
f32 frameDuration)
|
f32 frameDuration)
|
||||||
{
|
{
|
||||||
#ifdef DENGINE_DEBUG
|
#ifdef DENGINE_DEBUG
|
||||||
ASSERT(assetManager && atlasIndexes)
|
ASSERT(assetManager && frameIndex)
|
||||||
ASSERT(!assetManager->anims[animId].atlasIndexes);
|
ASSERT(!assetManager->anims[animId].frameIndex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Animation anim = {0};
|
Animation anim = {0};
|
||||||
// TODO(doyle): Do we need texture to be bound to animation?
|
|
||||||
anim.tex = asset_getTexture(assetManager, texId);
|
|
||||||
anim.atlas = asset_getTextureAtlas(assetManager, texId);
|
anim.atlas = asset_getTextureAtlas(assetManager, texId);
|
||||||
|
|
||||||
anim.atlasIndexes = PLATFORM_MEM_ALLOC(numFrames, i32);
|
anim.frameIndex = PLATFORM_MEM_ALLOC(numFrames, i32);
|
||||||
for (i32 i = 0; i < numFrames; i++)
|
for (i32 i = 0; i < numFrames; i++) anim.frameIndex[i] = frameIndex[i];
|
||||||
anim.atlasIndexes[i] = atlasIndexes[i];
|
|
||||||
|
|
||||||
anim.numFrames = numFrames;
|
anim.numFrames = numFrames;
|
||||||
anim.frameDuration = frameDuration;
|
anim.frameDuration = frameDuration;
|
||||||
|
@ -229,8 +229,8 @@ void renderer_entity(Renderer *renderer, v4 cameraBounds, Entity *entity,
|
|||||||
{
|
{
|
||||||
EntityAnim_ *entityAnim = &entity->anim[entity->currAnimId];
|
EntityAnim_ *entityAnim = &entity->anim[entity->currAnimId];
|
||||||
Animation *anim = entityAnim->anim;
|
Animation *anim = entityAnim->anim;
|
||||||
i32 atlasIndex = anim->atlasIndexes[entityAnim->currFrame];
|
i32 frameIndex = anim->frameIndex[entityAnim->currFrame];
|
||||||
v4 animTexRect = anim->atlas->texRect[atlasIndex];
|
v4 animTexRect = anim->atlas->texRect[frameIndex];
|
||||||
|
|
||||||
if (entity->direction == direction_east)
|
if (entity->direction == direction_east)
|
||||||
{
|
{
|
||||||
|
@ -320,6 +320,12 @@ INTERNAL inline void setActiveEntityAnim(Entity *entity,
|
|||||||
entity->currAnimCyclesCompleted = 0;
|
entity->currAnimCyclesCompleted = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INTERNAL inline v4 getEntityScreenRect(Entity entity)
|
||||||
|
{
|
||||||
|
v4 result = math_getRect(entity.pos, entity.hitboxSize);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
INTERNAL void parseInput(GameState *state, const f32 dt)
|
INTERNAL void parseInput(GameState *state, const f32 dt)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -338,55 +344,60 @@ INTERNAL void parseInput(GameState *state, const f32 dt)
|
|||||||
Entity *hero = &world->entities[world->heroIndex];
|
Entity *hero = &world->entities[world->heroIndex];
|
||||||
v2 ddPos = V2(0, 0);
|
v2 ddPos = V2(0, 0);
|
||||||
|
|
||||||
// TODO(doyle): As we need to handle more key spam input, we want to track
|
if (hero->stats->busyDuration <= 0)
|
||||||
// if a button ended down
|
|
||||||
LOCAL_PERSIST b32 spaceBarWasDown = FALSE;
|
|
||||||
|
|
||||||
if (state->keys[GLFW_KEY_RIGHT])
|
|
||||||
{
|
{
|
||||||
ddPos.x = 1.0f;
|
// TODO(doyle): As we need to handle more key spam input, we want to
|
||||||
hero->direction = direction_east;
|
// track
|
||||||
}
|
// if a button ended down
|
||||||
|
LOCAL_PERSIST b32 spaceBarWasDown = FALSE;
|
||||||
|
|
||||||
if (state->keys[GLFW_KEY_LEFT])
|
if (state->keys[GLFW_KEY_RIGHT])
|
||||||
{
|
|
||||||
ddPos.x = -1.0f;
|
|
||||||
hero->direction = direction_west;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state->keys[GLFW_KEY_UP])
|
|
||||||
{
|
|
||||||
ddPos.y = 1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state->keys[GLFW_KEY_DOWN])
|
|
||||||
{
|
|
||||||
ddPos.y = -1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ddPos.x != 0.0f && ddPos.y != 0.0f)
|
|
||||||
{
|
|
||||||
// NOTE(doyle): Cheese it and pre-compute the vector for diagonal using
|
|
||||||
// pythagoras theorem on a unit triangle
|
|
||||||
// 1^2 + 1^2 = c^2
|
|
||||||
ddPos = v2_scale(ddPos, 0.70710678118f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(doyle): Revisit key input with state checking for last ended down
|
|
||||||
#if 0
|
|
||||||
if (state->keys[GLFW_KEY_SPACE] && !spaceBarWasDown)
|
|
||||||
{
|
|
||||||
if (!(hero->currAnimId == entityanimid_tackle &&
|
|
||||||
hero->currAnimCyclesCompleted == 0))
|
|
||||||
{
|
{
|
||||||
spaceBarWasDown = TRUE;
|
ddPos.x = 1.0f;
|
||||||
|
hero->direction = direction_east;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->keys[GLFW_KEY_LEFT])
|
||||||
|
{
|
||||||
|
ddPos.x = -1.0f;
|
||||||
|
hero->direction = direction_west;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->keys[GLFW_KEY_UP])
|
||||||
|
{
|
||||||
|
ddPos.y = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->keys[GLFW_KEY_DOWN])
|
||||||
|
{
|
||||||
|
ddPos.y = -1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ddPos.x != 0.0f && ddPos.y != 0.0f)
|
||||||
|
{
|
||||||
|
// NOTE(doyle): Cheese it and pre-compute the vector for diagonal
|
||||||
|
// using
|
||||||
|
// pythagoras theorem on a unit triangle
|
||||||
|
// 1^2 + 1^2 = c^2
|
||||||
|
ddPos = v2_scale(ddPos, 0.70710678118f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(doyle): Revisit key input with state checking for last ended down
|
||||||
|
#if 0
|
||||||
|
if (state->keys[GLFW_KEY_SPACE] && !spaceBarWasDown)
|
||||||
|
{
|
||||||
|
if (!(hero->currAnimId == entityanimid_tackle &&
|
||||||
|
hero->currAnimCyclesCompleted == 0))
|
||||||
|
{
|
||||||
|
spaceBarWasDown = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!state->keys[GLFW_KEY_SPACE])
|
||||||
|
{
|
||||||
|
spaceBarWasDown = FALSE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (!state->keys[GLFW_KEY_SPACE])
|
|
||||||
{
|
|
||||||
spaceBarWasDown = FALSE;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE(doyle): Clipping threshold for snapping velocity to 0
|
// NOTE(doyle): Clipping threshold for snapping velocity to 0
|
||||||
f32 epsilon = 0.5f;
|
f32 epsilon = 0.5f;
|
||||||
@ -476,8 +487,8 @@ INTERNAL void updateEntityAnim(Entity *entity, f32 dt)
|
|||||||
// TODO(doyle): Recheck why we have this twice
|
// TODO(doyle): Recheck why we have this twice
|
||||||
EntityAnim_ *entityAnim = &entity->anim[entity->currAnimId];
|
EntityAnim_ *entityAnim = &entity->anim[entity->currAnimId];
|
||||||
Animation anim = *entityAnim->anim;
|
Animation anim = *entityAnim->anim;
|
||||||
i32 atlasIndex = anim.atlasIndexes[entityAnim->currFrame];
|
i32 frameIndex = anim.frameIndex[entityAnim->currFrame];
|
||||||
v4 texRect = anim.atlas->texRect[atlasIndex];
|
v4 texRect = anim.atlas->texRect[frameIndex];
|
||||||
|
|
||||||
entityAnim->currDuration -= dt;
|
entityAnim->currDuration -= dt;
|
||||||
if (entityAnim->currDuration <= 0.0f)
|
if (entityAnim->currDuration <= 0.0f)
|
||||||
@ -485,10 +496,10 @@ INTERNAL void updateEntityAnim(Entity *entity, f32 dt)
|
|||||||
if (++entityAnim->currFrame >= anim.numFrames)
|
if (++entityAnim->currFrame >= anim.numFrames)
|
||||||
entity->currAnimCyclesCompleted++;
|
entity->currAnimCyclesCompleted++;
|
||||||
|
|
||||||
entityAnim->currFrame = entityAnim->currFrame % anim.numFrames;
|
entityAnim->currFrame = entityAnim->currFrame % anim.numFrames;
|
||||||
atlasIndex = entityAnim->anim->atlasIndexes[entityAnim->currFrame];
|
frameIndex = entityAnim->anim->frameIndex[entityAnim->currFrame];
|
||||||
texRect = anim.atlas->texRect[atlasIndex];
|
texRect = anim.atlas->texRect[frameIndex];
|
||||||
entityAnim->currDuration = anim.frameDuration;
|
entityAnim->currDuration = anim.frameDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(doyle): If humanoid entity, let animation dictate render size which
|
// NOTE(doyle): If humanoid entity, let animation dictate render size which
|
||||||
|
@ -60,9 +60,8 @@ typedef struct TexAtlas
|
|||||||
|
|
||||||
typedef struct Animation
|
typedef struct Animation
|
||||||
{
|
{
|
||||||
Texture *tex;
|
|
||||||
TexAtlas *atlas;
|
TexAtlas *atlas;
|
||||||
i32 *atlasIndexes;
|
i32 *frameIndex;
|
||||||
i32 numFrames;
|
i32 numFrames;
|
||||||
f32 frameDuration;
|
f32 frameDuration;
|
||||||
} Animation;
|
} Animation;
|
||||||
|
@ -78,6 +78,10 @@ typedef struct Entity
|
|||||||
b32 collides;
|
b32 collides;
|
||||||
|
|
||||||
// TODO(doyle): String based access
|
// TODO(doyle): String based access
|
||||||
|
// TODO(doyle): Separate animation refs from curr animation state, entity
|
||||||
|
// only ever has one active current animation. ATM every entity animation
|
||||||
|
// has a currframe and duration .. either that or we stop resetting
|
||||||
|
// animation on entity context switch
|
||||||
EntityAnim_ anim[16];
|
EntityAnim_ anim[16];
|
||||||
i32 currAnimId;
|
i32 currAnimId;
|
||||||
u32 currAnimCyclesCompleted;
|
u32 currAnimCyclesCompleted;
|
||||||
@ -85,10 +89,4 @@ typedef struct Entity
|
|||||||
EntityStats *stats;
|
EntityStats *stats;
|
||||||
} Entity;
|
} Entity;
|
||||||
|
|
||||||
INTERNAL inline v4 getEntityScreenRect(Entity entity)
|
|
||||||
{
|
|
||||||
v4 result = math_getRect(entity.pos, entity.hitboxSize);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user