Map loading and rendering
This commit is contained in:
@@ -31,7 +31,7 @@ errorret_t rpgInit(void) {
|
||||
entityInit(ent, ENTITY_TYPE_PLAYER);
|
||||
RPG_CAMERA.mode = RPG_CAMERA_MODE_FOLLOW_ENTITY;
|
||||
RPG_CAMERA.followEntity.followEntityId = ent->id;
|
||||
ent->position.x = 4, ent->position.y = 4;
|
||||
ent->position.x = 0, ent->position.y = 0;
|
||||
|
||||
ent = &ENTITIES[1];
|
||||
entityInit(ent, ENTITY_TYPE_NPC);
|
||||
|
||||
@@ -26,11 +26,12 @@ void rpgCameraUpdate(void) {
|
||||
entity_t *entity = &ENTITIES[RPG_CAMERA.followEntity.followEntityId];
|
||||
if(entity->type == ENTITY_TYPE_NULL) return;
|
||||
|
||||
// Update map position to match camera.
|
||||
// Update map position to match camera. By default map wants to know the
|
||||
// top left but we want to set the center, so we need to sub half map size
|
||||
mapPositionSet(
|
||||
(int16_t)(entity->position.x / CHUNK_WIDTH),
|
||||
(int16_t)(entity->position.y / CHUNK_HEIGHT),
|
||||
(int16_t)(entity->position.z / CHUNK_DEPTH)
|
||||
(int16_t)(entity->position.x / CHUNK_WIDTH) - (MAP_CHUNK_WIDTH / 2),
|
||||
(int16_t)(entity->position.y / CHUNK_HEIGHT) - (MAP_CHUNK_HEIGHT / 2),
|
||||
(int16_t)(entity->position.z / CHUNK_DEPTH) - (MAP_CHUNK_DEPTH / 2)
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
#pragma once
|
||||
#include "rpg/world/tile.h"
|
||||
|
||||
#define CHUNK_WIDTH 16
|
||||
#define CHUNK_HEIGHT 16
|
||||
#define CHUNK_DEPTH 16
|
||||
#define CHUNK_WIDTH 4
|
||||
#define CHUNK_HEIGHT 4
|
||||
#define CHUNK_DEPTH 32
|
||||
#define CHUNK_TILE_COUNT (CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH)
|
||||
|
||||
typedef struct chunk_s {
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
#pragma once
|
||||
#include "rpg/world/chunk.h"
|
||||
|
||||
#define MAP_CHUNK_WIDTH 4
|
||||
#define MAP_CHUNK_HEIGHT 4
|
||||
#define MAP_CHUNK_DEPTH 4
|
||||
#define MAP_CHUNK_WIDTH 3
|
||||
#define MAP_CHUNK_HEIGHT 3
|
||||
#define MAP_CHUNK_DEPTH 1
|
||||
#define MAP_CHUNK_COUNT (MAP_CHUNK_WIDTH * MAP_CHUNK_HEIGHT * MAP_CHUNK_DEPTH)
|
||||
|
||||
typedef struct map_s {
|
||||
|
||||
Reference in New Issue
Block a user