diff options
author | elioat <elioat@tilde.institute> | 2023-12-31 16:42:35 -0500 |
---|---|---|
committer | elioat <elioat@tilde.institute> | 2023-12-31 16:42:35 -0500 |
commit | 6b7318545a102f5e01eaa571e12e3d3adab6d8ce (patch) | |
tree | 0b60961293994c3b06a19716da28696175bd8c66 /js | |
parent | 4ea7cab6c36bc91a0f7a96bbc79667c1cceb6b8d (diff) | |
download | tour-6b7318545a102f5e01eaa571e12e3d3adab6d8ce.tar.gz |
*
Diffstat (limited to 'js')
-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); } } |