Compare commits

...

3 Commits

Author SHA1 Message Date
2fc025b760 📋 Faza 1 Master Production Plan
 COMPLETE ROADMAP:
- 73 sprites total for farm expansion
- 3-week production schedule
- Detailed breakdowns per category

📊 BREAKDOWN:
1. Animal Animations: 39 sprites (10 animals × 4 frames)
2. Farm Infrastructure: 13 sprites (greenhouse, irrigation, storage)
3. Tool Upgrades: 21 sprites (stone, iron, steel + specials)

⏱️ TIME ESTIMATE:
- ~18 hours total work
- 3 hours/day = 6 days
- 6 hours/day = 3 days

🎯 PRIORITY:
1. HIGH: Animals + greenhouse + stone/iron tools
2. MED: Irrigation + storage + steel tools
3. LOW: Special tools + windmill

📂 FILE STRUCTURE:
- Organized by animal folders
- Infrastructure categories
- Tool tiers

Status: 3/73 (4%)
Target: 100% in 1 week!
2026-01-08 23:38:22 +01:00
55b496a2ce 🤖 AI Behavior System + Sound Manifest
 NEW SYSTEMS:
1. AnimalBehavior.js - Wander, Flee, Follow, Glowing Eyes
2. NPCIdleBehavior.js - Idle animations (hat fix, sweat wipe)
3. ANIMAL_SOUND_MANIFEST.md - 40+ sound mappings

🎮 AI FEATURES:
- Smooth movement (not grid-based) ✓
- Flee from player (100px range) ✓
- Follow with delay (cargo animals: llama, horse, donkey) ✓
- Glowing eyes in darkness (NOIR EFFECT!) ✓
  - Neon pink/green eyes visible at distance
  - Perfect for 'eyes in forest' atmosphere

👤 NPC FEATURES:
- Random idle animations every 3-8 seconds
- Fix hat, wipe sweat, look around, scratch head
- Gronk-specific: coin counting, item polishing

🔊 SOUND SYSTEM:
- Kenney pack mapping for 23 animal sounds
- Footstep variations (mud, grass, cobble)
- Noir sound design: muffled distant sounds + reverb

DEMO: 56/60 sprites (93%)!
Next: 4 remaining sprites + integration testing
2026-01-08 23:34:22 +01:00
86915519f1 🎮 Jan 8 Demo Complete - 16 Final Sprites + AI Prep
 FENCE (3): vertical, horizontal, corner
 TILES (7): cobble (4 variants), dirt (3 variants)
 UI (3): trial badge, purchase button, lock icon
 BOUNDARY (3): town gate, locked sign, fog wall

DEMO: 56/60 sprites (93%)
Next: AI Behavior System
2026-01-08 23:31:43 +01:00
21 changed files with 957 additions and 8 deletions

158
ANIMAL_SOUND_MANIFEST.md Normal file
View File

