pixel?
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
exec "config/init-base";
|
||||
|
||||
screen height 270;
|
||||
screen height 270;
|
||||
|
||||
bind ` toggleconsole;
|
||||
|
@@ -8,7 +8,6 @@
|
||||
#include "entity.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "display/tileset/tileset_entities.h"
|
||||
#include "time/time.h"
|
||||
#include "util/math.h"
|
||||
|
||||
@@ -51,16 +50,57 @@ void entityUpdate(entity_t *entity) {
|
||||
playerMovement(entity);
|
||||
}
|
||||
|
||||
// Add velcoity
|
||||
glm_vec3_muladds(entity->velocity, TIME.delta, entity->position);
|
||||
// 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;
|
||||
|
||||
// Apply friction
|
||||
glm_vec3_muladds(
|
||||
entity->velocity, -ENTITY_FRICTION * TIME.delta, entity->velocity
|
||||
);
|
||||
// Hit test on other entities.
|
||||
entity_t *start = ENTITIES;
|
||||
entity_t *end = &ENTITIES[ENTITY_COUNT];
|
||||
|
||||
// Clamp small velocities to zero
|
||||
if(glm_vec3_norm(entity->velocity) < ENTITY_MIN_VELOCITY) {
|
||||
glm_vec3_zero(entity->velocity);
|
||||
// Our hitbox
|
||||
physicscircle_t self;
|
||||
glm_vec2_copy(entity->position, self.position);
|
||||
self.radius = 0.5f;
|
||||
|
||||
physicscircle_t other;
|
||||
other.radius = self.radius;
|
||||
|
||||
// TODO: what if multiple collisions?
|
||||
do {
|
||||
if(start == entity) continue;
|
||||
if(start->type == ENTITY_TYPE_NULL) continue;
|
||||
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.delta, 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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -32,6 +32,9 @@ typedef struct entity_s {
|
||||
vec3 position;
|
||||
vec3 velocity;
|
||||
|
||||
vec2 hitbox;
|
||||
float_t hitboxRadius;
|
||||
|
||||
union {
|
||||
player_t player;
|
||||
npc_t npc;
|
||||
|
@@ -64,54 +64,54 @@ void playerMovement(entity_t *entity) {
|
||||
}
|
||||
|
||||
void playerInteraction(entity_t *entity) {
|
||||
// assertNotNull(entity, "Entity pointer cannot be NULL");
|
||||
assertNotNull(entity, "Entity pointer cannot be NULL");
|
||||
|
||||
// if(!inputPressed(INPUT_ACTION_ACCEPT)) return;
|
||||
if(!inputPressed(INPUT_ACTION_ACCEPT)) return;
|
||||
|
||||
// physicsbox_t interactBox;
|
||||
physicsbox_t interactBox;
|
||||
|
||||
// // Get direction vector
|
||||
// directionGetVec2(entity->direction, interactBox.min);
|
||||
// Get direction vector
|
||||
directionGetVec2(entity->direction, interactBox.min);
|
||||
|
||||
// // Scale by interact range
|
||||
// glm_vec2_scale(interactBox.min, PLAYER_INTERACTION_RANGE, interactBox.min);
|
||||
// Scale by interact range
|
||||
glm_vec2_scale(interactBox.min, PLAYER_INTERACTION_RANGE, interactBox.min);
|
||||
|
||||
// // Add entity position, this makes the center of the box.
|
||||
// glm_vec2_add(interactBox.min, entity->position, interactBox.min);
|
||||
// Add entity position, this makes the center of the box.
|
||||
glm_vec2_add(interactBox.min, entity->position, interactBox.min);
|
||||
|
||||
// // Copy to max
|
||||
// glm_vec2_copy(interactBox.min, interactBox.max);
|
||||
// Copy to max
|
||||
glm_vec2_copy(interactBox.min, interactBox.max);
|
||||
|
||||
// // Size of the hitbox
|
||||
// vec2 halfSize = {
|
||||
// TILESET_ENTITIES.tileWidth * PLAYER_INTERACTION_SIZE * 0.5f,
|
||||
// TILESET_ENTITIES.tileHeight * PLAYER_INTERACTION_SIZE * 0.5f
|
||||
// };
|
||||
// Size of the hitbox
|
||||
vec2 halfSize = {
|
||||
TILESET_ENTITIES.tileWidth * PLAYER_INTERACTION_SIZE * 0.5f,
|
||||
TILESET_ENTITIES.tileHeight * PLAYER_INTERACTION_SIZE * 0.5f
|
||||
};
|
||||
|
||||
// // Subtract from min, add to max.
|
||||
// glm_vec2_sub(interactBox.min, halfSize, interactBox.min);
|
||||
// glm_vec2_add(interactBox.max, halfSize, interactBox.max);
|
||||
// Subtract from min, add to max.
|
||||
glm_vec2_sub(interactBox.min, halfSize, interactBox.min);
|
||||
glm_vec2_add(interactBox.max, halfSize, interactBox.max);
|
||||
|
||||
// // For each entity
|
||||
// entity_t *start = entity->map->entities;
|
||||
// entity_t *end = &entity->map->entities[entity->map->entityCount];
|
||||
// vec2 otherSize = { TILESET_ENTITIES.tileWidth, TILESET_ENTITIES.tileHeight };
|
||||
// physicsbox_t otherBox;
|
||||
// physicsboxboxresult_t result;
|
||||
// For each entity
|
||||
entity_t *start = ENTITIES;
|
||||
entity_t *end = &ENTITIES[ENTITY_COUNT];
|
||||
vec2 otherSize = { TILESET_ENTITIES.tileWidth, TILESET_ENTITIES.tileHeight };
|
||||
physicsbox_t otherBox;
|
||||
physicsboxboxresult_t result;
|
||||
|
||||
// do {
|
||||
// if(start->type != ENTITY_TYPE_NPC) continue;
|
||||
do {
|
||||
if(start->type != ENTITY_TYPE_NPC) continue;
|
||||
|
||||
// // Setup other box.
|
||||
// glm_vec2_copy(start->position, otherBox.min);
|
||||
// glm_vec2_copy(start->position, otherBox.max);
|
||||
// glm_vec2_sub(otherBox.min, otherSize, otherBox.min);
|
||||
// glm_vec2_add(otherBox.min, otherSize, otherBox.max);
|
||||
// Setup other box.
|
||||
glm_vec2_copy(start->position, otherBox.min);
|
||||
glm_vec2_copy(start->position, otherBox.max);
|
||||
glm_vec2_sub(otherBox.min, otherSize, otherBox.min);
|
||||
glm_vec2_add(otherBox.min, otherSize, otherBox.max);
|
||||
|
||||
// physicsBoxCheckBox(interactBox, otherBox, &result);
|
||||
// if(!result.hit) continue;
|
||||
physicsBoxCheckBox(interactBox, otherBox, &result);
|
||||
if(!result.hit) continue;
|
||||
|
||||
// printf("Interacted with entity at (%.2f, %.2f)\n", start->position[0], start->position[1]);
|
||||
// break;
|
||||
// } while(++start != end);
|
||||
printf("Interacted with entity at (%.2f, %.2f)\n", start->position[0], start->position[1]);
|
||||
break;
|
||||
} while(++start != end);
|
||||
}
|
@@ -12,8 +12,9 @@
|
||||
#include "rpg/entity/entity.h"
|
||||
#include "display/screen.h"
|
||||
#include "rpg/rpgcamera.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
#define TILE_SIZE 8
|
||||
#define TILE_SIZE 1
|
||||
|
||||
errorret_t sceneMapInit(scenedata_t *data) {
|
||||
cameraInitPerspective(&data->sceneMap.camera);
|
||||
@@ -42,7 +43,7 @@ void sceneMapRender(scenedata_t *data) {
|
||||
);
|
||||
|
||||
// Apply pixel perfect offset and camera offset
|
||||
const float_t camOffset = 32.0f;
|
||||
const float_t camOffset = 0.01f;
|
||||
const float_t pixelPerfectOffset = tanf(
|
||||
data->sceneMap.camera.perspective.fov / 2.0f
|
||||
) * ((float_t)SCREEN.height / 2.0f);
|
||||
@@ -53,6 +54,22 @@ void sceneMapRender(scenedata_t *data) {
|
||||
data->sceneMap.camera.lookat.target[2] + pixelPerfectOffset
|
||||
}, data->sceneMap.camera.lookat.position);
|
||||
|
||||
// TESTING ONLY
|
||||
camera_t backup = data->sceneMap.camera;
|
||||
cameraInitOrthographic(&data->sceneMap.camera);
|
||||
data->sceneMap.camera.projType = CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC;
|
||||
glm_vec3_copy((vec3){
|
||||
RPG_CAMERA.position[0] * TILE_SIZE,
|
||||
RPG_CAMERA.position[1] * TILE_SIZE,
|
||||
10.0f
|
||||
}, data->sceneMap.camera._2d.position);
|
||||
data->sceneMap.camera.orthographic.left = 0.0f;
|
||||
data->sceneMap.camera.orthographic.right = SCREEN.width;
|
||||
data->sceneMap.camera.orthographic.top = 0.0f;
|
||||
data->sceneMap.camera.orthographic.bottom = SCREEN.height;
|
||||
data->sceneMap.camera.nearClip = -100.0f;
|
||||
data->sceneMap.camera.farClip = 100.0f;
|
||||
|
||||
// Push camera
|
||||
cameraPushMatrix(&data->sceneMap.camera);
|
||||
|
||||
@@ -65,6 +82,9 @@ void sceneMapRender(scenedata_t *data) {
|
||||
|
||||
// Finished, pop back camera.
|
||||
cameraPopMatrix();
|
||||
|
||||
//END TESTING
|
||||
data->sceneMap.camera = backup;
|
||||
}
|
||||
|
||||
void sceneMapRenderEntity(entity_t *entity) {
|
||||
@@ -73,7 +93,8 @@ void sceneMapRenderEntity(entity_t *entity) {
|
||||
if(entity->type == ENTITY_TYPE_NULL) return;
|
||||
|
||||
vec3 posMin, posMax;
|
||||
glm_vec3_scale(entity->position, TILE_SIZE, posMin);
|
||||
// glm_vec3_scale(entity->position, TILE_SIZE, posMin);
|
||||
posMin[0] = 1, posMin[1] = 1, posMin[2] = 0;
|
||||
glm_vec3_add(posMin, (vec3){TILE_SIZE, TILE_SIZE, TILE_SIZE }, posMax);
|
||||
|
||||
vec2 uv0 = { 0.0f, 0.0f };
|
||||
|
Reference in New Issue
Block a user