38 lines
626 B
JavaScript
38 lines
626 B
JavaScript
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");
|
|
|
|
|
|
|
|
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);
|
|
});
|
|
|
|
on_press(" ", _ => {
|
|
world.set_tile(player.box, player.x + 1, player.y, {
|
|
type: "box",
|
|
box: world.create_box(),
|
|
});
|
|
});
|
|
|
|
export function get_player_box () {
|
|
return player.box;
|
|
}
|