@@ -0,0 +1,158 @@
# 🔊 **ANIMAL & NPC SOUND MANIFEST**
**Krvava Žetev - Gothic Farm Game**
**Source:** Kenney Sound Packs (already downloaded)
**Location:** `/assets/audio/sfx/`
---
## 🐮 **FARM ANIMAL SOUNDS**
### **Required Sounds (23 total):**
**COW:**
- `cow_idle.wav` - Low moo, ambient
- `cow_flee.wav` - Alarmed moo, louder
- `cow_footstep.wav` - Heavy hoof step
**PIG:**
- `pig_idle.wav` - Snort, oink
- `pig_flee.wav` - Squealing
- `pig_footstep.wav` - Medium step
**SHEEP:**
- `sheep_idle.wav` - Baa sound
- `sheep_flee.wav` - Panicked baa
- `sheep_footstep.wav` - Light hoof step
**CHICKEN:**
- `chicken_idle.wav` - Cluck
- `chicken_flee.wav` - Fast clucking/cackle
- `chicken_footstep.wav` - Light scratch
**DUCK:**
- `duck_idle.wav` - Quack
- `duck_flee.wav` - Fast quacking
- `duck_footstep.wav` - Paddle sound
**GOAT:**
- `goat_idle.wav` - Maa/bleat
- `goat_flee.wav` - Loud bleat
- `goat_footstep.wav` - Hoof clatter
**HORSE:**
- `horse_idle.wav` - Neigh/whinny
- `horse_flee.wav` - Gallop neigh
- `horse_footstep.wav` - Heavy gallop
**RABBIT:**
- `rabbit_idle.wav` - Light chitter
- `rabbit_flee.wav` - Quick squeak
- `rabbit_footstep.wav` - Soft hop
---
## 👤 **NPC AMBIENT SOUNDS**
**GRONK (Shop):**
- `gronk_idle_breath.wav` - Heavy breathing
- `gronk_coins.wav` - Coin counting
- `gronk_grumble.wav` - Low grumble
**GENERIC NPC:**
- `npc_footstep_dirt.wav` - Walking on dirt
- `npc_footstep_cobble.wav` - Walking on cobblestone
- `npc_clothing_rustle.wav` - Moving
---
## 🌾 **ENVIRONMENTAL SOUNDS (Related)**
**MUD & TERRAIN:**
- `footstep_mud_1.wav` - Squelch
- `footstep_mud_2.wav` - Squelch variant
- `footstep_grass.wav` - Soft grass step
- `footstep_cobble.wav` - Hard stone step
**FARM AMBIENCE:**
- `farm_wind.wav` - Light wind
- `farm_distant_animals.wav` - Mixed distant sounds
- `gate_creak.wav` - Gate opening/closing
- `chain_rattle.wav` - Metal chains (locked gate)
---
## 📂 **KENNEY PACK MAPPING**
**Where to find these in your Kenney downloads:**
**Animal Sounds:** `Kenney/Voice-Over Pack/`
- Look for: animal, creature sounds
- Variants: low, high pitch versions
**Footsteps:** `Kenney/Impact Sounds/`
- Look for: step, walk, shuffle
- Different surfaces: grass, stone, mud
**Ambient:** `Kenney/RPG Audio/`
- Environment loops
- Object interactions
**UI/Interact:** `Kenney/Interface Sounds/`
- For shop interactions
---
## 🎮 **IMPLEMENTATION CHECKLIST**
**Phase 1 - Priority (10 sounds):**
- [ ] `cow_idle.wav`
- [ ] `cow_flee.wav`
- [ ] `pig_idle.wav`
- [ ] `sheep_idle.wav`
- [ ] `chicken_idle.wav`
- [ ] `horse_idle.wav`
- [ ] `footstep_mud_1.wav`
- [ ] `footstep_grass.wav`
- [ ] `npc_footstep_dirt.wav`
- [ ] `gronk_grumble.wav`
**Phase 2 - Full Set (All 40+ sounds)**
---
## 🔧 **PROCESSING NOTES**
**Format:** Convert all to `.wav` or `.ogg`
**Sample Rate:** 44.1kHz
**Channels:** Mono (stereo for ambience)
**Normalization:** -3dB peak
**Volume Levels:**
- Idle sounds: 70%
- Flee sounds: 90%
- Footsteps: 50%
- Ambience: 40%
---
## 💡 **NOIR SOUND DESIGN TWIST**
**For glowing-eye effect in darkness:**
When animal is in shadow/distant:
1. Mute normal animal sounds
2. Play low-pass filtered version (muffled)
3. Add eerie reverb/echo
4. Optional: Add faint heartbeat or breathing
**When Kai's flashlight shines on them:**
1. Sharp sound cue (surprise!)
2. Immediate flee sound trigger
3. Rapid footstep sequence
This makes the "glowing eyes in forest" moment EXTRA creepy! 👀✨
---
**Start with Phase 1 (10 sounds), test, then expand!**

View File

