This commit is contained in:
2025-10-25 21:15:13 -05:00
parent 5c3db5d991
commit d74226dab1
4 changed files with 8 additions and 7 deletions

View File

@@ -25,6 +25,7 @@ void entityInit(entity_t *entity, const entitytype_t type) {
memoryZero(entity, sizeof(entity_t)); memoryZero(entity, sizeof(entity_t));
entity->id = (uint8_t)(entity - ENTITIES); entity->id = (uint8_t)(entity - ENTITIES);
entity->type = type; entity->type = type;
entity->hitboxRadius = .5f;
// Init. I did use a callback struct but it was not flexible enough. // Init. I did use a callback struct but it was not flexible enough.
switch(type) { switch(type) {
@@ -46,6 +47,7 @@ void entityUpdate(entity_t *entity) {
assertTrue(entity->type < ENTITY_TYPE_COUNT, "Invalid entity type"); assertTrue(entity->type < ENTITY_TYPE_COUNT, "Invalid entity type");
assertTrue(entity->type != ENTITY_TYPE_NULL, "Cannot have NULL entity type"); assertTrue(entity->type != ENTITY_TYPE_NULL, "Cannot have NULL entity type");
//
if(entity->type == ENTITY_TYPE_PLAYER) { if(entity->type == ENTITY_TYPE_PLAYER) {
playerMovement(entity); playerMovement(entity);
} }
@@ -67,15 +69,15 @@ void entityUpdate(entity_t *entity) {
// Our hitbox // Our hitbox
physicscircle_t self; physicscircle_t self;
glm_vec2_copy(entity->position, self.position); glm_vec2_copy(entity->position, self.position);
self.radius = 0.5f; self.radius = entity->hitboxRadius;
physicscircle_t other; physicscircle_t other;
other.radius = self.radius;
// TODO: what if multiple collisions? // TODO: what if multiple collisions?
do { do {
if(start == entity) continue; if(start == entity) continue;
if(start->type == ENTITY_TYPE_NULL) continue; if(start->type == ENTITY_TYPE_NULL) continue;
other.radius = start->hitboxRadius;
glm_vec2_copy(start->position, other.position); glm_vec2_copy(start->position, other.position);
physicscirclecircleresult_t result; physicscirclecircleresult_t result;
@@ -90,7 +92,7 @@ void entityUpdate(entity_t *entity) {
// Friction (and dampening) // Friction (and dampening)
glm_vec3_muladds( glm_vec3_muladds(
entity->velocity, -ENTITY_FRICTION * TIME.delta, entity->velocity entity->velocity, -ENTITY_FRICTION * TIME.fixedDelta, entity->velocity
); );
if(mathAbs(entity->velocity[0]) < ENTITY_MIN_VELOCITY) { if(mathAbs(entity->velocity[0]) < ENTITY_MIN_VELOCITY) {

View File

@@ -32,7 +32,6 @@ typedef struct entity_s {
vec3 position; vec3 position;
vec3 velocity; vec3 velocity;
vec2 hitbox;
float_t hitboxRadius; float_t hitboxRadius;
union { union {

View File

@@ -8,8 +8,8 @@
#pragma once #pragma once
#include "dusk.h" #include "dusk.h"
#define PLAYER_SPEED 32.0f #define PLAYER_SPEED 48.0f
#define PLAYER_SPEED_RUNNING 64.0f #define PLAYER_SPEED_RUNNING 72.0f
#define PLAYER_INTERACTION_RANGE 1.0f #define PLAYER_INTERACTION_RANGE 1.0f
#define PLAYER_INTERACTION_SIZE 0.5f #define PLAYER_INTERACTION_SIZE 0.5f

View File

@@ -41,7 +41,7 @@ void timeUpdate(void) {
TIME.time += TIME.delta; TIME.time += TIME.delta;
// Perform a fixed time step. // Perform a fixed time step.
if(TIME.time - TIME.fixedTime >= TIME_STEP) { if(TIME.time - TIME.fixedTime >= (TIME_STEP * 0.9f)) {
TIME.fixedUpdate = true; TIME.fixedUpdate = true;
TIME.fixedDelta = TIME_STEP; TIME.fixedDelta = TIME_STEP;
TIME.fixedTime += TIME_STEP; TIME.fixedTime += TIME_STEP;