From aad68d877531ebdfb117a90c77ea7e538d858f2a Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 5 Jul 2024 23:25:23 -0500 Subject: implement resource collection --- level.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'level.js') diff --git a/level.js b/level.js index c10139c..d511fa7 100644 --- a/level.js +++ b/level.js @@ -98,7 +98,21 @@ export function setupLevelUi(level, root, audio) { function stepLevel(ui, level, index) { render(ui.ctx, level, index); + const pos = level.path[index]; + const distances = level.resources + .map((x, i) => [x, i]) + .filter(([x, _]) => x.collected === false) + .map(([x, i]) => [ distance(pos, x.position), i ]) + .forEach(([d, i]) => { + console.log(d); + if (d < 0.4) { + level.resources[i].collected = true; + } + }); + + + if (distance(pos, level.home) < 0.4) { level.running = false; ui.rocketGain.gain.setTargetAtTime(0, ui.audio.currentTime, FAST_RAMP); -- cgit v1.2.1