@@ -1,14 +1,14 @@
# 📋 **DEMO PRODUCTION TASKS - COMPLETE CHECKLIST**
**Created:** Jan 8, 2026 21:37 CET
**Updated:** Jan 8, 2026 22:03 CET
**Updated:** Jan 8, 2026 23:31 CET
**Purpose:** ALL remaining demo assets as tasks
**Target:** 60 sprites total (5 house + 5 barn + 50 remaining)
**Status:** 12/60 complete (20%)
**Target:** 60 sprites total
**Status:** 56/60 complete (93%) 🎉
---
## ✅ **COMPLETED (12/60):**
## ✅ **COMPLETED (40/60):**
### **Kai's House (5 stages):**
- [x] Stage 1: Sleeping bag only (48px)
@@ -17,7 +17,7 @@
- [x] Stage 4: Gothic house (128px)
- [x] Stage 5: Gothic manor (192px)
### **Barn (5 stages + 2 extras = 7 total):**
### **Barn (7 total):**
- [x] Stage 1: Ruined barn (128px)
- [x] Stage 2: Partial repair (128px)
- [x] Stage 3: Repaired basic (128px)
@@ -26,6 +26,38 @@
- [x] EXTRA: Barn door (64x96px)
- [x] EXTRA: Barn interior with hay (96px)
### **Shop Counter (15 total):**
- [x] Shop front wall
- [x] Shop counter window (with merchant!)
- [x] Shop roof overhang
- [x] Shop sign hanging
- [x] Shop shelves (with Grim Reaper!)
- [x] Counter surface
- [x] Cash box
- [x] Sell button (red)
- [x] Price panel
- [x] Gold coin icon
- [x] Buy button (green)
- [x] Display area
- [x] UI arrow (inventory→shop)
- [x] Currency counter
- [x] Confirm panel ("CONFIRM RITUAL?")
### **Farm Props (13 total):**
- [x] Scarecrow (pumpkin head)
- [x] Compost bin
- [x] Wheelbarrow
- [x] Water trough
- [x] Hay bales
- [x] Tool rack
- [x] Flower bed
- [x] Beehive
- [x] Animal pen fence
- [x] Chicken coop - Stage 1 (broken)
- [x] Chicken coop - Stage 2 (repaired)
- [x] Chicken coop - Stage 3 (upgraded)
- [x] Chicken coop - Stage 4 (deluxe)
---
## 🏗️ **FARM BUILDINGS (4 remaining):**
@@ -139,13 +171,13 @@
|----------|-------|------|-----------|---|
| **House** | 5 | 5 | 0 | ✅ 100% |
| **Barn** | 7 | 7 | 0 | ✅ 100% |
| **Shop Counter** | 15 | 15 | 0 | ✅ 100% |
| **Farm Props** | 13 | 13 | 0 | ✅ 100% |
| **Farm Buildings** | 4 | 0 | 4 | 0% |
| **Shop Counter** | 15 | 0 | 15 | 0% |
| **Town Path** | 10 | 0 | 10 | 0% |
| **Farm Props** | 10 | 0 | 10 | 0% |
| **UI Polish** | 5 | 0 | 5 | 0% |
| **Bonus** | 5 | 0 | 5 | 0% |
| **TOTAL** | **60** | **12** | **48** | **20%** |
| **TOTAL** | **64** | **40** | **24** | **62%** |
---

328
FAZA_1_PRODUCTION_PLAN.md Normal file
View File

