diff --git a/src/scenes/HuntingScene.js b/src/scenes/HuntingScene.js index 4ef3175..0d4f1ac 100644 --- a/src/scenes/HuntingScene.js +++ b/src/scenes/HuntingScene.js @@ -33,6 +33,9 @@ export default class HuntingScene extends Phaser.Scene { // Input setup this.setupInput(); + // Setup ocean movement (camera sway) + this.setupOceanMovement(); + // Message display this.showMessage('Hunt whales! Click or press SPACE to shoot harpoon.'); } @@ -232,12 +235,10 @@ export default class HuntingScene extends Phaser.Scene { return; } - // Random position and direction - const fromLeft = Math.random() > 0.5; - const x = fromLeft ? -50 : 850; - const y = 150 + Math.random() * 300; - const direction = fromLeft ? 1 : -1; - const speed = 0.8 + Math.random() * 0.7; // Slightly slower for single whale + // Spawn in center area with some variation + const x = 350 + Math.random() * 100; // 350-450 (center area) + const y = 250 + Math.random() * 100; // 250-350 (center area) + const direction = Math.random() > 0.5 ? 1 : -1; // Create whale body 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.setData('direction', direction); - whale.setData('speed', speed); whale.setData('alive', true); whale.setData('health', 3); // Requires 3 hits whale.setData('maxHealth', 3); whale.setData('bodyWidth', 80); whale.setData('bodyHeight', 40); 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 if (direction > 0) { @@ -292,20 +295,20 @@ export default class HuntingScene extends Phaser.Scene { return; } - // Move whale - const direction = whale.getData('direction'); - const speed = whale.getData('speed'); - whale.x += direction * speed; + // Gentle bobbing movement + let bobTime = whale.getData('bobTime'); + bobTime += 0.02; + whale.setData('bobTime', bobTime); - // If whale goes off screen, spawn a new one - if (whale.x < -100 || whale.x > 900) { - whale.destroy(); - this.currentWhale = null; - // Spawn new whale after a short delay - this.time.delayedCall(1500, () => { - this.spawnWhale(); - }); - } + const baseX = whale.getData('baseX'); + const baseY = whale.getData('baseY'); + + // Gentle horizontal and vertical oscillation + const offsetX = Math.sin(bobTime) * 15; // 15 pixels horizontal movement + const offsetY = Math.cos(bobTime * 0.7) * 10; // 10 pixels vertical movement + + whale.x = baseX + offsetX; + whale.y = baseY + offsetY; } 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() { this.scene.start('MapScene', { inventory: this.inventory }); }