This commit is contained in:
2025-10-09 15:07:07 -05:00
parent 7622f81309
commit c4c43b23ad
11 changed files with 162 additions and 32 deletions

View File

@@ -24,6 +24,7 @@ void entityInit(entity_t *entity, const entitytype_t type) {
);
memoryZero(entity, sizeof(entity_t));
entity->id = (uint8_t)(entity - ENTITIES);
entity->type = type;
// Init. I did use a callback struct but it was not flexible enough.
@@ -54,7 +55,7 @@ void entityUpdate(entity_t *entity) {
for(uint8_t i = 0; i < WORLD_DIMENSIONS; i++) {
if(entity->velocity[i] == 0) continue;
worldChunkPosAdd(&entity->position[i], entity->velocity[i]);
worldPosAddSubtile(&entity->position[i], entity->velocity[i]);
// Friction
worldsubtile_t v = entity->velocity[i];

View File

@@ -12,7 +12,7 @@
#include "physics/physics.h"
#include "rpg/world/worldunit.h"
#define ENTITY_FRICTION 1
#define ENTITY_FRICTION 2
#define ENTITY_MIN_VELOCITY 1
#define ENTITY_COUNT 256
@@ -27,9 +27,10 @@ typedef enum {
} entitytype_t;
typedef struct entity_s {
uint8_t id;
entitytype_t type;
direction_t direction;
worldchunkpos_t position[WORLD_DIMENSIONS];
worldpos_t position[WORLD_DIMENSIONS];
worldsubtile_t velocity[WORLD_DIMENSIONS];
union {

View File

@@ -9,6 +9,8 @@
#include "assert/assert.h"
#include "input/input.h"
#include "display/tileset/tileset_entities.h"
#include "rpg/rpgcamera.h"
#include "util/memory.h"
void playerInit(entity_t *entity) {
assertNotNull(entity, "Entity pointer cannot be NULL");
@@ -20,13 +22,13 @@ void playerMovement(entity_t *entity) {
// Get movement angle as 0-> normalized vector.
vec2 dir = {
inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT),
inputAxis(INPUT_ACTION_DOWN, INPUT_ACTION_UP)
inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN)
};
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]);
entity->velocity[0] += (worldsubtile_t)((float_t)PLAYER_SPEED * dir[0]);
entity->velocity[1] += (worldsubtile_t)((float_t)PLAYER_SPEED * dir[1]);
// Update direction.
if(dir[0] > 0) {

View File

@@ -8,7 +8,7 @@
#pragma once
#include "dusk.h"
#define PLAYER_SPEED 3
#define PLAYER_SPEED 4
#define PLAYER_INTERACTION_RANGE 1.0f
#define PLAYER_INTERACTION_SIZE 0.5f