@@ -0,0 +1,328 @@
# 🌾 **FAZA 1 - FARM EXPANSION PRODUCTION PLAN**
**Created:** Jan 8, 2026 23:37 CET
**Purpose:** Complete production roadmap for Faza 1 farm assets
**Target:** 73 sprites total
**Status:** 3/73 complete (4%)
---
## 📊 **CURRENT STATUS:**
### **✅ COMPLETED (3):**
- [x] Cow idle animation (prototype)
- [x] Greenhouse stage 1 (broken)
- [x] Stone hoe (prototype)
### **❌ REMAINING (70):**
- [ ] Animal animations: 39 sprites
- [ ] Farm infrastructure: 13 sprites
- [ ] Tool upgrades: 21 sprites
---
## 🐮 **ANIMAL ANIMATIONS (39 sprites)**
**Method:** Use existing 10 animal references + generate 4 frames each
### **COW (3 remaining):**
- [x] Idle - DONE
- [ ] Walk (moving animation)
- [ ] Eat (head down, chewing)
- [ ] Milk (being milked, still)
### **PIG (4):**
- [ ] Idle (standing, slight movement)
- [ ] Walk (trotting)
- [ ] Eat (snout in trough)
- [ ] Dig (snout in dirt)
### **SHEEP (4):**
- [ ] Idle (standing, wool visible)
- [ ] Walk (waddle)
- [ ] Eat (grazing)
- [ ] Shear (being sheared, wool removal)
### **CHICKEN (4):**
- [ ] Idle (standing, head bob)
- [ ] Walk (pecking walk)
- [ ] Peck (pecking ground)
- [ ] Lay egg (sitting, egg appears)
### **DUCK (4):**
- [ ] Idle (standing on water)
- [ ] Walk (waddle on land)
- [ ] Swim (paddling)
- [ ] Peck (head in water)
### **GOAT (4):**
- [ ] Idle (standing, chewing)
- [ ] Walk (confident stride)
- [ ] Eat (grazing)
- [ ] Butt (headbutt action, aggressive)
### **HORSE (4):**
- [ ] Idle (standing, tail swish)
- [ ] Walk (slow walk)
- [ ] Gallop (fast run)
- [ ] Eat (head down, hay)
### **RABBIT (4):**
- [ ] Idle (sitting, nose twitch)
- [ ] Hop (jumping motion)
- [ ] Eat (nibbling carrot)
- [ ] Burrow (digging hole)
### **DONKEY (4):**
- [ ] Idle (standing, ears move)
- [ ] Walk (slow plod)
- [ ] Eat (munching hay)
- [ ] Bray (mouth open, loud)
### **LLAMA (4):**
- [ ] Idle (standing, neck high)
- [ ] Walk (elegant stride)
- [ ] Eat (grazing, long neck)
- [ ] Spit (aggressive, spitting)
---
## 🏗️ **FARM INFRASTRUCTURE (13 sprites)**
### **GREENHOUSE (4 remaining):**
- [x] Stage 1: Broken (shattered glass) - DONE
- [ ] Stage 2: Repaired (patched glass)
- [ ] Stage 3: Functional (clean glass)
- [ ] Stage 4: Advanced (automated)
- [ ] Stage 5: Deluxe (gothic glass palace)
### **IRRIGATION SYSTEM (4):**
- [ ] Pipe straight (horizontal water line)
- [ ] Pipe corner (90° turn)
- [ ] Sprinkler head (water spray)
- [ ] Pump station (water source)
### **STORAGE BUILDINGS (3):**
- [ ] Crop storage shed (vegetables/fruits)
- [ ] Feed storage (animal food)
- [ ] Silo (tall grain tower)
### **FARM ELEMENTS (2):**
- [ ] Manure pile (fertilizer source)
- [ ] Windmill (grinding grain)
---
## 🔨 **TOOL UPGRADES (21 sprites)**
**6 Tool Types × 3 Tiers = 18 basic + 4 special = 22 total**
### **STONE TIER (5 remaining):**
- [x] Stone hoe - DONE
- [ ] Stone axe (tree chopping)
- [ ] Stone pickaxe (rock breaking)
- [ ] Stone watering can (crops)
- [ ] Stone scythe (harvesting)
- [ ] Stone shovel (digging)
### **IRON TIER (6):**
- [ ] Iron hoe
- [ ] Iron axe
- [ ] Iron pickaxe
- [ ] Iron watering can
- [ ] Iron scythe
- [ ] Iron shovel
### **STEEL TIER (6):**
- [ ] Steel hoe
- [ ] Steel axe
- [ ] Steel pickaxe
- [ ] Steel watering can
- [ ] Steel scythe
- [ ] Steel shovel
### **SPECIAL TOOLS (4):**
- [ ] Fishing rod (catch fish)
- [ ] Net (catch insects/fish)
- [ ] Hammer (building/crafting)
- [ ] Wrench (machine repairs)
---
## 📅 **PRODUCTION SCHEDULE:**
### **WEEK 1 - ANIMAL ANIMATIONS (40 sprites):**
**Day 1-2: Mammals (16 sprites)**
- Cow (3), Pig (4), Sheep (4), Goat (4)
**Day 3-4: Birds & Equines (12 sprites)**
- Chicken (4), Duck (4), Horse (4)
**Day 5-6: Small & Pack Animals (12 sprites)**
- Rabbit (4), Donkey (4), Llama (4)
**Day 7: Review & Polish**
- Test animations in-game
- Adjust timing/frames
---
### **WEEK 2 - INFRASTRUCTURE (13 sprites):**
**Day 1-2: Greenhouse (4 sprites)**
- Stages 2-5 completion
**Day 3: Irrigation (4 sprites)**
- Pipe straight, corner, sprinkler, pump
**Day 4: Storage (3 sprites)**
- Crop shed, feed storage, silo
**Day 5: Farm Elements (2 sprites)**
- Manure pile, windmill
**Day 6-7: Integration & Testing**
- Place in Tiled map
- Test interactions
---
### **WEEK 3 - TOOL UPGRADES (21 sprites):**
**Day 1-2: Stone Tier (5 sprites)**
- Complete stone tool set
**Day 3-4: Iron Tier (6 sprites)**
- Complete iron tool set
**Day 5-6: Steel Tier (6 sprites)**
- Complete steel tool set
**Day 7: Special Tools (4 sprites)**
- Fishing rod, net, hammer, wrench
---
## 🎨 **STYLE GUIDE:**
**All sprites must match:**
- ✅ Thick black outlines
- ✅ Dark-chibi gothic aesthetic
- ✅ "Cult of the Lamb" inspired
- ✅ Smooth vector art (NOT pixel art)
- ✅ Transparent backgrounds
- ✅ Consistent with existing 10 animal refs
**Animation Requirements:**
- 4 frames per animal action
- Smooth transitions
- Natural movement
- Gothic subtle touches (glowing eyes optional)
---
## 💾 **FILE ORGANIZATION:**
```
/assets/references/
├── creatures/farm_animals/
│ ├── cow/
│ │ ├── idle.png ✓
│ │ ├── walk.png
│ │ ├── eat.png
│ │ └── milk.png
│ ├── pig/
│ │ ├── idle.png
│ │ ├── walk.png
│ │ ├── eat.png
│ │ └── dig.png
│ └── ... (8 more animals)
├── faza1_infrastructure/
│ ├── greenhouse/
│ │ ├── 01_broken.png ✓
│ │ ├── 02_repaired.png
│ │ ├── 03_functional.png
│ │ ├── 04_advanced.png
│ │ └── 05_deluxe.png
│ ├── irrigation/
│ ├── storage/
│ └── farm_elements/
└── tool_upgrades/
├── stone/
│ ├── hoe.png ✓
│ ├── axe.png
│ ├── pickaxe.png
│ ├── watering_can.png
│ ├── scythe.png
│ └── shovel.png
├── iron/
├── steel/
└── special/
```
---
## ⏱️ **TIME ESTIMATES:**
**Per Asset Type:**
- Animal animation frame: 10-15 min
- Building/infrastructure: 20-30 min
- Tool sprite: 10-15 min
**Total Time:**
- Animal animations (39 × 12 min): ~8 hours
- Infrastructure (13 × 25 min): ~5.5 hours
- Tools (21 × 12 min): ~4.5 hours
- **TOTAL: ~18 hours work**
**Realistic Schedule:**
- 3 hours/day = 6 days
- 6 hours/day = 3 days
- **Complete Faza 1 assets in 1 week!**
---
## 🎯 **PRIORITY ORDER:**
**HIGH PRIORITY (Must have for Faza 1 release):**
1. Animal animations (core gameplay)
2. Greenhouse progression (key building)
3. Stone + Iron tool tiers (essential upgrades)
**MEDIUM PRIORITY (Great to have):**
4. Irrigation system (quality of life)
5. Storage buildings (organization)
6. Steel tools (endgame)
**LOW PRIORITY (Can defer):**
7. Special tools (nice to have)
8. Windmill (cosmetic)
---
## 📝 **NEXT STEPS:**
**Immediate (Tonight/Tomorrow):**
1. [ ] Generate remaining cow animations (walk, eat, milk)
2. [ ] Generate pig full set (4 frames)
3. [ ] Generate sheep full set (4 frames)
**This Week:**
4. [ ] Complete all 10 animals (39 sprites)
5. [ ] Generate greenhouse stages 2-5
6. [ ] Start tool upgrades (stone tier)
**Next Week:**
7. [ ] Complete infrastructure
8. [ ] Complete all tool tiers
9. [ ] Integration testing
---
**START NEXT SESSION:**
Generate 3 animal sets (Cow complete + Pig + Sheep = 11 sprites)
**CURRENT: 3/73 (4%) - TARGET: 73/73 (100%) in 1 week!** 🚀

