diff options
-rw-r--r-- | level.js | 14 | ||||
-rw-r--r-- | main.js | 2 | ||||
-rw-r--r-- | render.js | 2 |
3 files changed, 16 insertions, 2 deletions
@@ -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); @@ -39,7 +39,7 @@ window.onload = () => { ) musicList[0].element.play(); - const level = setupLevel([], [7, 7]); + const level = setupLevel([[2, 2], [3,3]], [7, 7]); const ui = setupLevelUi(level, root, audio); }; root.appendChild(start); @@ -10,7 +10,7 @@ export function render(ctx, level, index) { drawShip(ctx, [x0, y0], angle); level.resources .filter(({ collected }) => collected === false) - .forEach(({ pos }) => drawMark(ctx, '+', pos[0], pos[1])); + .forEach(({ position}) => drawMark(ctx, '+', position[0], position[1])); drawMark(ctx, '※', level.home[0], level.home[1]); } |