2016-06-28 06:00:03 +00:00
|
|
|
#include "WorldTraveller/WorldTraveller.h"
|
2016-06-16 14:14:58 +00:00
|
|
|
|
2016-07-16 13:27:52 +00:00
|
|
|
#include "Dengine/Debug.h"
|
|
|
|
#include "Dengine/Platform.h"
|
|
|
|
|
|
|
|
enum State
|
|
|
|
{
|
|
|
|
state_active,
|
|
|
|
state_menu,
|
|
|
|
state_win,
|
|
|
|
};
|
2016-06-23 08:40:00 +00:00
|
|
|
|
2016-07-17 07:16:09 +00:00
|
|
|
INTERNAL void attackEntity(Entity *attacker, Entity *defender)
|
|
|
|
{
|
|
|
|
// TODO(doyle): Use attacker stats in battle equations
|
|
|
|
defender->stats->health--;
|
|
|
|
}
|
|
|
|
|
2016-07-09 11:42:36 +00:00
|
|
|
INTERNAL Entity *addEntity(World *world, v2 pos, v2 size, enum EntityType type,
|
|
|
|
enum Direction direction, Texture *tex, b32 collides)
|
2016-07-08 07:44:41 +00:00
|
|
|
{
|
|
|
|
|
2016-07-09 10:46:04 +00:00
|
|
|
#ifdef DENGINE_DEBUG
|
2016-07-08 07:44:41 +00:00
|
|
|
ASSERT(tex && world);
|
|
|
|
ASSERT(world->freeEntityIndex < world->maxEntities);
|
2016-07-08 07:54:56 +00:00
|
|
|
ASSERT(type < entitytype_count);
|
2016-07-08 07:44:41 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
Entity entity = {0};
|
|
|
|
entity.pos = pos;
|
|
|
|
entity.size = size;
|
2016-07-08 07:54:56 +00:00
|
|
|
entity.type = type;
|
2016-07-08 07:44:41 +00:00
|
|
|
entity.direction = direction;
|
|
|
|
entity.tex = tex;
|
|
|
|
entity.collides = collides;
|
|
|
|
|
2016-07-16 10:06:52 +00:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case entitytype_hero:
|
|
|
|
case entitytype_mob:
|
|
|
|
{
|
|
|
|
entity.stats = PLATFORM_MEM_ALLOC(1, EntityStats);
|
|
|
|
entity.stats->maxHealth = 100;
|
|
|
|
entity.stats->health = entity.stats->maxHealth;
|
2016-07-17 05:27:37 +00:00
|
|
|
entity.stats->actionRate = 100;
|
|
|
|
entity.stats->actionTimer = entity.stats->actionRate;
|
|
|
|
entity.stats->actionSpdMul = 100;
|
2016-07-16 10:06:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-07-08 07:44:41 +00:00
|
|
|
world->entities[world->freeEntityIndex++] = entity;
|
|
|
|
Entity *result = &world->entities[world->freeEntityIndex-1];
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-07-17 07:16:09 +00:00
|
|
|
INTERNAL void addAnim(Entity *entity, enum EntityAnimId animId, v4 *rects,
|
|
|
|
i32 numRects, f32 duration)
|
2016-07-08 07:44:41 +00:00
|
|
|
{
|
|
|
|
|
2016-07-09 10:46:04 +00:00
|
|
|
#ifdef DENGINE_DEBUG
|
2016-07-08 07:44:41 +00:00
|
|
|
ASSERT(rects && numRects >= 0)
|
2016-07-17 07:16:09 +00:00
|
|
|
ASSERT(animId < entityanimid_count);
|
2016-07-08 07:44:41 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
EntityAnim result = {0};
|
|
|
|
result.rect = rects;
|
|
|
|
result.numRects = numRects;
|
|
|
|
result.duration = duration;
|
|
|
|
result.currDuration = duration;
|
|
|
|
|
2016-07-17 07:16:09 +00:00
|
|
|
entity->anim[animId] = result;
|
2016-07-08 07:44:41 +00:00
|
|
|
}
|
|
|
|
|
2016-07-17 13:45:59 +00:00
|
|
|
INTERNAL void rendererInit(GameState *state, v2 windowSize)
|
2016-06-16 14:14:58 +00:00
|
|
|
{
|
2016-06-29 08:23:51 +00:00
|
|
|
AssetManager *assetManager = &state->assetManager;
|
2016-07-09 06:08:03 +00:00
|
|
|
Renderer *renderer = &state->renderer;
|
2016-07-17 13:45:59 +00:00
|
|
|
renderer->size = windowSize;
|
2016-07-08 11:06:43 +00:00
|
|
|
// NOTE(doyle): Value to map a screen coordinate to NDC coordinate
|
|
|
|
renderer->vertexNdcFactor =
|
|
|
|
V2(1.0f / renderer->size.w, 1.0f / renderer->size.h);
|
|
|
|
renderer->shader = asset_getShader(assetManager, shaderlist_sprite);
|
|
|
|
shader_use(renderer->shader);
|
|
|
|
|
|
|
|
const mat4 projection =
|
|
|
|
mat4_ortho(0.0f, renderer->size.w, 0.0f, renderer->size.h, 0.0f, 1.0f);
|
|
|
|
shader_uniformSetMat4fv(renderer->shader, "projection", projection);
|
|
|
|
glCheckError();
|
|
|
|
|
|
|
|
/* Create buffers */
|
|
|
|
glGenVertexArrays(1, &renderer->vao);
|
|
|
|
glGenBuffers(1, &renderer->vbo);
|
|
|
|
glCheckError();
|
|
|
|
|
|
|
|
/* Bind buffers */
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, renderer->vbo);
|
|
|
|
glBindVertexArray(renderer->vao);
|
|
|
|
|
|
|
|
/* Configure VAO */
|
|
|
|
const GLuint numVertexElements = 4;
|
|
|
|
const GLuint vertexSize = sizeof(v4);
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
glVertexAttribPointer(0, numVertexElements, GL_FLOAT, GL_FALSE, vertexSize,
|
|
|
|
(GLvoid *)0);
|
|
|
|
glCheckError();
|
|
|
|
|
|
|
|
/* Unbind */
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
glBindVertexArray(0);
|
|
|
|
glCheckError();
|
|
|
|
|
2016-07-09 06:08:03 +00:00
|
|
|
}
|
|
|
|
|
2016-07-17 13:45:59 +00:00
|
|
|
void worldTraveller_gameInit(GameState *state, v2 windowSize)
|
2016-07-09 06:08:03 +00:00
|
|
|
{
|
|
|
|
AssetManager *assetManager = &state->assetManager;
|
|
|
|
/* Initialise assets */
|
2016-07-16 07:15:03 +00:00
|
|
|
/* Create empty 1x1 4bpp black texture */
|
|
|
|
u32 bitmap = (0xFF << 24) | (0xFF << 16) | (0xFF << 8) | (0xFF << 0);
|
|
|
|
Texture emptyTex = texture_gen(1, 1, 4, CAST(u8 *)(&bitmap));
|
|
|
|
assetManager->textures[texlist_empty] = emptyTex;
|
|
|
|
|
|
|
|
/* Load textures */
|
2016-07-09 06:08:03 +00:00
|
|
|
asset_loadTextureImage(assetManager,
|
|
|
|
"data/textures/WorldTraveller/TerraSprite1024.png",
|
|
|
|
texlist_hero);
|
2016-07-16 08:51:26 +00:00
|
|
|
TexAtlas *heroAtlas = asset_getTextureAtlas(assetManager, texlist_hero);
|
2016-07-17 09:24:19 +00:00
|
|
|
heroAtlas->texRect[herorects_idle] = V4(746, 1018, 804, 920);
|
|
|
|
heroAtlas->texRect[herorects_walkA] = V4(641, 1018, 699, 920);
|
|
|
|
heroAtlas->texRect[herorects_walkB] = V4(849, 1018, 904, 920);
|
|
|
|
heroAtlas->texRect[herorects_head] = V4(108, 1024, 159, 975);
|
|
|
|
heroAtlas->texRect[herorects_waveA] = V4(944, 918, 1010, 816);
|
|
|
|
heroAtlas->texRect[herorects_waveB] = V4(944, 812, 1010, 710);
|
|
|
|
heroAtlas->texRect[herorects_battlePose] = V4(8, 910, 71, 814);
|
|
|
|
heroAtlas->texRect[herorects_castA] = V4(428, 910, 493, 814);
|
|
|
|
heroAtlas->texRect[herorects_castB] = V4(525, 919, 590, 816);
|
|
|
|
heroAtlas->texRect[herorects_castC] = V4(640, 916, 698, 816);
|
2016-07-09 06:08:03 +00:00
|
|
|
|
|
|
|
asset_loadTextureImage(assetManager,
|
|
|
|
"data/textures/WorldTraveller/Terrain.png",
|
|
|
|
texlist_terrain);
|
|
|
|
TexAtlas *terrainAtlas =
|
|
|
|
asset_getTextureAtlas(assetManager, texlist_terrain);
|
|
|
|
f32 atlasTileSize = 128.0f;
|
2016-07-09 10:46:04 +00:00
|
|
|
const i32 texSize = 1024;
|
|
|
|
v2 texOrigin = V2(0, CAST(f32)(texSize - 128));
|
2016-07-09 06:08:03 +00:00
|
|
|
terrainAtlas->texRect[terraincoords_ground] =
|
2016-07-16 07:15:03 +00:00
|
|
|
V4(texOrigin.x, texOrigin.y, texOrigin.x + atlasTileSize,
|
|
|
|
texOrigin.y - atlasTileSize);
|
2016-07-09 06:08:03 +00:00
|
|
|
|
2016-07-16 07:15:03 +00:00
|
|
|
/* Load shaders */
|
2016-07-09 06:08:03 +00:00
|
|
|
asset_loadShaderFiles(assetManager, "data/shaders/sprite.vert.glsl",
|
2016-07-16 07:15:03 +00:00
|
|
|
"data/shaders/sprite.frag.glsl",
|
|
|
|
shaderlist_sprite);
|
2016-07-09 06:08:03 +00:00
|
|
|
|
|
|
|
asset_loadTTFont(assetManager, "C:/Windows/Fonts/Arialbd.ttf");
|
|
|
|
glCheckError();
|
|
|
|
|
|
|
|
state->state = state_active;
|
|
|
|
state->currWorldIndex = 0;
|
|
|
|
state->tileSize = 64;
|
|
|
|
|
|
|
|
/* Init renderer */
|
|
|
|
rendererInit(state, windowSize);
|
|
|
|
|
2016-07-08 06:09:18 +00:00
|
|
|
/* Init world */
|
2016-07-17 14:45:39 +00:00
|
|
|
const i32 targetWorldWidth = 100 * METERS_TO_PIXEL;
|
|
|
|
const i32 targetWorldHeight = 10 * METERS_TO_PIXEL;
|
2016-07-17 13:45:59 +00:00
|
|
|
v2 worldDimensionInTiles = V2i(targetWorldWidth / state->tileSize,
|
|
|
|
targetWorldHeight / state->tileSize);
|
2016-06-25 11:23:15 +00:00
|
|
|
|
|
|
|
for (i32 i = 0; i < ARRAY_COUNT(state->world); i++)
|
|
|
|
{
|
2016-07-08 06:09:18 +00:00
|
|
|
World *const world = &state->world[i];
|
2016-07-17 14:45:39 +00:00
|
|
|
world->maxEntities = 16384;
|
2016-07-09 11:42:36 +00:00
|
|
|
world->entities = PLATFORM_MEM_ALLOC(world->maxEntities, Entity);
|
2016-07-08 06:09:18 +00:00
|
|
|
world->texType = texlist_terrain;
|
|
|
|
|
2016-07-16 07:15:03 +00:00
|
|
|
world->bounds =
|
2016-07-17 13:45:59 +00:00
|
|
|
math_getRect(V2(0, 0), v2_scale(worldDimensionInTiles,
|
2016-07-16 07:15:03 +00:00
|
|
|
CAST(f32) state->tileSize));
|
2016-07-08 11:21:49 +00:00
|
|
|
|
2016-07-08 06:09:18 +00:00
|
|
|
TexAtlas *const atlas =
|
|
|
|
asset_getTextureAtlas(assetManager, world->texType);
|
|
|
|
|
|
|
|
for (i32 y = 0; y < worldDimensionInTiles.y; y++)
|
2016-06-25 11:23:15 +00:00
|
|
|
{
|
2016-07-08 06:09:18 +00:00
|
|
|
for (i32 x = 0; x < worldDimensionInTiles.x; x++)
|
2016-06-25 11:23:15 +00:00
|
|
|
{
|
2016-07-09 10:46:04 +00:00
|
|
|
#ifdef DENGINE_DEBUG
|
2016-07-08 06:09:18 +00:00
|
|
|
ASSERT(worldDimensionInTiles.x * worldDimensionInTiles.y <
|
|
|
|
world->maxEntities);
|
|
|
|
#endif
|
2016-07-08 07:44:41 +00:00
|
|
|
v2 pos = V2(CAST(f32) x * state->tileSize,
|
|
|
|
CAST(f32) y * state->tileSize);
|
|
|
|
v2 size =
|
2016-07-08 06:09:18 +00:00
|
|
|
V2(CAST(f32) state->tileSize, CAST(f32) state->tileSize);
|
2016-07-08 07:54:56 +00:00
|
|
|
enum EntityType type = entitytype_tile;
|
2016-07-08 07:44:41 +00:00
|
|
|
enum Direction dir = direction_null;
|
|
|
|
Texture *tex = asset_getTexture(assetManager, world->texType);
|
|
|
|
b32 collides = FALSE;
|
2016-07-08 07:54:56 +00:00
|
|
|
Entity *tile =
|
|
|
|
addEntity(world, pos, size, type, dir, tex, collides);
|
2016-07-08 07:44:41 +00:00
|
|
|
|
|
|
|
f32 duration = 1.0f;
|
|
|
|
i32 numRects = 1;
|
2016-07-09 11:42:36 +00:00
|
|
|
v4 *animRects = PLATFORM_MEM_ALLOC(numRects, v4);
|
2016-07-08 07:44:41 +00:00
|
|
|
animRects[0] = atlas->texRect[terraincoords_ground];
|
2016-07-17 07:16:09 +00:00
|
|
|
addAnim(tile, entityanimid_idle, animRects, numRects, duration);
|
2016-06-25 11:23:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-17 14:40:40 +00:00
|
|
|
|
2016-07-08 06:09:18 +00:00
|
|
|
World *const world = &state->world[state->currWorldIndex];
|
2016-07-08 11:06:43 +00:00
|
|
|
world->cameraPos = V2(0.0f, 0.0f);
|
2016-07-08 06:09:18 +00:00
|
|
|
|
2016-07-08 07:44:41 +00:00
|
|
|
/* Init hero entity */
|
|
|
|
world->heroIndex = world->freeEntityIndex;
|
|
|
|
|
2016-07-15 16:34:44 +00:00
|
|
|
Renderer *renderer = &state->renderer;
|
2016-07-08 07:54:56 +00:00
|
|
|
v2 size = V2(58.0f, 98.0f);
|
2016-07-15 16:34:44 +00:00
|
|
|
v2 pos = V2(size.x, CAST(f32) state->tileSize);
|
2016-07-08 07:54:56 +00:00
|
|
|
enum EntityType type = entitytype_hero;
|
|
|
|
enum Direction dir = direction_east;
|
|
|
|
Texture *tex = asset_getTexture(assetManager, texlist_hero);
|
|
|
|
b32 collides = TRUE;
|
|
|
|
Entity *hero = addEntity(world, pos, size, type, dir, tex, collides);
|
2016-07-08 07:44:41 +00:00
|
|
|
|
|
|
|
/* Add idle animation */
|
2016-07-08 11:06:43 +00:00
|
|
|
f32 duration = 1.0f;
|
|
|
|
i32 numRects = 1;
|
2016-07-09 11:42:36 +00:00
|
|
|
v4 *heroIdleRects = PLATFORM_MEM_ALLOC(numRects, v4);
|
2016-07-17 09:24:19 +00:00
|
|
|
heroIdleRects[0] = heroAtlas->texRect[herorects_idle];
|
2016-07-17 07:16:09 +00:00
|
|
|
addAnim(hero, entityanimid_idle, heroIdleRects, numRects, duration);
|
2016-07-17 10:24:51 +00:00
|
|
|
hero->currAnimId = entityanimid_idle;
|
2016-07-08 07:44:41 +00:00
|
|
|
|
|
|
|
/* Add walking animation */
|
2016-07-08 11:06:43 +00:00
|
|
|
duration = 0.10f;
|
|
|
|
numRects = 3;
|
2016-07-09 11:42:36 +00:00
|
|
|
v4 *heroWalkRects = PLATFORM_MEM_ALLOC(numRects, v4);
|
2016-07-17 09:24:19 +00:00
|
|
|
heroWalkRects[0] = heroAtlas->texRect[herorects_walkA];
|
|
|
|
heroWalkRects[1] = heroAtlas->texRect[herorects_idle];
|
|
|
|
heroWalkRects[2] = heroAtlas->texRect[herorects_walkB];
|
2016-07-17 07:16:09 +00:00
|
|
|
addAnim(hero, entityanimid_walk, heroWalkRects, numRects, duration);
|
|
|
|
|
|
|
|
/* Add hero waving animation */
|
|
|
|
duration = 0.30f;
|
|
|
|
numRects = 2;
|
|
|
|
v4 *heroWaveRects = PLATFORM_MEM_ALLOC(numRects, v4);
|
2016-07-17 09:24:19 +00:00
|
|
|
heroWaveRects[0] = heroAtlas->texRect[herorects_waveA];
|
|
|
|
heroWaveRects[1] = heroAtlas->texRect[herorects_waveB];
|
2016-07-17 07:16:09 +00:00
|
|
|
addAnim(hero, entityanimid_wave, heroWaveRects, numRects, duration);
|
2016-06-18 10:45:14 +00:00
|
|
|
|
2016-07-17 09:24:19 +00:00
|
|
|
/* Add hero battle stance animation */
|
|
|
|
duration = 1.0f;
|
|
|
|
numRects = 1;
|
|
|
|
v4 *heroBattlePoseRects = PLATFORM_MEM_ALLOC(numRects, v4);
|
|
|
|
heroBattlePoseRects[0] = heroAtlas->texRect[herorects_battlePose];
|
|
|
|
addAnim(hero, entityanimid_battlePose, heroBattlePoseRects, numRects,
|
|
|
|
duration);
|
|
|
|
|
|
|
|
/* Add hero battle tackle animation */
|
2016-07-17 13:45:59 +00:00
|
|
|
duration = 0.15f;
|
2016-07-17 09:24:19 +00:00
|
|
|
numRects = 3;
|
|
|
|
v4 *heroTackleRects = PLATFORM_MEM_ALLOC(numRects, v4);
|
|
|
|
heroTackleRects[0] = heroAtlas->texRect[herorects_castA];
|
|
|
|
heroTackleRects[1] = heroAtlas->texRect[herorects_castB];
|
|
|
|
heroTackleRects[2] = heroAtlas->texRect[herorects_castC];
|
|
|
|
addAnim(hero, entityanimid_tackle, heroTackleRects, numRects,
|
|
|
|
duration);
|
|
|
|
|
2016-06-23 08:40:00 +00:00
|
|
|
/* Create a NPC */
|
2016-07-15 16:34:44 +00:00
|
|
|
pos = V2(hero->pos.x * 3, CAST(f32) state->tileSize);
|
2016-07-08 07:44:41 +00:00
|
|
|
size = hero->size;
|
2016-07-12 08:11:31 +00:00
|
|
|
type = entitytype_npc;
|
2016-07-08 07:44:41 +00:00
|
|
|
dir = direction_null;
|
|
|
|
tex = hero->tex;
|
2016-07-12 08:11:31 +00:00
|
|
|
collides = FALSE;
|
2016-07-08 07:54:56 +00:00
|
|
|
Entity *npc = addEntity(world, pos, size, type, dir, tex, collides);
|
2016-07-08 07:44:41 +00:00
|
|
|
|
|
|
|
/* Add npc waving animation */
|
2016-07-17 07:16:09 +00:00
|
|
|
duration = 0.30f;
|
|
|
|
numRects = 2;
|
2016-07-09 11:42:36 +00:00
|
|
|
v4 *npcWavingRects = PLATFORM_MEM_ALLOC(numRects, v4);
|
2016-07-17 09:24:19 +00:00
|
|
|
npcWavingRects[0] = heroAtlas->texRect[herorects_waveA];
|
|
|
|
npcWavingRects[1] = heroAtlas->texRect[herorects_waveB];
|
2016-07-17 07:16:09 +00:00
|
|
|
addAnim(npc, entityanimid_wave, npcWavingRects, numRects, duration);
|
2016-07-17 10:24:51 +00:00
|
|
|
npc->currAnimId = entityanimid_wave;
|
2016-06-18 10:45:14 +00:00
|
|
|
|
2016-07-12 08:11:31 +00:00
|
|
|
/* Create a Mob */
|
|
|
|
pos = V2(renderer->size.w - (renderer->size.w / 3.0f),
|
|
|
|
CAST(f32) state->tileSize);
|
|
|
|
size = hero->size;
|
|
|
|
type = entitytype_mob;
|
|
|
|
dir = direction_west;
|
|
|
|
tex = hero->tex;
|
|
|
|
collides = TRUE;
|
|
|
|
Entity *mob = addEntity(world, pos, size, type, dir, tex, collides);
|
|
|
|
|
|
|
|
/* Add mob idle animation */
|
|
|
|
duration = 1.0f;
|
|
|
|
numRects = 1;
|
|
|
|
v4 *mobIdleRects = PLATFORM_MEM_ALLOC(numRects, v4);
|
|
|
|
mobIdleRects[0] = heroIdleRects[0];
|
2016-07-17 07:16:09 +00:00
|
|
|
addAnim(mob, entityanimid_idle, mobIdleRects, numRects, duration);
|
2016-07-17 10:24:51 +00:00
|
|
|
mob->currAnimId = entityanimid_idle;
|
2016-07-12 08:11:31 +00:00
|
|
|
|
|
|
|
/* Add mob walking animation */
|
|
|
|
duration = 0.10f;
|
|
|
|
numRects = 3;
|
|
|
|
v4 *mobWalkRects = PLATFORM_MEM_ALLOC(numRects, v4);
|
|
|
|
mobWalkRects[0] = heroWalkRects[0];
|
|
|
|
mobWalkRects[1] = heroWalkRects[1];
|
|
|
|
mobWalkRects[2] = heroWalkRects[2];
|
2016-07-17 07:16:09 +00:00
|
|
|
addAnim(mob, entityanimid_walk, mobWalkRects, numRects, duration);
|
|
|
|
}
|
2016-07-12 08:11:31 +00:00
|
|
|
|
2016-07-17 09:24:19 +00:00
|
|
|
INTERNAL inline void setActiveEntityAnim(Entity *entity,
|
|
|
|
enum EntityAnimId animId)
|
2016-07-17 07:16:09 +00:00
|
|
|
{
|
2016-07-17 09:24:19 +00:00
|
|
|
#ifdef DENGINE_DEBUG
|
|
|
|
ASSERT(animId < entityanimid_count);
|
|
|
|
ASSERT(entity->anim[animId].rect);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Reset current anim data */
|
2016-07-17 10:24:51 +00:00
|
|
|
EntityAnim *currAnim = &entity->anim[entity->currAnimId];
|
2016-07-17 07:16:09 +00:00
|
|
|
currAnim->currDuration = currAnim->duration;
|
|
|
|
currAnim->currRectIndex = 0;
|
2016-07-17 09:24:19 +00:00
|
|
|
|
|
|
|
/* Set entity active animation */
|
2016-07-17 10:24:51 +00:00
|
|
|
entity->currAnimId = animId;
|
|
|
|
entity->currAnimCyclesCompleted = 0;
|
2016-06-16 14:14:58 +00:00
|
|
|
}
|
|
|
|
|
2016-06-17 14:40:40 +00:00
|
|
|
INTERNAL void parseInput(GameState *state, const f32 dt)
|
2016-06-16 14:14:58 +00:00
|
|
|
{
|
2016-06-17 08:11:23 +00:00
|
|
|
/*
|
|
|
|
Equations of Motion
|
|
|
|
f(t) = position m
|
|
|
|
f'(t) = velocity m/s
|
|
|
|
f"(t) = acceleration m/s^2
|
|
|
|
|
|
|
|
The user supplies an acceleration, a, and by integrating
|
|
|
|
f"(t) = a, where a is a constant, acceleration
|
|
|
|
f'(t) = a*t + v, where v is a constant, old velocity
|
|
|
|
f (t) = (a/2)*t^2 + v*t + p, where p is a constant, old position
|
|
|
|
*/
|
|
|
|
|
2016-07-08 06:09:18 +00:00
|
|
|
World *const world = &state->world[state->currWorldIndex];
|
2016-07-17 07:16:09 +00:00
|
|
|
Entity *hero = &world->entities[world->heroIndex];
|
|
|
|
v2 ddPos = V2(0, 0);
|
2016-06-16 14:14:58 +00:00
|
|
|
|
2016-07-17 07:16:09 +00:00
|
|
|
// TODO(doyle): As we need to handle more key spam input, we want to track
|
|
|
|
// if a button ended down
|
|
|
|
LOCAL_PERSIST b32 spaceBarWasDown = FALSE;
|
2016-06-16 14:14:58 +00:00
|
|
|
|
2016-06-17 14:40:40 +00:00
|
|
|
if (state->keys[GLFW_KEY_RIGHT])
|
2016-06-16 14:14:58 +00:00
|
|
|
{
|
2016-06-17 08:11:23 +00:00
|
|
|
ddPos.x = 1.0f;
|
2016-06-23 08:40:00 +00:00
|
|
|
hero->direction = direction_east;
|
2016-06-17 08:11:23 +00:00
|
|
|
}
|
2016-07-17 10:24:51 +00:00
|
|
|
|
2016-06-17 14:40:40 +00:00
|
|
|
if (state->keys[GLFW_KEY_LEFT])
|
2016-06-17 08:11:23 +00:00
|
|
|
{
|
|
|
|
ddPos.x = -1.0f;
|
2016-06-23 08:40:00 +00:00
|
|
|
hero->direction = direction_west;
|
2016-06-17 08:11:23 +00:00
|
|
|
}
|
|
|
|
|
2016-06-17 14:40:40 +00:00
|
|
|
if (state->keys[GLFW_KEY_UP])
|
2016-06-17 08:11:23 +00:00
|
|
|
{
|
|
|
|
ddPos.y = 1.0f;
|
2016-06-16 14:14:58 +00:00
|
|
|
}
|
2016-07-17 07:16:09 +00:00
|
|
|
|
2016-06-17 14:40:40 +00:00
|
|
|
if (state->keys[GLFW_KEY_DOWN])
|
2016-06-16 14:14:58 +00:00
|
|
|
{
|
2016-06-17 08:11:23 +00:00
|
|
|
ddPos.y = -1.0f;
|
2016-06-16 14:14:58 +00:00
|
|
|
}
|
2016-06-17 08:11:23 +00:00
|
|
|
|
|
|
|
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
|
2016-06-18 09:12:09 +00:00
|
|
|
ddPos = v2_scale(ddPos, 0.70710678118f);
|
2016-06-17 08:11:23 +00:00
|
|
|
}
|
|
|
|
|
2016-07-17 14:45:39 +00:00
|
|
|
if (state->keys[GLFW_KEY_SPACE] && !spaceBarWasDown)
|
|
|
|
{
|
|
|
|
if (!(hero->currAnimId == entityanimid_tackle &&
|
|
|
|
hero->currAnimCyclesCompleted == 0))
|
|
|
|
{
|
|
|
|
spaceBarWasDown = TRUE;
|
|
|
|
setActiveEntityAnim(hero, entityanimid_tackle);
|
|
|
|
|
|
|
|
if (hero->direction == direction_east)
|
2016-07-17 14:54:21 +00:00
|
|
|
{
|
2016-07-17 14:45:39 +00:00
|
|
|
ddPos.x = 1.0f;
|
2016-07-17 14:54:21 +00:00
|
|
|
hero->dPos.x += (1.0f * METERS_TO_PIXEL);
|
|
|
|
}
|
2016-07-17 14:45:39 +00:00
|
|
|
else
|
2016-07-17 14:54:21 +00:00
|
|
|
{
|
2016-07-17 14:45:39 +00:00
|
|
|
ddPos.x = -1.0f;
|
2016-07-17 14:54:21 +00:00
|
|
|
hero->dPos.x -= (1.0f * METERS_TO_PIXEL);
|
|
|
|
}
|
2016-07-17 14:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!state->keys[GLFW_KEY_SPACE])
|
|
|
|
{
|
|
|
|
spaceBarWasDown = FALSE;
|
|
|
|
}
|
|
|
|
|
2016-07-08 06:09:18 +00:00
|
|
|
// NOTE(doyle): Clipping threshold for snapping velocity to 0
|
2016-07-17 14:45:39 +00:00
|
|
|
f32 epsilon = 0.5f;
|
2016-06-23 11:34:38 +00:00
|
|
|
v2 epsilonDpos = v2_sub(V2(epsilon, epsilon),
|
2016-07-14 13:15:42 +00:00
|
|
|
V2(ABS(hero->dPos.x), ABS(hero->dPos.y)));
|
2016-07-17 07:16:09 +00:00
|
|
|
|
2016-06-23 11:34:38 +00:00
|
|
|
if (epsilonDpos.x >= 0.0f && epsilonDpos.y >= 0.0f)
|
|
|
|
{
|
|
|
|
hero->dPos = V2(0.0f, 0.0f);
|
2016-07-17 10:24:51 +00:00
|
|
|
if (hero->currAnimId == entityanimid_walk)
|
2016-06-23 11:34:38 +00:00
|
|
|
{
|
2016-07-17 09:24:19 +00:00
|
|
|
setActiveEntityAnim(hero, entityanimid_idle);
|
2016-06-23 11:34:38 +00:00
|
|
|
}
|
2016-06-25 09:12:25 +00:00
|
|
|
}
|
2016-07-17 10:24:51 +00:00
|
|
|
else if (hero->currAnimId == entityanimid_idle)
|
2016-06-23 11:34:38 +00:00
|
|
|
{
|
2016-07-17 09:24:19 +00:00
|
|
|
setActiveEntityAnim(hero, entityanimid_walk);
|
2016-06-23 11:34:38 +00:00
|
|
|
}
|
|
|
|
|
2016-07-17 14:45:39 +00:00
|
|
|
f32 heroSpeed = 6.2f * METERS_TO_PIXEL;
|
2016-06-17 14:40:40 +00:00
|
|
|
if (state->keys[GLFW_KEY_LEFT_SHIFT])
|
2016-07-08 11:21:49 +00:00
|
|
|
heroSpeed = CAST(f32)(22.0f * 10.0f * METERS_TO_PIXEL);
|
2016-06-17 08:11:23 +00:00
|
|
|
|
2016-07-17 14:45:39 +00:00
|
|
|
ddPos = v2_scale(ddPos, heroSpeed);
|
2016-06-17 08:11:23 +00:00
|
|
|
// TODO(doyle): Counteracting force on player's acceleration is arbitrary
|
2016-06-18 09:12:09 +00:00
|
|
|
ddPos = v2_sub(ddPos, v2_scale(hero->dPos, 5.5f));
|
2016-06-17 08:11:23 +00:00
|
|
|
|
2016-06-18 09:12:09 +00:00
|
|
|
/*
|
|
|
|
NOTE(doyle): Calculate new position from acceleration with old velocity
|
|
|
|
new Position = (a/2) * (t^2) + (v*t) + p,
|
|
|
|
acceleration = (a/2) * (t^2)
|
|
|
|
old velocity = (v*t)
|
|
|
|
*/
|
2016-07-14 13:15:42 +00:00
|
|
|
v2 ddPosNew = v2_scale(v2_scale(ddPos, 0.5f), SQUARED(dt));
|
2016-06-18 09:12:09 +00:00
|
|
|
v2 dPos = v2_scale(hero->dPos, dt);
|
|
|
|
v2 newHeroP = v2_add(v2_add(ddPosNew, dPos), hero->pos);
|
2016-06-17 08:11:23 +00:00
|
|
|
|
2016-07-08 06:09:18 +00:00
|
|
|
// TODO(doyle): Only check collision for entities within small bounding box
|
|
|
|
// of the hero
|
2016-06-25 09:12:25 +00:00
|
|
|
b32 heroCollided = FALSE;
|
|
|
|
if (hero->collides == TRUE)
|
|
|
|
{
|
2016-07-08 06:09:18 +00:00
|
|
|
for (i32 i = 0; i < world->maxEntities; i++)
|
2016-06-25 09:12:25 +00:00
|
|
|
{
|
2016-07-08 06:09:18 +00:00
|
|
|
if (i == world->heroIndex) continue;
|
|
|
|
Entity entity = world->entities[i];
|
2016-06-25 09:12:25 +00:00
|
|
|
if (entity.collides)
|
|
|
|
{
|
|
|
|
v4 heroRect =
|
|
|
|
V4(newHeroP.x, newHeroP.y, (newHeroP.x + hero->size.x),
|
|
|
|
(newHeroP.y + hero->size.y));
|
|
|
|
v4 entityRect = getEntityScreenRect(entity);
|
|
|
|
|
|
|
|
if (((heroRect.z >= entityRect.x && heroRect.z <= entityRect.z) ||
|
|
|
|
(heroRect.x >= entityRect.x && heroRect.x <= entityRect.z)) &&
|
|
|
|
((heroRect.w <= entityRect.y && heroRect.w >= entityRect.w) ||
|
|
|
|
(heroRect.y <= entityRect.y && heroRect.y >= entityRect.w)))
|
|
|
|
{
|
|
|
|
heroCollided = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (heroCollided)
|
|
|
|
{
|
|
|
|
hero->dPos = V2(0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// f'(t) = curr velocity = a*t + v, where v is old velocity
|
|
|
|
hero->dPos = v2_add(hero->dPos, v2_scale(ddPos, dt));
|
|
|
|
hero->pos = newHeroP;
|
2016-07-08 11:06:43 +00:00
|
|
|
|
|
|
|
v2 offsetFromHeroToOrigin =
|
|
|
|
V2((hero->pos.x - (0.5f * state->renderer.size.w)), (0.0f));
|
|
|
|
|
|
|
|
// NOTE(doyle): Hero position is offset to the center so -recenter it
|
|
|
|
offsetFromHeroToOrigin.x += (hero->size.x * 0.5f);
|
|
|
|
world->cameraPos = offsetFromHeroToOrigin;
|
2016-06-25 09:12:25 +00:00
|
|
|
}
|
2016-06-16 14:14:58 +00:00
|
|
|
}
|
|
|
|
|
2016-07-17 09:24:19 +00:00
|
|
|
INTERNAL void updateEntityAnim(Entity *entity, f32 dt)
|
|
|
|
{
|
2016-07-17 10:24:51 +00:00
|
|
|
EntityAnim *anim = &entity->anim[entity->currAnimId];
|
2016-07-17 09:24:19 +00:00
|
|
|
v4 texRect = anim->rect[anim->currRectIndex];
|
|
|
|
|
|
|
|
anim->currDuration -= dt;
|
|
|
|
if (anim->currDuration <= 0.0f)
|
|
|
|
{
|
2016-07-17 10:24:51 +00:00
|
|
|
if (++anim->currRectIndex >= anim->numRects)
|
|
|
|
entity->currAnimCyclesCompleted++;
|
|
|
|
|
2016-07-17 09:24:19 +00:00
|
|
|
anim->currRectIndex = anim->currRectIndex % anim->numRects;
|
|
|
|
texRect = anim->rect[anim->currRectIndex];
|
|
|
|
anim->currDuration = anim->duration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-17 14:40:40 +00:00
|
|
|
void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt)
|
2016-06-16 14:14:58 +00:00
|
|
|
{
|
2016-06-17 14:40:40 +00:00
|
|
|
/* Update */
|
|
|
|
parseInput(state, dt);
|
|
|
|
glCheckError();
|
|
|
|
|
2016-06-29 08:23:51 +00:00
|
|
|
AssetManager *assetManager = &state->assetManager;
|
2016-06-29 10:44:35 +00:00
|
|
|
Renderer *renderer = &state->renderer;
|
2016-07-15 16:34:44 +00:00
|
|
|
World *const world = &state->world[state->currWorldIndex];
|
|
|
|
Entity *hero = &world->entities[world->heroIndex];
|
|
|
|
#ifdef DENGINE_DEBUG
|
|
|
|
Font *font = &assetManager->font;
|
|
|
|
#endif
|
2016-06-29 08:23:51 +00:00
|
|
|
|
2016-07-15 16:34:44 +00:00
|
|
|
/* Recalculate rendering bounds */
|
2016-07-16 07:15:03 +00:00
|
|
|
v4 cameraBounds = math_getRect(world->cameraPos, renderer->size);
|
2016-07-08 11:21:49 +00:00
|
|
|
// NOTE(doyle): Lock camera if it passes the bounds of the world
|
|
|
|
if (cameraBounds.x <= world->bounds.x)
|
|
|
|
{
|
|
|
|
cameraBounds.x = world->bounds.x;
|
|
|
|
cameraBounds.z = cameraBounds.x + renderer->size.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(doyle): Do the Y component when we need it
|
|
|
|
if (cameraBounds.y >= world->bounds.y) cameraBounds.y = world->bounds.y;
|
|
|
|
|
|
|
|
if (cameraBounds.z >= world->bounds.z)
|
|
|
|
{
|
|
|
|
cameraBounds.z = world->bounds.z;
|
|
|
|
cameraBounds.x = cameraBounds.z - renderer->size.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cameraBounds.w <= world->bounds.w) cameraBounds.w = world->bounds.w;
|
|
|
|
|
2016-07-17 14:54:21 +00:00
|
|
|
/* Update and render entity loop */
|
2016-07-15 16:34:44 +00:00
|
|
|
ASSERT(world->freeEntityIndex < world->maxEntities);
|
2016-07-08 06:09:18 +00:00
|
|
|
for (i32 i = 0; i < world->freeEntityIndex; i++)
|
2016-06-18 16:16:16 +00:00
|
|
|
{
|
2016-07-17 14:54:21 +00:00
|
|
|
/* Game logic */
|
|
|
|
Entity *const entity = &world->entities[i];
|
2016-07-17 10:24:51 +00:00
|
|
|
u32 oldAnimCycleCount = entity->currAnimCyclesCompleted;
|
2016-07-17 09:24:19 +00:00
|
|
|
updateEntityAnim(entity, dt);
|
|
|
|
|
|
|
|
v2 entityRenderSize = entity->size;
|
2016-07-17 14:54:21 +00:00
|
|
|
if (entity->type == entitytype_hero)
|
2016-07-14 13:15:42 +00:00
|
|
|
{
|
2016-07-17 10:24:51 +00:00
|
|
|
#ifdef DENGINE_DEBUG
|
2016-07-17 14:54:21 +00:00
|
|
|
DEBUG_PUSH_STRING("HeroAnimCycleCount: %d",
|
|
|
|
entity->currAnimCyclesCompleted, "i32");
|
2016-07-17 10:24:51 +00:00
|
|
|
#endif
|
2016-07-17 14:54:21 +00:00
|
|
|
// NOTE(doyle): If dynamic entity, allow animations to exceed
|
|
|
|
// the actual hitbox of character
|
|
|
|
EntityAnim *anim = &entity->anim[entity->currAnimId];
|
|
|
|
v4 texRect = anim->rect[anim->currRectIndex];
|
|
|
|
entityRenderSize = math_getRectSize(texRect);
|
2016-07-17 10:24:51 +00:00
|
|
|
|
2016-07-17 14:54:21 +00:00
|
|
|
if (oldAnimCycleCount != entity->currAnimCyclesCompleted)
|
|
|
|
{
|
|
|
|
if (entity->currAnimId == entityanimid_tackle)
|
2016-07-17 10:24:51 +00:00
|
|
|
{
|
2016-07-17 14:54:21 +00:00
|
|
|
setActiveEntityAnim(entity, entityanimid_idle);
|
|
|
|
if (hero->direction == direction_east)
|
|
|
|
hero->dPos.x -= (1.0f * METERS_TO_PIXEL);
|
|
|
|
else
|
|
|
|
hero->dPos.x += (1.0f * METERS_TO_PIXEL);
|
|
|
|
}
|
|
|
|
}
|
2016-07-14 13:15:42 +00:00
|
|
|
}
|
2016-07-17 05:27:37 +00:00
|
|
|
// TODO(doyle): Undefined behaviour when multiple entities on screen
|
2016-07-17 14:54:21 +00:00
|
|
|
else if (entity->type == entitytype_mob)
|
2016-07-15 16:34:44 +00:00
|
|
|
{
|
|
|
|
// TODO(doyle): Currently calculated in pixels, how about meaningful
|
|
|
|
// game units?
|
|
|
|
f32 distance = v2_magnitude(hero->pos, entity->pos);
|
|
|
|
#ifdef DENGINE_DEBUG
|
|
|
|
DEBUG_PUSH_STRING("Hero to Entity Magnitude: %06.2f", distance,
|
|
|
|
"f32");
|
|
|
|
#endif
|
2016-07-17 05:27:37 +00:00
|
|
|
f32 battleThreshold = 500.0f;
|
|
|
|
if (distance <= battleThreshold)
|
2016-07-15 16:34:44 +00:00
|
|
|
{
|
|
|
|
#ifdef DENGINE_DEBUG
|
|
|
|
v4 color = V4(1.0f, 0, 0, 1);
|
|
|
|
char *battleStr = "IN-BATTLE RANGE";
|
|
|
|
f32 strLenInPixels =
|
|
|
|
CAST(f32)(font->maxSize.w * common_strlen(battleStr));
|
|
|
|
v2 strPos =
|
|
|
|
V2((renderer->size.w * 0.5f) - (strLenInPixels * 0.5f),
|
|
|
|
renderer->size.h - 300.0f);
|
|
|
|
renderer_staticString(&state->renderer, font, battleStr, strPos,
|
|
|
|
0, color);
|
|
|
|
#endif
|
2016-07-17 05:27:37 +00:00
|
|
|
/* Render targetting reticule */
|
2016-07-16 07:15:03 +00:00
|
|
|
Texture *emptyTex =
|
|
|
|
asset_getTexture(assetManager, texlist_empty);
|
2016-07-16 07:41:17 +00:00
|
|
|
v2 heroCenter = v2_add(hero->pos, v2_scale(hero->size, 0.5f));
|
2016-07-16 10:21:49 +00:00
|
|
|
|
|
|
|
RenderTex renderTex = {emptyTex, V4(0, 1, 1, 0)};
|
2016-07-16 07:41:17 +00:00
|
|
|
renderer_rect(renderer, cameraBounds, heroCenter,
|
2016-07-17 07:16:09 +00:00
|
|
|
V2(distance, 5.0f), 0, renderTex,
|
|
|
|
V4(1, 0, 0, 0.25f));
|
2016-07-17 05:27:37 +00:00
|
|
|
|
|
|
|
/* Update action timer */
|
|
|
|
#ifdef DENGINE_DEBUG
|
|
|
|
ASSERT(entity->stats)
|
|
|
|
#endif
|
2016-07-17 09:24:19 +00:00
|
|
|
setActiveEntityAnim(hero, entityanimid_battlePose);
|
2016-07-17 07:16:09 +00:00
|
|
|
|
2016-07-17 05:27:37 +00:00
|
|
|
hero->stats->actionTimer -= dt * hero->stats->actionSpdMul;
|
|
|
|
entity->stats->actionTimer -= dt * entity->stats->actionSpdMul;
|
2016-07-17 07:16:09 +00:00
|
|
|
|
|
|
|
if (hero->stats->health > 0)
|
2016-07-17 05:27:37 +00:00
|
|
|
{
|
2016-07-17 07:16:09 +00:00
|
|
|
if (hero->stats->actionTimer <= 0)
|
|
|
|
{
|
|
|
|
//attackEntity(hero, entity);
|
|
|
|
hero->stats->actionTimer = hero->stats->actionRate;
|
|
|
|
}
|
2016-07-17 05:27:37 +00:00
|
|
|
}
|
|
|
|
|
2016-07-17 07:16:09 +00:00
|
|
|
if (entity->stats->health > 0)
|
2016-07-17 05:27:37 +00:00
|
|
|
{
|
2016-07-17 07:16:09 +00:00
|
|
|
if (entity->stats->actionTimer <= 0)
|
|
|
|
{
|
|
|
|
entity->stats->actionTimer = entity->stats->actionRate;
|
|
|
|
}
|
2016-07-17 05:27:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
entity->stats->actionTimer = entity->stats->actionRate;
|
|
|
|
hero->stats->actionTimer = hero->stats->actionRate;
|
2016-07-15 16:34:44 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-12 08:11:31 +00:00
|
|
|
|
2016-07-17 14:54:21 +00:00
|
|
|
f32 rotate = 0.0f;
|
|
|
|
renderer_entity(&state->renderer, cameraBounds, entity,
|
|
|
|
entityRenderSize, rotate, V4(1, 1, 1, 1));
|
|
|
|
|
2016-07-12 08:11:31 +00:00
|
|
|
#ifdef DENGINE_DEBUG
|
2016-07-15 16:34:44 +00:00
|
|
|
/* Render debug markers on entities */
|
|
|
|
v4 color = V4(1, 1, 1, 1);
|
2016-07-12 08:11:31 +00:00
|
|
|
char *debugString = NULL;
|
2016-07-15 16:34:44 +00:00
|
|
|
switch (entity->type)
|
2016-07-12 08:11:31 +00:00
|
|
|
{
|
2016-07-16 10:06:52 +00:00
|
|
|
case entitytype_mob:
|
2016-07-15 16:34:44 +00:00
|
|
|
color = V4(1, 0, 0, 1);
|
|
|
|
debugString = "MOB";
|
|
|
|
break;
|
|
|
|
|
2016-07-16 10:06:52 +00:00
|
|
|
case entitytype_hero:
|
2016-07-15 16:34:44 +00:00
|
|
|
color = V4(0, 0, 1.0f, 1);
|
|
|
|
debugString = "HERO";
|
|
|
|
break;
|
|
|
|
|
2016-07-16 10:06:52 +00:00
|
|
|
case entitytype_npc:
|
2016-07-15 16:34:44 +00:00
|
|
|
color = V4(0, 1.0f, 0, 1);
|
|
|
|
debugString = "NPC";
|
|
|
|
break;
|
|
|
|
|
2016-07-16 10:06:52 +00:00
|
|
|
default:
|
2016-07-15 16:34:44 +00:00
|
|
|
break;
|
2016-07-12 08:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (debugString)
|
|
|
|
{
|
2016-07-15 16:34:44 +00:00
|
|
|
v2 strPos = v2_add(entity->pos, entity->size);
|
2016-07-17 13:45:59 +00:00
|
|
|
i32 indexOfLowerAInMetrics = 'a' - CAST(i32)font->codepointRange.x;
|
2016-07-12 08:11:31 +00:00
|
|
|
strPos.y += font->charMetrics[indexOfLowerAInMetrics].offset.y;
|
|
|
|
|
|
|
|
renderer_string(&state->renderer, cameraBounds, font, debugString,
|
|
|
|
strPos, 0, color);
|
|
|
|
|
|
|
|
f32 stringLineGap = 1.1f * asset_getVFontSpacing(font->metrics);
|
|
|
|
strPos.y -= GLOBAL_debugState.stringLineGap;
|
|
|
|
|
2016-07-16 10:06:52 +00:00
|
|
|
char entityPosStr[128];
|
2016-07-12 08:11:31 +00:00
|
|
|
snprintf(entityPosStr, ARRAY_COUNT(entityPosStr), "%06.2f, %06.2f",
|
|
|
|
entity->pos.x, entity->pos.y);
|
|
|
|
renderer_string(&state->renderer, cameraBounds, font, entityPosStr,
|
|
|
|
strPos, 0, color);
|
2016-07-15 16:34:44 +00:00
|
|
|
|
|
|
|
strPos.y -= GLOBAL_debugState.stringLineGap;
|
2016-07-16 10:06:52 +00:00
|
|
|
char entityIDStr[32];
|
2016-07-15 16:34:44 +00:00
|
|
|
snprintf(entityIDStr, ARRAY_COUNT(entityIDStr), "ID: %4d/%d", i,
|
|
|
|
world->maxEntities);
|
|
|
|
renderer_string(&state->renderer, cameraBounds, font, entityIDStr,
|
|
|
|
strPos, 0, color);
|
2016-07-16 10:06:52 +00:00
|
|
|
|
|
|
|
if (entity->stats)
|
|
|
|
{
|
|
|
|
strPos.y -= GLOBAL_debugState.stringLineGap;
|
|
|
|
char entityHealth[32];
|
|
|
|
snprintf(entityHealth, ARRAY_COUNT(entityHealth), "HP: %3.0f/%3.0f",
|
|
|
|
entity->stats->health, entity->stats->maxHealth);
|
|
|
|
renderer_string(&state->renderer, cameraBounds, font,
|
|
|
|
entityHealth, strPos, 0, color);
|
2016-07-17 05:27:37 +00:00
|
|
|
|
|
|
|
strPos.y -= GLOBAL_debugState.stringLineGap;
|
|
|
|
char entityTimer[32];
|
|
|
|
snprintf(entityTimer, ARRAY_COUNT(entityTimer), "ATB: %3.0f/%3.0f",
|
|
|
|
entity->stats->actionTimer, entity->stats->actionRate);
|
|
|
|
renderer_string(&state->renderer, cameraBounds, font,
|
|
|
|
entityTimer, strPos, 0, color);
|
2016-07-16 10:06:52 +00:00
|
|
|
}
|
2016-07-12 08:11:31 +00:00
|
|
|
}
|
|
|
|
#endif
|
2016-06-23 08:40:00 +00:00
|
|
|
}
|
2016-06-18 14:34:20 +00:00
|
|
|
|
2016-07-16 08:51:26 +00:00
|
|
|
TexAtlas *heroAtlas = asset_getTextureAtlas(assetManager, texlist_hero);
|
2016-07-17 09:24:19 +00:00
|
|
|
v4 heroAvatarTexRect = heroAtlas->texRect[herorects_head];
|
2016-07-16 08:51:26 +00:00
|
|
|
v2 heroAvatarSize = math_getRectSize(heroAvatarTexRect);
|
|
|
|
v2 heroAvatarP =
|
|
|
|
V2(10.0f, (renderer->size.h * 0.5f) - (0.5f * heroAvatarSize.h));
|
2016-07-16 10:21:49 +00:00
|
|
|
|
|
|
|
RenderTex heroRenderTex = {hero->tex, heroAvatarTexRect};
|
2016-07-16 11:08:30 +00:00
|
|
|
renderer_staticRect(renderer, heroAvatarP, heroAvatarSize, 0, heroRenderTex,
|
|
|
|
V4(1, 1, 1, 1));
|
2016-07-16 08:51:26 +00:00
|
|
|
|
|
|
|
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,
|
2016-07-16 11:08:30 +00:00
|
|
|
V4(0, 0, 1, 1));
|
2016-07-16 08:51:26 +00:00
|
|
|
|
2016-07-09 10:46:04 +00:00
|
|
|
#ifdef DENGINE_DEBUG
|
2016-07-15 16:34:44 +00:00
|
|
|
/* Render debug info stack */
|
|
|
|
DEBUG_PUSH_STRING("Hero Pos: %06.2f, %06.2f", hero->pos, "v2");
|
|
|
|
DEBUG_PUSH_STRING("Hero dPos: %06.2f, %06.2f", hero->dPos, "v2");
|
|
|
|
DEBUG_PUSH_STRING("FreeEntityIndex: %d", world->freeEntityIndex, "i32");
|
2016-07-09 10:59:54 +00:00
|
|
|
|
|
|
|
DEBUG_PUSH_STRING("glDrawArray Calls: %d",
|
2016-07-15 16:34:44 +00:00
|
|
|
GLOBAL_debugState.callCount[debugcallcount_drawArrays],
|
2016-07-09 10:59:54 +00:00
|
|
|
"i32");
|
2016-07-09 11:42:36 +00:00
|
|
|
|
|
|
|
i32 debug_kbAllocated = GLOBAL_debugState.totalMemoryAllocated / 1024;
|
2016-07-15 16:34:44 +00:00
|
|
|
DEBUG_PUSH_STRING("TotalMemoryAllocated: %dkb", debug_kbAllocated, "i32");
|
2016-07-09 10:46:04 +00:00
|
|
|
debug_stringUpdateAndRender(&state->renderer, font, dt);
|
2016-07-09 10:59:54 +00:00
|
|
|
debug_clearCallCounter();
|
2016-07-08 04:37:18 +00:00
|
|
|
#endif
|
2016-06-16 14:14:58 +00:00
|
|
|
}
|