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.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