User prompt
El animatronico tenga un cuerpo
User prompt
Pon le forma de oso y de conejo y pato
User prompt
Pon les formas
User prompt
La carga dure mas
User prompt
Mejora a bunny y a freddy y a chica ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Mejorar la grafica y las luces y animatronicos ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Mejorar los botones
User prompt
Dinamicas
User prompt
Please fix the bug: 'tween.to is not a function' in or related to this line: 'tween.to(ambientLight, {' Line Number: 808 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
God grafics
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'statusText.style.fill = 0xff0000;' Line Number: 582
User prompt
Characters
User prompt
Add animatronics
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'toGlobal')' in or related to this line: 'var localPos = self.toLocal(obj.parent.toGlobal(obj.position));' Line Number: 405
User prompt
Add security
User prompt
Add a doors
User prompt
add a mask a
User prompt
Add fredy and chica
Code edit (1 edits merged)
Please save this source code
User prompt
Five Nights a Bunny
Initial prompt
Five nights a bunny
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var BalloonBoy = Container.expand(function () {
var self = Container.call(this);
var bbGraphics = self.attachAsset('chica', {
anchorX: 0.5,
anchorY: 1.0
});
bbGraphics.tint = 0x4169E1; // Blue tint for Balloon Boy
bbGraphics.scaleX = 0.7; // Smaller than other animatronics
bbGraphics.scaleY = 0.7;
self.currentRoom = 'gameArea';
self.moveTimer = 0;
self.moveDelay = 300;
self.isInVent = false;
self.ventTimer = 0;
self.hasDisabledFlashlight = false;
self.move = function () {
if (self.isInVent) return;
var moveChance = 0.05 + currentNight * 0.06;
if (Math.random() < moveChance) {
var rooms = ['gameArea', 'leftVent', 'rightVent'];
var newRoom = rooms[Math.floor(Math.random() * rooms.length)];
self.currentRoom = newRoom;
// Enter office through vents
if (self.currentRoom === 'leftVent' || self.currentRoom === 'rightVent') {
self.isInVent = true;
self.ventTimer = 180; // 3 seconds to crawl through
}
}
};
self.update = function () {
self.moveTimer++;
if (self.moveTimer >= self.moveDelay) {
self.moveTimer = 0;
self.move();
}
if (self.isInVent) {
self.ventTimer--;
if (self.ventTimer <= 0) {
// BB enters office and disables flashlight
self.currentRoom = 'office';
self.isInVent = false;
self.hasDisabledFlashlight = true;
// Player can no longer use flashlight effectively
}
}
};
return self;
});
var Bonnie = Container.expand(function () {
var self = Container.call(this);
var bonnieGraphics = self.attachAsset('chica', {
anchorX: 0.5,
anchorY: 1.0
});
bonnieGraphics.tint = 0x4169E1; // Blue tint for Bonnie
self.currentRoom = 'stage';
self.moveTimer = 0;
self.moveDelay = 320; // Medium-slow speed
self.isAtDoor = false;
self.doorSide = '';
self.isHiding = false;
self.hideTimer = 0;
self.rooms = ['stage', 'hall', 'dining', 'leftHall', 'backstage'];
self.move = function () {
if (self.isAtDoor || self.isHiding) return;
// Bonnie AI - prefers left side, can hide from cameras
var moveChance = 0.07 + currentNight * 0.07;
if (Math.random() < moveChance) {
var newRoom = self.rooms[Math.floor(Math.random() * self.rooms.length)];
self.currentRoom = newRoom;
// Sometimes hide from cameras
if (Math.random() < 0.3) {
self.isHiding = true;
self.hideTimer = 180; // Hide for 3 seconds
}
// Bonnie only approaches left door
if (self.currentRoom === 'leftHall') {
self.isAtDoor = true;
self.doorSide = 'left';
self.attackTimer = 190; // 3.1 seconds to close door
}
}
};
self.update = function () {
self.moveTimer++;
if (self.moveTimer >= self.moveDelay) {
self.moveTimer = 0;
self.move();
}
if (self.isHiding) {
self.hideTimer--;
if (self.hideTimer <= 0) {
self.isHiding = false;
}
}
if (self.isAtDoor) {
self.attackTimer--;
if (self.attackTimer <= 0) {
// Check if door is closed
var door = leftDoor; // Bonnie only uses left door
if (door.isOpen) {
// Jumpscare!
triggerJumpscare();
} else {
// Bonnie retreats
self.isAtDoor = false;
self.currentRoom = 'stage';
}
}
}
};
return self;
});
var Bunny = Container.expand(function () {
var self = Container.call(this);
var bunnyGraphics = self.attachAsset('bunny', {
anchorX: 0.5,
anchorY: 1.0
});
// Enhanced Bunny properties
self.currentRoom = 'hall';
self.moveTimer = 0;
self.moveDelay = 300; // Frames between moves
self.isAtDoor = false;
self.doorSide = '';
self.huntingMode = false;
self.stalkingTimer = 0;
self.aggressionLevel = 0;
self.lastPlayerAction = 0;
self.adaptiveSpeed = 1.0;
self.rooms = ['hall', 'kitchen', 'dining', 'leftHall', 'rightHall', 'backstage', 'gameArea'];
// Enhanced movement AI with advanced behavior patterns
self.move = function () {
if (self.isAtDoor) return;
// Advanced Bunny AI - learns and adapts to player behavior
var baseMoveChance = 0.08 + currentNight * 0.08;
var stressModifier = playerStressLevel * 0.025;
var aggressionModifier = globalAggression * 0.012;
var temperatureModifier = (temperatureLevel - 50) * 0.002;
// Adaptive behavior based on player patterns
if (consecutiveDoorUses > 3) {
self.aggressionLevel += 2;
self.adaptiveSpeed *= 1.2;
}
// Hunting mode activation
if (self.aggressionLevel > 15 && !self.huntingMode) {
self.huntingMode = true;
self.stalkingTimer = 600; // 10 seconds of hunting
baseMoveChance *= 2.0;
}
// Calculate final move chance with all modifiers
var moveChance = baseMoveChance + stressModifier + aggressionModifier + temperatureModifier;
moveChance *= self.adaptiveSpeed;
// Bunny becomes extremely aggressive if doors are overused
if (consecutiveDoorUses > 8) {
moveChance *= 2.5;
self.huntingMode = true;
}
if (Math.random() < moveChance) {
// Smart room selection based on hunting mode
var availableRooms = self.rooms.slice();
if (self.huntingMode) {
// Prefer rooms closer to doors when hunting
availableRooms = ['leftHall', 'rightHall', 'hall', 'dining'];
}
var newRoom = availableRooms[Math.floor(Math.random() * availableRooms.length)];
self.currentRoom = newRoom;
// Enhanced door approach with variable timing
if (self.currentRoom === 'leftHall' || self.currentRoom === 'rightHall') {
self.isAtDoor = true;
self.doorSide = self.currentRoom === 'leftHall' ? 'left' : 'right';
// Dynamic attack timer based on aggression and night
var baseTime = 180 - currentNight * 20 - self.aggressionLevel * 2;
self.attackTimer = Math.max(60, baseTime); // Minimum 1 second
}
}
};
self.update = function () {
self.moveTimer++;
// Adaptive move delay based on stress and conditions
var dynamicDelay = self.moveDelay;
if (self.huntingMode) {
dynamicDelay *= 0.6; // Move faster when hunting
}
if (batteryLevel < 30) {
dynamicDelay *= 0.8; // Exploit low battery
}
if (self.moveTimer >= dynamicDelay) {
self.moveTimer = 0;
self.move();
}
// Update hunting mode
if (self.huntingMode) {
self.stalkingTimer--;
if (self.stalkingTimer <= 0) {
self.huntingMode = false;
self.adaptiveSpeed = 1.0;
}
}
// Slowly decay aggression when not at door
if (!self.isAtDoor && self.aggressionLevel > 0) {
self.aggressionLevel -= 0.1;
}
// Enhanced door behavior with smart timing
if (self.isAtDoor) {
self.attackTimer--;
// Give audio cue when close to attacking
if (self.attackTimer === 30) {
// Play subtle audio warning at 0.5 seconds remaining
if (Math.random() < 0.7) {
LK.getSound('door').play();
}
}
if (self.attackTimer <= 0) {
// Check if door is closed or mask is on
var door = self.doorSide === 'left' ? leftDoor : rightDoor;
if (door.isOpen && !hasMask) {
// Enhanced jumpscare with buildup
// Flash red before jumpscare
LK.effects.flashScreen(0xff0000, 300);
LK.setTimeout(function () {
triggerJumpscare();
}, 300);
} else {
// Bunny retreats but learns from the encounter
self.isAtDoor = false;
self.currentRoom = 'hall';
// Increase aggression when blocked
self.aggressionLevel += 3;
// Remember this defensive action
self.lastPlayerAction = LK.ticks;
}
}
}
};
return self;
});
var Button = Container.expand(function (text, color, action) {
var self = Container.call(this);
// Button states
self.isPressed = false;
self.isHovered = false;
self.isEnabled = true;
self.actionCallback = action;
// Button background layers
var buttonBg = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
buttonBg.tint = color || 0x4a4a4a;
// Button highlight effect
var buttonHighlight = self.attachAsset('buttonHighlight', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
buttonHighlight.tint = 0xffffff;
// Button pressed effect
var buttonPressed = self.attachAsset('buttonPressed', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
buttonPressed.tint = 0x000000;
// Button glow effect
var buttonGlow = self.attachAsset('buttonGlow', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0,
scaleX: 1.0,
scaleY: 1.0
});
buttonGlow.tint = color || 0x00ff00;
// Button text
var buttonText = new Text2(text || 'BUTTON', {
size: 24,
fill: 0xffffff
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
// Visual feedback methods
self.setEnabled = function (enabled) {
self.isEnabled = enabled;
if (enabled) {
buttonBg.alpha = 1.0;
buttonText.alpha = 1.0;
} else {
buttonBg.alpha = 0.5;
buttonText.alpha = 0.5;
}
};
self.showPressed = function () {
if (!self.isEnabled) return;
self.isPressed = true;
buttonPressed.alpha = 0.6;
buttonHighlight.alpha = 0;
buttonText.y = 2;
LK.getSound('buttonClick').play();
// Press animation
tween(buttonBg, {
scaleX: 0.95,
scaleY: 0.95
}, {
duration: 100
});
};
self.showReleased = function () {
self.isPressed = false;
buttonPressed.alpha = 0;
buttonText.y = 0;
// Release animation
tween(buttonBg, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 150
});
// Trigger action
if (self.isEnabled && self.actionCallback) {
self.actionCallback();
}
};
self.showHover = function () {
if (!self.isEnabled || self.isPressed) return;
self.isHovered = true;
buttonHighlight.alpha = 0.3;
buttonGlow.alpha = 0.2;
LK.getSound('buttonHover').play();
// Hover glow animation
tween(buttonGlow, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200
});
};
self.hideHover = function () {
self.isHovered = false;
if (!self.isPressed) {
buttonHighlight.alpha = 0;
}
buttonGlow.alpha = 0;
// Reset glow
tween(buttonGlow, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
};
self.setText = function (newText) {
buttonText.setText(newText);
};
self.setColor = function (newColor) {
buttonBg.tint = newColor;
buttonGlow.tint = newColor;
};
// Event handlers
self.down = function (x, y, obj) {
if (!self.isEnabled) return;
self.showPressed();
};
self.up = function (x, y, obj) {
if (!self.isEnabled) return;
self.showReleased();
};
return self;
});
var Camera = Container.expand(function (roomName, x, y) {
var self = Container.call(this);
var cameraGraphics = self.attachAsset('camera', {
anchorX: 0.5,
anchorY: 0.5
});
self.roomName = roomName;
self.isActive = false;
self.activate = function () {
if (batteryLevel <= 0) return;
// Deactivate all other cameras
for (var i = 0; i < cameras.length; i++) {
cameras[i].isActive = false;
cameras[i].getChildAt(0).tint = 0xffffff;
}
self.isActive = true;
cameraGraphics.tint = 0x00ff00;
batteryDrain += 1;
currentCamera = self;
LK.getSound('camera').play();
};
self.down = function (x, y, obj) {
self.activate();
};
return self;
});
var Chica = Container.expand(function () {
var self = Container.call(this);
var chicaGraphics = self.attachAsset('chica', {
anchorX: 0.5,
anchorY: 1.0
});
// Enhanced Chica properties
self.currentRoom = 'kitchen';
self.moveTimer = 0;
self.moveDelay = 350; // Medium speed
self.isAtDoor = false;
self.doorSide = '';
self.kitchenDominance = 100; // Territorial control of kitchen area
self.soundSensitivity = 0;
self.sneakMode = false;
self.patrolPattern = 0;
self.cupcakeCompanion = false;
self.lastNoiseDetection = 0;
self.ambushTimer = 0;
self.rooms = ['kitchen', 'dining', 'hall', 'rightHall', 'gameArea']; // Expanded territory
// Enhanced movement with kitchen territorial behavior
self.move = function () {
if (self.isAtDoor) return;
// Advanced Chica AI - kitchen-focused with sound detection and cunning tactics
var baseMoveChance = 0.07 + currentNight * 0.09;
// Kitchen dominance affects movement patterns
if (self.currentRoom === 'kitchen') {
self.kitchenDominance = Math.min(100, self.kitchenDominance + 2);
// Stronger in kitchen, less likely to leave
baseMoveChance *= 0.7;
} else {
self.kitchenDominance = Math.max(0, self.kitchenDominance - 1);
// Tendency to return to kitchen when away
if (self.kitchenDominance < 50) {
baseMoveChance += 0.03; // More likely to move when away from kitchen
}
}
// Sound detection system - Chica reacts to player noise
if (noiseLevel > 3) {
self.soundSensitivity += noiseLevel * 0.5;
self.lastNoiseDetection = LK.ticks;
baseMoveChance += noiseLevel * 0.02;
}
// Sneak mode activation - triggered by player behavior
if (consecutiveDoorUses > 4 && !self.sneakMode) {
self.sneakMode = true;
self.ambushTimer = 900; // 15 seconds of sneaky behavior
}
// Environmental modifiers
var temperatureModifier = (temperatureLevel - 50) * 0.0015;
var batteryModifier = batteryLevel < 40 ? 0.025 : 0;
var stressModifier = playerStressLevel * 0.018;
var moveChance = baseMoveChance + temperatureModifier + batteryModifier + stressModifier;
// Sneak mode makes movement more calculated
if (self.sneakMode) {
moveChance *= 1.4;
// Prefer routes that lead to right door
var distanceToTarget = self.calculateDistanceToRightDoor();
if (distanceToTarget <= 2) {
moveChance *= 1.8; // Much more likely to advance when close
}
}
if (Math.random() < moveChance) {
// Strategic room selection based on patrol pattern and mode
var targetRoom = self.selectTargetRoom();
self.currentRoom = targetRoom;
// Update patrol pattern
self.patrolPattern = (self.patrolPattern + 1) % 4;
// Enhanced right door approach with variable timing
if (self.currentRoom === 'rightHall') {
self.isAtDoor = true;
self.doorSide = 'right';
// Dynamic attack timer based on conditions
var baseTime = 170 - currentNight * 15;
if (self.sneakMode) baseTime -= 30; // Faster when sneaking
if (self.soundSensitivity > 10) baseTime -= 20; // Faster when sound-triggered
if (batteryLevel < 20) baseTime -= 25; // Exploit low battery
if (self.kitchenDominance > 80) baseTime -= 15; // Confident when dominant
self.attackTimer = Math.max(80, baseTime); // Minimum 1.3 seconds - very fast!
}
}
};
// Strategic room selection based on current state and goals
self.selectTargetRoom = function () {
if (self.sneakMode) {
// Sneak mode: prefer direct path to right door
switch (self.currentRoom) {
case 'kitchen':
return Math.random() < 0.7 ? 'dining' : 'hall';
case 'dining':
return Math.random() < 0.8 ? 'rightHall' : 'hall';
case 'hall':
return Math.random() < 0.6 ? 'rightHall' : 'dining';
case 'gameArea':
return 'hall';
case 'rightHall':
return 'rightHall';
// Stay at door
default:
return 'kitchen';
}
}
// Normal mode: patrol pattern with kitchen preference
switch (self.patrolPattern) {
case 0:
// Kitchen focus
return self.kitchenDominance > 60 ? 'kitchen' : Math.random() < 0.5 ? 'dining' : 'kitchen';
case 1:
// Dining exploration
return Math.random() < 0.6 ? 'dining' : 'hall';
case 2:
// Hall movement
return Math.random() < 0.4 ? 'rightHall' : Math.random() < 0.5 ? 'hall' : 'gameArea';
case 3:
// Return cycle
return self.kitchenDominance < 40 ? 'kitchen' : self.rooms[Math.floor(Math.random() * self.rooms.length)];
default:
return 'kitchen';
}
};
// Calculate strategic distance to right door for pathfinding
self.calculateDistanceToRightDoor = function () {
var distances = {
'kitchen': 3,
'dining': 2,
'hall': 2,
'gameArea': 3,
'rightHall': 0
};
return distances[self.currentRoom] || 4;
};
self.update = function () {
self.moveTimer++;
// Dynamic move delay based on current state
var adjustedDelay = self.moveDelay;
if (self.sneakMode) {
adjustedDelay *= 0.75; // Move faster when sneaking
}
if (self.soundSensitivity > 8) {
adjustedDelay *= 0.85; // React faster to noise
}
if (self.kitchenDominance > 90) {
adjustedDelay *= 1.15; // Slower when very comfortable in kitchen
}
if (self.moveTimer >= adjustedDelay) {
self.moveTimer = 0;
self.move();
}
// Update sneak mode timer
if (self.sneakMode) {
self.ambushTimer--;
if (self.ambushTimer <= 0) {
self.sneakMode = false;
}
}
// Decay sound sensitivity over time
if (self.soundSensitivity > 0) {
self.soundSensitivity -= 0.2;
}
// Enhanced door behavior with psychological tactics
if (self.isAtDoor) {
self.attackTimer--;
// Chica's signature fast approach - audio cues at specific intervals
if (self.attackTimer === Math.floor(self.attackTimer * 0.8)) {
// First warning at 80% remaining time
if (Math.random() < 0.5) {
LK.getSound('buttonHover').play(); // Subtle kitchen sound
}
}
if (self.attackTimer === 45) {
// Critical warning at 0.75 seconds
if (Math.random() < 0.9) {
LK.getSound('camera').play(); // Clear warning sound
}
}
if (self.attackTimer <= 0) {
// Check if door is closed
var door = rightDoor; // Chica only uses right door
if (door.isOpen) {
// Enhanced jumpscare with Chica's signature approach
// Quick double-flash to represent Chica's speed
LK.effects.flashScreen(0xffd700, 150); // Golden flash
LK.setTimeout(function () {
LK.effects.flashScreen(0xff4500, 200); // Orange flash
LK.setTimeout(function () {
triggerJumpscare();
}, 200);
}, 150);
} else {
// Chica retreats but becomes more cunning
self.isAtDoor = false;
self.currentRoom = 'kitchen';
// Learn from the defensive action
self.soundSensitivity += 5;
self.kitchenDominance = Math.min(100, self.kitchenDominance + 10);
// Activate sneak mode for next attempt
if (!self.sneakMode) {
self.sneakMode = true;
self.ambushTimer = 600; // 10 seconds of enhanced cunning
}
// Increase global pressure
globalAggression += 1.5;
noiseLevel += 1; // Player door action creates noise
}
}
}
};
return self;
});
var Door = Container.expand(function (side) {
var self = Container.call(this);
var doorGraphics = self.attachAsset('door', {
anchorX: 0.5,
anchorY: 1.0
});
self.isOpen = true;
self.side = side;
self.toggle = function () {
if (batteryLevel <= 0) return;
self.isOpen = !self.isOpen;
if (self.isOpen) {
doorGraphics.alpha = 0.5;
} else {
doorGraphics.alpha = 1.0;
batteryDrain += 2;
}
LK.getSound('door').play();
};
self.down = function (x, y, obj) {
self.toggle();
};
return self;
});
var Foxy = Container.expand(function () {
var self = Container.call(this);
var foxyGraphics = self.attachAsset('bunny', {
anchorX: 0.5,
anchorY: 1.0
});
foxyGraphics.tint = 0x8B0000; // Dark red tint for Foxy
self.currentRoom = 'pirateCove';
self.moveTimer = 0;
self.moveDelay = 250; // Fast movement
self.isRunning = false;
self.runTimer = 0;
self.aggressionLevel = 0; // Builds up when not watched
self.move = function () {
if (self.isRunning) return;
// Dynamic Foxy aggression - responds to noise and attention
if (currentCamera && currentCamera.roomName === 'pirateCove') {
self.aggressionLevel = Math.max(0, self.aggressionLevel - 2);
} else {
var baseIncrease = 1 + currentNight * 0.5;
// Noise level increases Foxy's aggression
var noiseModifier = noiseLevel * 0.1;
// Consecutive door usage makes Foxy more aggressive
var doorModifier = consecutiveDoorUses * 0.2;
self.aggressionLevel += baseIncrease + noiseModifier + doorModifier;
}
// When aggression is high enough, Foxy runs
if (self.aggressionLevel > 100) {
self.isRunning = true;
self.runTimer = 120; // 2 seconds to close door
self.currentRoom = 'leftHall';
self.aggressionLevel = 0;
}
};
self.update = function () {
self.moveTimer++;
if (self.moveTimer >= self.moveDelay) {
self.moveTimer = 0;
self.move();
}
if (self.isRunning) {
self.runTimer--;
if (self.runTimer <= 0) {
// Check if left door is closed
if (leftDoor.isOpen) {
// Jumpscare!
triggerJumpscare();
} else {
// Foxy bangs on door and returns
self.isRunning = false;
self.currentRoom = 'pirateCove';
batteryDrain += 5; // Penalty for using door against Foxy
}
}
}
};
return self;
});
var Freddy = Container.expand(function () {
var self = Container.call(this);
var freddyGraphics = self.attachAsset('freddy', {
anchorX: 0.5,
anchorY: 1.0
});
// Enhanced Freddy properties
self.currentRoom = 'stage';
self.moveTimer = 0;
self.moveDelay = 400; // Slower than bunny initially
self.isAtDoor = false;
self.doorSide = '';
self.huntingPhase = 0; // 0: dormant, 1: stalking, 2: hunting, 3: aggressive
self.playerObservation = 0;
self.intimidationTimer = 0;
self.lastCameraCheck = 0;
self.powerPlayMode = false;
self.territorialClaim = null;
self.rooms = ['stage', 'hall', 'dining', 'kitchen', 'leftHall', 'rightHall', 'backstage', 'gameArea'];
// Enhanced movement with multi-phase hunting behavior
self.move = function () {
if (self.isAtDoor) return;
// Advanced Freddy AI - multi-phase hunting system
var baseMoveChance = 0.06 + currentNight * 0.09;
// Phase progression based on player behavior
self.updateHuntingPhase();
// Phase-specific behavior modifiers
var phaseModifier = 1.0;
switch (self.huntingPhase) {
case 1:
// Stalking
phaseModifier = 1.3;
baseMoveChance += 0.02;
break;
case 2:
// Hunting
phaseModifier = 1.7;
baseMoveChance += 0.05;
break;
case 3:
// Aggressive
phaseModifier = 2.2;
baseMoveChance += 0.08;
break;
}
// Freddy exploits camera overuse with calculated timing
if (cameraSpamCount > 8) {
baseMoveChance *= 1.8;
self.huntingPhase = Math.min(3, self.huntingPhase + 1);
}
// Power play mode - Freddy becomes more active at low battery
if (batteryLevel < 25 && !self.powerPlayMode) {
self.powerPlayMode = true;
baseMoveChance *= 1.5;
self.huntingPhase = Math.max(2, self.huntingPhase);
}
// Environmental factors
var temperatureModifier = (temperatureLevel - 50) * 0.002;
var stressModifier = playerStressLevel * 0.02;
var noiseModifier = noiseLevel * 0.015;
var moveChance = baseMoveChance + temperatureModifier + stressModifier + noiseModifier + globalAggression * 0.018;
moveChance *= phaseModifier;
if (Math.random() < moveChance) {
// Strategic room selection based on hunting phase
var targetRooms = self.selectStrategicRooms();
var newRoom = targetRooms[Math.floor(Math.random() * targetRooms.length)];
self.currentRoom = newRoom;
// Establish territorial claims in key areas
if (self.huntingPhase >= 2) {
self.territorialClaim = self.currentRoom;
}
// Enhanced door approach with phase-based timing
if (self.currentRoom === 'leftHall' || self.currentRoom === 'rightHall') {
self.isAtDoor = true;
self.doorSide = self.currentRoom === 'leftHall' ? 'left' : 'right';
// Dynamic attack timer based on hunting phase and conditions
var baseTime = 220 - currentNight * 25 - self.huntingPhase * 30;
if (self.powerPlayMode) baseTime -= 40;
if (batteryLevel < 15) baseTime -= 30;
self.attackTimer = Math.max(90, baseTime); // Minimum 1.5 seconds
// Start intimidation sequence
self.intimidationTimer = self.attackTimer;
}
}
};
// Strategic room selection based on hunting phase
self.selectStrategicRooms = function () {
switch (self.huntingPhase) {
case 0:
// Dormant - stay near stage
return ['stage', 'hall', 'dining'];
case 1:
// Stalking - move through facility
return ['hall', 'dining', 'kitchen', 'backstage'];
case 2:
// Hunting - approach office
return ['hall', 'dining', 'leftHall', 'rightHall', 'gameArea'];
case 3:
// Aggressive - focus on doors
return ['leftHall', 'rightHall', 'hall'];
default:
return self.rooms;
}
};
// Update hunting phase based on player behavior
self.updateHuntingPhase = function () {
// Track player observation patterns
if (isCameraMode) {
self.playerObservation++;
} else {
self.playerObservation = Math.max(0, self.playerObservation - 1);
}
// Phase progression logic
if (self.playerObservation > 20 && self.huntingPhase < 1) {
self.huntingPhase = 1; // Enter stalking
} else if (consecutiveDoorUses > 6 && self.huntingPhase < 2) {
self.huntingPhase = 2; // Enter hunting
} else if (playerStressLevel > 18 && self.huntingPhase < 3) {
self.huntingPhase = 3; // Enter aggressive
}
// Time-based phase progression
if (nightTimer > 14400 && self.huntingPhase < 2) {
// After 4 minutes
self.huntingPhase = Math.max(1, self.huntingPhase);
}
if (nightTimer > 21600 && self.huntingPhase < 3) {
// After 6 minutes
self.huntingPhase = Math.max(2, self.huntingPhase);
}
};
self.update = function () {
self.moveTimer++;
// Dynamic move delay based on hunting phase
var adjustedDelay = self.moveDelay;
switch (self.huntingPhase) {
case 1:
adjustedDelay *= 0.85;
break;
case 2:
adjustedDelay *= 0.7;
break;
case 3:
adjustedDelay *= 0.55;
break;
}
if (self.powerPlayMode) {
adjustedDelay *= 0.8; // Faster when exploiting low power
}
if (self.moveTimer >= adjustedDelay) {
self.moveTimer = 0;
self.move();
}
// Enhanced door behavior with intimidation tactics
if (self.isAtDoor) {
self.attackTimer--;
self.intimidationTimer--;
// Psychological pressure - play subtle audio cues
if (self.intimidationTimer === Math.floor(self.attackTimer * 0.75)) {
// Audio cue at 75% of attack timer
if (Math.random() < 0.6) {
LK.getSound('camera').play(); // Subtle mechanical sound
}
}
if (self.intimidationTimer === Math.floor(self.attackTimer * 0.5)) {
// Audio cue at 50% of attack timer
if (Math.random() < 0.8) {
LK.getSound('door').play(); // More obvious warning
}
}
if (self.attackTimer <= 0) {
// Check if door is closed or mask is on
var door = self.doorSide === 'left' ? leftDoor : rightDoor;
if (door.isOpen && !hasMask) {
// Enhanced dramatic jumpscare sequence
// Multi-stage buildup
LK.effects.flashScreen(0x4b0082, 200); // Purple flash first
LK.setTimeout(function () {
LK.effects.flashScreen(0xff0000, 400); // Red flash intensifies
LK.setTimeout(function () {
triggerJumpscare();
}, 400);
}, 200);
} else {
// Freddy retreats but remembers the defensive action
self.isAtDoor = false;
self.currentRoom = 'stage';
// Adaptive learning - become more aggressive after being blocked
self.huntingPhase = Math.min(3, self.huntingPhase + 1);
self.playerObservation += 5; // Remember defensive behavior
self.lastCameraCheck = LK.ticks;
// Increase global tension after failed attack
globalAggression += 2;
playerStressLevel += 3;
}
}
}
};
return self;
});
var GoldenFreddy = Container.expand(function () {
var self = Container.call(this);
var goldenFreddyGraphics = self.attachAsset('freddy', {
anchorX: 0.5,
anchorY: 1.0
});
goldenFreddyGraphics.tint = 0xFFD700; // Golden tint
self.currentRoom = 'backstage';
self.moveTimer = 0;
self.moveDelay = 800; // Very slow movement
self.isActive = false;
self.teleportChance = 0.001; // Very low chance to activate
self.disappearTimer = 0;
self.move = function () {
// Golden Freddy has a very small chance to appear randomly
if (!self.isActive && Math.random() < self.teleportChance + currentNight * 0.0005) {
self.isActive = true;
self.currentRoom = 'office'; // Teleports directly to office
self.disappearTimer = 300; // 5 seconds before disappearing
}
};
self.update = function () {
self.moveTimer++;
if (self.moveTimer >= self.moveDelay) {
self.moveTimer = 0;
self.move();
}
if (self.isActive) {
self.disappearTimer--;
if (self.disappearTimer <= 0) {
// Check if player is looking at Golden Freddy (in office and not wearing mask)
if (!hasMask && !isCameraMode) {
// Immediate jumpscare
triggerJumpscare();
} else {
// Golden Freddy disappears
self.isActive = false;
self.currentRoom = 'backstage';
}
}
}
};
return self;
});
var Mangle = Container.expand(function () {
var self = Container.call(this);
var mangleGraphics = self.attachAsset('foxy', {
anchorX: 0.5,
anchorY: 1.0
});
mangleGraphics.tint = 0xFF69B4; // Pink and white tint for Mangle
self.currentRoom = 'kidsCove';
self.moveTimer = 0;
self.moveDelay = 280; // Medium speed
self.isOnCeiling = false;
self.dropTimer = 0;
self.staticNoise = false;
self.move = function () {
var moveChance = 0.06 + currentNight * 0.08;
if (Math.random() < moveChance) {
// Mangle can move through ceiling vents
var rooms = ['kidsCove', 'hall', 'leftHall', 'rightHall', 'office'];
var newRoom = rooms[Math.floor(Math.random() * rooms.length)];
self.currentRoom = newRoom;
// Sometimes appears on office ceiling
if (self.currentRoom === 'office') {
self.isOnCeiling = true;
self.dropTimer = 240; // 4 seconds hanging time
self.staticNoise = true;
}
}
};
self.update = function () {
self.moveTimer++;
if (self.moveTimer >= self.moveDelay) {
self.moveTimer = 0;
self.move();
}
if (self.isOnCeiling) {
self.dropTimer--;
// Create static interference with cameras
if (self.staticNoise && isCameraMode) {
batteryDrain += 0.5; // Extra drain from static
}
if (self.dropTimer <= 0) {
// Mangle drops and attacks
triggerJumpscare();
}
}
};
return self;
});
var Puppet = Container.expand(function () {
var self = Container.call(this);
var puppetGraphics = self.attachAsset('bunny', {
anchorX: 0.5,
anchorY: 1.0
});
puppetGraphics.tint = 0x2F2F2F; // Dark gray tint for Puppet
self.currentRoom = 'musicBox';
self.musicBoxLevel = 100;
self.isEscaping = false;
self.escapeTimer = 0;
self.moveDelay = 200; // Fast when escaping
self.update = function () {
var _currentCamera;
// Music box drains over time
if (!isSecurityMode || ((_currentCamera = currentCamera) === null || _currentCamera === void 0 ? void 0 : _currentCamera.roomName) !== 'musicBox') {
self.musicBoxLevel -= 0.1 + currentNight * 0.05;
} else {
// Wind up music box when watching
self.musicBoxLevel = Math.min(100, self.musicBoxLevel + 0.5);
}
if (self.musicBoxLevel <= 0 && !self.isEscaping) {
self.isEscaping = true;
self.escapeTimer = 600; // 10 seconds to reach office
}
if (self.isEscaping) {
self.escapeTimer--;
if (self.escapeTimer <= 0) {
// Puppet reaches office - instant jumpscare regardless of doors/mask
triggerJumpscare();
}
}
};
return self;
});
var SecurityMonitor = Container.expand(function (roomName, x, y) {
var self = Container.call(this);
var monitorGraphics = self.attachAsset('securityMonitor', {
anchorX: 0.5,
anchorY: 0.5
});
self.roomName = roomName;
self.isActive = false;
// Monitor label
var labelText = new Text2(roomName.toUpperCase(), {
size: 20,
fill: 0x00ff00
});
labelText.anchor.set(0.5, 0.5);
labelText.y = -80;
self.addChild(labelText);
// Status indicator
var statusText = new Text2('CLEAR', {
size: 16,
fill: 0x00ff00
});
statusText.anchor.set(0.5, 0.5);
statusText.y = 60;
self.addChild(statusText);
self.updateStatus = function (animatronics) {
var detected = [];
for (var i = 0; i < animatronics.length; i++) {
if (animatronics[i].currentRoom === self.roomName) {
detected.push(animatronics[i].constructor.name);
}
}
if (detected.length > 0) {
statusText.setText('ALERT: ' + detected.join(', '));
statusText.fill = 0xff0000;
monitorGraphics.tint = 0xff4444;
} else {
statusText.setText('CLEAR');
statusText.fill = 0x00ff00;
monitorGraphics.tint = 0xffffff;
}
};
self.down = function (x, y, obj) {
if (batteryLevel <= 0) return;
// Switch to this camera view
if (currentCamera) {
currentCamera.isActive = false;
currentCamera.getChildAt(0).tint = 0xffffff;
}
currentCamera = self;
self.isActive = true;
LK.getSound('security').play();
};
return self;
});
var SecuritySystem = Container.expand(function () {
var self = Container.call(this);
self.isActive = false;
self.lockdownMode = false;
self.systemPower = 100;
// Main security panel background
var panelBg = self.attachAsset('room', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 2.0,
alpha: 0.9
});
panelBg.tint = 0x2a2a2a;
// Security system title
var titleText = new Text2('SECURITY SYSTEM', {
size: 40,
fill: 0x00ff00
});
titleText.anchor.set(0.5, 0.5);
titleText.y = -250;
self.addChild(titleText);
// Lockdown button
var lockdownButton = self.addChild(LK.getAsset('securityButton', {
anchorX: 0.5,
anchorY: 0.5,
x: -100,
y: 200,
scaleX: 1.5,
scaleY: 1.5
}));
var lockdownText = new Text2('LOCKDOWN', {
size: 20,
fill: 0xffffff
});
lockdownText.anchor.set(0.5, 0.5);
lockdownText.y = 200;
lockdownText.x = -100;
self.addChild(lockdownText);
// Emergency lights button
var lightsButton = self.addChild(LK.getAsset('securityButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 100,
y: 200,
scaleX: 1.5,
scaleY: 1.5
}));
var lightsText = new Text2('LIGHTS', {
size: 20,
fill: 0xffffff
});
lightsText.anchor.set(0.5, 0.5);
lightsText.y = 200;
lightsText.x = 100;
self.addChild(lightsText);
// System status
var statusText = new Text2('SYSTEM ONLINE', {
size: 30,
fill: 0x00ff00
});
statusText.anchor.set(0.5, 0.5);
statusText.y = -200;
self.addChild(statusText);
self.activateLockdown = function () {
if (batteryLevel < 20) return; // Requires significant power
self.lockdownMode = !self.lockdownMode;
if (self.lockdownMode) {
// Close all doors and prevent opening
leftDoor.isOpen = false;
rightDoor.isOpen = false;
leftDoor.getChildAt(0).alpha = 1.0;
rightDoor.getChildAt(0).alpha = 1.0;
lockdownButton.tint = 0xff0000;
lockdownText.fill = 0xff0000;
statusText.setText('LOCKDOWN ACTIVE');
statusText.fill = 0xff0000;
batteryDrain += 5; // Heavy power consumption
} else {
lockdownButton.tint = 0xffffff;
lockdownText.fill = 0xffffff;
statusText.setText('SYSTEM ONLINE');
statusText.fill = 0x00ff00;
}
LK.getSound('security').play();
};
self.activateEmergencyLights = function () {
if (batteryLevel < 10) return;
// Flash all areas to temporarily stun animatronics
LK.effects.flashScreen(0xffffff, 500);
// Reset animatronic positions (they retreat)
bunny.isAtDoor = false;
bunny.currentRoom = 'hall';
freddy.isAtDoor = false;
freddy.currentRoom = 'stage';
chica.isAtDoor = false;
chica.currentRoom = 'kitchen';
foxy.isRunning = false;
foxy.currentRoom = 'pirateCove';
foxy.aggressionLevel = 0;
bonnie.isAtDoor = false;
bonnie.isHiding = false;
bonnie.currentRoom = 'stage';
goldenFreddy.isActive = false;
goldenFreddy.currentRoom = 'backstage';
puppet.isEscaping = false;
puppet.musicBoxLevel = 100;
mangle.isOnCeiling = false;
mangle.staticNoise = false;
mangle.currentRoom = 'kidsCove';
balloonBoy.isInVent = false;
balloonBoy.hasDisabledFlashlight = false;
balloonBoy.currentRoom = 'gameArea';
batteryDrain += 8;
LK.getSound('security').play();
};
self.down = function (x, y, obj) {
// Use direct coordinates instead of converting through parent to avoid undefined errors
// Check lockdown button
if (x > -160 && x < -40 && y > 170 && y < 230) {
self.activateLockdown();
}
// Check lights button
if (x > 40 && x < 160 && y > 170 && y < 230) {
self.activateEmergencyLights();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Game state variables
var currentNight = 1;
var nightTimer = 0;
var nightDuration = 28800; // 8 minutes in frames (60fps)
var batteryLevel = 100;
var batteryDrain = 0.3; // Slower base drain for longer duration
var baseBatteryDrain = 0.3; // Slower base drain
var batteryCharging = false;
var batteryChargeRate = 0.1;
var batteryChargeTimer = 0;
var chargeCooldown = 0;
var powerFluctuationTimer = 0;
var emergencyPowerMode = false;
var powerSurgeTimer = 0;
var isGameActive = true;
var globalAggression = 0;
var playerStressLevel = 0;
var consecutiveDoorUses = 0;
var cameraSpamCount = 0;
var actionTimer = 0;
var currentCamera = null;
var hasMask = false;
var maskCooldown = 0;
// UI Elements
var timeText = new Text2('12:00 AM', {
size: 80,
fill: 0xFFFFFF
});
timeText.anchor.set(0.5, 0);
LK.gui.top.addChild(timeText);
var nightText = new Text2('Night 1', {
size: 60,
fill: 0xFFFFFF
});
nightText.anchor.set(0, 0);
nightText.x = 50;
nightText.y = 50;
LK.gui.topLeft.addChild(nightText);
var batteryText = new Text2('Battery: 100%', {
size: 50,
fill: 0x00FF00
});
batteryText.anchor.set(1, 0);
LK.gui.topRight.addChild(batteryText);
// Temperature display
var temperatureText = new Text2('Temp: 50°F', {
size: 40,
fill: 0x00FFFF
});
temperatureText.anchor.set(1, 0);
temperatureText.x = -10;
temperatureText.y = 60;
LK.gui.topRight.addChild(temperatureText);
// Stress level indicator
var stressText = new Text2('Stress: 0', {
size: 40,
fill: 0xFFFF00
});
stressText.anchor.set(1, 0);
stressText.x = -10;
stressText.y = 120;
LK.gui.topRight.addChild(stressText);
// Office setup with enhanced visuals
var office = game.addChild(LK.getAsset('office', {
anchorX: 0.5,
anchorY: 1.0,
x: 1024,
y: 2732
}));
// Enhanced dynamic ambient lighting system
var ambientLight = game.addChild(LK.getAsset('room', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
scaleX: 5.0,
scaleY: 5.0,
alpha: 0.15
}));
ambientLight.tint = 0x4a4a2a; // Warm dim lighting
// Secondary lighting layer for depth
var ambientLight2 = game.addChild(LK.getAsset('room', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
scaleX: 4.5,
scaleY: 4.5,
alpha: 0.08
}));
ambientLight2.tint = 0x2a2a4a; // Cool secondary lighting
// Emergency lighting overlay
var emergencyLight = game.addChild(LK.getAsset('room', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
scaleX: 6.0,
scaleY: 6.0,
alpha: 0
}));
emergencyLight.tint = 0xff4444; // Red emergency lighting
// Add depth shadows with multiple layers
var officeShadow = game.addChild(LK.getAsset('office', {
anchorX: 0.5,
anchorY: 1.0,
x: 1030,
y: 2738,
alpha: 0.3
}));
officeShadow.tint = 0x000000;
// Additional shadow layer for more depth
var officeShadow2 = game.addChild(LK.getAsset('office', {
anchorX: 0.5,
anchorY: 1.0,
x: 1020,
y: 2728,
alpha: 0.15
}));
officeShadow2.tint = 0x111111;
// Dynamic lighting animation system
var lightingTimer = 0;
var lightingPhase = 0;
// Continuous ambient lighting animation
tween(ambientLight, {
alpha: 0.25
}, {
duration: 3000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(ambientLight, {
alpha: 0.15
}, {
duration: 2500,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Restart the cycle
tween(ambientLight, {
alpha: 0.25
}, {
duration: 3000,
easing: tween.easeInOut
});
}
});
}
});
// Secondary light pulsing
tween(ambientLight2, {
alpha: 0.12
}, {
duration: 4000,
easing: tween.easeInOut
});
// Doors with enhanced graphics
var leftDoor = game.addChild(new Door('left'));
leftDoor.x = 200;
leftDoor.y = 1800;
// Left door shadow
var leftDoorShadow = game.addChild(LK.getAsset('door', {
anchorX: 0.5,
anchorY: 1.0,
x: 206,
y: 1806,
alpha: 0.4
}));
leftDoorShadow.tint = 0x000000;
var rightDoor = game.addChild(new Door('right'));
rightDoor.x = 1848;
rightDoor.y = 1800;
// Right door shadow
var rightDoorShadow = game.addChild(LK.getAsset('door', {
anchorX: 0.5,
anchorY: 1.0,
x: 1854,
y: 1806,
alpha: 0.4
}));
rightDoorShadow.tint = 0x000000;
// Enhanced door control buttons
var leftDoorButton = game.addChild(new Button('LEFT\nDOOR', 0x00aa00, function () {
if (batteryLevel <= 0) return;
leftDoor.toggle();
consecutiveDoorUses++;
playerStressLevel += 2;
noiseLevel += 1.5;
updateDoorButtonStates();
}));
leftDoorButton.x = 100;
leftDoorButton.y = 1600;
var rightDoorButton = game.addChild(new Button('RIGHT\nDOOR', 0x00aa00, function () {
if (batteryLevel <= 0) return;
rightDoor.toggle();
consecutiveDoorUses++;
playerStressLevel += 2;
noiseLevel += 1.5;
updateDoorButtonStates();
}));
rightDoorButton.x = 1948;
rightDoorButton.y = 1600;
function updateDoorButtonStates() {
// Update left door button
if (leftDoor.isOpen) {
leftDoorButton.setColor(0x00aa00);
leftDoorButton.setText('LEFT\nDOOR\nOPEN');
} else {
leftDoorButton.setColor(0xaa0000);
leftDoorButton.setText('LEFT\nDOOR\nCLOSED');
}
// Update right door button
if (rightDoor.isOpen) {
rightDoorButton.setColor(0x00aa00);
rightDoorButton.setText('RIGHT\nDOOR\nOPEN');
} else {
rightDoorButton.setColor(0xaa0000);
rightDoorButton.setText('RIGHT\nDOOR\nCLOSED');
}
// Disable buttons if no battery
leftDoorButton.setEnabled(batteryLevel > 0);
rightDoorButton.setEnabled(batteryLevel > 0);
}
// Camera system with enhanced controls
var cameras = [];
var cameraPanel = game.addChild(LK.getAsset('room', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1000,
alpha: 0
}));
// Camera toggle button
var cameraToggleButton = game.addChild(new Button('CAMERAS', 0x0066cc, function () {
if (batteryLevel <= 0) return;
isCameraMode = !isCameraMode;
if (isCameraMode) {
cameraPanel.alpha = 0.8;
cameraSpamCount++;
playerStressLevel += 1;
var dynamicDrain = 1 + cameraSpamCount * 0.1;
batteryDrain += dynamicDrain;
cameraToggleButton.setText('CLOSE\nCAMERAS');
cameraToggleButton.setColor(0xcc6600);
} else {
cameraPanel.alpha = 0;
if (currentCamera) {
currentCamera.isActive = false;
currentCamera.getChildAt(0).tint = 0xffffff;
currentCamera = null;
}
cameraToggleButton.setText('CAMERAS');
cameraToggleButton.setColor(0x0066cc);
}
}));
cameraToggleButton.x = 1024;
cameraToggleButton.y = 2600;
// Flashlight button
var flashlightButton = game.addChild(new Button('LIGHT', 0xffaa00, function () {
if (batteryLevel <= 0 || isCameraMode || isSecurityMode) return;
isFlashlightOn = !isFlashlightOn;
if (isFlashlightOn) {
flashlight.alpha = 0.6;
flashlightBeam1.alpha = 0.3;
flashlightBeam2.alpha = 0.5;
batteryDrain += 2;
flashlightButton.setText('LIGHT\nON');
flashlightButton.setColor(0xffff00);
} else {
flashlight.alpha = 0;
flashlightBeam1.alpha = 0;
flashlightBeam2.alpha = 0;
flashlightButton.setText('LIGHT');
flashlightButton.setColor(0xffaa00);
}
}));
flashlightButton.x = 200;
flashlightButton.y = 2600;
// Battery charge button for extended gameplay duration
var chargeButton = game.addChild(new Button('CHARGE', 0x00ff00, function () {
if (batteryCharging || chargeCooldown > 0 || batteryLevel >= 95) return;
batteryCharging = true;
batteryChargeTimer = 600; // 10 seconds of charging
playerStressLevel += 3; // Charging creates stress
noiseLevel += 2; // Charging makes noise
chargeButton.setText('CHARGING...');
chargeButton.setColor(0xffff00);
LK.getSound('security').play();
}));
chargeButton.x = 1624;
chargeButton.y = 2600;
// Mask button
var maskButton = game.addChild(new Button('MASK', 0x8b4513, function () {
if (isCameraMode || maskCooldown > 0) return;
hasMask = !hasMask;
if (hasMask && batteryLevel > 0) {
mask.alpha = 0.8;
batteryDrain += 1.2; // Reduced drain for longer duration
maskCooldown = 60;
maskButton.setText('MASK\nON');
maskButton.setColor(0xaa6600);
} else {
mask.alpha = 0;
maskButton.setText('MASK');
maskButton.setColor(0x8b4513);
}
LK.getSound('mask').play();
}));
maskButton.x = 1848;
maskButton.y = 2600;
// Security system button
var securityButton = game.addChild(new Button('SECURITY', 0x660066, function () {
if (batteryLevel <= 0 || isCameraMode) return;
isSecurityMode = !isSecurityMode;
if (isSecurityMode) {
batteryDrain += 1;
securityButton.setText('SECURITY\nON');
securityButton.setColor(0x990099);
} else {
securityButton.setText('SECURITY');
securityButton.setColor(0x660066);
}
LK.getSound('security').play();
}));
securityButton.x = 1424;
securityButton.y = 2600;
// Create cameras
var hallCamera = game.addChild(new Camera('hall', 1024, 1100));
cameras.push(hallCamera);
var kitchenCamera = game.addChild(new Camera('kitchen', 924, 1100));
cameras.push(kitchenCamera);
var diningCamera = game.addChild(new Camera('dining', 1124, 1100));
cameras.push(diningCamera);
var leftHallCamera = game.addChild(new Camera('leftHall', 824, 1100));
cameras.push(leftHallCamera);
var rightHallCamera = game.addChild(new Camera('rightHall', 1224, 1100));
cameras.push(rightHallCamera);
var stageCamera = game.addChild(new Camera('stage', 724, 1100));
cameras.push(stageCamera);
var pirateCoveCamera = game.addChild(new Camera('pirateCove', 624, 1100));
cameras.push(pirateCoveCamera);
var backstageCamera = game.addChild(new Camera('backstage', 524, 1100));
cameras.push(backstageCamera);
var musicBoxCamera = game.addChild(new Camera('musicBox', 424, 1100));
cameras.push(musicBoxCamera);
var kidsCoveCamera = game.addChild(new Camera('kidsCove', 324, 1100));
cameras.push(kidsCoveCamera);
var gameAreaCamera = game.addChild(new Camera('gameArea', 224, 1100));
cameras.push(gameAreaCamera);
// Security monitoring system
var securityMonitors = [];
var securityPanel = game.addChild(LK.getAsset('room', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 500,
alpha: 0,
scaleX: 2.0,
scaleY: 1.5
}));
// Create security monitors for each room
var hallMonitor = game.addChild(new SecurityMonitor('hall', 824, 400));
securityMonitors.push(hallMonitor);
var kitchenMonitor = game.addChild(new SecurityMonitor('kitchen', 1024, 400));
securityMonitors.push(kitchenMonitor);
var diningMonitor = game.addChild(new SecurityMonitor('dining', 1224, 400));
securityMonitors.push(diningMonitor);
var leftHallMonitor = game.addChild(new SecurityMonitor('leftHall', 724, 500));
securityMonitors.push(leftHallMonitor);
var rightHallMonitor = game.addChild(new SecurityMonitor('rightHall', 1324, 500));
securityMonitors.push(rightHallMonitor);
var stageMonitor = game.addChild(new SecurityMonitor('stage', 924, 500));
securityMonitors.push(stageMonitor);
var pirateCoveMonitor = game.addChild(new SecurityMonitor('pirateCove', 824, 600));
securityMonitors.push(pirateCoveMonitor);
var backstageMonitor = game.addChild(new SecurityMonitor('backstage', 1124, 600));
securityMonitors.push(backstageMonitor);
var musicBoxMonitor = game.addChild(new SecurityMonitor('musicBox', 624, 600));
securityMonitors.push(musicBoxMonitor);
var kidsCoveMonitor = game.addChild(new SecurityMonitor('kidsCove', 924, 600));
securityMonitors.push(kidsCoveMonitor);
var gameAreaMonitor = game.addChild(new SecurityMonitor('gameArea', 1224, 600));
securityMonitors.push(gameAreaMonitor);
// Main security system
var securitySystem = game.addChild(new SecuritySystem());
securitySystem.x = 1024;
securitySystem.y = 600;
securitySystem.alpha = 0;
// Security mode state
var isSecurityMode = false;
// Enhanced animatronics with advanced visual effects
var bunny = game.addChild(new Bunny());
bunny.x = 1024;
bunny.y = 1500;
// Multi-layered Bunny effects
var bunnyShadow = game.addChild(LK.getAsset('bunny', {
anchorX: 0.5,
anchorY: 1.0,
x: 1030,
y: 1510,
alpha: 0.4,
scaleX: 0.9,
scaleY: 0.3
}));
bunnyShadow.tint = 0x000000;
var bunnyGlow = game.addChild(LK.getAsset('bunny', {
anchorX: 0.5,
anchorY: 1.0,
x: 1024,
y: 1500,
alpha: 0,
scaleX: 1.3,
scaleY: 1.3
}));
bunnyGlow.tint = 0x8b0000;
var bunnyEyes = game.addChild(LK.getAsset('bunny', {
anchorX: 0.5,
anchorY: 1.0,
x: 1024,
y: 1485,
alpha: 0,
scaleX: 0.2,
scaleY: 0.2
}));
bunnyEyes.tint = 0xff0000;
var freddy = game.addChild(new Freddy());
freddy.x = 900;
freddy.y = 1500;
// Enhanced Freddy effects with multiple glow layers
var freddyGlow = game.addChild(LK.getAsset('freddy', {
anchorX: 0.5,
anchorY: 1.0,
x: 900,
y: 1500,
alpha: 0,
scaleX: 1.2,
scaleY: 1.2
}));
freddyGlow.tint = 0x4b0082;
var freddyAura = game.addChild(LK.getAsset('freddy', {
anchorX: 0.5,
anchorY: 1.0,
x: 900,
y: 1500,
alpha: 0,
scaleX: 1.5,
scaleY: 1.5
}));
freddyAura.tint = 0x2a0051;
var freddyEyes = game.addChild(LK.getAsset('freddy', {
anchorX: 0.5,
anchorY: 1.0,
x: 900,
y: 1485,
alpha: 0,
scaleX: 0.15,
scaleY: 0.15
}));
freddyEyes.tint = 0xffffff;
var chica = game.addChild(new Chica());
chica.x = 1150;
chica.y = 1500;
// Enhanced Chica effects
var chicaGlint = game.addChild(LK.getAsset('chica', {
anchorX: 0.5,
anchorY: 1.0,
x: 1150,
y: 1500,
alpha: 0,
scaleX: 1.1,
scaleY: 1.1
}));
chicaGlint.tint = 0xffffff;
var chicaGlow = game.addChild(LK.getAsset('chica', {
anchorX: 0.5,
anchorY: 1.0,
x: 1150,
y: 1500,
alpha: 0,
scaleX: 1.3,
scaleY: 1.3
}));
chicaGlow.tint = 0xffa500;
var foxy = game.addChild(new Foxy());
foxy.x = 800;
foxy.y = 1500;
// Enhanced Foxy effects with menacing presence
var foxyAura = game.addChild(LK.getAsset('bunny', {
anchorX: 0.5,
anchorY: 1.0,
x: 800,
y: 1500,
alpha: 0,
scaleX: 1.3,
scaleY: 1.3
}));
foxyAura.tint = 0x8b0000;
var foxyTrail = game.addChild(LK.getAsset('bunny', {
anchorX: 0.5,
anchorY: 1.0,
x: 800,
y: 1500,
alpha: 0,
scaleX: 1.6,
scaleY: 1.6
}));
foxyTrail.tint = 0x4a0000;
var foxyEyes = game.addChild(LK.getAsset('bunny', {
anchorX: 0.5,
anchorY: 1.0,
x: 800,
y: 1485,
alpha: 0,
scaleX: 0.18,
scaleY: 0.18
}));
foxyEyes.tint = 0xffff00;
var bonnie = game.addChild(new Bonnie());
bonnie.x = 850;
bonnie.y = 1500;
// Enhanced Bonnie stealth effects
var bonnieGlow = game.addChild(LK.getAsset('chica', {
anchorX: 0.5,
anchorY: 1.0,
x: 850,
y: 1500,
alpha: 0,
scaleX: 1.25,
scaleY: 1.25
}));
bonnieGlow.tint = 0x4169e1;
var bonnieStealth = game.addChild(LK.getAsset('chica', {
anchorX: 0.5,
anchorY: 1.0,
x: 850,
y: 1500,
alpha: 0,
scaleX: 1.4,
scaleY: 1.4
}));
bonnieStealth.tint = 0x1a1a3a;
var goldenFreddy = game.addChild(new GoldenFreddy());
goldenFreddy.x = 1024;
goldenFreddy.y = 1500;
// Enhanced Golden Freddy supernatural effects
var goldenGlow = game.addChild(LK.getAsset('freddy', {
anchorX: 0.5,
anchorY: 1.0,
x: 1024,
y: 1500,
alpha: 0,
scaleX: 1.4,
scaleY: 1.4
}));
goldenGlow.tint = 0xffd700;
var goldenAura = game.addChild(LK.getAsset('freddy', {
anchorX: 0.5,
anchorY: 1.0,
x: 1024,
y: 1500,
alpha: 0,
scaleX: 1.8,
scaleY: 1.8
}));
goldenAura.tint = 0xffaa00;
var goldenParticles = game.addChild(LK.getAsset('freddy', {
anchorX: 0.5,
anchorY: 1.0,
x: 1024,
y: 1500,
alpha: 0,
scaleX: 2.2,
scaleY: 2.2
}));
goldenParticles.tint = 0xffff88;
var puppet = game.addChild(new Puppet());
puppet.x = 600;
puppet.y = 1500;
// Enhanced Puppet eerie effects
var puppetGlow = game.addChild(LK.getAsset('bunny', {
anchorX: 0.5,
anchorY: 1.0,
x: 600,
y: 1500,
alpha: 0,
scaleX: 1.2,
scaleY: 1.2
}));
puppetGlow.tint = 0x4a4a4a;
var puppetTears = game.addChild(LK.getAsset('bunny', {
anchorX: 0.5,
anchorY: 1.0,
x: 600,
y: 1485,
alpha: 0,
scaleX: 0.12,
scaleY: 0.4
}));
puppetTears.tint = 0x000000;
var mangle = game.addChild(new Mangle());
mangle.x = 1200;
mangle.y = 1500;
// Enhanced Mangle effects
var mangleStatic = game.addChild(LK.getAsset('foxy', {
anchorX: 0.5,
anchorY: 1.0,
x: 1200,
y: 1500,
alpha: 0,
scaleX: 1.3,
scaleY: 1.3
}));
mangleStatic.tint = 0xcccccc;
var mangleGlitch = game.addChild(LK.getAsset('foxy', {
anchorX: 0.5,
anchorY: 1.0,
x: 1205,
y: 1495,
alpha: 0,
scaleX: 1.1,
scaleY: 1.1
}));
mangleGlitch.tint = 0xff69b4;
var balloonBoy = game.addChild(new BalloonBoy());
balloonBoy.x = 750;
balloonBoy.y = 1500;
// Enhanced Balloon Boy effects
var bbGlow = game.addChild(LK.getAsset('chica', {
anchorX: 0.5,
anchorY: 1.0,
x: 750,
y: 1500,
alpha: 0,
scaleX: 0.9,
scaleY: 0.9
}));
bbGlow.tint = 0x6495ed;
// Mask with enhanced visuals
var mask = game.addChild(LK.getAsset('mask', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1400,
alpha: 0
}));
// Mask glow effect
var maskGlow = game.addChild(LK.getAsset('mask', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1400,
alpha: 0,
scaleX: 1.1,
scaleY: 1.1
}));
maskGlow.tint = 0xffd700;
// Mask shadow
var maskShadow = game.addChild(LK.getAsset('mask', {
anchorX: 0.5,
anchorY: 0.5,
x: 1030,
y: 1410,
alpha: 0,
scaleX: 0.95,
scaleY: 0.95
}));
maskShadow.tint = 0x000000;
// Flashlight with enhanced beam effects
var flashlight = game.addChild(LK.getAsset('flashlight', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1600,
alpha: 0
}));
// Flashlight beam layers for realistic lighting
var flashlightBeam1 = game.addChild(LK.getAsset('flashlight', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1500,
alpha: 0,
scaleX: 2.0,
scaleY: 3.0
}));
flashlightBeam1.tint = 0xffffaa;
var flashlightBeam2 = game.addChild(LK.getAsset('flashlight', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1400,
alpha: 0,
scaleX: 1.5,
scaleY: 2.5
}));
flashlightBeam2.tint = 0xffffff;
// Subtle flashlight flicker effect
var flashlightFlicker = false;
var environmentalEffectsTimer = 0;
var lightningTimer = 0;
var ventilationTimer = 0;
var temperatureLevel = 50; // Room temperature affects animatronics
var noiseLevel = 0; // Accumulated noise affects detection
var isFlashlightOn = false;
var isCameraMode = false;
// Enhanced battery display
var batteryBar = LK.gui.bottom.addChild(LK.getAsset('battery', {
anchorX: 0.5,
anchorY: 1.0,
y: -50
}));
// Battery background frame
var batteryFrame = LK.gui.bottom.addChild(LK.getAsset('battery', {
anchorX: 0.5,
anchorY: 1.0,
y: -50,
scaleY: 1.2,
alpha: 0.3
}));
batteryFrame.tint = 0x333333;
// Battery warning overlay
var batteryWarning = LK.gui.bottom.addChild(LK.getAsset('battery', {
anchorX: 0.5,
anchorY: 1.0,
y: -50,
alpha: 0
}));
batteryWarning.tint = 0xff3333;
// Battery charge indicator particles
var batteryParticles = [];
for (var p = 0; p < 5; p++) {
var particle = LK.gui.bottom.addChild(LK.getAsset('battery', {
anchorX: 0.5,
anchorY: 0.5,
x: -120 + p * 60,
y: -70,
scaleX: 0.1,
scaleY: 0.1,
alpha: 0
}));
particle.tint = 0x00ff00;
batteryParticles.push(particle);
}
function updateTime() {
var hours = Math.floor(nightTimer / 4800) + 12; // Each hour is 4800 frames
var minutes = Math.floor(nightTimer % 4800 / 80); // Each minute is 80 frames
if (hours > 12) hours -= 12;
if (hours === 0) hours = 12;
var ampm = nightTimer < 21600 ? 'AM' : 'AM'; // All night hours are AM
var timeString = hours + ':' + (minutes < 10 ? '0' : '') + minutes + ' ' + ampm;
timeText.setText(timeString);
}
function updateBattery() {
// Dynamic power consumption system with extended duration
powerFluctuationTimer++;
// Power fluctuations every 8 seconds for longer stability periods
if (powerFluctuationTimer >= 480) {
powerFluctuationTimer = 0;
// Smaller random power fluctuation for more gradual changes
var fluctuation = (Math.random() - 0.5) * 0.2;
batteryDrain = baseBatteryDrain + fluctuation;
// Reduced chance for power surge but longer duration
if (Math.random() < 0.03) {
powerSurgeTimer = 300; // 5 seconds instead of 3
batteryDrain *= 1.5; // Reduced surge intensity
}
}
// Handle power surge
if (powerSurgeTimer > 0) {
powerSurgeTimer--;
if (powerSurgeTimer <= 0) {
batteryDrain = baseBatteryDrain;
}
}
// Emergency power mode when battery is very low
if (batteryLevel < 15 && !emergencyPowerMode) {
emergencyPowerMode = true;
batteryDrain *= 0.3; // Even more reduced consumption for longer duration
LK.effects.flashScreen(0xffff00, 500); // Yellow flash for emergency mode
}
// Exit emergency mode when battery recovers - higher threshold for longer duration
if (batteryLevel > 35 && emergencyPowerMode) {
emergencyPowerMode = false;
batteryDrain = baseBatteryDrain;
}
// Battery charging system for longer duration gameplay
if (batteryCharging && chargeCooldown <= 0) {
batteryLevel += batteryChargeRate / 60; // Charge per frame
batteryChargeTimer--;
if (batteryChargeTimer <= 0) {
batteryCharging = false;
chargeCooldown = 1800; // 30 second cooldown before next charge
}
} else {
batteryLevel -= batteryDrain / 80; // Slower drain for longer duration (was /60)
}
// Update charge cooldown
if (chargeCooldown > 0) {
chargeCooldown--;
}
// Clamp battery level
if (batteryLevel < 0) batteryLevel = 0;
if (batteryLevel > 100) batteryLevel = 100;
batteryText.setText('Battery: ' + Math.floor(batteryLevel) + '%');
// Update battery bar color with smooth transitions
if (batteryLevel > 50) {
batteryBar.tint = 0x00ff00;
batteryWarning.alpha = 0;
} else if (batteryLevel > 25) {
batteryBar.tint = 0xffffff;
batteryWarning.alpha = 0;
} else {
batteryBar.tint = 0xff0000;
// Critical battery warning effect
if (batteryLevel < 25) {
batteryWarning.alpha = 0.3 + Math.sin(LK.ticks * 0.3) * 0.2;
}
}
// Scale battery bar with smooth animation
tween(batteryBar, {
scaleX: batteryLevel / 100
}, {
duration: 100
});
// Update battery particle effects
for (var i = 0; i < batteryParticles.length; i++) {
var particle = batteryParticles[i];
if (i < Math.floor(batteryLevel / 20)) {
particle.alpha = 0.8;
if (batteryLevel > 80) particle.tint = 0x00ff00;else if (batteryLevel > 40) particle.tint = 0xffff00;else particle.tint = 0xff0000;
// Subtle pulse animation
particle.scaleX = 0.1 + Math.sin(LK.ticks * 0.2 + i) * 0.02;
particle.scaleY = 0.1 + Math.sin(LK.ticks * 0.2 + i) * 0.02;
} else {
particle.alpha = 0.2;
}
}
// Reset battery drain
batteryDrain = 0.5;
}
function triggerJumpscare() {
if (!isGameActive) return;
isGameActive = false;
LK.getSound('jumpscare').play();
LK.effects.flashScreen(0xff0000, 2000);
LK.setTimeout(function () {
LK.showGameOver();
}, 2000);
}
function completeNight() {
currentNight++;
if (currentNight > 5) {
LK.showYouWin();
return;
}
// Reset for next night
nightTimer = 0;
batteryLevel = 100;
nightText.setText('Night ' + currentNight);
// Reset bunny
bunny.currentRoom = 'hall';
bunny.isAtDoor = false;
bunny.moveDelay = Math.max(120, 300 - currentNight * 30); // Faster each night
// Reset freddy
freddy.currentRoom = 'stage';
freddy.isAtDoor = false;
freddy.moveDelay = Math.max(150, 400 - currentNight * 40); // Faster each night
// Reset chica
chica.currentRoom = 'kitchen';
chica.isAtDoor = false;
chica.moveDelay = Math.max(130, 350 - currentNight * 35); // Faster each night
// Reset foxy
foxy.currentRoom = 'pirateCove';
foxy.isRunning = false;
foxy.aggressionLevel = 0;
foxy.moveDelay = Math.max(100, 250 - currentNight * 25); // Much faster each night
// Reset bonnie
bonnie.currentRoom = 'stage';
bonnie.isAtDoor = false;
bonnie.isHiding = false;
bonnie.moveDelay = Math.max(140, 320 - currentNight * 30); // Faster each night
// Reset Golden Freddy
goldenFreddy.isActive = false;
goldenFreddy.currentRoom = 'backstage';
goldenFreddy.teleportChance = 0.001;
// Reset Puppet
puppet.musicBoxLevel = 100;
puppet.isEscaping = false;
puppet.currentRoom = 'musicBox';
// Reset Mangle
mangle.isOnCeiling = false;
mangle.staticNoise = false;
mangle.currentRoom = 'kidsCove';
mangle.moveDelay = Math.max(120, 280 - currentNight * 25);
// Reset Balloon Boy
balloonBoy.isInVent = false;
balloonBoy.hasDisabledFlashlight = false;
balloonBoy.currentRoom = 'gameArea';
balloonBoy.moveDelay = Math.max(150, 300 - currentNight * 30);
// Reset mask
hasMask = false;
mask.alpha = 0;
maskCooldown = 0;
// Reset doors
leftDoor.isOpen = true;
rightDoor.isOpen = true;
leftDoor.getChildAt(0).alpha = 0.5;
rightDoor.getChildAt(0).alpha = 0.5;
// Reset door button colors
leftDoorButton.tint = 0x00ff00;
rightDoorButton.tint = 0x00ff00;
// Reset security system
isSecurityMode = false;
if (securitySystem) {
securitySystem.lockdownMode = false;
securitySystem.getChildAt(2).tint = 0xffffff; // Reset lockdown button
}
}
// Event handlers
game.down = function (x, y, obj) {
// Legacy fallback camera toggle for backward compatibility
if (y > 2500 && x > 900 && x < 1148 && !cameraToggleButton.isPressed) {
// Allow direct camera panel interaction if button isn't being pressed
}
};
game.update = function () {
if (!isGameActive) return;
nightTimer++;
updateTime();
updateBattery();
// Update temperature display with color coding
temperatureText.setText('Temp: ' + Math.floor(temperatureLevel) + '°F');
if (temperatureLevel > 65) {
temperatureText.fill = 0xFF4444; // Red when hot
} else if (temperatureLevel < 40) {
temperatureText.fill = 0x4444FF; // Blue when cold
} else {
temperatureText.fill = 0x00FFFF; // Cyan when normal
}
// Update stress display
stressText.setText('Stress: ' + Math.floor(playerStressLevel));
if (playerStressLevel > 15) {
stressText.fill = 0xFF0000; // Red when high stress
} else if (playerStressLevel > 8) {
stressText.fill = 0xFFFF00; // Yellow when medium stress
} else {
stressText.fill = 0x00FF00; // Green when low stress
}
// Check if night is complete
if (nightTimer >= nightDuration) {
completeNight();
return;
}
// Update mask cooldown
if (maskCooldown > 0) {
maskCooldown--;
}
// Update enhanced button states
updateDoorButtonStates();
// Update charge button state for longer duration gameplay
if (batteryCharging) {
chargeButton.setText('CHARGING\n' + Math.ceil(batteryChargeTimer / 60) + 's');
chargeButton.setColor(0xffff00);
} else if (chargeCooldown > 0) {
chargeButton.setText('CHARGE\nCOOL: ' + Math.ceil(chargeCooldown / 60));
chargeButton.setColor(0x666666);
} else if (batteryLevel >= 95) {
chargeButton.setText('CHARGE\nFULL');
chargeButton.setColor(0x666666);
} else {
chargeButton.setText('CHARGE');
chargeButton.setColor(0x00ff00);
}
chargeButton.setEnabled(!batteryCharging && chargeCooldown <= 0 && batteryLevel < 95);
// Update other button states based on conditions
flashlightButton.setEnabled(batteryLevel > 0 && !isCameraMode && !isSecurityMode);
maskButton.setEnabled(!isCameraMode && maskCooldown <= 0);
securityButton.setEnabled(batteryLevel > 0 && !isCameraMode);
cameraToggleButton.setEnabled(batteryLevel > 0);
// Update button text based on cooldowns
if (maskCooldown > 0) {
maskButton.setText('MASK\nCOOL: ' + Math.ceil(maskCooldown / 60));
}
// Turn off mask and flashlight if battery is dead
if (batteryLevel <= 0) {
flashlight.alpha = 0;
flashlightBeam1.alpha = 0;
flashlightBeam2.alpha = 0;
isFlashlightOn = false;
mask.alpha = 0;
maskGlow.alpha = 0;
maskShadow.alpha = 0;
hasMask = false;
// Force doors closed if battery is dead
if (leftDoor.isOpen) {
leftDoor.isOpen = false;
leftDoor.getChildAt(0).alpha = 1.0;
}
if (rightDoor.isOpen) {
rightDoor.isOpen = false;
rightDoor.getChildAt(0).alpha = 1.0;
}
}
// Enhanced dynamic environmental effects
environmentalEffectsTimer++;
// Advanced lighting phase management
lightingPhase = (lightingPhase + 1) % 3600; // 60 second cycle
// Dynamic lighting color shifts based on time and stress
if (environmentalEffectsTimer % 30 === 0) {
var stressLighting = Math.min(playerStressLevel / 20, 1.0);
var timeLighting = Math.sin(lightingPhase * 0.01) * 0.3;
// Stress-induced lighting changes
if (stressLighting > 0.5) {
tween(ambientLight, {
tint: 0x6a3a2a + Math.floor(stressLighting * 0x200000)
}, {
duration: 1000
});
}
}
// Update temperature based on time and activities
if (environmentalEffectsTimer % 60 === 0) {
// Every second
// Temperature naturally decreases over time
temperatureLevel -= 0.1;
// Using electronics increases temperature
if (isCameraMode) temperatureLevel += 0.3;
if (isFlashlightOn) temperatureLevel += 0.2;
if (!leftDoor.isOpen || !rightDoor.isOpen) temperatureLevel += 0.1;
// Keep temperature in realistic range
temperatureLevel = Math.max(30, Math.min(80, temperatureLevel));
// Temperature affects lighting
if (temperatureLevel > 70) {
tween(ambientLight2, {
tint: 0x4a2a2a,
alpha: 0.15
}, {
duration: 1500
});
} else if (temperatureLevel < 35) {
tween(ambientLight2, {
tint: 0x2a2a4a,
alpha: 0.12
}, {
duration: 1500
});
}
}
// Enhanced lightning effect with atmospheric changes
lightningTimer++;
if (lightningTimer > 1800 && Math.random() < 0.001) {
// Every 30 seconds chance
lightningTimer = 0;
LK.effects.flashScreen(0xffffff, 200);
// Lightning temporarily changes all lighting
tween(ambientLight, {
tint: 0x8888aa,
alpha: 0.4
}, {
duration: 300,
onFinish: function onFinish() {
tween(ambientLight, {
tint: 0x4a4a2a,
alpha: 0.2
}, {
duration: 2000
});
}
});
// Flash all animatronic glows briefly
tween(freddyGlow, {
alpha: 0.8
}, {
duration: 100
});
tween(bunnyGlow, {
alpha: 0.6
}, {
duration: 100
});
tween(chicaGlow, {
alpha: 0.5
}, {
duration: 100
});
tween(foxyAura, {
alpha: 0.7
}, {
duration: 100
});
// Lightning temporarily reduces animatronic aggression
globalAggression = Math.max(0, globalAggression - 5);
noiseLevel += 2; // But increases noise
}
// Ventilation system effects
ventilationTimer++;
if (ventilationTimer >= 1200) {
// Every 20 seconds
ventilationTimer = 0;
temperatureLevel -= 2; // Cooling effect
noiseLevel += 1; // Ventilation makes noise
}
// Decay noise over time
if (noiseLevel > 0) {
noiseLevel -= 0.02;
if (noiseLevel < 0) noiseLevel = 0;
}
// Update action timer for tracking player behavior
actionTimer++;
if (actionTimer >= 300) {
// Reset every 5 seconds
actionTimer = 0;
consecutiveDoorUses = Math.max(0, consecutiveDoorUses - 1);
cameraSpamCount = Math.max(0, cameraSpamCount - 2);
playerStressLevel = Math.max(0, playerStressLevel - 1);
}
// Global aggression increases over time
if (environmentalEffectsTimer % 120 === 0) {
// Every 2 seconds
globalAggression += 0.1 + currentNight * 0.05;
globalAggression = Math.min(50, globalAggression); // Cap at 50
}
// Update atmospheric effects based on game state
// Advanced lighting effects system
lightingTimer++;
// Dynamic ambient lighting based on game state
if (lightingTimer % 60 === 0) {
// Emergency lighting when battery is low
if (batteryLevel < 20) {
emergencyLight.alpha = 0.15 + Math.sin(LK.ticks * 0.1) * 0.1;
tween(ambientLight, {
tint: 0xff4444
}, {
duration: 500
});
} else if (batteryLevel < 50) {
emergencyLight.alpha = 0.05;
tween(ambientLight, {
tint: 0x6a4a2a
}, {
duration: 1000
});
} else {
emergencyLight.alpha = 0;
tween(ambientLight, {
tint: 0x4a4a2a
}, {
duration: 1500
});
}
// Temperature-based lighting
if (temperatureLevel > 65) {
tween(ambientLight2, {
tint: 0x4a2a2a
}, {
duration: 800
});
} else if (temperatureLevel < 40) {
tween(ambientLight2, {
tint: 0x2a2a4a
}, {
duration: 800
});
}
}
// Enhanced flashlight effects with particle simulation
if (isFlashlightOn && (batteryLevel < 30 || temperatureLevel > 70)) {
flashlightFlicker = !flashlightFlicker;
if (flashlightFlicker && Math.random() < 0.1) {
flashlightBeam1.alpha *= 0.7;
flashlightBeam2.alpha *= 0.8;
}
// Add flashlight beam wobble when battery is low
if (batteryLevel < 15) {
flashlightBeam1.x = 1024 + Math.sin(LK.ticks * 0.3) * 5;
flashlightBeam2.x = 1024 + Math.sin(LK.ticks * 0.25) * 3;
}
}
// Advanced mask effects with breathing and fog
if (hasMask) {
maskGlow.alpha = 0.2 + Math.sin(LK.ticks * 0.08) * 0.1;
maskShadow.alpha = 0.3;
// Enhanced breathing effect
var breathScale = 1.0 + Math.sin(LK.ticks * 0.1) * 0.02;
var breathIntensity = 1.0 + Math.sin(LK.ticks * 0.05) * 0.01;
mask.scaleX = breathScale * breathIntensity;
mask.scaleY = breathScale * breathIntensity;
maskGlow.scaleX = breathScale * 1.1;
maskGlow.scaleY = breathScale * 1.1;
} else {
maskGlow.alpha = 0;
maskShadow.alpha = 0;
}
// Enhanced animatronic visual effects
// Bunny effects
if (bunny.isAtDoor) {
bunnyGlow.alpha = 0.5 + Math.sin(LK.ticks * 0.3) * 0.2;
bunnyEyes.alpha = 0.8 + Math.sin(LK.ticks * 0.4) * 0.2;
tween(bunnyGlow, {
scaleX: 1.4,
scaleY: 1.4
}, {
duration: 300
});
} else {
bunnyGlow.alpha = 0;
bunnyEyes.alpha = 0;
}
// Enhanced Freddy effects
if (freddy.isAtDoor) {
freddyGlow.alpha = 0.4 + Math.sin(LK.ticks * 0.2) * 0.2;
freddyAura.alpha = 0.2 + Math.sin(LK.ticks * 0.15) * 0.1;
freddyEyes.alpha = 0.9 + Math.sin(LK.ticks * 0.5) * 0.1;
// Pulsing intimidation effect
tween(freddyAura, {
scaleX: 1.7,
scaleY: 1.7
}, {
duration: 400,
easing: tween.easeInOut
});
} else {
freddyGlow.alpha = 0;
freddyAura.alpha = 0;
freddyEyes.alpha = 0;
}
// Enhanced Golden Freddy supernatural effects
if (goldenFreddy.isActive) {
goldenGlow.alpha = 0.5 + Math.sin(LK.ticks * 0.15) * 0.3;
goldenAura.alpha = 0.3 + Math.sin(LK.ticks * 0.12) * 0.2;
goldenParticles.alpha = 0.2 + Math.sin(LK.ticks * 0.18) * 0.15;
// Supernatural floating effect
goldenGlow.y = 1500 + Math.sin(LK.ticks * 0.08) * 8;
goldenAura.y = 1500 + Math.sin(LK.ticks * 0.06) * 12;
// Reality distortion effect
if (Math.random() < 0.02) {
tween(goldenParticles, {
scaleX: 2.8,
scaleY: 2.8,
alpha: 0.4
}, {
duration: 150,
onFinish: function onFinish() {
tween(goldenParticles, {
scaleX: 2.2,
scaleY: 2.2,
alpha: 0.2
}, {
duration: 200
});
}
});
}
} else {
goldenGlow.alpha = 0;
goldenAura.alpha = 0;
goldenParticles.alpha = 0;
}
// Enhanced Puppet effects
if (puppet.isEscaping) {
puppetGlow.alpha = 0.6 + Math.sin(LK.ticks * 0.25) * 0.2;
puppetTears.alpha = 0.7;
// Eerie floating movement
puppet.y = 1500 + Math.sin(LK.ticks * 0.1) * 5;
puppetGlow.y = 1500 + Math.sin(LK.ticks * 0.1) * 5;
} else {
puppetGlow.alpha = 0;
puppetTears.alpha = 0;
}
// Enhanced Foxy effects with running animation
if (foxy.isRunning) {
foxyAura.alpha = 0.7 + Math.sin(LK.ticks * 0.4) * 0.2;
foxyTrail.alpha = 0.4;
foxyEyes.alpha = 0.9;
// Running motion blur effect
tween(foxyAura, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200
});
tween(foxyTrail, {
scaleX: 2.0,
scaleY: 1.8,
alpha: 0.2
}, {
duration: 300
});
} else {
foxyAura.alpha = 0;
foxyTrail.alpha = 0;
foxyEyes.alpha = 0;
foxyAura.scaleX = 1.3;
foxyAura.scaleY = 1.3;
}
// Enhanced Chica effects
if (chica.isAtDoor) {
chicaGlow.alpha = 0.4 + Math.sin(LK.ticks * 0.25) * 0.2;
if (Math.random() < 0.05) {
chicaGlint.alpha = 1.0;
tween(chicaGlint, {
alpha: 0
}, {
duration: 300
});
}
} else {
chicaGlow.alpha = 0;
}
// Enhanced Bonnie stealth effects
if (bonnie.isAtDoor) {
bonnieGlow.alpha = 0.3 + Math.sin(LK.ticks * 0.2) * 0.15;
bonnieStealth.alpha = 0.2;
} else if (bonnie.isHiding) {
bonnieGlow.alpha = 0.1;
bonnieStealth.alpha = 0.4 + Math.sin(LK.ticks * 0.15) * 0.2;
} else {
bonnieGlow.alpha = 0;
bonnieStealth.alpha = 0;
}
// Enhanced Mangle glitch effects
if (mangle.isOnCeiling) {
mangleStatic.alpha = 0.3 + Math.sin(LK.ticks * 0.6) * 0.2;
mangleGlitch.alpha = 0.4;
// Glitch position effect
if (Math.random() < 0.1) {
mangleGlitch.x = 1200 + (Math.random() - 0.5) * 10;
mangleGlitch.y = 1500 + (Math.random() - 0.5) * 8;
}
} else {
mangleStatic.alpha = 0;
mangleGlitch.alpha = 0;
}
// Enhanced Balloon Boy effects
if (balloonBoy.isInVent) {
bbGlow.alpha = 0.3 + Math.sin(LK.ticks * 0.3) * 0.1;
} else {
bbGlow.alpha = 0;
}
// Update security monitors
if (isSecurityMode) {
var animatronics = [bunny, freddy, chica, foxy, bonnie, goldenFreddy, puppet, mangle, balloonBoy];
for (var i = 0; i < securityMonitors.length; i++) {
securityMonitors[i].updateStatus(animatronics);
}
// Security system power drain
batteryDrain += 1.5;
// Show security elements with dynamic effects
securityPanel.alpha = 0.8;
securitySystem.alpha = 1.0;
// Security monitors flicker based on power and stress
for (var j = 0; j < securityMonitors.length; j++) {
var monitor = securityMonitors[j];
if (batteryLevel < 20 || playerStressLevel > 20) {
// Flickering effect when systems are stressed
monitor.alpha = 0.7 + Math.sin(LK.ticks * 0.5) * 0.3;
} else {
monitor.alpha = 1.0;
}
}
} else {
// Hide security elements
securityPanel.alpha = 0;
securitySystem.alpha = 0;
for (var k = 0; k < securityMonitors.length; k++) {
securityMonitors[k].alpha = 0;
}
}
// Update camera visibility
if (isCameraMode && currentCamera) {
// Show animatronics if in same room as camera
if (bunny.currentRoom === currentCamera.roomName) {
bunny.alpha = 1.0;
} else {
bunny.alpha = 0.3;
}
if (freddy.currentRoom === currentCamera.roomName) {
freddy.alpha = 1.0;
} else {
freddy.alpha = 0.3;
}
if (chica.currentRoom === currentCamera.roomName) {
chica.alpha = 1.0;
} else {
chica.alpha = 0.3;
}
if (foxy.currentRoom === currentCamera.roomName && !foxy.isHiding) {
foxy.alpha = 1.0;
} else {
foxy.alpha = 0.3;
}
if (bonnie.currentRoom === currentCamera.roomName && !bonnie.isHiding) {
bonnie.alpha = 1.0;
} else {
bonnie.alpha = 0.3;
}
if (goldenFreddy.currentRoom === currentCamera.roomName && goldenFreddy.isActive) {
goldenFreddy.alpha = 1.0;
} else {
goldenFreddy.alpha = 0.3;
}
if (puppet.currentRoom === currentCamera.roomName) {
puppet.alpha = 1.0;
} else {
puppet.alpha = 0.3;
}
if (mangle.currentRoom === currentCamera.roomName) {
mangle.alpha = 1.0;
} else {
mangle.alpha = 0.3;
}
if (balloonBoy.currentRoom === currentCamera.roomName) {
balloonBoy.alpha = 1.0;
} else {
balloonBoy.alpha = 0.3;
}
} else if (!isSecurityMode) {
bunny.alpha = 0;
freddy.alpha = 0;
chica.alpha = 0;
foxy.alpha = 0;
bonnie.alpha = 0;
goldenFreddy.alpha = 0;
puppet.alpha = 0;
mangle.alpha = 0;
balloonBoy.alpha = 0;
}
};
// Start ambient music
LK.playMusic('ambient'); ===================================================================
--- original.js
+++ change.js
@@ -1215,10 +1215,14 @@
var currentNight = 1;
var nightTimer = 0;
var nightDuration = 28800; // 8 minutes in frames (60fps)
var batteryLevel = 100;
-var batteryDrain = 0.5;
-var baseBatteryDrain = 0.5;
+var batteryDrain = 0.3; // Slower base drain for longer duration
+var baseBatteryDrain = 0.3; // Slower base drain
+var batteryCharging = false;
+var batteryChargeRate = 0.1;
+var batteryChargeTimer = 0;
+var chargeCooldown = 0;
var powerFluctuationTimer = 0;
var emergencyPowerMode = false;
var powerSurgeTimer = 0;
var isGameActive = true;
@@ -1482,15 +1486,28 @@
}
}));
flashlightButton.x = 200;
flashlightButton.y = 2600;
+// Battery charge button for extended gameplay duration
+var chargeButton = game.addChild(new Button('CHARGE', 0x00ff00, function () {
+ if (batteryCharging || chargeCooldown > 0 || batteryLevel >= 95) return;
+ batteryCharging = true;
+ batteryChargeTimer = 600; // 10 seconds of charging
+ playerStressLevel += 3; // Charging creates stress
+ noiseLevel += 2; // Charging makes noise
+ chargeButton.setText('CHARGING...');
+ chargeButton.setColor(0xffff00);
+ LK.getSound('security').play();
+}));
+chargeButton.x = 1624;
+chargeButton.y = 2600;
// Mask button
var maskButton = game.addChild(new Button('MASK', 0x8b4513, function () {
if (isCameraMode || maskCooldown > 0) return;
hasMask = !hasMask;
if (hasMask && batteryLevel > 0) {
mask.alpha = 0.8;
- batteryDrain += 1.5;
+ batteryDrain += 1.2; // Reduced drain for longer duration
maskCooldown = 60;
maskButton.setText('MASK\nON');
maskButton.setColor(0xaa6600);
} else {
@@ -1944,20 +1961,20 @@
var timeString = hours + ':' + (minutes < 10 ? '0' : '') + minutes + ' ' + ampm;
timeText.setText(timeString);
}
function updateBattery() {
- // Dynamic power consumption system
+ // Dynamic power consumption system with extended duration
powerFluctuationTimer++;
- // Power fluctuations every 5 seconds
- if (powerFluctuationTimer >= 300) {
+ // Power fluctuations every 8 seconds for longer stability periods
+ if (powerFluctuationTimer >= 480) {
powerFluctuationTimer = 0;
- // Random power fluctuation
- var fluctuation = (Math.random() - 0.5) * 0.3;
+ // Smaller random power fluctuation for more gradual changes
+ var fluctuation = (Math.random() - 0.5) * 0.2;
batteryDrain = baseBatteryDrain + fluctuation;
- // Chance for power surge
- if (Math.random() < 0.05) {
- powerSurgeTimer = 180; // 3 seconds
- batteryDrain *= 2.0;
+ // Reduced chance for power surge but longer duration
+ if (Math.random() < 0.03) {
+ powerSurgeTimer = 300; // 5 seconds instead of 3
+ batteryDrain *= 1.5; // Reduced surge intensity
}
}
// Handle power surge
if (powerSurgeTimer > 0) {
@@ -1968,18 +1985,34 @@
}
// Emergency power mode when battery is very low
if (batteryLevel < 15 && !emergencyPowerMode) {
emergencyPowerMode = true;
- batteryDrain *= 0.5; // Reduced consumption
+ batteryDrain *= 0.3; // Even more reduced consumption for longer duration
LK.effects.flashScreen(0xffff00, 500); // Yellow flash for emergency mode
}
- // Exit emergency mode when battery recovers
- if (batteryLevel > 25 && emergencyPowerMode) {
+ // Exit emergency mode when battery recovers - higher threshold for longer duration
+ if (batteryLevel > 35 && emergencyPowerMode) {
emergencyPowerMode = false;
batteryDrain = baseBatteryDrain;
}
- batteryLevel -= batteryDrain / 60; // Drain per frame
+ // Battery charging system for longer duration gameplay
+ if (batteryCharging && chargeCooldown <= 0) {
+ batteryLevel += batteryChargeRate / 60; // Charge per frame
+ batteryChargeTimer--;
+ if (batteryChargeTimer <= 0) {
+ batteryCharging = false;
+ chargeCooldown = 1800; // 30 second cooldown before next charge
+ }
+ } else {
+ batteryLevel -= batteryDrain / 80; // Slower drain for longer duration (was /60)
+ }
+ // Update charge cooldown
+ if (chargeCooldown > 0) {
+ chargeCooldown--;
+ }
+ // Clamp battery level
if (batteryLevel < 0) batteryLevel = 0;
+ if (batteryLevel > 100) batteryLevel = 100;
batteryText.setText('Battery: ' + Math.floor(batteryLevel) + '%');
// Update battery bar color with smooth transitions
if (batteryLevel > 50) {
batteryBar.tint = 0x00ff00;
@@ -2134,8 +2167,23 @@
maskCooldown--;
}
// Update enhanced button states
updateDoorButtonStates();
+ // Update charge button state for longer duration gameplay
+ if (batteryCharging) {
+ chargeButton.setText('CHARGING\n' + Math.ceil(batteryChargeTimer / 60) + 's');
+ chargeButton.setColor(0xffff00);
+ } else if (chargeCooldown > 0) {
+ chargeButton.setText('CHARGE\nCOOL: ' + Math.ceil(chargeCooldown / 60));
+ chargeButton.setColor(0x666666);
+ } else if (batteryLevel >= 95) {
+ chargeButton.setText('CHARGE\nFULL');
+ chargeButton.setColor(0x666666);
+ } else {
+ chargeButton.setText('CHARGE');
+ chargeButton.setColor(0x00ff00);
+ }
+ chargeButton.setEnabled(!batteryCharging && chargeCooldown <= 0 && batteryLevel < 95);
// Update other button states based on conditions
flashlightButton.setEnabled(batteryLevel > 0 && !isCameraMode && !isSecurityMode);
maskButton.setEnabled(!isCameraMode && maskCooldown <= 0);
securityButton.setEnabled(batteryLevel > 0 && !isCameraMode);