Physics I guess
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,8 @@ void rpgInit() {
|
||||
|
||||
entity_t *npc = mapEntityAdd(&testMap);
|
||||
entityInit(npc, ENTITY_TYPE_NPC);
|
||||
npc->x = 32.0f;
|
||||
npc->y = 32.0f;
|
||||
npc->position[0] = 32.0f;
|
||||
npc->position[1] = 32.0f;
|
||||
}
|
||||
|
||||
void rpgUpdate() {
|
||||
|
||||
@@ -10,9 +10,25 @@
|
||||
|
||||
#define MAP_ENTITY_COUNT_MAX 32
|
||||
|
||||
#define MAP_WIDTH_MAX 64
|
||||
#define MAP_HEIGHT_MAX 64
|
||||
#define MAP_TILE_COUNT_MAX (MAP_WIDTH_MAX * MAP_HEIGHT_MAX)
|
||||
|
||||
typedef struct {
|
||||
uint8_t id;
|
||||
} tile_t;
|
||||
|
||||
typedef struct {
|
||||
tile_t tiles[MAP_TILE_COUNT_MAX];
|
||||
} maplayer_t;
|
||||
|
||||
typedef struct {
|
||||
entity_t entities[MAP_ENTITY_COUNT_MAX];
|
||||
uint8_t entityCount;
|
||||
|
||||
uint8_t width, height;
|
||||
maplayer_t base;
|
||||
maplayer_t overlay;
|
||||
} map_t;
|
||||
|
||||
extern map_t testMap;
|
||||
|
||||
16
src/rpg/world/tile.h
Normal file
16
src/rpg/world/tile.h
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
TILE_TYPE_NULL,
|
||||
} tiletype_t;
|
||||
|
||||
typedef struct {
|
||||
tiletype_t type;
|
||||
} tile_t;
|
||||
Reference in New Issue
Block a user