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 Bunny = Container.expand(function () {
var self = Container.call(this);
var bunnyGraphics = self.attachAsset('bunny', {
anchorX: 0.5,
anchorY: 1.0
});
self.currentRoom = 'hall';
self.moveTimer = 0;
self.moveDelay = 300; // Frames between moves
self.isAtDoor = false;
self.doorSide = '';
self.rooms = ['hall', 'kitchen', 'dining', 'leftHall', 'rightHall'];
self.move = function () {
if (self.isAtDoor) return;
// Bunny AI - becomes more aggressive each night
var moveChance = 0.1 + currentNight * 0.1;
if (Math.random() < moveChance) {
var newRoom = self.rooms[Math.floor(Math.random() * self.rooms.length)];
self.currentRoom = newRoom;
// Check if bunny reaches door
if (self.currentRoom === 'leftHall' || self.currentRoom === 'rightHall') {
self.isAtDoor = true;
self.doorSide = self.currentRoom === 'leftHall' ? 'left' : 'right';
self.attackTimer = 180; // 3 seconds to close door
}
}
};
self.update = function () {
self.moveTimer++;
if (self.moveTimer >= self.moveDelay) {
self.moveTimer = 0;
self.move();
}
if (self.isAtDoor) {
self.attackTimer--;
if (self.attackTimer <= 0) {
// Check if door is closed
var door = self.doorSide === 'left' ? leftDoor : rightDoor;
if (door.isOpen) {
// Jumpscare!
triggerJumpscare();
} else {
// Bunny retreats
self.isAtDoor = false;
self.currentRoom = 'hall';
}
}
}
};
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 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;
});
/****
* 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.5;
var isGameActive = true;
var currentCamera = null;
// 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);
// Office setup
var office = game.addChild(LK.getAsset('office', {
anchorX: 0.5,
anchorY: 1.0,
x: 1024,
y: 2732
}));
// Doors
var leftDoor = game.addChild(new Door('left'));
leftDoor.x = 200;
leftDoor.y = 1800;
var rightDoor = game.addChild(new Door('right'));
rightDoor.x = 1848;
rightDoor.y = 1800;
// Camera system
var cameras = [];
var cameraPanel = game.addChild(LK.getAsset('room', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1000,
alpha: 0
}));
// 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);
// Bunny
var bunny = game.addChild(new Bunny());
bunny.x = 1024;
bunny.y = 1500;
// Flashlight
var flashlight = game.addChild(LK.getAsset('flashlight', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1600,
alpha: 0
}));
var isFlashlightOn = false;
var isCameraMode = false;
// Battery bar
var batteryBar = LK.gui.bottom.addChild(LK.getAsset('battery', {
anchorX: 0.5,
anchorY: 1.0,
y: -50
}));
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() {
batteryLevel -= batteryDrain / 60; // Drain per frame
if (batteryLevel < 0) batteryLevel = 0;
batteryText.setText('Battery: ' + Math.floor(batteryLevel) + '%');
// Update battery bar color
if (batteryLevel > 50) {
batteryBar.tint = 0x00ff00;
} else if (batteryLevel > 25) {
batteryBar.tint = 0xffffff;
} else {
batteryBar.tint = 0xff0000;
}
// Scale battery bar
batteryBar.scaleX = batteryLevel / 100;
// 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 doors
leftDoor.isOpen = true;
rightDoor.isOpen = true;
leftDoor.getChildAt(0).alpha = 0.5;
rightDoor.getChildAt(0).alpha = 0.5;
}
// Event handlers
game.down = function (x, y, obj) {
// Toggle camera mode
if (y > 1200) {
isCameraMode = !isCameraMode;
if (isCameraMode) {
cameraPanel.alpha = 0.8;
batteryDrain += 1;
} else {
cameraPanel.alpha = 0;
if (currentCamera) {
currentCamera.isActive = false;
currentCamera.getChildAt(0).tint = 0xffffff;
currentCamera = null;
}
}
}
// Toggle flashlight
if (y < 1200 && !isCameraMode) {
isFlashlightOn = !isFlashlightOn;
if (isFlashlightOn && batteryLevel > 0) {
flashlight.alpha = 0.6;
batteryDrain += 2;
} else {
flashlight.alpha = 0;
}
}
};
game.update = function () {
if (!isGameActive) return;
nightTimer++;
updateTime();
updateBattery();
// Check if night is complete
if (nightTimer >= nightDuration) {
completeNight();
return;
}
// Turn off flashlight if battery is dead
if (batteryLevel <= 0) {
flashlight.alpha = 0;
isFlashlightOn = false;
// Close doors if battery is dead
if (leftDoor.isOpen) {
leftDoor.getChildAt(0).alpha = 0.5;
}
if (rightDoor.isOpen) {
rightDoor.getChildAt(0).alpha = 0.5;
}
}
// Update camera visibility
if (isCameraMode && currentCamera) {
// Show bunny if in same room as camera
if (bunny.currentRoom === currentCamera.roomName) {
bunny.alpha = 1.0;
} else {
bunny.alpha = 0.3;
}
} else {
bunny.alpha = 0;
}
};
// Start ambient music
LK.playMusic('ambient'); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,322 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Bunny = Container.expand(function () {
+ var self = Container.call(this);
+ var bunnyGraphics = self.attachAsset('bunny', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ self.currentRoom = 'hall';
+ self.moveTimer = 0;
+ self.moveDelay = 300; // Frames between moves
+ self.isAtDoor = false;
+ self.doorSide = '';
+ self.rooms = ['hall', 'kitchen', 'dining', 'leftHall', 'rightHall'];
+ self.move = function () {
+ if (self.isAtDoor) return;
+ // Bunny AI - becomes more aggressive each night
+ var moveChance = 0.1 + currentNight * 0.1;
+ if (Math.random() < moveChance) {
+ var newRoom = self.rooms[Math.floor(Math.random() * self.rooms.length)];
+ self.currentRoom = newRoom;
+ // Check if bunny reaches door
+ if (self.currentRoom === 'leftHall' || self.currentRoom === 'rightHall') {
+ self.isAtDoor = true;
+ self.doorSide = self.currentRoom === 'leftHall' ? 'left' : 'right';
+ self.attackTimer = 180; // 3 seconds to close door
+ }
+ }
+ };
+ self.update = function () {
+ self.moveTimer++;
+ if (self.moveTimer >= self.moveDelay) {
+ self.moveTimer = 0;
+ self.move();
+ }
+ if (self.isAtDoor) {
+ self.attackTimer--;
+ if (self.attackTimer <= 0) {
+ // Check if door is closed
+ var door = self.doorSide === 'left' ? leftDoor : rightDoor;
+ if (door.isOpen) {
+ // Jumpscare!
+ triggerJumpscare();
+ } else {
+ // Bunny retreats
+ self.isAtDoor = false;
+ self.currentRoom = 'hall';
+ }
+ }
+ }
+ };
+ 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 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;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
backgroundColor: 0x000000
-});
\ No newline at end of file
+});
+
+/****
+* 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.5;
+var isGameActive = true;
+var currentCamera = null;
+// 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);
+// Office setup
+var office = game.addChild(LK.getAsset('office', {
+ anchorX: 0.5,
+ anchorY: 1.0,
+ x: 1024,
+ y: 2732
+}));
+// Doors
+var leftDoor = game.addChild(new Door('left'));
+leftDoor.x = 200;
+leftDoor.y = 1800;
+var rightDoor = game.addChild(new Door('right'));
+rightDoor.x = 1848;
+rightDoor.y = 1800;
+// Camera system
+var cameras = [];
+var cameraPanel = game.addChild(LK.getAsset('room', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 1024,
+ y: 1000,
+ alpha: 0
+}));
+// 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);
+// Bunny
+var bunny = game.addChild(new Bunny());
+bunny.x = 1024;
+bunny.y = 1500;
+// Flashlight
+var flashlight = game.addChild(LK.getAsset('flashlight', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 1024,
+ y: 1600,
+ alpha: 0
+}));
+var isFlashlightOn = false;
+var isCameraMode = false;
+// Battery bar
+var batteryBar = LK.gui.bottom.addChild(LK.getAsset('battery', {
+ anchorX: 0.5,
+ anchorY: 1.0,
+ y: -50
+}));
+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() {
+ batteryLevel -= batteryDrain / 60; // Drain per frame
+ if (batteryLevel < 0) batteryLevel = 0;
+ batteryText.setText('Battery: ' + Math.floor(batteryLevel) + '%');
+ // Update battery bar color
+ if (batteryLevel > 50) {
+ batteryBar.tint = 0x00ff00;
+ } else if (batteryLevel > 25) {
+ batteryBar.tint = 0xffffff;
+ } else {
+ batteryBar.tint = 0xff0000;
+ }
+ // Scale battery bar
+ batteryBar.scaleX = batteryLevel / 100;
+ // 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 doors
+ leftDoor.isOpen = true;
+ rightDoor.isOpen = true;
+ leftDoor.getChildAt(0).alpha = 0.5;
+ rightDoor.getChildAt(0).alpha = 0.5;
+}
+// Event handlers
+game.down = function (x, y, obj) {
+ // Toggle camera mode
+ if (y > 1200) {
+ isCameraMode = !isCameraMode;
+ if (isCameraMode) {
+ cameraPanel.alpha = 0.8;
+ batteryDrain += 1;
+ } else {
+ cameraPanel.alpha = 0;
+ if (currentCamera) {
+ currentCamera.isActive = false;
+ currentCamera.getChildAt(0).tint = 0xffffff;
+ currentCamera = null;
+ }
+ }
+ }
+ // Toggle flashlight
+ if (y < 1200 && !isCameraMode) {
+ isFlashlightOn = !isFlashlightOn;
+ if (isFlashlightOn && batteryLevel > 0) {
+ flashlight.alpha = 0.6;
+ batteryDrain += 2;
+ } else {
+ flashlight.alpha = 0;
+ }
+ }
+};
+game.update = function () {
+ if (!isGameActive) return;
+ nightTimer++;
+ updateTime();
+ updateBattery();
+ // Check if night is complete
+ if (nightTimer >= nightDuration) {
+ completeNight();
+ return;
+ }
+ // Turn off flashlight if battery is dead
+ if (batteryLevel <= 0) {
+ flashlight.alpha = 0;
+ isFlashlightOn = false;
+ // Close doors if battery is dead
+ if (leftDoor.isOpen) {
+ leftDoor.getChildAt(0).alpha = 0.5;
+ }
+ if (rightDoor.isOpen) {
+ rightDoor.getChildAt(0).alpha = 0.5;
+ }
+ }
+ // Update camera visibility
+ if (isCameraMode && currentCamera) {
+ // Show bunny if in same room as camera
+ if (bunny.currentRoom === currentCamera.roomName) {
+ bunny.alpha = 1.0;
+ } else {
+ bunny.alpha = 0.3;
+ }
+ } else {
+ bunny.alpha = 0;
+ }
+};
+// Start ambient music
+LK.playMusic('ambient');
\ No newline at end of file