diff --git a/src/physics/CMakeLists.txt b/src/physics/CMakeLists.txt deleted file mode 100644 index 525b700..0000000 --- a/src/physics/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (c) 2025 Dominic Masters -# -# This software is released under the MIT License. -# https://opensource.org/licenses/MIT - -# Sources -target_sources(${DUSK_TARGET_NAME} - PRIVATE - physicscircle.c - physicsbox.c -) \ No newline at end of file diff --git a/src/physics/physics.h b/src/physics/physics.h deleted file mode 100644 index c347539..0000000 --- a/src/physics/physics.h +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Copyright (c) 2025 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#pragma once -#include "physicscircle.h" -#include "physicsbox.h" \ No newline at end of file diff --git a/src/physics/physicsbox.c b/src/physics/physicsbox.c deleted file mode 100644 index 6259a5f..0000000 --- a/src/physics/physicsbox.c +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (c) 2025 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#include "physicsbox.h" - -void physicsBoxCheckBox( - const physicsbox_t a, - const physicsbox_t b, - physicsboxboxresult_t *out -) { - float_t dx = (b.min[0] + b.max[0]) / 2.0f - (a.min[0] + a.max[0]) / 2.0f; - float_t dy = (b.min[1] + b.max[1]) / 2.0f - (a.min[1] + a.max[1]) / 2.0f; - float_t combinedHalfWidths = (a.max[0] - a.min[0]) / 2.0f + (b.max[0] - b.min[0]) / 2.0f; - float_t combinedHalfHeights = (a.max[1] - a.min[1]) / 2.0f + (b.max[1] - b.min[1]) / 2.0f; - - if (fabsf(dx) < combinedHalfWidths && fabsf(dy) < combinedHalfHeights) { - out->hit = true; - float_t overlapX = combinedHalfWidths - fabsf(dx); - float_t overlapY = combinedHalfHeights - fabsf(dy); - - if (overlapX < overlapY) { - if (dx > 0) { - out->normal[0] = 1.0f; - out->normal[1] = 0.0f; - } else { - out->normal[0] = -1.0f; - out->normal[1] = 0.0f; - } - out->depth = overlapX; - } else { - if (dy > 0) { - out->normal[0] = 0.0f; - out->normal[1] = 1.0f; - } else { - out->normal[0] = 0.0f; - out->normal[1] = -1.0f; - } - out->depth = overlapY; - } - } else { - out->hit = false; - } -} \ No newline at end of file diff --git a/src/physics/physicsbox.h b/src/physics/physicsbox.h deleted file mode 100644 index 0c378a7..0000000 --- a/src/physics/physicsbox.h +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) 2025 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#pragma once -#include "dusk.h" - -typedef struct physicsbox_s { - vec2 min; - vec2 max; -} physicsbox_t; - -typedef struct physicsboxboxresult_s { - bool_t hit; - vec2 normal; - float_t depth; -} physicsboxboxresult_t; - -/** - * Check for collision between two boxes. - * - * @param a The first box. - * @param b The second box. - * @param out Pointer to the result structure to populate. - */ -void physicsBoxCheckBox( - const physicsbox_t a, - const physicsbox_t b, - physicsboxboxresult_t *out -); \ No newline at end of file diff --git a/src/physics/physicscircle.c b/src/physics/physicscircle.c deleted file mode 100644 index 8acfea6..0000000 --- a/src/physics/physicscircle.c +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) 2025 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#include "physicscircle.h" - -void physicsCircleCheckCircle( - const physicscircle_t a, - const physicscircle_t b, - physicscirclecircleresult_t *out -) { - vec2 delta; - glm_vec2_sub(b.position, a.position, delta); - float_t distSq = glm_vec2_dot(delta, delta); - float_t radiusSum = a.radius + b.radius; - float_t radiusSumSq = radiusSum * radiusSum; - - if(distSq < radiusSumSq) { - out->hit = true; - if (distSq != 0.0f) { - glm_vec2_normalize_to(delta, out->normal); - } else { - out->normal[0] = 1.0f; - out->normal[1] = 0.0f; - } - out->depth = radiusSum - sqrtf(distSq); - } else { - out->hit = false; - } -} \ No newline at end of file diff --git a/src/physics/physicscircle.h b/src/physics/physicscircle.h deleted file mode 100644 index ce3f447..0000000 --- a/src/physics/physicscircle.h +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) 2025 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#pragma once -#include "dusk.h" - -typedef struct physicscircle_s { - vec2 position; - float_t radius; -} physicscircle_t; - -typedef struct physicscirclecircleresult_s { - bool_t hit; - vec2 normal; - float_t depth; -} physicscirclecircleresult_t; - -/** - * Check for collision between two circles. - * - * @param a The first circle. - * @param b The second circle. - * @param out Pointer to the result structure to populate. - */ -void physicsCircleCheckCircle( - const physicscircle_t a, - const physicscircle_t b, - physicscirclecircleresult_t *out -); \ No newline at end of file diff --git a/src/rpg/entity/entity.c b/src/rpg/entity/entity.c index 86c8f3d..9d5f3ed 100644 --- a/src/rpg/entity/entity.c +++ b/src/rpg/entity/entity.c @@ -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; - } - } } \ No newline at end of file diff --git a/src/rpg/entity/entity.h b/src/rpg/entity/entity.h index 9e53ae6..a2cf461 100644 --- a/src/rpg/entity/entity.h +++ b/src/rpg/entity/entity.h @@ -9,10 +9,7 @@ #include "direction.h" #include "rpg/entity/player.h" #include "npc.h" -#include "physics/physics.h" -#define ENTITY_FRICTION 16.0f -#define ENTITY_MIN_VELOCITY 0.1f #define ENTITY_COUNT 256 typedef struct map_s map_t; @@ -29,10 +26,7 @@ typedef struct entity_s { uint8_t id; entitytype_t type; direction_t direction; - vec3 position; - vec3 velocity; - - float_t hitboxRadius; + uint32_t position;// Tile index union { player_t player; diff --git a/src/rpg/entity/player.h b/src/rpg/entity/player.h index 13ee43b..ea08ef3 100644 --- a/src/rpg/entity/player.h +++ b/src/rpg/entity/player.h @@ -8,11 +8,6 @@ #pragma once #include "dusk.h" -#define PLAYER_SPEED 48.0f -#define PLAYER_SPEED_RUNNING 72.0f -#define PLAYER_INTERACTION_RANGE 1.0f -#define PLAYER_INTERACTION_SIZE 0.5f - typedef struct entity_s entity_t; typedef struct {