Improve whale boundary behavior to avoid edge sticking

- 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 <noreply@anthropic.com>
This commit is contained in:
Thomas Richter
2025-12-16 23:29:14 +01:00
parent 604c26fcc1
commit 09fd0629af

View File

@@ -347,30 +347,35 @@ export default class HuntingScene extends Phaser.Scene {
whale.x += bobOffsetX; whale.x += bobOffsetX;
whale.y += bobOffsetY; whale.y += bobOffsetY;
// Keep whale within visible bounds // Keep whale within visible bounds with better bounce behavior
const margin = 60; // Account for whale size and bobbing const margin = 100; // Larger margin to keep whale away from edges
const minX = margin; const minX = margin;
const maxX = 800 - margin; const maxX = 800 - margin;
const minY = 120; const minY = 150;
const maxY = 550; const maxY = 500;
// Bounce off screen edges and clamp position // Bounce off screen edges with push into play area
if (whale.x < minX) { if (whale.x < minX) {
whale.x = minX; whale.x = minX + 20; // Push away from edge
whale.setData('swimSpeedX', Math.abs(swimSpeedX)); // Swim right // Add random variation to bounce direction
whale.setScale(-Math.abs(whale.scaleX), whale.scaleY); // Face right 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) { } else if (whale.x > maxX) {
whale.x = maxX; whale.x = maxX - 20; // Push away from edge
whale.setData('swimSpeedX', -Math.abs(swimSpeedX)); // Swim left const newSpeed = -(Math.abs(swimSpeedX) + (Math.random() * 0.2));
whale.setScale(Math.abs(whale.scaleX), whale.scaleY); // Face left 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) { if (whale.y < minY) {
whale.y = minY; whale.y = minY + 20; // Push away from edge
whale.setData('swimSpeedY', Math.abs(swimSpeedY)); // Swim down whale.setData('swimSpeedY', Math.abs(swimSpeedY) + (Math.random() * 0.1));
} else if (whale.y > maxY) { } else if (whale.y > maxY) {
whale.y = maxY; whale.y = maxY - 20; // Push away from edge
whale.setData('swimSpeedY', -Math.abs(swimSpeedY)); // Swim up whale.setData('swimSpeedY', -(Math.abs(swimSpeedY) + (Math.random() * 0.1)));
} }
// Update opacity based on diving // Update opacity based on diving