User prompt
Make the doors open when the first night starts
User prompt
The power will go out quicker when the doors are closed and or if the light are on
User prompt
I can't use the lights at the door please make it so I can see outside the doors
User prompt
Make the power go out slower
User prompt
Make the doors black when they're open ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
I can't tell when the doors are open or closed
User prompt
The lights don't work please fix the lights
Code edit (1 edits merged)
Please save this source code
User prompt
Midnight Meow Terror
Initial prompt
Let make a 2D point and click horror game inspired by Five nights at freddy's with a green and blue cat as the theat
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
currentNight: 1,
highestNight: 1
});
/****
* Classes
****/
var CameraButton = Container.expand(function (id, x, y) {
var self = Container.call(this);
self.roomId = id;
var button = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
var text = new Text2('CAM ' + id, {
size: 60,
fill: 0xFFFFFF
});
text.anchor.set(0.5, 0.5);
self.addChild(text);
self.x = x;
self.y = y;
self.interactive = true;
self.down = function () {
tween(button, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
LK.getSound('camera').play();
};
self.up = function () {
tween(button, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
if (currentCamera !== self.roomId) {
currentCamera = self.roomId;
showCamera(self.roomId);
}
};
return self;
});
var DoorButton = Container.expand(function (side) {
var self = Container.call(this);
self.side = side; // "left" or "right"
self.isOpen = true;
var button = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 150,
height: 150
});
var text = new Text2('DOOR', {
size: 40,
fill: 0xFFFFFF
});
text.anchor.set(0.5, 0.5);
self.addChild(text);
self.interactive = true;
self.down = function () {
tween(button, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
};
self.up = function () {
tween(button, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
self.toggleDoor();
LK.getSound('door').play();
};
self.toggleDoor = function () {
self.isOpen = !self.isOpen;
if (self.isOpen) {
text.setText("DOOR");
button.tint = 0x333333;
if (doors[self.side]) {
tween(doors[self.side], {
y: 2732 - doors[self.side].height / 2
}, {
duration: 300
});
}
} else {
text.setText("OPEN");
button.tint = 0x555555;
powerDrain += 5;
if (doors[self.side]) {
tween(doors[self.side], {
y: 2732 - doors[self.side].height
}, {
duration: 300
});
}
}
};
return self;
});
var LightButton = Container.expand(function (side) {
var self = Container.call(this);
self.side = side; // "left" or "right"
self.isOn = false;
var button = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 150,
height: 150
});
var text = new Text2('LIGHT', {
size: 40,
fill: 0xFFFFFF
});
text.anchor.set(0.5, 0.5);
self.addChild(text);
self.interactive = true;
self.down = function () {
tween(button, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
if (!self.isOn) {
self.isOn = true;
text.setText("OFF");
powerDrain += 1;
if (warnings[self.side]) {
warnings[self.side].visible = animatronicAtDoor === self.side;
if (animatronicAtDoor === self.side) {
LK.getSound('warning').play();
}
}
}
};
self.up = function () {
tween(button, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
if (self.isOn) {
self.isOn = false;
text.setText("LIGHT");
powerDrain -= 1;
if (warnings[self.side]) {
warnings[self.side].visible = false;
}
}
};
return self;
});
var Room = Container.expand(function (roomId, hasAnimatronic) {
var self = Container.call(this);
self.roomId = roomId;
self.hasAnimatronic = hasAnimatronic || false;
var background = self.attachAsset('cameraBg', {
anchorX: 0.5,
anchorY: 0.5
});
var roomText = new Text2('Room ' + roomId, {
size: 80,
fill: 0xFFFFFF
});
roomText.anchor.set(0.5, 0);
roomText.y = -background.height / 2 + 50;
self.addChild(roomText);
var animatronic = null;
if (hasAnimatronic) {
animatronic = self.attachAsset('animatronic', {
anchorX: 0.5,
anchorY: 1,
y: background.height / 2 - 100
});
self.animatronic = animatronic;
animatronic.visible = true;
}
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Game constants
var GAME_WIDTH = 2048;
var GAME_HEIGHT = 2732;
var MAX_POWER = 100;
var POWER_DRAIN_RATE = 0.01;
var GAME_DURATION = 90000; // 90 seconds for testing, would be longer in production
var ROOM_COUNT = 5;
// Game state variables
var currentNight = storage.currentNight || 1;
var power = MAX_POWER;
var powerDrain = 1; // Base power drain
var gameTime = 0;
var currentCamera = 1;
var isCameraActive = false;
var gameStarted = false;
var gameOver = false;
var animatronicRoom = 1;
var animatronicMoveProbability = 0.05 * currentNight;
var animatronicAtDoor = null; // "left", "right", or null
var lastAnimatronicMove = 0;
var doorLeftOpen = true;
var doorRightOpen = true;
var rooms = [];
var cameraButtons = [];
var doors = {
left: null,
right: null
};
var warnings = {
left: null,
right: null
};
// Initialize the office view
var office = game.addChild(LK.getAsset('office', {
anchorX: 0.5,
anchorY: 0.5,
x: GAME_WIDTH / 2,
y: GAME_HEIGHT / 2
}));
// Setup camera view
var cameraView = new Container();
cameraView.x = GAME_WIDTH / 2;
cameraView.y = GAME_HEIGHT / 2;
cameraView.visible = false;
game.addChild(cameraView);
var cameraScreen = cameraView.addChild(LK.getAsset('cameraScreen', {
anchorX: 0.5,
anchorY: 0.5
}));
// Create rooms for the camera system
for (var i = 1; i <= ROOM_COUNT; i++) {
var room = new Room(i, i === animatronicRoom);
room.x = 0;
room.y = 0;
room.visible = false;
cameraView.addChild(room);
rooms.push(room);
}
// Make the first room visible initially
rooms[0].visible = true;
// Create camera buttons panel
var cameraPanel = new Container();
cameraPanel.x = GAME_WIDTH / 2;
cameraPanel.y = GAME_HEIGHT - 300;
cameraPanel.visible = false;
game.addChild(cameraPanel);
for (var i = 1; i <= ROOM_COUNT; i++) {
var col = (i - 1) % 3;
var row = Math.floor((i - 1) / 3);
var button = new CameraButton(i, (col - 1) * 350, row * 220);
cameraPanel.addChild(button);
cameraButtons.push(button);
}
// Create camera toggle button
var toggleCameraBtn = game.addChild(LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
x: GAME_WIDTH / 2,
y: GAME_HEIGHT - 150
}));
var cameraText = new Text2('CAMERAS', {
size: 60,
fill: 0xFFFFFF
});
cameraText.anchor.set(0.5, 0.5);
cameraText.x = toggleCameraBtn.x;
cameraText.y = toggleCameraBtn.y;
game.addChild(cameraText);
// Create power indicator
var powerBarBg = game.addChild(LK.getAsset('powerBar', {
anchorX: 0,
anchorY: 0.5,
x: 150,
y: 150,
tint: 0x555555
}));
var powerBarFg = game.addChild(LK.getAsset('powerBar', {
anchorX: 0,
anchorY: 0.5,
x: 150,
y: 150
}));
var powerText = new Text2('Power: 100%', {
size: 40,
fill: 0xFFFFFF
});
powerText.anchor.set(0, 0.5);
powerText.x = 150;
powerText.y = 200;
game.addChild(powerText);
// Create clock
var clockBg = game.addChild(LK.getAsset('clockBg', {
anchorX: 0.5,
anchorY: 0.5,
x: GAME_WIDTH - 200,
y: 100
}));
var clockText = new Text2('12:00 AM', {
size: 50,
fill: 0xFFFFFF
});
clockText.anchor.set(0.5, 0.5);
clockText.x = clockBg.x;
clockText.y = clockBg.y;
game.addChild(clockText);
// Create night indicator
var nightText = new Text2('Night ' + currentNight, {
size: 70,
fill: 0xFFFFFF
});
nightText.anchor.set(0.5, 0.5);
nightText.x = GAME_WIDTH / 2;
nightText.y = 100;
game.addChild(nightText);
// Create door controls
var doorLeft = new DoorButton("left");
doorLeft.x = 150;
doorLeft.y = GAME_HEIGHT / 2;
game.addChild(doorLeft);
var doorRight = new DoorButton("right");
doorRight.x = GAME_WIDTH - 150;
doorRight.y = GAME_HEIGHT / 2;
game.addChild(doorRight);
// Create light controls
var lightLeft = new LightButton("left");
lightLeft.x = 150;
lightLeft.y = GAME_HEIGHT / 2 + 200;
game.addChild(lightLeft);
var lightRight = new LightButton("right");
lightRight.x = GAME_WIDTH - 150;
lightRight.y = GAME_HEIGHT / 2 + 200;
game.addChild(lightRight);
// Create door visuals
var leftDoor = game.addChild(LK.getAsset('door', {
anchorX: 0.5,
anchorY: 0,
x: 400,
y: GAME_HEIGHT - 800
}));
doors.left = leftDoor;
var rightDoor = game.addChild(LK.getAsset('door', {
anchorX: 0.5,
anchorY: 0,
x: GAME_WIDTH - 400,
y: GAME_HEIGHT - 800
}));
doors.right = rightDoor;
// Create warning lights
var warningLeft = game.addChild(LK.getAsset('warningLight', {
anchorX: 0.5,
anchorY: 0.5,
x: 400,
y: GAME_HEIGHT / 2
}));
warningLeft.visible = false;
warnings.left = warningLeft;
var warningRight = game.addChild(LK.getAsset('warningLight', {
anchorX: 0.5,
anchorY: 0.5,
x: GAME_WIDTH - 400,
y: GAME_HEIGHT / 2
}));
warningRight.visible = false;
warnings.right = warningRight;
// Create start game instructions
var instructionText = new Text2("Click to start Night " + currentNight, {
size: 80,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = GAME_WIDTH / 2;
instructionText.y = GAME_HEIGHT / 2;
game.addChild(instructionText);
// Helper function to show camera
function showCamera(roomId) {
// Hide all rooms
for (var i = 0; i < rooms.length; i++) {
rooms[i].visible = false;
}
// Show the selected room
if (roomId >= 1 && roomId <= rooms.length) {
rooms[roomId - 1].visible = true;
}
}
// Helper function to toggle camera view
function toggleCamera() {
isCameraActive = !isCameraActive;
cameraView.visible = isCameraActive;
cameraPanel.visible = isCameraActive;
if (isCameraActive) {
LK.getSound('camera').play();
cameraText.setText("CLOSE");
showCamera(currentCamera);
powerDrain += 1;
} else {
cameraText.setText("CAMERAS");
powerDrain -= 1;
}
}
// Update animatronic location
function updateAnimatronicLocation() {
if (!gameStarted || gameOver) {
return;
}
var now = LK.ticks;
if (now - lastAnimatronicMove < 60) {
return;
} // Limit movement frequency
if (Math.random() < animatronicMoveProbability * (isCameraActive ? 0.5 : 1)) {
// Hide animatronic from current room
if (animatronicRoom >= 1 && animatronicRoom <= ROOM_COUNT) {
var currentRoomIdx = animatronicRoom - 1;
if (rooms[currentRoomIdx].hasAnimatronic) {
rooms[currentRoomIdx].hasAnimatronic = false;
if (rooms[currentRoomIdx].animatronic) {
rooms[currentRoomIdx].animatronic.visible = false;
}
}
}
// Decide where to move
if (animatronicRoom === 1) {
// From starting room, move to room 2
animatronicRoom = 2;
} else if (animatronicRoom === 2) {
// From room 2, move to either room 3 or back to 1
animatronicRoom = Math.random() < 0.7 ? 3 : 1;
} else if (animatronicRoom === 3) {
// From room 3, move to either room 4, room 2, or to a door
var r = Math.random();
if (r < 0.5) {
animatronicRoom = 4;
} else if (r < 0.8) {
animatronicRoom = 2;
} else {
animatronicRoom = -1; // Special case, animatronic at door
animatronicAtDoor = Math.random() < 0.5 ? "left" : "right";
}
} else if (animatronicRoom === 4) {
// From room 4, move to room 3 or to a door
if (Math.random() < 0.7) {
animatronicRoom = 3;
} else {
animatronicRoom = -1; // Special case, animatronic at door
animatronicAtDoor = Math.random() < 0.5 ? "left" : "right";
}
} else if (animatronicRoom === 5) {
// From room 5, move to room 4 or 3 or to a door
var r = Math.random();
if (r < 0.4) {
animatronicRoom = 4;
} else if (r < 0.7) {
animatronicRoom = 3;
} else {
animatronicRoom = -1; // Special case, animatronic at door
animatronicAtDoor = Math.random() < 0.5 ? "left" : "right";
}
} else if (animatronicRoom === -1) {
// Animatronic is at a door
// If door is closed, return to nearby room
var doorObj = animatronicAtDoor === "left" ? doorLeft : doorRight;
if (!doorObj.isOpen) {
animatronicRoom = Math.floor(Math.random() * 3) + 3; // Rooms 3, 4, or 5
animatronicAtDoor = null;
} else {
// Door is open, trigger jumpscare
triggerJumpscare();
}
}
// Show animatronic in new room (if it's a regular room)
if (animatronicRoom >= 1 && animatronicRoom <= ROOM_COUNT) {
var newRoomIdx = animatronicRoom - 1;
rooms[newRoomIdx].hasAnimatronic = true;
if (rooms[newRoomIdx].animatronic) {
rooms[newRoomIdx].animatronic.visible = true;
}
}
LK.getSound('footstep').play();
lastAnimatronicMove = now;
}
}
// Trigger jumpscare
function triggerJumpscare() {
if (gameOver) {
return;
}
gameOver = true;
LK.getSound('jumpscare').play();
// Create jumpscare animation
var jumpscare = game.addChild(LK.getAsset('animatronic', {
anchorX: 0.5,
anchorY: 0.5,
x: GAME_WIDTH / 2,
y: GAME_HEIGHT / 2,
scaleX: 3,
scaleY: 3
}));
LK.effects.flashScreen(0xff0000, 500);
LK.setTimeout(function () {
LK.showGameOver();
}, 1500);
}
// Handle winning the night
function winNight() {
if (gameOver) {
return;
}
gameOver = true;
// Save progress
if (currentNight >= storage.highestNight) {
storage.highestNight = currentNight + 1;
}
storage.currentNight = currentNight + 1;
// Display winning message
var winText = new Text2("You survived Night " + currentNight + "!", {
size: 80,
fill: 0xFFFFFF
});
winText.anchor.set(0.5, 0.5);
winText.x = GAME_WIDTH / 2;
winText.y = GAME_HEIGHT / 2;
game.addChild(winText);
LK.setTimeout(function () {
LK.showYouWin();
}, 3000);
}
// Event handlers
game.down = function (x, y, obj) {
if (!gameStarted) {
// Start game when clicked
gameStarted = true;
instructionText.visible = false;
LK.getSound('ambience').play();
LK.playMusic('backgroundMusic');
return;
}
// Handle camera toggle button
if (x >= toggleCameraBtn.x - toggleCameraBtn.width / 2 && x <= toggleCameraBtn.x + toggleCameraBtn.width / 2 && y >= toggleCameraBtn.y - toggleCameraBtn.height / 2 && y <= toggleCameraBtn.y + toggleCameraBtn.height / 2) {
toggleCamera();
}
};
// Game update loop
game.update = function () {
if (!gameStarted || gameOver) {
return;
}
// Update game time
gameTime += 16.67; // Approximate milliseconds per frame at 60fps
// Update clock (6 hours from 12AM to 6AM in game duration)
var gameProgress = Math.min(gameTime / GAME_DURATION, 1);
var hour = Math.floor(gameProgress * 6) + 12;
hour = hour > 12 ? hour - 12 : hour;
var minute = Math.floor(gameProgress * 6 % 1 * 60);
var ampm = hour >= 6 && hour < 12 ? "AM" : "PM";
clockText.setText(hour + ":" + (minute < 10 ? "0" + minute : minute) + " " + ampm);
// Win condition - survive until 6AM
if (gameProgress >= 1) {
winNight();
return;
}
// Update power
power -= POWER_DRAIN_RATE * powerDrain;
power = Math.max(0, power);
var powerPercent = Math.floor(power);
powerText.setText("Power: " + powerPercent + "%");
powerBarFg.width = power / MAX_POWER * powerBarBg.width;
// Game over if power runs out
if (power <= 0) {
triggerJumpscare();
return;
}
// Update animatronic
if (LK.ticks % 60 === 0) {
updateAnimatronicLocation();
}
// Update warning lights visibility based on light button state
if (animatronicAtDoor === "left" && lightLeft.isOn) {
warningLeft.visible = true;
} else {
warningLeft.visible = false;
}
if (animatronicAtDoor === "right" && lightRight.isOn) {
warningRight.visible = true;
} else {
warningRight.visible = false;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -87,8 +87,9 @@
self.toggleDoor = function () {
self.isOpen = !self.isOpen;
if (self.isOpen) {
text.setText("DOOR");
+ button.tint = 0x333333;
if (doors[self.side]) {
tween(doors[self.side], {
y: 2732 - doors[self.side].height / 2
}, {
@@ -96,8 +97,9 @@
});
}
} else {
text.setText("OPEN");
+ button.tint = 0x555555;
powerDrain += 5;
if (doors[self.side]) {
tween(doors[self.side], {
y: 2732 - doors[self.side].height
An anthropomorphic blue and green cat animatronic wearing rockstar attire. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Metal door. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Two doorways. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Pet store. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows