package arm;
import iron.object.Object;
class NPC extends Object {
public function new() {
super();
}
override function onInit() {
// Initialize NPC behavior
trace("NPC initialized");
}
override function onUpdate() {
// NPC movement and cleaning logic
moveToNextSpot();
}
function moveToNextSpot() {
// Logic to move NPC to the next cleaning spot
// Add your movement code here
}
function detectMurder() {
// Logic to detect player near murder spot
// Add your detection code here
}
function flee() {
// Logic for NPC to flee to a safe spot
// Add your fleeing code here
}
}
package arm;
import iron.object.Object;
import iron.math.Vec4;
class NPC extends Object {
var cleaningSpots:Array = ;
var currentSpot:Int = 0;
var cleaning:Bool = false;
var cleaningTime:Float = 2.0; // Time spent cleaning each spot
var isMurderDetected:Bool = false;
public function new() {
super();
}
override function onInit() {
trace("NPC initialized");
// Initialize cleaning spots (example positions)
cleaningSpots = [new Vec4(1, 0, 1, 1), new Vec4(2, 0, 2, 1), new Vec4(3, 0, 3, 1)];
}
override function onUpdate() {
if (isMurderDetected) {
flee();
} else if (!cleaning) {
moveToNextSpot();
}
}
function moveToNextSpot() {
if (cleaningSpots.length == 0) return;
var targetSpot = cleaningSpots[currentSpot];
moveTowards(targetSpot);
if (Vec4.distance(position, targetSpot) < 0.1) {
startCleaning();
}
}
function startCleaning() {
cleaning = true;
trace("Cleaning at spot: " + currentSpot);
iron.system.Timer.after(cleaningTime, function() {
currentSpot = (currentSpot + 1) % cleaningSpots.length;
cleaning = false;
});
}
function detectMurder(playerPosition:Vec4) {
var murderSpot = new Vec4(2, 0, 2, 1); // Example position
if (Vec4.distance(playerPosition, murderSpot) < 5.0) { // Detection radius
isMurderDetected = true;
}
}
function flee() {
var safeSpot = new Vec4(0, 0, 0, 1); // Example safe position
moveTowards(safeSpot);
if (Vec4.distance(position, safeSpot) < 0.1) {
isMurderDetected = false; // Stop fleeing when safe
trace("Reached safe spot");
}
}
function moveTowards(target:Vec4) {
var direction = target.subtract(position).normalize();
position.addSelf(direction.scale(0.05)); // Adjust speed as necessary
}
}