diff --git a/src/display/camera.c b/src/display/camera.c index d60507e..abccd9a 100644 --- a/src/display/camera.c +++ b/src/display/camera.c @@ -20,7 +20,7 @@ void cameraInitPerspective(camera_t *camera) { camera->projType = CAMERA_PROJECTION_TYPE_PERSPECTIVE; camera->perspective.fov = glm_rad(45.0f); camera->nearClip = 0.1f; - camera->farClip = 100.0f; + camera->farClip = 10000.0f; camera->viewType = CAMERA_VIEW_TYPE_LOOKAT; glm_vec3_copy((vec3){ 5.0f, 5.0f, 5.0f }, camera->lookat.position); diff --git a/src/rpg/entity/entity.c b/src/rpg/entity/entity.c index ab329d3..ea0f152 100644 --- a/src/rpg/entity/entity.c +++ b/src/rpg/entity/entity.c @@ -46,6 +46,10 @@ void entityUpdate(entity_t *entity) { assertTrue(entity->type < ENTITY_TYPE_COUNT, "Invalid entity type"); assertTrue(entity->type != ENTITY_TYPE_NULL, "Cannot have NULL entity type"); + if(entity->type == ENTITY_TYPE_PLAYER) { + playerMovement(entity); + } + // Velocity for(uint8_t i = 0; i < WORLD_DIMENSIONS; i++) { if(entity->velocity[i] == 0) continue; diff --git a/src/rpg/entity/player.c b/src/rpg/entity/player.c index 5a95f46..13dea19 100644 --- a/src/rpg/entity/player.c +++ b/src/rpg/entity/player.c @@ -17,17 +17,20 @@ void playerInit(entity_t *entity) { void playerMovement(entity_t *entity) { assertNotNull(entity, "Entity pointer cannot be NULL"); - // // Update velocity. - // vec2 dir = { - // inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT), - // inputAxis(INPUT_ACTION_DOWN, INPUT_ACTION_UP) - // }; - // if(dir[0] == 0 && dir[1] == 0) return; + // Get movement angle as 0-> normalized vector. + { + vec2 dir = { + inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT), + inputAxis(INPUT_ACTION_DOWN, INPUT_ACTION_UP) + }; + if(dir[0] == 0 && dir[1] == 0) return; + glm_vec2_normalize(dir); + + entity->velocity[0] += (worldsubtile_t)(PLAYER_SPEED * dir[0]); + entity->velocity[1] += (worldsubtile_t)(PLAYER_SPEED * dir[1]); + } + - // glm_vec2_normalize(dir); - // entity->velocity[0] += PLAYER_SPEED * dir[0]; - // entity->velocity[1] += PLAYER_SPEED * dir[1]; - // // Update direction. // if(dir[0] > 0) { // if(entity->direction == DIRECTION_RIGHT) { diff --git a/src/rpg/entity/player.h b/src/rpg/entity/player.h index efb3326..41bd590 100644 --- a/src/rpg/entity/player.h +++ b/src/rpg/entity/player.h @@ -8,7 +8,7 @@ #pragma once #include "dusk.h" -#define PLAYER_SPEED 64.0f +#define PLAYER_SPEED 4 #define PLAYER_INTERACTION_RANGE 1.0f #define PLAYER_INTERACTION_SIZE 0.5f diff --git a/src/rpg/rpg.c b/src/rpg/rpg.c index 6046e08..4770329 100644 --- a/src/rpg/rpg.c +++ b/src/rpg/rpg.c @@ -7,6 +7,7 @@ #include "rpg.h" #include "entity/entity.h" +#include "time/time.h" errorret_t rpgInit(void) { // TEST @@ -20,6 +21,8 @@ errorret_t rpgInit(void) { } void rpgUpdate(void) { + if(!TIME.fixedUpdate) return; + entity_t *ent = &ENTITIES[0]; do { if(ent->type == ENTITY_TYPE_NULL) continue; diff --git a/src/scene/scene/scenemap.c b/src/scene/scene/scenemap.c index 917d1d8..fe9691d 100644 --- a/src/scene/scene/scenemap.c +++ b/src/scene/scene/scenemap.c @@ -10,6 +10,7 @@ #include "display/spritebatch.h" #include "assert/assert.h" #include "rpg/entity/entity.h" +#include "display/screen.h" #define TILE_WIDTH 1 #define TILE_HEIGHT TILE_WIDTH @@ -17,10 +18,6 @@ errorret_t sceneMapInit(scenedata_t *data) { cameraInitPerspective(&data->sceneMap.camera); - data->sceneMap.camera.lookat.position[0] = 3; - data->sceneMap.camera.lookat.position[1] = 3; - data->sceneMap.camera.lookat.position[2] = 3; - errorOk(); } @@ -28,6 +25,19 @@ void sceneMapUpdate(scenedata_t *data) { } void sceneMapRender(scenedata_t *data) { + const float_t camOffset = 12.0f; + const float_t pixelPerfectOffset = tanf( + data->sceneMap.camera.perspective.fov / 2.0f + ) * ((float_t)SCREEN.height / 2.0f); + + glm_vec3_copy((vec3){ + data->sceneMap.camera.lookat.target[0], + data->sceneMap.camera.lookat.target[1] + camOffset, + data->sceneMap.camera.lookat.target[2] + pixelPerfectOffset + }, data->sceneMap.camera.lookat.position); + + // + cameraPushMatrix(&data->sceneMap.camera); entity_t *ent = ENTITIES; diff --git a/src/time/time.h b/src/time/time.h index 9fd756f..354af4f 100644 --- a/src/time/time.h +++ b/src/time/time.h @@ -19,7 +19,7 @@ typedef struct { extern dusktime_t TIME; -#define TIME_STEP (1.0f / 60.0f) // Default to 60FPS +#define TIME_STEP (1.0f / 60.0f) // 60 Ticks per second. /** * Initializes the time system.