zeroed-some/cob / cb6cb9b

Browse files

better obstacle distribution

Authored by espadonne
SHA
cb6cb9b4aeefb3bdf6f4e427eaa1ef357ae31ddd
Parents
3dd0bf8
Tree
67ca52d

1 changed file

StatusFile+-
M js/game.js 60 22
js/game.jsmodified
@@ -43,35 +43,56 @@ function setup() {
4343
     
4444
     spider = new Spider(width / 2, height - 50);
4545
     
46
-    // Create obstacles
46
+    // Create obstacles with better distribution
4747
     let numObstacles = Math.floor((width * height) / 60000);
48
-    numObstacles = constrain(numObstacles, 8, 20);
48
+    numObstacles = constrain(numObstacles, 10, 25);
4949
     
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++;
6183
             }
6284
         }
63
-        
64
-        if (valid) {
65
-            obstacles.push(new Obstacle(x, y, radius, type));
66
-        }
6785
     }
6886
     
69
-    // Add guaranteed anchor points
87
+    // Add guaranteed anchor points with better bottom coverage
7088
     obstacles.push(new Obstacle(50, height/2, 35, 'branch'));
7189
     obstacles.push(new Obstacle(width - 50, height/2, 35, 'branch'));
7290
     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'));
7596
     
7697
     if (width > 1200) {
7798
         obstacles.push(new Obstacle(width/3, height/3, 35, 'leaf'));
@@ -132,9 +153,26 @@ function draw() {
132153
         }
133154
     }
134155
     
135
-    for (let strand of webStrands) {
156
+    for (let i = webStrands.length - 1; i >= 0; i--) {
157
+        let strand = webStrands[i];
136158
         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
+        }
138176
     }
139177
     
140178
     for (let node of webNodes) {