46 lines
871 B
JavaScript
46 lines
871 B
JavaScript
import { assert } from "./test.mjs";
|
|
|
|
import * as Entity from "./entity.mjs";
|
|
import { register_tick } from "./tick.mjs";
|
|
import { get_player } from "./player.mjs";
|
|
|
|
import * as Event from "./event.mjs";
|
|
import { underride } from "./underride.mjs";
|
|
|
|
|
|
|
|
const goal = Entity.create(0, 0, 40, 40);
|
|
|
|
export function get_goal () {
|
|
return goal;
|
|
}
|
|
|
|
register_tick(_ => {
|
|
if (Entity.touches(goal, get_player())) {
|
|
Event.trigger("level/win");
|
|
}
|
|
});
|
|
|
|
Event.listen("level/unload", _ => {
|
|
Entity.set_visible(goal, false);
|
|
Entity.set_physical(goal, false);
|
|
});
|
|
|
|
Event.listen("level/load/goal", (data = {}) => {
|
|
data = underride(data, {
|
|
pos: {
|
|
x: 0,
|
|
y: 0,
|
|
},
|
|
size: {
|
|
x: 40,
|
|
y: 40,
|
|
},
|
|
});
|
|
|
|
Entity.set_pos(goal, data.pos.x, data.pos.y);
|
|
Entity.set_size(goal, data.size.x, data.size.y);
|
|
|
|
Entity.set_visible(goal, true);
|
|
Entity.set_physical(goal, true);
|
|
});
|