diff --git a/sketch.js b/sketch.js index 0bfc512..9112f2a 100644 --- a/sketch.js +++ b/sketch.js @@ -156,12 +156,14 @@ function startGame(full_start, update_objects) { width: 50, points: [], }; - } else + } else { + if (canyons[i - 1].x + 600 > finish_position_x) break; canyons[i] = { x: canyons[i - 1].x + 300 + 200 * random(0.5, 1), width: 50 + 30 * random(), points: [], }; + } } for (i = 0; i < 100; i++) { if (i == 0) { @@ -171,15 +173,19 @@ function startGame(full_start, update_objects) { size: 75, isFound: false, }; - } else + } else { + if (collectables[i - 1].x + 200 > finish_position_x) { + break; + } collectables[i] = { - x: collectables[i - 1].x + 50 + 150 * random(0.5, 1), + x: collectables[i - 1].x + 50 + 100 * random(0.5, 1), y: gameChar.possibleGroundPosY[ - ceil(random(0, gameChar.possibleGroundPosY.length)) + floor(random(0, gameChar.possibleGroundPosY.length)) ], size: 75, isFound: false, }; + } } } flagpole = { @@ -205,7 +211,7 @@ function draw() { fill(0); translate(-cameraPosX, 0); // Scrolling - cameraPosX = gameChar.x - width / 2; // Scrolling + if (gameChar.x < finish_position_x) cameraPosX = gameChar.x - width / 2; // Scrolling // -------- CLOUDS -------------- drawClouds(); @@ -512,7 +518,7 @@ function drawGround() { ); stroke(1); translate(-cameraPosX, 0); - for (i = 0; i < finish_position_x; i += 20) { + for (i = -width/2; i < finish_position_x + width/2; i += 20) { line( i, floorPos_y + (2 * (height - floorPos_y)) / 6,