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