This commit is contained in:
2025-12-12 10:17:21 +01:00
parent 84b07bb433
commit a210638002
30 changed files with 3731 additions and 999 deletions

View File

@@ -94,6 +94,11 @@ class BuildSystem {
if (!this.buildings[buildingId]) return;
this.selectedBuilding = buildingId;
// Play UI click sound
if (this.scene.soundManager) {
this.scene.soundManager.playUIClick();
}
// Refresh preview
if (this.buildMode) {
this.destroyPreview();
@@ -319,6 +324,11 @@ class BuildSystem {
collision: building.collision
});
// Play build sound
if (this.scene.soundManager) {
this.scene.soundManager.playBuild();
}
console.log(`🏗️ Placed ${building.name} at (${gridX}, ${gridY})`);
// Update UI

View File

@@ -56,6 +56,11 @@ class FarmingSystem {
this.scene.terrainSystem.tilledSprites.set(key, sprite);
}
// Play dig sound
if (this.scene.soundManager) {
this.scene.soundManager.playDig();
}
console.log(`✅ Tilled soil at (${gridX}, ${gridY})`);
return true;
}
@@ -98,6 +103,11 @@ class FarmingSystem {
this.scene.farmStats.cropsPlanted++;
}
// Play plant sound
if (this.scene.soundManager) {
this.scene.soundManager.playPlant();
}
console.log(`🌱 Planted ${cropType} at (${gridX}, ${gridY})`);
return true;
}
@@ -164,6 +174,11 @@ class FarmingSystem {
if (crop.sprite) crop.sprite.destroy();
this.crops = this.crops.filter(c => c !== crop);
// Play harvest sound
if (this.scene.soundManager) {
this.scene.soundManager.playHarvest();
}
console.log(`🌾 Harvested ${crop.type}! (+${goldEarned} gold)`);
// Show floating text

76
src/systems/NPCSpawner.js Normal file
View File

@@ -0,0 +1,76 @@
// NPCSpawner.js - Sistem za spawnjanje NPCjev
class NPCSpawner {
constructor(scene) {
this.scene = scene;
this.spawnInterval = 30000; // 30 sekund
this.maxNPCs = 3; // 3 NPCji na 100x100 mapo
this.spawnTimer = 0;
console.log('🧑 NPCSpawner: Initialized');
}
spawnInitialNPCs() {
// Spawn 3 NPCs at random locations
for (let i = 0; i < this.maxNPCs; i++) {
this.spawnRandomNPC();
}
console.log(`✅ Spawned ${this.maxNPCs} initial NPCs`);
}
spawnRandomNPC() {
if (!this.scene.terrainSystem || !this.scene.npcs) return;
// Random position (avoid farm area 20,20)
let x, y, attempts = 0;
do {
x = Phaser.Math.Between(5, 95);
y = Phaser.Math.Between(5, 95);
attempts++;
} while (this.isTooCloseToFarm(x, y) && attempts < 50);
// Check if tile is valid
const tile = this.scene.terrainSystem.getTile(x, y);
if (!tile || tile.type === 'water') return;
// Check if decoration exists
const key = `${x},${y}`;
if (this.scene.terrainSystem.decorationsMap.has(key)) return;
// Spawn NPC
const npc = new NPC(
this.scene,
x,
y,
this.scene.terrainOffsetX || 0,
this.scene.terrainOffsetY || 0,
'zombie' // Type
);
// Set to PASSIVE mode (random walk)
npc.state = 'PASSIVE';
npc.isTamed = false;
this.scene.npcs.push(npc);
console.log(`🧟 Spawned NPC at (${x}, ${y})`);
}
isTooCloseToFarm(x, y) {
const farmX = 50; // Farm center (updated from 20,20 to 50,50)
const farmY = 50;
const farmRadius = 15;
const dist = Math.sqrt((x - farmX) ** 2 + (y - farmY) ** 2);
return dist < farmRadius;
}
update(delta) {
// Check if we need to spawn more NPCs
if (this.scene.npcs.length < this.maxNPCs) {
this.spawnTimer += delta;
if (this.spawnTimer >= this.spawnInterval) {
this.spawnTimer = 0;
this.spawnRandomNPC();
}
}
}
}

View File

@@ -299,7 +299,8 @@ class SoundManager {
playHarvest() { this.playSFX('harvest'); }
playBuild() { this.playSFX('build'); }
playPickup() { this.playSFX('pickup'); }
playDig() { this.playSFX('dig'); } // Dodano
playDig() { this.playSFX('dig'); }
playUIClick() { this.beepUIClick(); } // UI click sound
playAttack() { this.beepAttack(); }
playHit() { this.beepHit(); }
playFootstep() { this.beepFootstep(); }
@@ -307,6 +308,22 @@ class SoundManager {
playRainSound() { this.startRainNoise(); }
stopRainSound() { this.stopRainNoise(); }
beepUIClick() {
if (!this.scene.sound.context) return;
const ctx = this.scene.sound.context;
const osc = ctx.createOscillator();
const gain = ctx.createGain();
osc.connect(gain);
gain.connect(ctx.destination);
// Quick, pleasant click sound
osc.frequency.value = 800;
osc.type = 'sine';
gain.gain.setValueAtTime(0.08, ctx.currentTime);
gain.gain.exponentialRampToValueAtTime(0.01, ctx.currentTime + 0.05);
osc.start();
osc.stop(ctx.currentTime + 0.05);
}
beepDig() {
if (!this.scene.sound.context) return;
const ctx = this.scene.sound.context;

View File

@@ -833,8 +833,9 @@ class TerrainSystem {
const isSolid = !isSmallDecor && (
typeLower.includes('tree') ||
typeLower.includes('sapling') ||
typeLower.includes('rock') ||
typeLower.includes('stone') ||
// ROCKS REMOVED - walkable now!
// typeLower.includes('rock') ||
// typeLower.includes('stone') ||
// fence REMOVED - it's walkable now!
typeLower.includes('wall') ||
typeLower.includes('signpost') ||