Add direction to the door

This commit is contained in:
2024-10-06 23:21:28 -05:00
parent a1d4b0a1d7
commit 5334f0944e
5 changed files with 66 additions and 6 deletions

@ -45,7 +45,12 @@
{
"type": 4,
"x": 6,
"y": 8
"y": 8,
"door": {
"x": 0,
"y": 0,
"direction": 3
}
}
]
}

@ -129,6 +129,32 @@ void assetMapLoad(
signTextSet(&ent->sign, val->string);
}
break;
case ENTITY_TYPE_DOOR:
val = assetJsonGetObjectValue(jEnt, "door");
if(val != NULL) {
assetjson_t *door = assetJsonGetObjectValue(val, "x");
x = (int32_t)door->number;
assertTrue(
door->type == ASSET_JSON_DATA_TYPE_NUMBER,
"assetMapLoad: Door x is not a number!"
);
door = assetJsonGetObjectValue(val, "y");
y = (int32_t)door->number;
assertTrue(
door->type == ASSET_JSON_DATA_TYPE_NUMBER,
"assetMapLoad: Door y is not a number!"
);
entitydirection_t direction = (entitydirection_t)assetJsonGetObjectValue(
val, "direction"
)->number;
doorDestinationSet(&ent->door, x, y, direction);
}
break;
default:
break;
}
// TODO: Parse any extra data.

@ -10,5 +10,16 @@
void doorInit(door_t *door) {
assertNotNull(door, "Door cannot be NULL.");
door->bruv = 0;
}
void doorDestinationSet(
door_t *door,
const int32_t x,
const int32_t y,
const entitydirection_t direction
) {
assertNotNull(door, "Door cannot be NULL.");
door->x = x;
door->y = y;
door->direction = direction;
}

@ -6,10 +6,12 @@
*/
#pragma once
#include "dawn.h"
#include "entitydirection.h"
typedef struct {
uint8_t bruv;
int32_t x;
int32_t y;
entitydirection_t direction;
} door_t;
/**
@ -17,4 +19,19 @@ typedef struct {
*
* @param door Door to initialize.
*/
void doorInit(door_t *door);
void doorInit(door_t *door);
/**
* Sets the destination of a door.
*
* @param door Door to set the destination of.
* @param x X coordinate of the destination.
* @param y Y coordinate of the destination.
* @param direction Direction the player should face when they arrive.
*/
void doorDestinationSet(
door_t *door,
const int32_t x,
const int32_t y,
const entitydirection_t direction
);

@ -32,7 +32,8 @@ void entityInteractEntity(
return;
case ENTITY_TYPE_DOOR:
textboxSetText("Door", "It's a door.");
entityPositionSet(source, target->door.x, target->door.y);
source->direction = target->door.direction;
return;
default: