diff options
-rw-r--r-- | js/hill/game.js | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/js/hill/game.js b/js/hill/game.js index b6a43e0..831e98e 100644 --- a/js/hill/game.js +++ b/js/hill/game.js @@ -27,16 +27,22 @@ const terrain = { const objects = []; function initialize() { - terrain.start = { x: 0, y: canvas.height - 22 }; - terrain.end = { x: canvas.width, y: canvas.height - 22 }; + terrain.start = { x: 0, y: 0 }; + terrain.end = { x: canvas.width, y: canvas.height }; for (let i = 0; i < 50; i++) { const object = { x: i * 10 * canvas.width / 10, - y: terrain.start.y - Math.random() * 22, width: 20, height: Math.random() * 22 }; + + // Calculate the y-coordinate of the terrain line at the x-coordinate of the object + let terrainY = ((terrain.end.y - terrain.start.y) / (terrain.end.x - terrain.start.x)) * (object.x - terrain.start.x) + terrain.start.y; + + // Set the y-coordinate of the object to the y-coordinate of the terrain line + object.y = terrainY; + objects.push(object); } } |