@@ -350,126 +350,133 @@ class Spider { |
| 350 | 350 | this.land() |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | | - land () { |
| 354 | | - this.vel.mult(0) |
| 355 | | - this.isAirborne = false |
| 356 | | - this.canJump = true |
| 353 | +land() { |
| 354 | + this.vel.mult(0); |
| 355 | + this.isAirborne = false; |
| 356 | + this.canJump = true; |
| 357 | + |
| 358 | + // FIX: Check if we're actually landing on something valid |
| 359 | + let landedOnSomething = false; |
| 360 | + let landingPoint = null; // Store where we're landing for anchor |
| 361 | + let landingObstacle = null; // NEW: Track which obstacle we're landing on |
| 362 | + |
| 363 | + // Check if on ground |
| 364 | + if (this.pos.y >= height - this.radius - 5) { |
| 365 | + landedOnSomething = true; |
| 366 | + landingPoint = createVector(this.pos.x, height); |
| 367 | + } |
| 357 | 368 | |
| 358 | | - // FIX: Check if we're actually landing on something valid |
| 359 | | - let landedOnSomething = false |
| 360 | | - let landingPoint = null // Store where we're landing for anchor |
| 361 | | - |
| 362 | | - // Check if on ground |
| 363 | | - if (this.pos.y >= height - this.radius - 5) { |
| 364 | | - landedOnSomething = true |
| 365 | | - landingPoint = createVector(this.pos.x, height) |
| 366 | | - } |
| 367 | | - |
| 368 | | - // Check if on an obstacle |
| 369 | | - if (!landedOnSomething) { |
| 370 | | - for (let obstacle of obstacles) { |
| 371 | | - if (this.checkObstacleCollision(obstacle)) { |
| 372 | | - landedOnSomething = true |
| 373 | | - // Calculate edge point for anchor |
| 374 | | - let angle = atan2(this.pos.y - obstacle.y, this.pos.x - obstacle.x) |
| 375 | | - landingPoint = createVector( |
| 376 | | - obstacle.x + cos(angle) * obstacle.radius, |
| 377 | | - obstacle.y + sin(angle) * obstacle.radius |
| 378 | | - ) |
| 379 | | - break |
| 380 | | - } |
| 369 | + // Check if on an obstacle |
| 370 | + if (!landedOnSomething) { |
| 371 | + for (let obstacle of obstacles) { |
| 372 | + if (this.checkObstacleCollision(obstacle)) { |
| 373 | + landedOnSomething = true; |
| 374 | + landingObstacle = obstacle; // NEW: Store the obstacle |
| 375 | + // Calculate edge point for anchor |
| 376 | + let angle = atan2(this.pos.y - obstacle.y, this.pos.x - obstacle.x); |
| 377 | + landingPoint = createVector( |
| 378 | + obstacle.x + cos(angle) * obstacle.radius, |
| 379 | + obstacle.y + sin(angle) * obstacle.radius |
| 380 | + ); |
| 381 | + break; |
| 381 | 382 | } |
| 382 | 383 | } |
| 384 | + } |
| 383 | 385 | |
| 384 | | - // Check if on a web strand |
| 385 | | - if (!landedOnSomething) { |
| 386 | | - for (let strand of webStrands) { |
| 387 | | - if ( |
| 388 | | - strand !== currentStrand && |
| 389 | | - !strand.broken && |
| 390 | | - this.checkStrandCollision(strand) |
| 391 | | - ) { |
| 392 | | - landedOnSomething = true |
| 393 | | - // For web strands, use spider position as anchor |
| 394 | | - landingPoint = this.pos.copy() |
| 395 | | - break |
| 396 | | - } |
| 386 | + // Check if on a web strand |
| 387 | + if (!landedOnSomething) { |
| 388 | + for (let strand of webStrands) { |
| 389 | + if (strand !== currentStrand && !strand.broken && this.checkStrandCollision(strand)) { |
| 390 | + landedOnSomething = true; |
| 391 | + // For web strands, use spider position as anchor |
| 392 | + landingPoint = this.pos.copy(); |
| 393 | + break; |
| 397 | 394 | } |
| 398 | 395 | } |
| 396 | + } |
| 399 | 397 | |
| 400 | | - // Check if on home branch |
| 401 | | - if (!landedOnSomething && window.homeBranch) { |
| 402 | | - let branch = window.homeBranch |
| 403 | | - let branchStart = Math.min(branch.startX, branch.endX) |
| 404 | | - let branchEnd = Math.max(branch.startX, branch.endX) |
| 405 | | - |
| 406 | | - if (this.pos.x >= branchStart - 10 && this.pos.x <= branchEnd + 10) { |
| 407 | | - let t = (this.pos.x - branchStart) / (branchEnd - branchStart) |
| 408 | | - t = constrain(t, 0, 1) |
| 409 | | - let branchTopThickness = lerp( |
| 410 | | - branch.thickness * 0.9, |
| 411 | | - branch.thickness * 0.35, |
| 412 | | - t |
| 413 | | - ) |
| 414 | | - let branchSurfaceY = branch.y - branchTopThickness |
| 415 | | - let angleCorrection = (this.pos.x - branchStart) * branch.angle |
| 416 | | - branchSurfaceY += angleCorrection |
| 417 | | - |
| 418 | | - if (abs(this.pos.y - branchSurfaceY) < this.radius + 10) { |
| 419 | | - landedOnSomething = true |
| 420 | | - landingPoint = createVector(this.pos.x, branchSurfaceY) |
| 421 | | - } |
| 398 | + // Check if on home branch |
| 399 | + if (!landedOnSomething && window.homeBranch) { |
| 400 | + let branch = window.homeBranch; |
| 401 | + let branchStart = Math.min(branch.startX, branch.endX); |
| 402 | + let branchEnd = Math.max(branch.startX, branch.endX); |
| 403 | + |
| 404 | + if (this.pos.x >= branchStart - 10 && this.pos.x <= branchEnd + 10) { |
| 405 | + let t = (this.pos.x - branchStart) / (branchEnd - branchStart); |
| 406 | + t = constrain(t, 0, 1); |
| 407 | + let branchTopThickness = lerp(branch.thickness * 0.9, branch.thickness * 0.35, t); |
| 408 | + let branchSurfaceY = branch.y - branchTopThickness; |
| 409 | + let angleCorrection = (this.pos.x - branchStart) * branch.angle; |
| 410 | + branchSurfaceY += angleCorrection; |
| 411 | + |
| 412 | + if (abs(this.pos.y - branchSurfaceY) < this.radius + 10) { |
| 413 | + landedOnSomething = true; |
| 414 | + landingPoint = createVector(this.pos.x, branchSurfaceY); |
| 422 | 415 | } |
| 423 | 416 | } |
| 417 | + } |
| 424 | 418 | |
| 425 | | - // FIX: If we're deploying web but didn't land on anything valid, destroy the web |
| 426 | | - if (currentStrand && isDeployingWeb && (spacePressed || touchHolding)) { |
| 427 | | - if (landedOnSomething && landingPoint) { |
| 428 | | - // Valid landing - finalize the web at the landing point |
| 429 | | - currentStrand.end = landingPoint.copy() // Use edge point, not spider center |
| 430 | | - if (!currentStrand.path || currentStrand.path.length === 0) { |
| 431 | | - currentStrand.path = [landingPoint.copy()] |
| 432 | | - } else { |
| 433 | | - currentStrand.path.push(landingPoint.copy()) |
| 434 | | - } |
| 435 | | - webNodes.push(new WebNode(landingPoint.x, landingPoint.y)) |
| 436 | | - |
| 437 | | - // Update last anchor for next web |
| 438 | | - this.lastAnchorPoint = landingPoint.copy() |
| 419 | + // FIX: If we're deploying web but didn't land on anything valid, destroy the web |
| 420 | + if (currentStrand && isDeployingWeb && (spacePressed || touchHolding)) { |
| 421 | + if (landedOnSomething && landingPoint) { |
| 422 | + // Valid landing - finalize the web at the landing point |
| 423 | + currentStrand.end = landingPoint.copy(); // Use edge point, not spider center |
| 424 | + |
| 425 | + // NEW: Track obstacle attachment for the end point |
| 426 | + if (landingObstacle) { |
| 427 | + currentStrand.endObstacle = landingObstacle; |
| 428 | + currentStrand.endAngle = atan2( |
| 429 | + landingPoint.y - landingObstacle.y, |
| 430 | + landingPoint.x - landingObstacle.x |
| 431 | + ); |
| 432 | + } |
| 433 | + |
| 434 | + if (!currentStrand.path || currentStrand.path.length === 0) { |
| 435 | + currentStrand.path = [landingPoint.copy()]; |
| 439 | 436 | } else { |
| 440 | | - // Invalid landing in mid-air - destroy the web! |
| 441 | | - if ( |
| 442 | | - webStrands.length > 0 && |
| 443 | | - webStrands[webStrands.length - 1] === currentStrand |
| 444 | | - ) { |
| 445 | | - webStrands.pop() // Remove the invalid strand |
| 437 | + currentStrand.path.push(landingPoint.copy()); |
| 438 | + } |
| 439 | + |
| 440 | + let newNode = new WebNode(landingPoint.x, landingPoint.y); |
| 441 | + // NEW: Track node attachment |
| 442 | + if (landingObstacle) { |
| 443 | + newNode.attachedObstacle = landingObstacle; |
| 444 | + newNode.attachmentAngle = currentStrand.endAngle; |
| 445 | + } |
| 446 | + webNodes.push(newNode); |
| 446 | 447 | |
| 447 | | - // Create poof particles |
| 448 | | - for (let i = 0; i < 8; i++) { |
| 449 | | - let p = new Particle(this.pos.x, this.pos.y) |
| 450 | | - p.color = color(255, 255, 255, 150) |
| 451 | | - p.vel = createVector(random(-3, 3), random(-3, 3)) |
| 452 | | - p.size = 4 |
| 453 | | - particles.push(p) |
| 454 | | - } |
| 448 | + // Update last anchor for next web |
| 449 | + this.lastAnchorPoint = landingPoint.copy(); |
| 450 | + } else { |
| 451 | + // Invalid landing in mid-air - destroy the web! |
| 452 | + if (webStrands.length > 0 && webStrands[webStrands.length - 1] === currentStrand) { |
| 453 | + webStrands.pop(); // Remove the invalid strand |
| 455 | 454 | |
| 456 | | - // Notification |
| 457 | | - if (notifications.length < 3) { |
| 458 | | - notifications.push( |
| 459 | | - new Notification('Web needs anchor point!', color(255, 150, 150)) |
| 460 | | - ) |
| 461 | | - } |
| 455 | + // Create poof particles |
| 456 | + for (let i = 0; i < 8; i++) { |
| 457 | + let p = new Particle(this.pos.x, this.pos.y); |
| 458 | + p.color = color(255, 255, 255, 150); |
| 459 | + p.vel = createVector(random(-3, 3), random(-3, 3)); |
| 460 | + p.size = 4; |
| 461 | + particles.push(p); |
| 462 | + } |
| 463 | + |
| 464 | + // Notification |
| 465 | + if (notifications.length < 3) { |
| 466 | + notifications.push(new Notification("Web needs anchor point!", color(255, 150, 150))); |
| 462 | 467 | } |
| 463 | 468 | } |
| 464 | | - } else if (landedOnSomething && landingPoint) { |
| 465 | | - // Update last anchor point even when not deploying web |
| 466 | | - this.lastAnchorPoint = landingPoint.copy() |
| 467 | 469 | } |
| 468 | | - |
| 469 | | - currentStrand = null |
| 470 | | - isDeployingWeb = false |
| 470 | + } else if (landedOnSomething && landingPoint) { |
| 471 | + // Update last anchor point even when not deploying web |
| 472 | + this.lastAnchorPoint = landingPoint.copy(); |
| 471 | 473 | } |
| 472 | 474 | |
| 475 | + currentStrand = null; |
| 476 | + isDeployingWeb = false; |
| 477 | +} |
| 478 | + |
| 479 | + |
| 473 | 480 | display () { |
| 474 | 481 | push() |
| 475 | 482 | translate(this.pos.x, this.pos.y) |
@@ -904,38 +911,50 @@ class Obstacle { |
| 904 | 911 | } |
| 905 | 912 | } |
| 906 | 913 | |
| 907 | | - updateAttachedStrands () { |
| 908 | | - // Update web strands that are connected to this obstacle |
| 909 | | - for (let strand of webStrands) { |
| 910 | | - // Check if strand starts near this obstacle's edge |
| 911 | | - let startDist = dist(strand.start.x, strand.start.y, this.x, this.y) |
| 912 | | - if (startDist >= this.radius - 5 && startDist <= this.radius + 15) { |
| 913 | | - // Strand is attached to edge - update to maintain edge connection |
| 914 | | - let angle = atan2(strand.start.y - this.y, strand.start.x - this.x) |
| 915 | | - strand.start.x = this.x + cos(angle) * this.radius |
| 916 | | - strand.start.y = this.y + sin(angle) * this.radius |
| 917 | | - if (strand.path && strand.path.length > 0) { |
| 918 | | - strand.path[0].x = strand.start.x |
| 919 | | - strand.path[0].y = strand.start.y |
| 920 | | - } |
| 914 | +updateAttachedStrands() { |
| 915 | + // Update web strands that are connected to this obstacle |
| 916 | + for (let strand of webStrands) { |
| 917 | + if (!strand || strand.broken) continue; |
| 918 | + |
| 919 | + // Check if strand starts at this obstacle |
| 920 | + if (strand.startObstacle === this) { |
| 921 | + // Update the start position to maintain the attachment |
| 922 | + let angle = strand.startAngle; // Use stored angle |
| 923 | + strand.start.x = this.x + cos(angle) * this.radius; |
| 924 | + strand.start.y = this.y + sin(angle) * this.radius; |
| 925 | + |
| 926 | + // Update path if it exists |
| 927 | + if (strand.path && strand.path.length > 0) { |
| 928 | + strand.path[0].x = strand.start.x; |
| 929 | + strand.path[0].y = strand.start.y; |
| 921 | 930 | } |
| 922 | | - |
| 923 | | - // Check if strand ends near this obstacle's edge |
| 924 | | - if (strand.end) { |
| 925 | | - let endDist = dist(strand.end.x, strand.end.y, this.x, this.y) |
| 926 | | - if (endDist >= this.radius - 5 && endDist <= this.radius + 15) { |
| 927 | | - // Strand is attached to edge - update to maintain edge connection |
| 928 | | - let angle = atan2(strand.end.y - this.y, strand.end.x - this.x) |
| 929 | | - strand.end.x = this.x + cos(angle) * this.radius |
| 930 | | - strand.end.y = this.y + sin(angle) * this.radius |
| 931 | | - if (strand.path && strand.path.length > 0) { |
| 932 | | - strand.path[strand.path.length - 1].x = strand.end.x |
| 933 | | - strand.path[strand.path.length - 1].y = strand.end.y |
| 934 | | - } |
| 935 | | - } |
| 931 | + } |
| 932 | + |
| 933 | + // Check if strand ends at this obstacle |
| 934 | + if (strand.endObstacle === this) { |
| 935 | + // Update the end position to maintain the attachment |
| 936 | + let angle = strand.endAngle; // Use stored angle |
| 937 | + strand.end.x = this.x + cos(angle) * this.radius; |
| 938 | + strand.end.y = this.y + sin(angle) * this.radius; |
| 939 | + |
| 940 | + // Update path if it exists |
| 941 | + if (strand.path && strand.path.length > 0) { |
| 942 | + strand.path[strand.path.length - 1].x = strand.end.x; |
| 943 | + strand.path[strand.path.length - 1].y = strand.end.y; |
| 936 | 944 | } |
| 937 | 945 | } |
| 938 | 946 | } |
| 947 | + |
| 948 | + // Also update web nodes attached to this obstacle |
| 949 | + for (let node of webNodes) { |
| 950 | + if (node.attachedObstacle === this) { |
| 951 | + let angle = node.attachmentAngle; |
| 952 | + node.x = this.x + cos(angle) * this.radius; |
| 953 | + node.y = this.y + sin(angle) * this.radius; |
| 954 | + } |
| 955 | + } |
| 956 | +} |
| 957 | + |
| 939 | 958 | |
| 940 | 959 | breakAttachedStrands () { |
| 941 | 960 | // Check for strands attached to this obstacle's edge |