boxes/js/player.mjs

38 lines
636 B
JavaScript
Raw Normal View History

2023-06-23 10:05:40 +00:00
import * as world from "./world.mjs";
import { on_press } from "./input.mjs";
import * as entity from "./entity.mjs";
const player = entity.create(world.get_root(), 2, 1, "#0f0");
2023-06-23 10:05:40 +00:00
export function move (d_x, d_y) {
entity.move(player, d_x, d_y);
}
on_press("ArrowLeft", _ => {
move(-1, 0);
});
on_press("ArrowRight", _ => {
move(1, 0);
});
on_press("ArrowUp", _ => {
move(0, -1);
});
on_press("ArrowDown", _ => {
move(0, 1);
});
2023-06-23 10:05:40 +00:00
on_press(" ", _ => {
world.set_tile(player.box, player.x + 1, player.y, {
2023-06-23 10:05:40 +00:00
type: "box",
box: world.create_box(player.box),
2023-06-23 10:05:40 +00:00
});
});
export function get_player_box () {
return player.box;
}