@@ -43,35 +43,56 @@ function setup() { |
| 43 | 43 | |
| 44 | 44 | spider = new Spider(width / 2, height - 50); |
| 45 | 45 | |
| 46 | | - // Create obstacles |
| 46 | + // Create obstacles with better distribution |
| 47 | 47 | let numObstacles = Math.floor((width * height) / 60000); |
| 48 | | - numObstacles = constrain(numObstacles, 8, 20); |
| 48 | + numObstacles = constrain(numObstacles, 10, 25); |
| 49 | 49 | |
| 50 | | - for (let i = 0; i < numObstacles; i++) { |
| 51 | | - let x = random(100, width - 100); |
| 52 | | - let y = random(100, height - 150); |
| 53 | | - let radius = random(25, 45); |
| 54 | | - let type = random() < 0.6 ? 'branch' : 'leaf'; |
| 55 | | - |
| 56 | | - let valid = true; |
| 57 | | - for (let obstacle of obstacles) { |
| 58 | | - if (dist(x, y, obstacle.x, obstacle.y) < radius + obstacle.radius + 30) { |
| 59 | | - valid = false; |
| 60 | | - break; |
| 50 | + // Divide screen into zones for better distribution |
| 51 | + let zones = [ |
| 52 | + { minY: 50, maxY: height * 0.3 }, // Top zone |
| 53 | + { minY: height * 0.3, maxY: height * 0.6 }, // Middle zone |
| 54 | + { minY: height * 0.6, maxY: height - 100 } // Bottom zone |
| 55 | + ]; |
| 56 | + |
| 57 | + let obstaclesPerZone = Math.ceil(numObstacles / 3); |
| 58 | + |
| 59 | + for (let zone of zones) { |
| 60 | + for (let i = 0; i < obstaclesPerZone; i++) { |
| 61 | + let attempts = 0; |
| 62 | + let placed = false; |
| 63 | + |
| 64 | + while (!placed && attempts < 20) { |
| 65 | + let x = random(80, width - 80); |
| 66 | + let y = random(zone.minY, zone.maxY); |
| 67 | + let radius = random(25, 45); |
| 68 | + let type = random() < 0.6 ? 'branch' : 'leaf'; |
| 69 | + |
| 70 | + let valid = true; |
| 71 | + for (let obstacle of obstacles) { |
| 72 | + if (dist(x, y, obstacle.x, obstacle.y) < radius + obstacle.radius + 40) { |
| 73 | + valid = false; |
| 74 | + break; |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + if (valid) { |
| 79 | + obstacles.push(new Obstacle(x, y, radius, type)); |
| 80 | + placed = true; |
| 81 | + } |
| 82 | + attempts++; |
| 61 | 83 | } |
| 62 | 84 | } |
| 63 | | - |
| 64 | | - if (valid) { |
| 65 | | - obstacles.push(new Obstacle(x, y, radius, type)); |
| 66 | | - } |
| 67 | 85 | } |
| 68 | 86 | |
| 69 | | - // Add guaranteed anchor points |
| 87 | + // Add guaranteed anchor points with better bottom coverage |
| 70 | 88 | obstacles.push(new Obstacle(50, height/2, 35, 'branch')); |
| 71 | 89 | obstacles.push(new Obstacle(width - 50, height/2, 35, 'branch')); |
| 72 | 90 | obstacles.push(new Obstacle(width/2, 50, 40, 'leaf')); |
| 73 | | - obstacles.push(new Obstacle(width/4, height - 200, 30, 'leaf')); |
| 74 | | - obstacles.push(new Obstacle(3*width/4, height - 200, 30, 'branch')); |
| 91 | + |
| 92 | + // More bottom anchors for reachability |
| 93 | + obstacles.push(new Obstacle(width/4, height - 120, 35, 'leaf')); |
| 94 | + obstacles.push(new Obstacle(3*width/4, height - 120, 35, 'branch')); |
| 95 | + obstacles.push(new Obstacle(width/2, height - 150, 30, 'branch')); |
| 75 | 96 | |
| 76 | 97 | if (width > 1200) { |
| 77 | 98 | obstacles.push(new Obstacle(width/3, height/3, 35, 'leaf')); |
@@ -132,9 +153,26 @@ function draw() { |
| 132 | 153 | } |
| 133 | 154 | } |
| 134 | 155 | |
| 135 | | - for (let strand of webStrands) { |
| 156 | + for (let i = webStrands.length - 1; i >= 0; i--) { |
| 157 | + let strand = webStrands[i]; |
| 136 | 158 | strand.update(); |
| 137 | | - strand.display(); |
| 159 | + |
| 160 | + // Remove broken strands |
| 161 | + if (strand.broken) { |
| 162 | + // Create particles for breaking effect |
| 163 | + if (strand.path && strand.path.length > 0) { |
| 164 | + let midPoint = strand.path[Math.floor(strand.path.length / 2)]; |
| 165 | + for (let j = 0; j < 5; j++) { |
| 166 | + let p = new Particle(midPoint.x, midPoint.y); |
| 167 | + p.color = color(255, 255, 255); |
| 168 | + p.vel = createVector(random(-2, 2), random(-3, 0)); |
| 169 | + particles.push(p); |
| 170 | + } |
| 171 | + } |
| 172 | + webStrands.splice(i, 1); |
| 173 | + } else { |
| 174 | + strand.display(); |
| 175 | + } |
| 138 | 176 | } |
| 139 | 177 | |
| 140 | 178 | for (let node of webNodes) { |