add (currently useless) goal entity.
This commit is contained in:
parent
c2a1acb335
commit
884b276640
4 changed files with 48 additions and 1 deletions
32
js/goal.mjs
Normal file
32
js/goal.mjs
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { assert } from "./test.mjs";
|
||||
|
||||
import * as Entity from "./entity.mjs";
|
||||
import { register_tick } from "./tick.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;
|
||||
}
|
||||
|
||||
Event.listen("level/unload", _ => {
|
||||
Entity.set_visible(goal, false);
|
||||
});
|
||||
|
||||
Event.listen("level/load/goal", (data = {}) => {
|
||||
data = underride(data, {
|
||||
pos: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
});
|
||||
|
||||
Entity.set_pos(goal, data.pos.x, data.pos.y);
|
||||
|
||||
Entity.set_visible(goal, true);
|
||||
});
|
|
@ -1,6 +1,7 @@
|
|||
import { assert } from "./test.mjs";
|
||||
|
||||
import { get_player } from "./player.mjs";
|
||||
import { get_goal } from "./goal.mjs";
|
||||
import * as enemy from "./enemy.mjs";
|
||||
|
||||
import { get_pos, get_size, is_visible } from "./entity.mjs";
|
||||
|
@ -31,8 +32,9 @@ function draw_entity (entity, color) {
|
|||
}
|
||||
|
||||
export function render () {
|
||||
clear();
|
||||
clear("#111");
|
||||
|
||||
draw_entity(get_goal(), "#880");
|
||||
draw_entity(get_player(), "#0f0");
|
||||
|
||||
for (const e of enemy.get_all()) {
|
||||
|
|
|
@ -15,6 +15,7 @@ export function load (name) {
|
|||
const level = Levels.get_level(name);
|
||||
|
||||
Event.trigger("level/load/player", level.player);
|
||||
Event.trigger("level/load/goal", level.goal);
|
||||
Event.trigger("level/load/enemy", level.enemies);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,16 @@
|
|||
export default {
|
||||
player: {
|
||||
pos: {
|
||||
x: 300,
|
||||
y: 50,
|
||||
},
|
||||
},
|
||||
goal: {
|
||||
pos: {
|
||||
x: 300,
|
||||
y: 500,
|
||||
},
|
||||
},
|
||||
enemies: [
|
||||
{
|
||||
pos: [300, 100],
|
||||
|
|
Loading…
Reference in a new issue