---
# System prepended metadata

title: 'A Day in the Life of Spencer, the Village Guard:'

---

# A Day in the Life of Spencer, the Village Guard: 

 ```:javascript=

let name = "Spencer"; 
Let occupation = "village guard"; 
let village guard = { 
let health = 20; 
let strength = 15; 
let speed = 03;  
mainPlayerNear = false;
mainPlayerEngage = false;
mainPlayerAttacks: false;
walk: true;
runAway: false;
} 
//Spencer is the lone guard who patrols his village. 
//He's suspicious of everybody. 
//But he's a little slow because of an injury to his knee.

let guardSpeak = {
let speech1 = "I've got my eye on you stranger";
let speech2 = "I used to be an adventurer like you, then I took an arrow in the knee.";
let speech3 = "To shreds with you!";
let speech4 = "No one disturbs my village."; 
}

let village = {
structures: ["mill","house1","tavern","house2","house3","smithy","jail"]; 
day: true 
rain: true 
}
//It's a rainy day in the small village.

If mainPlayer is >50 yards from village {
tavernSpawn()
} 
//mainPlayer approaches the village. 
//Spencer appears in front of the tavern. 
//He begins his patrol around the village to keep the peace.

function patrolVillage 
//Spencer walks from the tavern to the jail; 
//Then he walks to the mill and scans his surroundings; 
//Then walks back to the tavern; 
//He loiters for 10 seconds, and then repeats. 

 do {
  patrolVillage 
}
while mainPlayerEngage = false;
//If Spencer does not pass mainPlayer, he continues to patrol the village. 

if mainPlayerNear = true
{
guardSpeak [speech1]
}
//mainPlayer walks by Spencer, but doesn't acknowledge him. 
//Spencer says, "I've got my eye on you stranger," as they pass each other.

if mainPlayerEngage = true {
walk = false
guardSpeak [speech2]
}
//mainPlayer walks up to Spencer to talk. Spencer stops and speaks first.
//"I used to be an adventurer like you, then I took an arrow in the knee." 
//Suddenly, mainPlayer reveals a massive war hammer.
//He bludgeons Spencer in the side of the helmet!

mainPlayerAttacks: true;
health: 11

function viciousCombat
guardSpeak [speech3]
//Spencer unsheathes his long sword and yells, "To shreds with you!" 
//He swings his sword and exchanges blows with mainPlayer. 

if health >5 {
runAway
}
//Spencer is clearly losing the battle as his health drops below 5. 
//He flees! (But with his bad knee, he probably won't make it far.)

If mainPlayer health = 0 {
guardSpeak [speech4]
patrolVillage 
}
//Somehow, against all odds, Spencer defeats mainPlayer. 
//Spencer stands over his defeated foe.
//He says, "Nobody disturbs my village," and resumes his patrol.

If mainPlayer is >50 yards from village 
{
Despawn()
}
//If mainPlayer leaves the village, Spencer disappears. 
 

