implement basic box entering and exiting in entity movement.

This commit is contained in:
HyperOnion 2023-06-24 10:08:37 +02:00 committed by transoptimal
parent 68c93726f0
commit b2b4d9dced
2 changed files with 7 additions and 11 deletions

View File

@ -41,20 +41,16 @@ export function set_pos (entity, x, y) {
entity.y = y; entity.y = y;
if (out_of_bounds(entity)) { if (out_of_bounds(entity)) {
clamp_pos(entity); if (entity.box.parent) {
/* entity.box = entity.box.parent;
const could_exit = world.exit_box(); // TODO: exit from side of box.
if (could_exit) {
set_player_pos(0, 0);
} else {
set_player_pos(previous_x, previous_y);
} }
return; clamp_pos(entity);
*/
} }
if (world.get_tile(entity.box, entity.x, entity.y)?.type === "box") { if (world.get_tile(entity.box, entity.x, entity.y)?.type === "box") {
// TODO entity.box = world.get_tile(entity.box, entity.x, entity.y).box;
// TODO: enter at edge of box.
} }
} }

View File

@ -28,7 +28,7 @@ on_press("ArrowDown", _ => {
on_press(" ", _ => { on_press(" ", _ => {
world.set_tile(player.box, player.x + 1, player.y, { world.set_tile(player.box, player.x + 1, player.y, {
type: "box", type: "box",
box: world.create_box(), box: world.create_box(player.box),
}); });
}); });