Add ocean movement and centered whale mechanics
- Whale now spawns in center area (350-450 x, 250-350 y) instead of from sides - Replaced linear whale movement with gentle bobbing oscillation - Whale bobs 15 pixels horizontally and 10 pixels vertically - Added camera sway to simulate ship rocking on ocean - Camera moves 8 pixels horizontal and 5 pixels vertical in smooth sine waves - Combined effects create realistic ship-based hunting experience - Significantly increases difficulty - must compensate for crosshair shake, whale bobbing, and camera sway - Natural ocean feel with continuous wave-like movement 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,9 @@ export default class HuntingScene extends Phaser.Scene {
|
|||||||
// Input setup
|
// Input setup
|
||||||
this.setupInput();
|
this.setupInput();
|
||||||
|
|
||||||
|
// Setup ocean movement (camera sway)
|
||||||
|
this.setupOceanMovement();
|
||||||
|
|
||||||
// Message display
|
// Message display
|
||||||
this.showMessage('Hunt whales! Click or press SPACE to shoot harpoon.');
|
this.showMessage('Hunt whales! Click or press SPACE to shoot harpoon.');
|
||||||
}
|
}
|
||||||
@@ -232,12 +235,10 @@ export default class HuntingScene extends Phaser.Scene {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Random position and direction
|
// Spawn in center area with some variation
|
||||||
const fromLeft = Math.random() > 0.5;
|
const x = 350 + Math.random() * 100; // 350-450 (center area)
|
||||||
const x = fromLeft ? -50 : 850;
|
const y = 250 + Math.random() * 100; // 250-350 (center area)
|
||||||
const y = 150 + Math.random() * 300;
|
const direction = Math.random() > 0.5 ? 1 : -1;
|
||||||
const direction = fromLeft ? 1 : -1;
|
|
||||||
const speed = 0.8 + Math.random() * 0.7; // Slightly slower for single whale
|
|
||||||
|
|
||||||
// Create whale body
|
// Create whale body
|
||||||
const whale = this.add.container(x, y);
|
const whale = this.add.container(x, y);
|
||||||
@@ -265,13 +266,15 @@ export default class HuntingScene extends Phaser.Scene {
|
|||||||
|
|
||||||
whale.add([body, tail, fin, healthBg, healthBar]);
|
whale.add([body, tail, fin, healthBg, healthBar]);
|
||||||
whale.setData('direction', direction);
|
whale.setData('direction', direction);
|
||||||
whale.setData('speed', speed);
|
|
||||||
whale.setData('alive', true);
|
whale.setData('alive', true);
|
||||||
whale.setData('health', 3); // Requires 3 hits
|
whale.setData('health', 3); // Requires 3 hits
|
||||||
whale.setData('maxHealth', 3);
|
whale.setData('maxHealth', 3);
|
||||||
whale.setData('bodyWidth', 80);
|
whale.setData('bodyWidth', 80);
|
||||||
whale.setData('bodyHeight', 40);
|
whale.setData('bodyHeight', 40);
|
||||||
whale.setData('healthBar', healthBar);
|
whale.setData('healthBar', healthBar);
|
||||||
|
whale.setData('baseX', x); // Store original position for bobbing
|
||||||
|
whale.setData('baseY', y);
|
||||||
|
whale.setData('bobTime', 0); // Timer for bobbing animation
|
||||||
|
|
||||||
// Flip if moving right
|
// Flip if moving right
|
||||||
if (direction > 0) {
|
if (direction > 0) {
|
||||||
@@ -292,20 +295,20 @@ export default class HuntingScene extends Phaser.Scene {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move whale
|
// Gentle bobbing movement
|
||||||
const direction = whale.getData('direction');
|
let bobTime = whale.getData('bobTime');
|
||||||
const speed = whale.getData('speed');
|
bobTime += 0.02;
|
||||||
whale.x += direction * speed;
|
whale.setData('bobTime', bobTime);
|
||||||
|
|
||||||
// If whale goes off screen, spawn a new one
|
const baseX = whale.getData('baseX');
|
||||||
if (whale.x < -100 || whale.x > 900) {
|
const baseY = whale.getData('baseY');
|
||||||
whale.destroy();
|
|
||||||
this.currentWhale = null;
|
// Gentle horizontal and vertical oscillation
|
||||||
// Spawn new whale after a short delay
|
const offsetX = Math.sin(bobTime) * 15; // 15 pixels horizontal movement
|
||||||
this.time.delayedCall(1500, () => {
|
const offsetY = Math.cos(bobTime * 0.7) * 10; // 10 pixels vertical movement
|
||||||
this.spawnWhale();
|
|
||||||
});
|
whale.x = baseX + offsetX;
|
||||||
}
|
whale.y = baseY + offsetY;
|
||||||
}
|
}
|
||||||
|
|
||||||
shootHarpoon() {
|
shootHarpoon() {
|
||||||
@@ -489,6 +492,31 @@ export default class HuntingScene extends Phaser.Scene {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupOceanMovement() {
|
||||||
|
// Create continuous camera sway to simulate ocean movement
|
||||||
|
// This makes the whole scene move as if on a rocking ship
|
||||||
|
|
||||||
|
// Initial camera position offset
|
||||||
|
this.cameraTime = 0;
|
||||||
|
|
||||||
|
// Store this in the update loop by creating a timer
|
||||||
|
this.time.addEvent({
|
||||||
|
delay: 16, // ~60fps
|
||||||
|
callback: () => {
|
||||||
|
this.cameraTime += 0.01;
|
||||||
|
|
||||||
|
// Smooth sine wave movement for natural ocean sway
|
||||||
|
const swayX = Math.sin(this.cameraTime) * 8; // 8 pixels horizontal sway
|
||||||
|
const swayY = Math.cos(this.cameraTime * 0.6) * 5; // 5 pixels vertical sway
|
||||||
|
|
||||||
|
// Apply to camera scroll
|
||||||
|
this.cameras.main.scrollX = swayX;
|
||||||
|
this.cameras.main.scrollY = swayY;
|
||||||
|
},
|
||||||
|
loop: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
returnToMap() {
|
returnToMap() {
|
||||||
this.scene.start('MapScene', { inventory: this.inventory });
|
this.scene.start('MapScene', { inventory: this.inventory });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user