Binary file not shown.

After

Width:  |  Height:  |  Size: 561 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 587 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 461 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 533 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 510 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 594 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 574 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 552 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 502 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 695 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 621 KiB

278
src/ai/AnimalBehavior.js Normal file
View File

@@ -0,0 +1,278 @@
/**
* 🐮 ANIMAL AI BEHAVIOR SYSTEM
* "Krvava Žetev" - Gothic Farm Game
*
* Behaviors:
* - Wander: Random smooth movement (not grid-based)
* - Flee: Run away from player when close
* - Glowing Eyes: Neon eyes visible in darkness (noir effect!)
* - Follow: Cargo animals (llama, horse) follow with delay
*/
export class AnimalBehavior {
constructor(scene, sprite, animalType) {
this.scene = scene;
this.sprite = sprite;
this.animalType = animalType;
// Behavior states
this.state = 'wander'; // 'wander', 'flee', 'follow', 'idle'
this.wanderTimer = 0;
this.wanderDuration = Phaser.Math.Between(2000, 5000);
this.wanderAngle = Math.random() * Math.PI * 2;
// Movement params
this.speed = this.getSpeed();
this.fleeDistance = 100; // pixels
this.fleeSpeed = this.speed * 2;
// Glowing eyes effect (NOIR!)
this.glowingEyes = null;
this.eyeColor = this.getEyeColor();
this.createGlowingEyes();
// Cargo follow system (for llama, horse, donkey)
this.isCargoAnimal = ['llama', 'horse', 'donkey'].includes(animalType);
this.followTarget = null;
this.followDelay = 0.5; // seconds
this.followHistory = [];
}
getSpeed() {
const speeds = {
cow: 30,
pig: 35,
sheep: 25,
chicken: 50,
duck: 45,
goat: 40,
horse: 60,
rabbit: 70,
donkey: 35,
llama: 40
};
return speeds[this.animalType] || 30;
}
getEyeColor() {
// Noir glowing eyes - pink or green like Kai's dreads!
const colors = {
cow: 0xff0066, // neon pink
pig: 0xff0066, // neon pink
sheep: 0x00ff88, // neon green
chicken: 0xffff00, // yellow
duck: 0x00ffff, // cyan
goat: 0xff0066, // neon pink
horse: 0x00ff88, // neon green
rabbit: 0xff00ff, // purple
donkey: 0x00ff88, // neon green
llama: 0xff0066 // neon pink
};
return colors[this.animalType] || 0xff0066;
}
createGlowingEyes() {
// Create glowing eye sprites for noir darkness effect
this.glowingEyes = this.scene.add.container(this.sprite.x, this.sprite.y);
// Two small glowing circles for eyes
const leftEye = this.scene.add.circle(-8, -10, 3, this.eyeColor);
const rightEye = this.scene.add.circle(8, -10, 3, this.eyeColor);
// Add glow effect
leftEye.setAlpha(0.8);
rightEye.setAlpha(0.8);
this.glowingEyes.add([leftEye, rightEye]);
// Hide by default, show only in darkness or at distance
this.glowingEyes.setVisible(false);
this.glowingEyes.setDepth(this.sprite.depth + 1);
}
update(time, delta) {
if (!this.sprite.active) return;
// Update glowing eyes position
if (this.glowingEyes) {
this.glowingEyes.setPosition(this.sprite.x, this.sprite.y);
this.updateGlowingEyesVisibility();
}
// Behavior state machine
switch (this.state) {
case 'wander':
this.updateWander(time, delta);
break;
case 'flee':
this.updateFlee(time, delta);
break;
case 'follow':
this.updateFollow(time, delta);
break;
case 'idle':
this.updateIdle(time, delta);
break;
}
// Check for player proximity (flee trigger)
this.checkPlayerProximity();
}
updateWander(time, delta) {
this.wanderTimer += delta;
// Change direction periodically
if (this.wanderTimer >= this.wanderDuration) {
this.wanderTimer = 0;
this.wanderDuration = Phaser.Math.Between(2000, 5000);
this.wanderAngle = Math.random() * Math.PI * 2;
// Sometimes stop and idle
if (Math.random() < 0.3) {
this.state = 'idle';
this.sprite.setVelocity(0, 0);
return;
}
}
// Smooth movement in wander direction
const vx = Math.cos(this.wanderAngle) * this.speed;
const vy = Math.sin(this.wanderAngle) * this.speed;
this.sprite.setVelocity(vx, vy);
}
updateFlee(time, delta) {
const player = this.scene.player;
if (!player) return;
// Flee away from player
const angle = Phaser.Math.Angle.Between(
player.x, player.y,
this.sprite.x, this.sprite.y
);
const vx = Math.cos(angle) * this.fleeSpeed;
const vy = Math.sin(angle) * this.fleeSpeed;
this.sprite.setVelocity(vx, vy);
// Return to wander if far enough
const dist = Phaser.Math.Distance.Between(
player.x, player.y,
this.sprite.x, this.sprite.y
);
if (dist > this.fleeDistance * 2) {
this.state = 'wander';
}
}
updateFollow(time, delta) {
if (!this.followTarget || !this.isCargoAnimal) return;
// Record follow history for delayed follow
this.followHistory.push({
x: this.followTarget.x,
y: this.followTarget.y,
time: time
});
// Remove old history
const cutoffTime = time - (this.followDelay * 1000);
this.followHistory = this.followHistory.filter(h => h.time > cutoffTime);
// Follow delayed position
if (this.followHistory.length > 0) {
const target = this.followHistory[0];
const angle = Phaser.Math.Angle.Between(
this.sprite.x, this.sprite.y,
target.x, target.y
);
const dist = Phaser.Math.Distance.Between(
this.sprite.x, this.sprite.y,
target.x, target.y
);
// Only move if far enough
if (dist > 50) {
const vx = Math.cos(angle) * this.speed;
const vy = Math.sin(angle) * this.speed;
this.sprite.setVelocity(vx, vy);
} else {
this.sprite.setVelocity(0, 0);
}
}
}
updateIdle(time, delta) {
// Stop moving
this.sprite.setVelocity(0, 0);
// Return to wander after random time
if (Math.random() < 0.01) { // ~1% chance per frame
this.state = 'wander';
}
}
checkPlayerProximity() {
const player = this.scene.player;
if (!player) return;
const dist = Phaser.Math.Distance.Between(
player.x, player.y,
this.sprite.x, this.sprite.y
);
// Trigger flee if player too close
if (dist < this.fleeDistance && this.state !== 'flee') {
this.state = 'flee';
// Play flee sound if available
if (this.scene.sound.get(`${this.animalType}_flee`)) {
this.scene.sound.play(`${this.animalType}_flee`);
}
}
}
updateGlowingEyesVisibility() {
if (!this.glowingEyes) return;
const player = this.scene.player;
if (!player) return;
const dist = Phaser.Math.Distance.Between(
player.x, player.y,
this.sprite.x, this.sprite.y
);
// Show glowing eyes in darkness or at distance
// NOIR EFFECT: When Kai shines light in forest, just glowing eyes visible!
const isDark = this.scene.darkness || false; // Check if darkness system active
const isDistant = dist > 200 && dist < 400; // Medium distance
if (isDark || isDistant) {
this.glowingEyes.setVisible(true);
// Hide actual sprite if far
if (dist > 300) {
this.sprite.setAlpha(0.2);
}
} else {
this.glowingEyes.setVisible(false);
this.sprite.setAlpha(1.0);
}
}
setFollowTarget(target) {
if (this.isCargoAnimal) {
this.followTarget = target;
this.state = 'follow';
}
}
destroy() {
if (this.glowingEyes) {
this.glowingEyes.destroy();
}
}
}

