From 6b7318545a102f5e01eaa571e12e3d3adab6d8ce Mon Sep 17 00:00:00 2001 From: elioat Date: Sun, 31 Dec 2023 16:42:35 -0500 Subject: * --- js/hill/game.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'js') 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); } } -- cgit 1.4.1-2-gfad0