Updated font, added interactions and testing frames.
This commit is contained in:
@ -11,7 +11,7 @@ tileset_t TILESETS[TILESET_COUNT] = {
|
||||
// TILESET_NULL
|
||||
{ 0, 0 },
|
||||
// TILESET_FONT
|
||||
{ 1, 88 }
|
||||
{ 16, 14 }
|
||||
};
|
||||
|
||||
tilesetid_t TILESET_SLOTS[TILESET_SLOT_COUNT] = {
|
||||
|
@ -32,6 +32,8 @@ void entityInit(
|
||||
// Call init
|
||||
assertNotNull(ENTITY_CALLBACKS[type].init, "Entity type init callback err.");
|
||||
ENTITY_CALLBACKS[type].init(ent);
|
||||
|
||||
entityTurn(ent, FACING_DIRECTION_SOUTH);
|
||||
}
|
||||
|
||||
void entityUpdate(entity_t *ent) {
|
||||
@ -61,7 +63,20 @@ void entityTurn(entity_t *ent, const facingdir_t dir) {
|
||||
assertTrue(dir < FACING_DIRECTION_COUNT, "Invalid facing direction");
|
||||
|
||||
ent->direction = dir;
|
||||
ent->frame = 1 + (dir * 3);
|
||||
switch(dir) {
|
||||
case FACING_DIRECTION_SOUTH:
|
||||
ent->frame = 25;
|
||||
break;
|
||||
case FACING_DIRECTION_NORTH:
|
||||
ent->frame = 24;
|
||||
break;
|
||||
case FACING_DIRECTION_EAST:
|
||||
ent->frame = 26;
|
||||
break;
|
||||
case FACING_DIRECTION_WEST:
|
||||
ent->frame = 27;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void entityMove(entity_t *ent, const facingdir_t dir) {
|
||||
@ -114,7 +129,7 @@ bool_t entityIsMoving(const entity_t *ent) {
|
||||
return ent->subX != 0 || ent->subY != 0;
|
||||
}
|
||||
|
||||
bool_t entityInteract(const entity_t *ent) {
|
||||
bool_t entityInteract(entity_t *ent) {
|
||||
assertNotNull(ent, "Entity cannot be NULL.");
|
||||
assertTrue(ent->type == ENTITY_TYPE_PLAYER, "Entity should be player.");
|
||||
if(entityIsMoving(ent)) return false;
|
||||
@ -129,7 +144,7 @@ bool_t entityInteract(const entity_t *ent) {
|
||||
assertTrue(target->type < ENTITY_TYPE_COUNT, "Invalid entity type.");
|
||||
|
||||
if(ENTITY_CALLBACKS[target->type].interact == NULL) return false;
|
||||
ENTITY_CALLBACKS[target->type].interact(target);
|
||||
ENTITY_CALLBACKS[target->type].interact(ent, target);
|
||||
|
||||
return true;
|
||||
}
|
@ -21,7 +21,7 @@ typedef enum {
|
||||
typedef struct {
|
||||
void (*init)(entity_t *);
|
||||
void (*update)(entity_t *);
|
||||
void (*interact)(entity_t *);
|
||||
void (*interact)(entity_t *, entity_t *);
|
||||
} entitycallback_t;
|
||||
|
||||
typedef struct _entity_t {
|
||||
@ -86,4 +86,4 @@ bool_t entityIsMoving(const entity_t *entity);
|
||||
* @param entity The entity that is doing the interaction.
|
||||
* @return TRUE if an entity was interacted with, FALSE otherwise.
|
||||
*/
|
||||
bool_t entityInteract(const entity_t *entity);
|
||||
bool_t entityInteract(entity_t *entity);
|
@ -47,4 +47,19 @@ void facingDirAdd(const facingdir_t dir, uint8_t *x, uint8_t *y) {
|
||||
|
||||
*x += dx;
|
||||
*y += dy;
|
||||
}
|
||||
|
||||
facingdir_t facingDirFace(
|
||||
const uint8_t x1, const uint8_t y1,
|
||||
const uint8_t x2, const uint8_t y2
|
||||
) {
|
||||
if(x1 == x2) {
|
||||
if(y1 < y2) return FACING_DIRECTION_SOUTH;
|
||||
if(y1 > y2) return FACING_DIRECTION_NORTH;
|
||||
} else if(y1 == y2) {
|
||||
if(x1 < x2) return FACING_DIRECTION_WEST;
|
||||
if(x1 > x2) return FACING_DIRECTION_EAST;
|
||||
}
|
||||
|
||||
return FACING_DIRECTION_SOUTH;
|
||||
}
|
@ -33,4 +33,18 @@ void facingDirGetRelative(const facingdir_t dir, int8_t *x, int8_t *y);
|
||||
* @param x The x position to add to.
|
||||
* @param y The y position to add to.
|
||||
*/
|
||||
void facingDirAdd(const facingdir_t dir, uint8_t *x, uint8_t *y);
|
||||
void facingDirAdd(const facingdir_t dir, uint8_t *x, uint8_t *y);
|
||||
|
||||
/**
|
||||
* Returns the facing direction to face from one position to another.
|
||||
*
|
||||
* @param x1 The x position to face from.
|
||||
* @param y1 The y position to face from.
|
||||
* @param x2 The x position to face to.
|
||||
* @param y2 The y position to face to.
|
||||
* @return The facing direction to face from one position to another.
|
||||
*/
|
||||
facingdir_t facingDirFace(
|
||||
const uint8_t x1, const uint8_t y1,
|
||||
const uint8_t x2, const uint8_t y2
|
||||
);
|
@ -5,7 +5,7 @@
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "npc.h"
|
||||
#include "entity.h"
|
||||
|
||||
void npcInit(entity_t *ent) {
|
||||
}
|
||||
@ -13,6 +13,7 @@ void npcInit(entity_t *ent) {
|
||||
void npcUpdate(entity_t *ent) {
|
||||
}
|
||||
|
||||
void npcInteract(entity_t *ent) {
|
||||
void npcInteract(entity_t *player, entity_t *ent) {
|
||||
printf("Interact\n");
|
||||
entityTurn(ent, facingDirFace(player->x, player->y, ent->x, ent->y));
|
||||
}
|
@ -31,6 +31,7 @@ void npcUpdate(entity_t *ent);
|
||||
/**
|
||||
* Handles interaction with an NPC.
|
||||
*
|
||||
* @param player The player entity interacting.
|
||||
* @param ent The entity to interact with.
|
||||
*/
|
||||
void npcInteract(entity_t *ent);
|
||||
void npcInteract(entity_t *player, entity_t *ent);
|
@ -15,5 +15,7 @@ out vec4 FragColor;
|
||||
|
||||
void main() {
|
||||
vec4 tColor = tilesetGetColor(uint(TILESET_SLOT_ENTITIES), v_TextureCoord);
|
||||
if(tColor.a == 0.0) discard;
|
||||
if(tColor.r == 0.0) discard;
|
||||
FragColor = vec4(1, 1, 1, 1) * tColor;
|
||||
}
|
||||
|
Reference in New Issue
Block a user