Starting ent stuff

This commit is contained in:
2025-11-03 17:04:07 -06:00
parent bcba693afb
commit f3d985ecbc
9 changed files with 2 additions and 235 deletions

View File

@@ -25,7 +25,6 @@ void entityInit(entity_t *entity, const entitytype_t type) {
memoryZero(entity, sizeof(entity_t));
entity->id = (uint8_t)(entity - ENTITIES);
entity->type = type;
entity->hitboxRadius = .5f;
// Init. I did use a callback struct but it was not flexible enough.
switch(type) {
@@ -47,62 +46,8 @@ 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");
//
// Movement code.
if(entity->type == ENTITY_TYPE_PLAYER) {
playerMovement(entity);
}
// Apply velocity
if(
entity->velocity[0] != 0.0f ||
entity->velocity[1] != 0.0f ||
entity->velocity[2] != 0.0f
) {
entity->position[0] += entity->velocity[0] * TIME.fixedDelta;
entity->position[1] += entity->velocity[1] * TIME.fixedDelta;
entity->position[2] += entity->velocity[2] * TIME.fixedDelta;
// Hit test on other entities.
entity_t *start = ENTITIES;
entity_t *end = &ENTITIES[ENTITY_COUNT];
// Our hitbox
physicscircle_t self;
glm_vec2_copy(entity->position, self.position);
self.radius = entity->hitboxRadius;
physicscircle_t other;
// TODO: what if multiple collisions?
do {
if(start == entity) continue;
if(start->type == ENTITY_TYPE_NULL) continue;
other.radius = start->hitboxRadius;
glm_vec2_copy(start->position, other.position);
physicscirclecircleresult_t result;
physicsCircleCheckCircle(self, other, &result);
if(result.hit) {
entity->position[0] -= result.normal[0] * result.depth;
entity->position[1] -= result.normal[1] * result.depth;
break;
}
} while((start++) != end);
// Friction (and dampening)
glm_vec3_muladds(
entity->velocity, -ENTITY_FRICTION * TIME.fixedDelta, entity->velocity
);
if(mathAbs(entity->velocity[0]) < ENTITY_MIN_VELOCITY) {
entity->velocity[0] = 0.0f;
}
if(mathAbs(entity->velocity[1]) < ENTITY_MIN_VELOCITY) {
entity->velocity[1] = 0.0f;
}
if(mathAbs(entity->velocity[2]) < ENTITY_MIN_VELOCITY) {
entity->velocity[2] = 0.0f;
}
}
}