From 09fd0629af3e27e2e18ac4bccc53c495fc6dcb6f Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Tue, 16 Dec 2025 23:29:14 +0100 Subject: [PATCH] Improve whale boundary behavior to avoid edge sticking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Increased boundary margin: 60 → 100 pixels - Push whale 20px away from edge when bouncing (not just clamping) - Add random variation to bounce speed - Randomize Y direction when hitting horizontal edges - Tighter vertical bounds: 150-500 (was 120-550) - Prevents whale from getting stuck near edges - More natural swimming patterns in center area 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- src/scenes/HuntingScene.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/scenes/HuntingScene.js b/src/scenes/HuntingScene.js index d5908bb..409f470 100644 --- a/src/scenes/HuntingScene.js +++ b/src/scenes/HuntingScene.js @@ -347,30 +347,35 @@ export default class HuntingScene extends Phaser.Scene { whale.x += bobOffsetX; whale.y += bobOffsetY; - // Keep whale within visible bounds - const margin = 60; // Account for whale size and bobbing + // Keep whale within visible bounds with better bounce behavior + const margin = 100; // Larger margin to keep whale away from edges const minX = margin; const maxX = 800 - margin; - const minY = 120; - const maxY = 550; + const minY = 150; + const maxY = 500; - // Bounce off screen edges and clamp position + // Bounce off screen edges with push into play area if (whale.x < minX) { - whale.x = minX; - whale.setData('swimSpeedX', Math.abs(swimSpeedX)); // Swim right - whale.setScale(-Math.abs(whale.scaleX), whale.scaleY); // Face right + whale.x = minX + 20; // Push away from edge + // Add random variation to bounce direction + const newSpeed = Math.abs(swimSpeedX) + (Math.random() * 0.2); + whale.setData('swimSpeedX', newSpeed); + whale.setData('swimSpeedY', (Math.random() - 0.5) * 0.3); // Random Y direction + whale.setScale(-Math.abs(whale.scaleX), whale.scaleY); } else if (whale.x > maxX) { - whale.x = maxX; - whale.setData('swimSpeedX', -Math.abs(swimSpeedX)); // Swim left - whale.setScale(Math.abs(whale.scaleX), whale.scaleY); // Face left + whale.x = maxX - 20; // Push away from edge + const newSpeed = -(Math.abs(swimSpeedX) + (Math.random() * 0.2)); + whale.setData('swimSpeedX', newSpeed); + whale.setData('swimSpeedY', (Math.random() - 0.5) * 0.3); // Random Y direction + whale.setScale(Math.abs(whale.scaleX), whale.scaleY); } if (whale.y < minY) { - whale.y = minY; - whale.setData('swimSpeedY', Math.abs(swimSpeedY)); // Swim down + whale.y = minY + 20; // Push away from edge + whale.setData('swimSpeedY', Math.abs(swimSpeedY) + (Math.random() * 0.1)); } else if (whale.y > maxY) { - whale.y = maxY; - whale.setData('swimSpeedY', -Math.abs(swimSpeedY)); // Swim up + whale.y = maxY - 20; // Push away from edge + whale.setData('swimSpeedY', -(Math.abs(swimSpeedY) + (Math.random() * 0.1))); } // Update opacity based on diving