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