Draw hero status on side with profile

Make hero texture rects start using the atlas data structure. Reduce the
number of slots for assets for now to minimise room for error.
This commit is contained in:
Doyle Thai 2016-07-16 18:51:26 +10:00
parent d74cabf5c6
commit 6c3ef63a65
2 changed files with 44 additions and 10 deletions

View File

@ -101,6 +101,13 @@ void worldTraveller_gameInit(GameState *state, v2i windowSize)
asset_loadTextureImage(assetManager,
"data/textures/WorldTraveller/TerraSprite1024.png",
texlist_hero);
TexAtlas *heroAtlas = asset_getTextureAtlas(assetManager, texlist_hero);
heroAtlas->texRect[herocoords_idle] = V4(746.0f, 1018.0f, 804.0f, 920.0f);
heroAtlas->texRect[herocoords_walkA] = V4(641.0f, 1018.0f, 699.0f, 920.0f);
heroAtlas->texRect[herocoords_walkB] = V4(849.0f, 1018.0f, 904.0f, 920.0f);
heroAtlas->texRect[herocoords_head] = V4(108.0f, 1024.0f, 159.0f, 975.0f);
heroAtlas->texRect[herocoords_waveA] = V4(944.0f, 918.0f, 1010.0f, 816.0f);
heroAtlas->texRect[herocoords_waveB] = V4(944.0f, 812.0f, 1010.0f, 710.0f);
asset_loadTextureImage(assetManager,
"data/textures/WorldTraveller/Terrain.png",
@ -198,16 +205,16 @@ void worldTraveller_gameInit(GameState *state, v2i windowSize)
f32 duration = 1.0f;
i32 numRects = 1;
v4 *heroIdleRects = PLATFORM_MEM_ALLOC(numRects, v4);
heroIdleRects[0] = V4(746.0f, 1018.0f, 804.0f, 920.0f);
heroIdleRects[0] = heroAtlas->texRect[herocoords_idle];
addAnim(hero, heroIdleRects, numRects, duration);
/* Add walking animation */
duration = 0.10f;
numRects = 3;
v4 *heroWalkRects = PLATFORM_MEM_ALLOC(numRects, v4);
heroWalkRects[0] = V4(641.0f, 1018.0f, 699.0f, 920.0f);
heroWalkRects[1] = V4(746.0f, 1018.0f, 804.0f, 920.0f);
heroWalkRects[2] = V4(849.0f, 1018.0f, 904.0f, 920.0f);
heroWalkRects[0] = heroAtlas->texRect[herocoords_walkA];
heroWalkRects[1] = heroAtlas->texRect[herocoords_idle];
heroWalkRects[2] = heroAtlas->texRect[herocoords_walkB];
addAnim(hero, heroWalkRects, numRects, duration);
/* Create a NPC */
@ -223,8 +230,8 @@ void worldTraveller_gameInit(GameState *state, v2i windowSize)
duration = 0.30f;
numRects = 2;
v4 *npcWavingRects = PLATFORM_MEM_ALLOC(numRects, v4);
npcWavingRects[0] = V4(944.0f, 918.0f, 1010.0f, 816.0f);
npcWavingRects[1] = V4(944.0f, 812.0f, 1010.0f, 710.0f);
npcWavingRects[0] = heroAtlas->texRect[herocoords_waveA];
npcWavingRects[1] = heroAtlas->texRect[herocoords_waveB];
addAnim(npc, npcWavingRects, numRects, duration);
/* Create a Mob */
@ -432,7 +439,7 @@ void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt)
if (cameraBounds.w <= world->bounds.w) cameraBounds.w = world->bounds.w;
/* Render and update loop */
/* Render entity and logic loop */
ASSERT(world->freeEntityIndex < world->maxEntities);
for (i32 i = 0; i < world->freeEntityIndex; i++)
{
@ -537,6 +544,22 @@ void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt)
#endif
}
TexAtlas *heroAtlas = asset_getTextureAtlas(assetManager, texlist_hero);
v4 heroAvatarTexRect = heroAtlas->texRect[herocoords_head];
v2 heroAvatarSize = math_getRectSize(heroAvatarTexRect);
v2 heroAvatarP =
V2(10.0f, (renderer->size.h * 0.5f) - (0.5f * heroAvatarSize.h));
renderer_rect(renderer, cameraBounds, heroAvatarP, heroAvatarSize, 0,
hero->tex, heroAvatarTexRect, V4(1, 1, 1, 1));
v4 color = V4(0, 0, 1.0f, 1);
char *heroAvatarStr = "HP: 100/100";
f32 strLenInPixels =
CAST(f32)(font->maxSize.w * common_strlen(heroAvatarStr));
v2 strPos = V2(heroAvatarP.x, heroAvatarP.y - (0.5f * heroAvatarSize.h));
renderer_staticString(&state->renderer, font, heroAvatarStr, strPos, 0,
color);
#ifdef DENGINE_DEBUG
/* Render debug info stack */
DEBUG_PUSH_STRING("Hero Pos: %06.2f, %06.2f", hero->pos, "v2");

View File

@ -27,6 +27,17 @@ enum TerrainCoords
terraincoords_count,
};
enum HeroCoords
{
herocoords_idle,
herocoords_walkA,
herocoords_walkB,
herocoords_head,
herocoords_waveA,
herocoords_waveB,
herocoords_count,
};
typedef struct TexAtlas
{
// TODO(doyle): String hash based lookup
@ -67,9 +78,9 @@ typedef struct Font
// TODO(doyle): Switch to hash based lookup
typedef struct AssetManager
{
Texture textures[256];
TexAtlas texAtlas[256];
Shader shaders[256];
Texture textures[32];
TexAtlas texAtlas[32];
Shader shaders[32];
Font font;
} AssetManager;