From 884b2766409aec75b0d8fdf0b053d212edc2fe1a Mon Sep 17 00:00:00 2001 From: trans_soup <> Date: Fri, 27 Oct 2023 12:54:38 +0200 Subject: [PATCH] add (currently useless) goal entity. --- js/goal.mjs | 32 ++++++++++++++++++++++++++++++++ js/graphics.mjs | 4 +++- js/level.mjs | 1 + js/levels/1.mjs | 12 ++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 js/goal.mjs diff --git a/js/goal.mjs b/js/goal.mjs new file mode 100644 index 0000000..0883a32 --- /dev/null +++ b/js/goal.mjs @@ -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); +}); diff --git a/js/graphics.mjs b/js/graphics.mjs index 46bba23..2044782 100644 --- a/js/graphics.mjs +++ b/js/graphics.mjs @@ -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()) { diff --git a/js/level.mjs b/js/level.mjs index 37350bf..47f4767 100644 --- a/js/level.mjs +++ b/js/level.mjs @@ -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); } diff --git a/js/levels/1.mjs b/js/levels/1.mjs index 4d70c7c..83d7055 100644 --- a/js/levels/1.mjs +++ b/js/levels/1.mjs @@ -1,4 +1,16 @@ export default { + player: { + pos: { + x: 300, + y: 50, + }, + }, + goal: { + pos: { + x: 300, + y: 500, + }, + }, enemies: [ { pos: [300, 100],