Restore battle system using hash data structs
This commit is contained in:
parent
7ca42f781a
commit
17cc6063a3
28
src/Entity.c
28
src/Entity.c
@ -19,6 +19,11 @@ void entity_setActiveAnim(Entity *entity, char *animName)
|
|||||||
if (common_strcmp(anim->key, animName) == 0)
|
if (common_strcmp(anim->key, animName) == 0)
|
||||||
{
|
{
|
||||||
entity->currAnimId = i;
|
entity->currAnimId = i;
|
||||||
|
EntityAnim *currEntityAnim =
|
||||||
|
&entity->animList[entity->currAnimId];
|
||||||
|
currEntityAnim->currDuration =
|
||||||
|
currEntityAnim->anim->frameDuration;
|
||||||
|
currEntityAnim->currFrame = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,29 +82,6 @@ void entity_addAnim(AssetManager *assetManager, Entity *entity, char *animName)
|
|||||||
DEBUG_LOG("No more free entity animation slots");
|
DEBUG_LOG("No more free entity animation slots");
|
||||||
}
|
}
|
||||||
|
|
||||||
void entity_addGenericMob(MemoryArena *arena, AssetManager *assetManager,
|
|
||||||
World *world, v2 pos)
|
|
||||||
{
|
|
||||||
#ifdef DENGINE_DEBUG
|
|
||||||
DEBUG_LOG("Mob entity spawned");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Entity *hero = &world->entities[entity_getIndex(world, world->heroId)];
|
|
||||||
|
|
||||||
v2 size = V2(58.0f, 98.0f);
|
|
||||||
enum EntityType type = entitytype_mob;
|
|
||||||
enum Direction dir = direction_west;
|
|
||||||
Texture *tex = asset_getTexture(assetManager, texlist_hero);
|
|
||||||
b32 collides = TRUE;
|
|
||||||
Entity *mob = entity_add(arena, world, pos, size, type, dir, tex, collides);
|
|
||||||
|
|
||||||
mob->audioRenderer = PLATFORM_MEM_ALLOC(arena, 1, AudioRenderer);
|
|
||||||
mob->audioRenderer->sourceIndex = AUDIO_SOURCE_UNASSIGNED;
|
|
||||||
|
|
||||||
/* Populate mob animation references */
|
|
||||||
entity_addAnim(assetManager, mob, "Claude idle");
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity *entity_add(MemoryArena *arena, World *world, v2 pos, v2 size,
|
Entity *entity_add(MemoryArena *arena, World *world, v2 pos, v2 size,
|
||||||
enum EntityType type, enum Direction direction, Texture *tex,
|
enum EntityType type, enum Direction direction, Texture *tex,
|
||||||
b32 collides)
|
b32 collides)
|
||||||
|
@ -269,7 +269,8 @@ void renderer_entity(Renderer *renderer, Rect camera, Entity *entity,
|
|||||||
updateBufferObject(renderer, &entityQuad, 1);
|
updateBufferObject(renderer, &entityQuad, 1);
|
||||||
|
|
||||||
v2 posInCameraSpace = v2_sub(entity->pos, camera.pos);
|
v2 posInCameraSpace = v2_sub(entity->pos, camera.pos);
|
||||||
renderObject(renderer, posInCameraSpace, entity->renderSize,
|
// TODO(doyle): Scale temporarily
|
||||||
|
renderObject(renderer, posInCameraSpace, v2_scale(entity->renderSize, 2),
|
||||||
pivotPoint, rotate, color, entity->tex);
|
pivotPoint, rotate, color, entity->tex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,33 @@ INTERNAL Entity *getHeroEntity(World *world)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INTERNAL void addGenericMob(MemoryArena *arena, AssetManager *assetManager,
|
||||||
|
World *world, v2 pos)
|
||||||
|
{
|
||||||
|
#ifdef DENGINE_DEBUG
|
||||||
|
DEBUG_LOG("Mob entity spawned");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Entity *hero = &world->entities[entity_getIndex(world, world->heroId)];
|
||||||
|
|
||||||
|
v2 size = V2(58.0f, 98.0f);
|
||||||
|
enum EntityType type = entitytype_mob;
|
||||||
|
enum Direction dir = direction_west;
|
||||||
|
Texture *tex = asset_getTexture(assetManager, texlist_claude);
|
||||||
|
b32 collides = TRUE;
|
||||||
|
Entity *mob = entity_add(arena, world, pos, size, type, dir, tex, collides);
|
||||||
|
|
||||||
|
mob->audioRenderer = PLATFORM_MEM_ALLOC(arena, 1, AudioRenderer);
|
||||||
|
mob->audioRenderer->sourceIndex = AUDIO_SOURCE_UNASSIGNED;
|
||||||
|
|
||||||
|
/* Populate mob animation references */
|
||||||
|
entity_addAnim(assetManager, mob, "claudeIdle");
|
||||||
|
entity_addAnim(assetManager, mob, "claudeRun");
|
||||||
|
entity_addAnim(assetManager, mob, "claudeBattleIdle");
|
||||||
|
entity_addAnim(assetManager, mob, "claudeAttack");
|
||||||
|
entity_setActiveAnim(mob, "claudeIdle");
|
||||||
|
}
|
||||||
|
|
||||||
INTERNAL void rendererInit(GameState *state, v2 windowSize)
|
INTERNAL void rendererInit(GameState *state, v2 windowSize)
|
||||||
{
|
{
|
||||||
AssetManager *assetManager = &state->assetManager;
|
AssetManager *assetManager = &state->assetManager;
|
||||||
@ -179,7 +206,7 @@ INTERNAL void assetInit(GameState *state)
|
|||||||
PlatformFileRead xmlFileRead = {0};
|
PlatformFileRead xmlFileRead = {0};
|
||||||
|
|
||||||
i32 result = platform_readFileToBuffer(
|
i32 result = platform_readFileToBuffer(
|
||||||
arena, "data/textures/WorldTraveller/ClaudeSpriteSheet.xml",
|
arena, "data/textures/WorldTraveller/ClaudeSprite.xml",
|
||||||
&xmlFileRead);
|
&xmlFileRead);
|
||||||
|
|
||||||
XmlToken *xmlTokens = PLATFORM_MEM_ALLOC(arena, 8192, XmlToken);
|
XmlToken *xmlTokens = PLATFORM_MEM_ALLOC(arena, 8192, XmlToken);
|
||||||
@ -605,68 +632,54 @@ INTERNAL void assetInit(GameState *state)
|
|||||||
DEBUG_LOG("Assets loaded");
|
DEBUG_LOG("Assets loaded");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* Load animations */
|
|
||||||
f32 duration = 1.0f;
|
|
||||||
i32 numRects = 1;
|
|
||||||
v4 *animRects = PLATFORM_MEM_ALLOC(arena, numRects, v4);
|
|
||||||
i32 terrainAnimAtlasIndexes[1] = {terrainrects_ground};
|
|
||||||
|
|
||||||
// TODO(doyle): Optimise animation storage, we waste space having 1:1 with
|
|
||||||
// animlist when some textures don't have certain animations
|
|
||||||
asset_addAnimation(assetManager, arena, texlist_terrain, animlist_terrain,
|
|
||||||
terrainAnimAtlasIndexes, numRects, duration);
|
|
||||||
|
|
||||||
// Idle animation
|
|
||||||
duration = 1.0f;
|
|
||||||
numRects = 1;
|
|
||||||
i32 idleAnimAtlasIndexes[1] = {herorects_idle};
|
|
||||||
asset_addAnimation(assetManager, arena, texlist_hero, animlist_hero_idle,
|
|
||||||
idleAnimAtlasIndexes, numRects, duration);
|
|
||||||
#else
|
|
||||||
f32 duration = 1.0f;
|
|
||||||
i32 numRects = 1;
|
|
||||||
TexAtlas *claudeAtlas =
|
TexAtlas *claudeAtlas =
|
||||||
asset_getTexAtlas(assetManager, "ClaudeSpriteSheet.png");
|
asset_getTexAtlas(assetManager, "ClaudeSprite.png");
|
||||||
|
|
||||||
duration = 1.0f;
|
char *claudeIdle[1] = {"ClaudeSprite_Walk_Left_01"};
|
||||||
numRects = 1;
|
f32 duration = 1.0f;
|
||||||
char *subTextureNames = {"ClaudeSprite_001"};
|
i32 numRects = ARRAY_COUNT(claudeIdle);
|
||||||
asset_addAnimation(assetManager, arena, "Claude_idle", claudeAtlas,
|
asset_addAnimation(assetManager, arena, "claudeIdle", claudeAtlas,
|
||||||
&subTextureNames, 1, 1.0f);
|
claudeIdle, numRects, duration);
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
// Run animation
|
||||||
// Walk animation
|
char *claudeRun[6] = {
|
||||||
duration = 0.10f;
|
"ClaudeSprite_Run_Left_01", "ClaudeSprite_Run_Left_02",
|
||||||
numRects = 3;
|
"ClaudeSprite_Run_Left_03", "ClaudeSprite_Run_Left_04",
|
||||||
i32 walkAnimAtlasIndexes[3] = {herorects_walkA, herorects_idle,
|
"ClaudeSprite_Run_Left_05", "ClaudeSprite_Run_Left_06"};
|
||||||
herorects_walkB};
|
duration = 0.1f;
|
||||||
asset_addAnimation(assetManager, arena, texlist_hero, animlist_hero_walk,
|
numRects = ARRAY_COUNT(claudeRun);
|
||||||
walkAnimAtlasIndexes, numRects, duration);
|
asset_addAnimation(assetManager, arena, "claudeRun", claudeAtlas,
|
||||||
|
claudeRun, numRects, duration);
|
||||||
|
|
||||||
// Wave animation
|
// Battle Idle animation
|
||||||
duration = 0.30f;
|
char *claudeBattleIdle[3] = {"ClaudeSprite_BattleIdle_Left_01",
|
||||||
numRects = 2;
|
"ClaudeSprite_BattleIdle_Left_02",
|
||||||
i32 waveAnimAtlasIndexes[2] = {herorects_waveA, herorects_waveB};
|
"ClaudeSprite_BattleIdle_Left_03"};
|
||||||
asset_addAnimation(assetManager, arena, texlist_hero, animlist_hero_wave,
|
numRects = ARRAY_COUNT(claudeBattleIdle);
|
||||||
waveAnimAtlasIndexes, numRects, duration);
|
duration = 0.2f;
|
||||||
|
asset_addAnimation(assetManager, arena, "claudeBattleIdle", claudeAtlas,
|
||||||
|
claudeBattleIdle, numRects, duration);
|
||||||
|
|
||||||
// Battle Stance animation
|
// Attack Left animation
|
||||||
duration = 1.0f;
|
char *claudeAttack[6] = {
|
||||||
numRects = 1;
|
"ClaudeSprite_Attack_Left_01", "ClaudeSprite_Attack_Left_02",
|
||||||
i32 battleStanceAnimAtlasIndexes[1] = {herorects_battlePose};
|
"ClaudeSprite_Attack_Left_03", "ClaudeSprite_Attack_Left_04",
|
||||||
asset_addAnimation(assetManager, arena, texlist_hero, animlist_hero_battlePose,
|
"ClaudeSprite_Attack_Left_05", "ClaudeSprite_Attack_Left_06"};
|
||||||
battleStanceAnimAtlasIndexes, numRects, duration);
|
numRects = ARRAY_COUNT(claudeAttack);
|
||||||
|
duration = 0.1f;
|
||||||
|
asset_addAnimation(assetManager, arena, "claudeAttack", claudeAtlas,
|
||||||
|
claudeAttack, numRects, duration);
|
||||||
|
|
||||||
// Battle tackle animation
|
// Victory animation
|
||||||
duration = 0.15f;
|
char *claudeVictory[8] = {
|
||||||
numRects = 3;
|
"ClaudeSprite_Battle_Victory_01", "ClaudeSprite_Battle_Victory_02",
|
||||||
i32 tackleAnimAtlasIndexes[3] = {herorects_castA, herorects_castB,
|
"ClaudeSprite_Battle_Victory_03", "ClaudeSprite_Battle_Victory_04",
|
||||||
herorects_castC};
|
"ClaudeSprite_Battle_Victory_05", "ClaudeSprite_Battle_Victory_06",
|
||||||
asset_addAnimation(assetManager, arena, texlist_hero, animlist_hero_tackle,
|
"ClaudeSprite_Battle_Victory_07", "ClaudeSprite_Battle_Victory_08"};
|
||||||
tackleAnimAtlasIndexes, numRects, duration);
|
numRects = ARRAY_COUNT(claudeVictory);
|
||||||
#endif
|
duration = 0.1f;
|
||||||
|
asset_addAnimation(assetManager, arena, "claudeVictory", claudeAtlas,
|
||||||
|
claudeVictory, numRects, duration);
|
||||||
|
|
||||||
#ifdef DENGINE_DEBUG
|
#ifdef DENGINE_DEBUG
|
||||||
DEBUG_LOG("Animations created");
|
DEBUG_LOG("Animations created");
|
||||||
@ -674,9 +687,10 @@ INTERNAL void assetInit(GameState *state)
|
|||||||
|
|
||||||
/* Load sound */
|
/* Load sound */
|
||||||
|
|
||||||
char *audioPath = "data/audio/Nobuo Uematsu - Battle 1.ogg";
|
char *audioPath =
|
||||||
|
"data/audio/Motoi Sakuraba - Stab the sword of justice.ogg";
|
||||||
asset_loadVorbis(assetManager, arena, audioPath, audiolist_battle);
|
asset_loadVorbis(assetManager, arena, audioPath, audiolist_battle);
|
||||||
audioPath = "data/audio/Yuki Kajiura - Swordland.ogg";
|
audioPath = "data/audio/Motoi Sakuraba - Field of Exper.ogg";
|
||||||
asset_loadVorbis(assetManager, arena, audioPath, audiolist_overworld);
|
asset_loadVorbis(assetManager, arena, audioPath, audiolist_overworld);
|
||||||
audioPath = "data/audio/nuindependent_hit22.ogg";
|
audioPath = "data/audio/nuindependent_hit22.ogg";
|
||||||
asset_loadVorbis(assetManager, arena, audioPath, audiolist_tackle);
|
asset_loadVorbis(assetManager, arena, audioPath, audiolist_tackle);
|
||||||
@ -777,14 +791,16 @@ INTERNAL void entityInit(GameState *state, v2 windowSize)
|
|||||||
|
|
||||||
hero->audioRenderer = PLATFORM_MEM_ALLOC(arena, 1, AudioRenderer);
|
hero->audioRenderer = PLATFORM_MEM_ALLOC(arena, 1, AudioRenderer);
|
||||||
hero->audioRenderer->sourceIndex = AUDIO_SOURCE_UNASSIGNED;
|
hero->audioRenderer->sourceIndex = AUDIO_SOURCE_UNASSIGNED;
|
||||||
world->heroId = hero->id;
|
world->heroId = hero->id;
|
||||||
world->cameraFollowingId = hero->id;
|
world->cameraFollowingId = hero->id;
|
||||||
|
|
||||||
/* Populate hero animation references */
|
/* Populate hero animation references */
|
||||||
entity_addAnim(assetManager, hero, "Claude_idle");
|
entity_addAnim(assetManager, hero, "claudeIdle");
|
||||||
entity_setActiveAnim(hero, "Claude_idle");
|
entity_addAnim(assetManager, hero, "claudeRun");
|
||||||
|
entity_addAnim(assetManager, hero, "claudeBattleIdle");
|
||||||
|
entity_addAnim(assetManager, hero, "claudeAttack");
|
||||||
|
entity_setActiveAnim(hero, "claudeIdle");
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* Create a NPC */
|
/* Create a NPC */
|
||||||
pos = V2(hero->pos.x * 3, CAST(f32) state->tileSize);
|
pos = V2(hero->pos.x * 3, CAST(f32) state->tileSize);
|
||||||
size = hero->hitboxSize;
|
size = hero->hitboxSize;
|
||||||
@ -795,14 +811,13 @@ INTERNAL void entityInit(GameState *state, v2 windowSize)
|
|||||||
Entity *npc = entity_add(arena, world, pos, size, type, dir, tex, collides);
|
Entity *npc = entity_add(arena, world, pos, size, type, dir, tex, collides);
|
||||||
|
|
||||||
/* Populate npc animation references */
|
/* Populate npc animation references */
|
||||||
entity_addAnim(assetManager, npc, animlist_hero_wave);
|
entity_addAnim(assetManager, npc, "claudeVictory");
|
||||||
npc->currAnimId = animlist_hero_wave;
|
entity_setActiveAnim(npc, "claudeVictory");
|
||||||
|
|
||||||
/* Create a Mob */
|
/* Create a Mob */
|
||||||
pos = V2(renderer->size.w - (renderer->size.w / 3.0f),
|
pos = V2(renderer->size.w - (renderer->size.w / 3.0f),
|
||||||
CAST(f32) state->tileSize);
|
CAST(f32) state->tileSize);
|
||||||
entity_addGenericMob(arena, assetManager, world, pos);
|
addGenericMob(arena, assetManager, world, pos);
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DENGINE_DEBUG
|
#ifdef DENGINE_DEBUG
|
||||||
DEBUG_LOG("World populated");
|
DEBUG_LOG("World populated");
|
||||||
@ -1130,7 +1145,7 @@ INTERNAL inline void updateWorldBattleEntities(World *world, Entity *entity,
|
|||||||
INTERNAL inline void resetEntityState(World *world, Entity *entity)
|
INTERNAL inline void resetEntityState(World *world, Entity *entity)
|
||||||
{
|
{
|
||||||
updateWorldBattleEntities(world, entity, ENTITY_NOT_IN_BATTLE);
|
updateWorldBattleEntities(world, entity, ENTITY_NOT_IN_BATTLE);
|
||||||
entity_setActiveAnim(entity, "Claude_idle");
|
entity_setActiveAnim(entity, "claudeIdle");
|
||||||
entity->stats->busyDuration = 0;
|
entity->stats->busyDuration = 0;
|
||||||
entity->stats->actionTimer = entity->stats->actionRate;
|
entity->stats->actionTimer = entity->stats->actionRate;
|
||||||
entity->stats->queuedAttack = entityattack_invalid;
|
entity->stats->queuedAttack = entityattack_invalid;
|
||||||
@ -1174,7 +1189,7 @@ INTERNAL void entityStateSwitch(EventQueue *eventQueue, World *world,
|
|||||||
// or not (i.e. has moved out of frame last frame).
|
// or not (i.e. has moved out of frame last frame).
|
||||||
case entitystate_dead:
|
case entitystate_dead:
|
||||||
registerEvent(eventQueue, eventtype_entity_died, CAST(void *)entity);
|
registerEvent(eventQueue, eventtype_entity_died, CAST(void *)entity);
|
||||||
entity_setActiveAnim(entity, "Claude_idle");
|
entity_setActiveAnim(entity, "claudeIdle");
|
||||||
entity->stats->busyDuration = 0;
|
entity->stats->busyDuration = 0;
|
||||||
entity->stats->actionTimer = entity->stats->actionRate;
|
entity->stats->actionTimer = entity->stats->actionRate;
|
||||||
entity->stats->queuedAttack = entityattack_invalid;
|
entity->stats->queuedAttack = entityattack_invalid;
|
||||||
@ -1214,7 +1229,7 @@ INTERNAL void entityStateSwitch(EventQueue *eventQueue, World *world,
|
|||||||
switch (newState)
|
switch (newState)
|
||||||
{
|
{
|
||||||
case entitystate_battle:
|
case entitystate_battle:
|
||||||
entity_setActiveAnim(entity, "Claude_idle");
|
entity_setActiveAnim(entity, "claudeBattleIdle");
|
||||||
entity->stats->actionTimer = entity->stats->actionRate;
|
entity->stats->actionTimer = entity->stats->actionRate;
|
||||||
entity->stats->busyDuration = 0;
|
entity->stats->busyDuration = 0;
|
||||||
break;
|
break;
|
||||||
@ -1266,7 +1281,6 @@ typedef struct AttackSpec
|
|||||||
INTERNAL void beginAttack(EventQueue *eventQueue, World *world,
|
INTERNAL void beginAttack(EventQueue *eventQueue, World *world,
|
||||||
Entity *attacker)
|
Entity *attacker)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
#ifdef DENGINE_DEBUG
|
#ifdef DENGINE_DEBUG
|
||||||
ASSERT(attacker->stats->entityIdToAttack != ENTITY_NULL_ID);
|
ASSERT(attacker->stats->entityIdToAttack != ENTITY_NULL_ID);
|
||||||
ASSERT(attacker->state == entitystate_battle);
|
ASSERT(attacker->state == entitystate_battle);
|
||||||
@ -1276,11 +1290,11 @@ INTERNAL void beginAttack(EventQueue *eventQueue, World *world,
|
|||||||
switch (attacker->stats->queuedAttack)
|
switch (attacker->stats->queuedAttack)
|
||||||
{
|
{
|
||||||
case entityattack_tackle:
|
case entityattack_tackle:
|
||||||
EntityAnim_ attackAnim = attacker->anim[animlist_hero_tackle];
|
EntityAnim attackAnim = attacker->animList[attacker->currAnimId];
|
||||||
f32 busyDuration = attackAnim.anim->frameDuration *
|
f32 busyDuration = attackAnim.anim->frameDuration *
|
||||||
CAST(f32) attackAnim.anim->numFrames;
|
CAST(f32) attackAnim.anim->numFrames;
|
||||||
attacker->stats->busyDuration = busyDuration;
|
attacker->stats->busyDuration = busyDuration;
|
||||||
entity_setActiveAnim(attacker, animlist_hero_tackle);
|
entity_setActiveAnim(attacker, "claudeAttack");
|
||||||
if (attacker->direction == direction_east)
|
if (attacker->direction == direction_east)
|
||||||
attacker->dPos.x += (1.0f * METERS_TO_PIXEL);
|
attacker->dPos.x += (1.0f * METERS_TO_PIXEL);
|
||||||
else
|
else
|
||||||
@ -1292,7 +1306,6 @@ INTERNAL void beginAttack(EventQueue *eventQueue, World *world,
|
|||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(doyle): MemArena here is temporary until we incorporate AttackSpec to
|
// TODO(doyle): MemArena here is temporary until we incorporate AttackSpec to
|
||||||
@ -1300,7 +1313,6 @@ INTERNAL void beginAttack(EventQueue *eventQueue, World *world,
|
|||||||
INTERNAL void endAttack(MemoryArena *arena, EventQueue *eventQueue,
|
INTERNAL void endAttack(MemoryArena *arena, EventQueue *eventQueue,
|
||||||
World *world, Entity *attacker)
|
World *world, Entity *attacker)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
#ifdef DENGINE_DEBUG
|
#ifdef DENGINE_DEBUG
|
||||||
ASSERT(attacker->stats->entityIdToAttack != ENTITY_NULL_ID);
|
ASSERT(attacker->stats->entityIdToAttack != ENTITY_NULL_ID);
|
||||||
#endif
|
#endif
|
||||||
@ -1379,7 +1391,6 @@ INTERNAL void endAttack(MemoryArena *arena, EventQueue *eventQueue,
|
|||||||
entityStateSwitch(eventQueue, world, attacker, entitystate_idle);
|
entityStateSwitch(eventQueue, world, attacker, entitystate_idle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void sortWorldEntityList(World *world)
|
INTERNAL void sortWorldEntityList(World *world)
|
||||||
@ -1511,8 +1522,7 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
|
|||||||
|
|
||||||
v2 pos =
|
v2 pos =
|
||||||
V2(renderer->size.w - (renderer->size.w / xModifier), yPos);
|
V2(renderer->size.w - (renderer->size.w / xModifier), yPos);
|
||||||
entity_addGenericMob(&state->arena, &state->assetManager, world,
|
addGenericMob(&state->arena, &state->assetManager, world, pos);
|
||||||
pos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1694,10 +1704,8 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
|
|||||||
if (ddPos.x != 0.0f && ddPos.y != 0.0f)
|
if (ddPos.x != 0.0f && ddPos.y != 0.0f)
|
||||||
{
|
{
|
||||||
// NOTE(doyle): Cheese it and pre-compute the vector for
|
// NOTE(doyle): Cheese it and pre-compute the vector for
|
||||||
// diagonal
|
// diagonal using pythagoras theorem on a unit triangle 1^2
|
||||||
// using
|
// + 1^2 = c^2
|
||||||
// pythagoras theorem on a unit triangle
|
|
||||||
// 1^2 + 1^2 = c^2
|
|
||||||
ddPos = v2_scale(ddPos, 0.70710678118f);
|
ddPos = v2_scale(ddPos, 0.70710678118f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1708,21 +1716,22 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
|
|||||||
**************************
|
**************************
|
||||||
*/
|
*/
|
||||||
// NOTE(doyle): Clipping threshold for snapping velocity to 0
|
// NOTE(doyle): Clipping threshold for snapping velocity to 0
|
||||||
f32 epsilon = 0.5f;
|
f32 epsilon = 15.0f;
|
||||||
v2 epsilonDpos = v2_sub(V2(epsilon, epsilon),
|
v2 epsilonDpos = v2_sub(V2(epsilon, epsilon),
|
||||||
V2(ABS(hero->dPos.x), ABS(hero->dPos.y)));
|
V2(ABS(hero->dPos.x), ABS(hero->dPos.y)));
|
||||||
|
|
||||||
|
char *currAnimName = hero->animList[hero->currAnimId].anim->key;
|
||||||
if (epsilonDpos.x >= 0.0f && epsilonDpos.y >= 0.0f)
|
if (epsilonDpos.x >= 0.0f && epsilonDpos.y >= 0.0f)
|
||||||
{
|
{
|
||||||
hero->dPos = V2(0.0f, 0.0f);
|
hero->dPos = V2(0.0f, 0.0f);
|
||||||
if (hero->currAnimId == animlist_hero_walk)
|
if (common_strcmp(currAnimName, "claudeRun") == 0)
|
||||||
{
|
{
|
||||||
entity_setActiveAnim(hero, "Claude_idle");
|
entity_setActiveAnim(hero, "claudeIdle");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (hero->currAnimId == animlist_hero_idle)
|
else if (common_strcmp(currAnimName, "claudeIdle") == 0)
|
||||||
{
|
{
|
||||||
entity_setActiveAnim(hero, "Claude_idle");
|
entity_setActiveAnim(hero, "claudeRun");
|
||||||
}
|
}
|
||||||
|
|
||||||
f32 heroSpeed = 6.2f * METERS_TO_PIXEL;
|
f32 heroSpeed = 6.2f * METERS_TO_PIXEL;
|
||||||
@ -1960,7 +1969,7 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
|
|||||||
{
|
{
|
||||||
hero->state = entitystate_idle;
|
hero->state = entitystate_idle;
|
||||||
world->entityIdInBattle[hero->id] = FALSE;
|
world->entityIdInBattle[hero->id] = FALSE;
|
||||||
entity_setActiveAnim(hero, "Claude_idle");
|
entity_setActiveAnim(hero, "claudeIdle");
|
||||||
}
|
}
|
||||||
hero->stats->entityIdToAttack = -1;
|
hero->stats->entityIdToAttack = -1;
|
||||||
hero->stats->actionTimer = hero->stats->actionRate;
|
hero->stats->actionTimer = hero->stats->actionRate;
|
||||||
@ -2040,15 +2049,19 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
|
|||||||
state->uiState.keyChar = keycode_null;
|
state->uiState.keyChar = keycode_null;
|
||||||
|
|
||||||
/* Draw hero avatar */
|
/* Draw hero avatar */
|
||||||
#if 0
|
TexAtlas *heroAtlas =
|
||||||
TexAtlas *heroAtlas = asset_getTextureAtlas(assetManager, texlist_hero);
|
asset_getTexAtlas(assetManager, "ClaudeSprite.png");
|
||||||
v4 heroAvatarTexRect = heroAtlas->texRect[herorects_head];
|
Rect heroAvatarRect =
|
||||||
v2 heroAvatarSize = math_getRectSize(heroAvatarTexRect);
|
asset_getAtlasSubTexRect(heroAtlas, "ClaudeSprite_Avatar_01");
|
||||||
v2 heroAvatarP =
|
v2 heroAvatarP =
|
||||||
V2(10.0f, (renderer->size.h * 0.5f) - (0.5f * heroAvatarSize.h));
|
V2(10.0f, (renderer->size.h * 0.5f) - (0.5f * heroAvatarRect.size.h));
|
||||||
|
|
||||||
|
v4 heroAvatarTexRect = {0};
|
||||||
|
heroAvatarTexRect.vec2[0] = heroAvatarRect.pos;
|
||||||
|
heroAvatarTexRect.vec2[1] = v2_add(heroAvatarRect.pos, heroAvatarRect.size);
|
||||||
|
|
||||||
RenderTex heroRenderTex = {hero->tex, heroAvatarTexRect};
|
RenderTex heroRenderTex = {hero->tex, heroAvatarTexRect};
|
||||||
renderer_staticRect(renderer, heroAvatarP, heroAvatarSize, V2(0, 0), 0,
|
renderer_staticRect(renderer, heroAvatarP, heroAvatarRect.size, V2(0, 0), 0,
|
||||||
heroRenderTex, V4(1, 1, 1, 1));
|
heroRenderTex, V4(1, 1, 1, 1));
|
||||||
|
|
||||||
char heroAvatarStr[20];
|
char heroAvatarStr[20];
|
||||||
@ -2056,13 +2069,13 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
|
|||||||
hero->stats->health, hero->stats->maxHealth);
|
hero->stats->health, hero->stats->maxHealth);
|
||||||
f32 strLenInPixels =
|
f32 strLenInPixels =
|
||||||
CAST(f32)(font->maxSize.w * common_strlen(heroAvatarStr));
|
CAST(f32)(font->maxSize.w * common_strlen(heroAvatarStr));
|
||||||
v2 strPos = V2(heroAvatarP.x, heroAvatarP.y - (0.5f * heroAvatarSize.h));
|
v2 strPos =
|
||||||
|
V2(heroAvatarP.x, heroAvatarP.y - (0.5f * heroAvatarRect.size.h));
|
||||||
renderer_staticString(&state->renderer, &state->arena, font, heroAvatarStr,
|
renderer_staticString(&state->renderer, &state->arena, font, heroAvatarStr,
|
||||||
strPos, V2(0, 0), 0, V4(0, 0, 1, 1));
|
strPos, V2(0, 0), 0, V4(0, 0, 1, 1));
|
||||||
|
|
||||||
renderer_staticString(&state->renderer, &state->arena, font, heroAvatarStr,
|
renderer_staticString(&state->renderer, &state->arena, font, heroAvatarStr,
|
||||||
strPos, V2(0, 0), 0, V4(0, 0, 1, 1));
|
strPos, V2(0, 0), 0, V4(0, 0, 1, 1));
|
||||||
#endif
|
|
||||||
|
|
||||||
for (i32 i = 0; i < world->maxEntities; i++)
|
for (i32 i = 0; i < world->maxEntities; i++)
|
||||||
{
|
{
|
||||||
@ -2092,7 +2105,7 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
|
|||||||
state->input.keys[i].newHalfTransitionCount;
|
state->input.keys[i].newHalfTransitionCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
********************
|
********************
|
||||||
* DEBUG CODE
|
* DEBUG CODE
|
||||||
********************
|
********************
|
||||||
|
@ -97,8 +97,6 @@ typedef struct Entity
|
|||||||
void entity_setActiveAnim(Entity *entity, char *animName);
|
void entity_setActiveAnim(Entity *entity, char *animName);
|
||||||
void entity_updateAnim(Entity *entity, f32 dt);
|
void entity_updateAnim(Entity *entity, f32 dt);
|
||||||
void entity_addAnim(AssetManager *assetManager, Entity *entity, char *animName);
|
void entity_addAnim(AssetManager *assetManager, Entity *entity, char *animName);
|
||||||
void entity_addGenericMob(MemoryArena *arena, AssetManager *assetManager,
|
|
||||||
World *world, v2 pos);
|
|
||||||
Entity *entity_add(MemoryArena *arena, World *world, v2 pos, v2 size,
|
Entity *entity_add(MemoryArena *arena, World *world, v2 pos, v2 size,
|
||||||
enum EntityType type, enum Direction direction, Texture *tex,
|
enum EntityType type, enum Direction direction, Texture *tex,
|
||||||
b32 collides);
|
b32 collides);
|
||||||
|
Loading…
Reference in New Issue
Block a user