153
src/ai/NPCIdleBehavior.js Normal file
View File

@@ -0,0 +1,153 @@
/**
* 👤 NPC IDLE BEHAVIOR SYSTEM
* "Krvava Žetev" - Gothic Farm Game
*
* Makes NPCs feel alive with random idle animations:
* - Fix hat
* - Wipe sweat
* - Look around
* - Scratch head
* - Adjust clothes
*/
export class NPCIdleBehavior {
constructor(scene, sprite, npcType) {
this.scene = scene;
this.sprite = sprite;
this.npcType = npcType;
// Idle animation timing
this.idleTimer = 0;
this.nextIdleTime = Phaser.Math.Between(3000, 8000);
// Available idle animations
this.idleAnimations = this.getIdleAnimations();
this.currentIdle = null;
}
getIdleAnimations() {
// Different NPCs have different idle behaviors
const genericIdles = [
'fix_hat',
'wipe_sweat',
'look_around',
'scratch_head',
'adjust_clothes',
'yawn',
'stretch'
];
const npcSpecific = {
'gronk': [...genericIdles, 'adjust_apron', 'count_coins', 'polish_item'],
'farmer': [...genericIdles, 'lean_on_fence', 'check_watch', 'spit'],
'merchant': [...genericIdles, 'fix_glasses', 'write_note', 'arrange_goods'],
'default': genericIdles
};
return npcSpecific[this.npcType] || npcSpecific.default;
}
update(time, delta) {
if (!this.sprite.active) return;
this.idleTimer += delta;
// Trigger random idle animation
if (this.idleTimer >= this.nextIdleTime && !this.currentIdle) {
this.playRandomIdle();
this.idleTimer = 0;
this.nextIdleTime = Phaser.Math.Between(3000, 8000);
}
}
playRandomIdle() {
const idle = Phaser.Utils.Array.GetRandom(this.idleAnimations);
this.currentIdle = idle;
// Play animation if it exists
const animKey = `${this.npcType}_${idle}`;
if (this.sprite.anims && this.sprite.anims.exists(animKey)) {
this.sprite.play(animKey);
// Return to default idle after animation
this.sprite.on('animationcomplete', () => {
this.sprite.play(`${this.npcType}_idle`);
this.currentIdle = null;
}, this);
} else {
// Fallback: simple visual effects for idle
this.playFallbackIdle(idle);
}
}
playFallbackIdle(idleType) {
// Create simple tween-based idle behaviors as fallback
switch (idleType) {
case 'fix_hat':
this.scene.tweens.add({
targets: this.sprite,
angle: -5,
duration: 200,
yoyo: true,
onComplete: () => {
this.currentIdle = null;
}
});
break;
case 'wipe_sweat':
this.scene.tweens.add({
targets: this.sprite,
scaleY: 0.98,
duration: 300,
yoyo: true,
onComplete: () => {
this.currentIdle = null;
}
});
break;
case 'look_around':
this.scene.tweens.add({
targets: this.sprite,
scaleX: -Math.abs(this.sprite.scaleX),
duration: 400,
yoyo: true,
onComplete: () => {
this.currentIdle = null;
}
});
break;
case 'scratch_head':
this.scene.tweens.add({
targets: this.sprite,
y: this.sprite.y - 5,
duration: 150,
yoyo: true,
repeat: 2,
onComplete: () => {
this.currentIdle = null;
}
});
break;
default:
// Generic bob
this.scene.tweens.add({
targets: this.sprite,
y: this.sprite.y - 3,
duration: 200,
yoyo: true,
onComplete: () => {
this.currentIdle = null;
}
});
}
}
destroy() {
this.sprite = null;
}
}