summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--level.js14
-rw-r--r--main.js2
-rw-r--r--render.js2
3 files changed, 16 insertions, 2 deletions
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);
diff --git a/main.js b/main.js
index 210822d..107c580 100644
--- a/main.js
+++ b/main.js
@@ -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);
diff --git a/render.js b/render.js
index 6adca2c..be3bc8e 100644
--- a/render.js
+++ b/render.js
@@ -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]);
}