78 lines
2.1 KiB
JavaScript
78 lines
2.1 KiB
JavaScript
/**
|
|
* 🐕 ANIMAL SYSTEM
|
|
* Handles all animal interactions including emotional triggers
|
|
*/
|
|
|
|
class Animal extends Phaser.GameObjects.Sprite {
|
|
constructor(scene, x, y, texture, type = 'domestic') {
|
|
super(scene, x, y, texture);
|
|
|
|
this.scene = scene;
|
|
this.type = type; // 'wild', 'domestic', 'infected'
|
|
|
|
// Animal properties
|
|
this.animalName = '';
|
|
this.isHostile = (type === 'infected' || type === 'wild');
|
|
this.triggerMemory = (type === 'domestic'); // Domestic animals trigger memories
|
|
|
|
// Proximity detection
|
|
this.proximityRadius = type === 'domestic' ? 150 : 100;
|
|
this.isPlayerNear = false;
|
|
|
|
// Memory trigger
|
|
this.memoryTriggered = false;
|
|
|
|
// Add to scene
|
|
scene.add.existing(this);
|
|
scene.physics.add.existing(this);
|
|
|
|
// Setup physics
|
|
this.body.setImmovable(true);
|
|
this.body.setCollideWorldBounds(true);
|
|
}
|
|
|
|
update(player) {
|
|
if (!player) return;
|
|
|
|
// Calculate distance to player
|
|
const distance = Phaser.Math.Distance.Between(
|
|
this.x, this.y,
|
|
player.x, player.y
|
|
);
|
|
|
|
const wasNear = this.isPlayerNear;
|
|
this.isPlayerNear = distance < this.proximityRadius;
|
|
|
|
// Trigger memory when player gets close to domestic animal (first time only)
|
|
if (this.triggerMemory && this.isPlayerNear && !wasNear && !this.memoryTriggered) {
|
|
this.onMemoryTriggered();
|
|
}
|
|
|
|
// Stop memory when player leaves
|
|
if (!this.isPlayerNear && wasNear && this.memoryTriggered) {
|
|
this.onMemoryEnded();
|
|
}
|
|
}
|
|
|
|
onMemoryTriggered() {
|
|
console.log(`💙 Kai remembers the family dog...`);
|
|
this.memoryTriggered = true;
|
|
|
|
// Emit event for UI to handle
|
|
this.scene.events.emit('animal:memory_triggered', {
|
|
animal: this,
|
|
type: 'domestic_dog'
|
|
});
|
|
}
|
|
|
|
onMemoryEnded() {
|
|
console.log(`💔 Memory fades...`);
|
|
|
|
this.scene.events.emit('animal:memory_ended', {
|
|
animal: this
|
|
});
|
|
}
|
|
}
|
|
|
|
export default Animal;
|