Physics I guess

This commit is contained in:
2025-09-15 19:37:01 -05:00
parent 07ab2b4b02
commit f799690d3c
25 changed files with 315 additions and 13 deletions

View File

@@ -8,6 +8,7 @@
#include "entity.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "display/tileset/tileset_entities.h"
entitycallback_t ENTITY_CALLBACKS[ENTITY_TYPE_COUNT] = {
{ NULL, NULL }, // ENTITY_TYPE_NULL

View File

@@ -9,6 +9,7 @@
// #include "direction.h"
#include "rpg/entity/player.h"
#include "npc.h"
#include "physics/physics.h"
typedef struct {
void (*init)(entity_t *entity);
@@ -25,10 +26,12 @@ typedef enum {
typedef struct entity_s {
// uint32_t id;// Completely unique ID for this entity.
float_t x, y;
entitytype_t type;
// direction_t dir;
vec2 position;
vec2 velocity;
union {
player_t player;
npc_t npc;

View File

@@ -11,6 +11,7 @@
#include "input/input.h"
#include "display/scene/overworld/sceneoverworld.h"
#include "display/tileset/tileset_entities.h"
void playerInit(entity_t *entity) {
assertNotNull(entity, "Entity pointer cannot be NULL");
@@ -26,9 +27,26 @@ void playerUpdate(entity_t *entity) {
inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN)
};
glm_vec2_normalize(dir);
entity->x += move * dir[0];
entity->y -= move * dir[1];
entity->position[0] += move * dir[0];
entity->position[1] -= move * dir[1];
SCENE_OVERWORLD.camera.lookat.target[0] = entity->x;
SCENE_OVERWORLD.camera.lookat.target[1] = entity->y;
SCENE_OVERWORLD.camera.lookat.target[0] = entity->position[0];
SCENE_OVERWORLD.camera.lookat.target[1] = entity->position[1];
// Can we move?
physicscircle_t npc = {
.position = { 32.0f, 32.0f },
.radius = TILESET_ENTITIES.tileWidth / 2.0f
};
physicscircle_t self;
glm_vec2_copy(entity->position, self.position);
self.radius = npc.radius;
physicscirclecircleresult_t result;
physicsCircleCheckCircle(self, npc, &result);
if(result.hit) {
entity->position[0] -= result.normal[0] * result.depth;
entity->position[1] -= result.normal[1] * result.depth;
}
}