entity dir
This commit is contained in:
@@ -37,6 +37,17 @@ errorret_t sceneOverworldInit(void) {
|
||||
}
|
||||
|
||||
void sceneOverworldUpdate(void) {
|
||||
// Move camera to player.
|
||||
const entity_t *start = &testMap.entities[0];
|
||||
const entity_t *end = &testMap.entities[testMap.entityCount];
|
||||
while(start < end) {
|
||||
if(start->type == ENTITY_TYPE_PLAYER) {
|
||||
SCENE_OVERWORLD.camera.lookat.target[0] = start->position[0];
|
||||
SCENE_OVERWORLD.camera.lookat.target[1] = start->position[1];
|
||||
break;
|
||||
}
|
||||
start++;
|
||||
}
|
||||
}
|
||||
|
||||
void sceneOverworldRender(void) {
|
||||
@@ -69,6 +80,7 @@ void sceneOverworldRenderMap(const map_t *map) {
|
||||
assertNotNull(map, "Map pointer cannot be NULL");
|
||||
|
||||
// Draw base layer
|
||||
sceneOverworldRenderMapLayer(map, &map->base);
|
||||
|
||||
// Draw entities
|
||||
const entity_t *start = &map->entities[0];
|
||||
@@ -78,8 +90,10 @@ void sceneOverworldRenderMap(const map_t *map) {
|
||||
sceneOverworldRenderEntity(start);
|
||||
start++;
|
||||
}
|
||||
spriteBatchFlush();
|
||||
|
||||
// Draw overlay layer.
|
||||
sceneOverworldRenderMapLayer(map, &map->overlay);
|
||||
}
|
||||
|
||||
void sceneOverworldRenderEntity(const entity_t *entity) {
|
||||
@@ -88,7 +102,7 @@ void sceneOverworldRenderEntity(const entity_t *entity) {
|
||||
assertTrue(entity->type != ENTITY_TYPE_NULL, "Cannot have NULL entity type");
|
||||
|
||||
vec4 uv;
|
||||
tilesetTileGetUV(&TILESET_ENTITIES, 0, uv);
|
||||
tilesetPositionGetUV(&TILESET_ENTITIES, entity->direction, 0, uv);
|
||||
|
||||
// For now, just draw a placeholder quad.
|
||||
spriteBatchPush(
|
||||
@@ -101,7 +115,30 @@ void sceneOverworldRenderEntity(const entity_t *entity) {
|
||||
);
|
||||
}
|
||||
|
||||
void sceneOverworldRenderMapLayer(const map_t *map, const maplayer_t *layer) {
|
||||
assertNotNull(layer, "Map layer pointer cannot be NULL");
|
||||
|
||||
for(uint32_t y = 0; y < map->height; y++) {
|
||||
for(uint32_t x = 0; x < map->width; x++) {
|
||||
const tile_t *tile = &layer->tiles[y * map->width + x];
|
||||
if(tile->id == 0) continue;
|
||||
|
||||
spriteBatchPush(
|
||||
NULL,
|
||||
x * TILESET_ENTITIES.tileWidth,
|
||||
y * TILESET_ENTITIES.tileHeight,
|
||||
(x + 1) * TILESET_ENTITIES.tileWidth,
|
||||
(y + 1) * TILESET_ENTITIES.tileHeight,
|
||||
COLOR_RED,
|
||||
0, 0, 1, 1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
spriteBatchFlush();
|
||||
}
|
||||
|
||||
void sceneOverworldDispose(void) {
|
||||
// Dispose of the overworld scene.
|
||||
if(testAsset) assetUnlock(testAsset, testAssetRef);
|
||||
}
|
||||
}
|
@@ -45,6 +45,14 @@ void sceneOverworldRenderMap(const map_t *map);
|
||||
*/
|
||||
void sceneOverworldRenderEntity(const entity_t *entity);
|
||||
|
||||
/**
|
||||
* Render a map layer in the overworld scene.
|
||||
*
|
||||
* @param map Pointer to the map the layer belongs to.
|
||||
* @param layer Pointer to the map layer to render.
|
||||
*/
|
||||
void sceneOverworldRenderMapLayer(const map_t *map, const maplayer_t *layer);
|
||||
|
||||
/**
|
||||
* Dispose of the overworld scene.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user