Skip to content

Prevent thought bubbles from overlapping on spawn#32

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-thought-bubbles-overlap
Draft

Prevent thought bubbles from overlapping on spawn#32
Copilot wants to merge 4 commits intomainfrom
copilot/fix-thought-bubbles-overlap

Conversation

Copy link
Contributor

Copilot AI commented Dec 27, 2025

Thought bubbles were spawning at random positions without collision detection, causing overlaps that made individual bubbles difficult to dismiss.

Changes

Added collision detection to src/hooks/useThoughtBubbles.js:

  • calculateDistance() - Euclidean distance between bubble positions (viewport %)
  • isPositionValid() - Validates 25% minimum separation from existing bubbles
  • Modified spawnBubble() to attempt up to 20 positions before fallback to vertical staggering
// Try to find non-overlapping position
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
  const candidatePosition = {
    x: Math.random() * 70 + 10, // 10-80% from left
    y: Math.random() * 35 + 20, // 20-55% from top
  };
  
  if (isPositionValid(candidatePosition, prev)) {
    position = candidatePosition;
    break;
  }
}

Result

Bubbles maintain clear separation (25% viewport distance) for reliable tap/swipe interactions:

Multiple bubbles with proper spacing

Bubbles separated across positions

Original prompt

This section details on the original issue you should resolve

<issue_title>Thought bubbles should not spawn on top of each other</issue_title>
<issue_description>Thought bubbles should not spawn on top of each other</issue_description>

Comments on the Issue (you are Copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Add calculateDistance helper to compute Euclidean distance between positions
- Add isPositionValid helper to check for overlapping bubbles
- Modify spawnBubble to try up to 20 positions before spawning
- Add fallback positioning if no valid position found after max attempts
- Set minimum distance threshold of 25% viewport units between bubbles
- Tested manually with multiple bubbles spawning successfully without overlap

Co-authored-by: Theaxiom <57013+Theaxiom@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 27, 2025

Deploying criticalmassgame with  Cloudflare Pages  Cloudflare Pages

Latest commit: d49e81c
Status: ✅  Deploy successful!
Preview URL: https://e5ae233d.criticalmassgame.pages.dev
Branch Preview URL: https://copilot-fix-thought-bubbles-n28n.criticalmassgame.pages.dev

View logs

Copilot AI and others added 2 commits December 27, 2025 08:33
- Extract magic numbers to named constants in fallback logic
- Add clear comments explaining vertical staggering parameters
- Remove misleading comments about old implementation
- Improve readability and maintainability of collision detection code

Co-authored-by: Theaxiom <57013+Theaxiom@users.noreply.github.com>
- Correct VERTICAL_RANGE calculation to produce 20-55% range (not 20-54%)
- Update constant name from MAX_VERTICAL_RANGE to VERTICAL_RANGE for clarity
- Simplify modulo expression for better readability
- Ensure fallback positioning matches documented behavior

Co-authored-by: Theaxiom <57013+Theaxiom@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix thought bubbles to prevent overlapping Prevent thought bubbles from overlapping on spawn Dec 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Thought bubbles should not spawn on top of each other

2 participants