/**** * Classes ****/ // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); // Attach head var head = self.attachAsset('enemyHead', { anchorX: 0.5, anchorY: 0.5, y: -70 }); // Attach body var body = self.attachAsset('enemyBody', { anchorX: 0.5, anchorY: 0.5 }); // Attach arms var leftArm = self.attachAsset('enemyArm', { anchorX: 0.5, anchorY: 0.5, x: -45, y: -20 }); var rightArm = self.attachAsset('enemyArm', { anchorX: 0.5, anchorY: 0.5, x: 45, y: -20 }); // Attach legs var leftLeg = self.attachAsset('enemyLeg', { anchorX: 0.5, anchorY: 0.5, x: -20, y: 60 }); var rightLeg = self.attachAsset('enemyLeg', { anchorX: 0.5, anchorY: 0.5, x: 20, y: 60 }); self.tired = false; self.energy = 100; // Initial energy level self.update = function () { // Decrease energy over time self.energy -= 0.1; // Decrease energy over time if (self.energy <= 0) { self.tired = true; // Set tired state when energy is depleted } // Logic to make the enemy slow down when tired if (self.tired) { speed = 3; // Reduce speed when tired } // Enemy movement logic to chase the player or NPCs if (!menuScreen.visible && game.currentMode) { var target = player; var minDistance = Math.sqrt(Math.pow(player.x - self.x, 2) + Math.pow(player.y - self.y, 2)); // Find the closest NPC for (var i = 0; i < npcs.length; i++) { var npc = npcs[i]; var npcDistance = Math.sqrt(Math.pow(npc.x - self.x, 2) + Math.pow(npc.y - self.y, 2)); if (npcDistance < minDistance) { minDistance = npcDistance; target = npc; } } var dx = target.x - self.x; var dy = target.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); var speed = game.currentMode === 'easy' ? 10 : game.currentMode === 'challenging' ? 200 : game.currentMode === 'timeAttack' ? 30 : 20; // Adjust speed for challenging mode if (distance > 0) { var newX = self.x + dx / distance * speed; var newY = self.y + dy / distance * speed; // Check if the new position would intersect with the house self.x = newX; self.y = newY; if (self.intersects(house)) { if (Math.abs(dx) > Math.abs(dy)) { self.y += (dy > 0 ? 1 : -1) * speed; } else { self.x += (dx > 0 ? 1 : -1) * speed; } } } } }; }); // Generator class var Generator = Container.expand(function () { var self = Container.call(this); var generatorGraphic = self.attachAsset('playerBody', { anchorX: 0.5, anchorY: 0.5 }); self.isOn = false; // Initial state of the generator self.energy = 100; // Initial energy level of the generator self.toggle = function () { self.isOn = !self.isOn; console.log("Generator is now " + (self.isOn ? "ON" : "OFF")); if (self.isOn && self.energy > 0) { self.energy -= 0.1; // Decrease energy over time console.log("Generator energy: " + self.energy.toFixed(1) + "/100"); if (self.energy <= 0) { self.isOn = false; // Turn off the generator when energy is depleted console.log("Generator is now OFF due to energy depletion"); } } }; self.update = function () { if (self.isOn && self.energy > 0) { self.energy -= 0.1; // Decrease energy over time console.log("Generator energy: " + self.energy.toFixed(1) + "/100"); if (self.energy <= 0) { self.isOn = false; // Turn off the generator when energy is depleted console.log("Generator is now OFF due to energy depletion"); } } }; }); // House class var House = Container.expand(function () { var self = Container.call(this); var houseBase = self.attachAsset('houseBase', { anchorX: 0.5, anchorY: 0.5 }); var houseRoof = self.attachAsset('houseRoof', { anchorX: 0.5, anchorY: 1.0, y: -75 }); // Attach door var houseDoor = self.attachAsset('houseBase', { anchorX: 0.5, anchorY: 0.5, width: 80, height: 150, color: 0x654321, y: 75 }); }); // Joystick class var Joystick = Container.expand(function () { var self = Container.call(this); var joystickButton = self.attachAsset('joystickButton', { anchorX: 0.5, anchorY: 0.5 }); self.active = false; self.startX = 0; self.startY = 0; self.down = function (x, y, obj) { self.active = true; self.startX = x; self.startY = y; }; self.move = function (x, y, obj) { if (self.active) { var dx = x - self.startX; var dy = y - self.startY; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { var speed = 5; // Adjust speed as necessary player.x += dx / distance * speed; player.y += dy / distance * speed; } self.startX = x; self.startY = y; } }; self.up = function (x, y, obj) { self.active = false; }; }); // MenuScreen class var MenuScreen = Container.expand(function () { var self = Container.call(this); var titleText = new Text2('Night of the Massacre', { size: 150, fill: 0xFF0000, // Change color to red for a scarier look font: "'Creepster', 'Arial Black', Tahoma" // Use a scary font }); titleText.anchor.set(0.5, 0.5); titleText.x = 2048 / 2; titleText.y = 2732 / 2 - 650; // Position title above the start game button self.addChild(titleText); var surviveTextMenu = new Text2('SURVIVE UNTIL 6 AM', { size: 100, fill: 0xFFFFFF }); surviveTextMenu.anchor.set(0.5, 0.5); surviveTextMenu.x = 2048 / 2; surviveTextMenu.y = 2732 / 2 + 300; // Move further below the house self.addChild(surviveTextMenu); var startButton = new Text2('start game', { size: 150, fill: 0xFFFFFF }); startButton.anchor.set(0.5, 0.5); startButton.x = 2048 / 2; startButton.y = 2732 / 2 - 500; // Position the start button further from the house self.addChild(startButton); startButton.down = function (x, y, obj) { console.log("Start Game button pressed!"); self.visible = false; // Hide the menu screen // Create a game mode selection screen var gameModeScreen = new Container(); gameModeScreen.visible = true; var easyModeButton = new Text2('Easy Mode', { size: 100, fill: 0x00FF00 // Green color for easy mode }); easyModeButton.anchor.set(0.5, 0.5); easyModeButton.x = 2048 / 2; easyModeButton.y = 2732 / 2 - 300; // Move further above the normal mode button gameModeScreen.addChild(easyModeButton); var normalModeButton = new Text2('Normal Mode', { size: 100, fill: 0xFFFFFF }); normalModeButton.anchor.set(0.5, 0.5); normalModeButton.x = 2048 / 2; normalModeButton.y = 2732 / 2 - 100; gameModeScreen.addChild(normalModeButton); var timeAttackModeButton = new Text2('NIGHTMARE MODE', { size: 100, fill: 0xFF0000 // Change font color to red }); timeAttackModeButton.anchor.set(0.5, 0.5); timeAttackModeButton.x = 2048 / 2; timeAttackModeButton.y = 2732 / 2 + 100; gameModeScreen.addChild(timeAttackModeButton); var challengingModeButton = new Text2('IMPOSSIBLE MODE', { size: 100, fill: 0xFF8C00 // Orange color for impossible mode }); challengingModeButton.anchor.set(0.5, 0.5); challengingModeButton.x = 2048 / 2; challengingModeButton.y = 2732 / 2 + 300; gameModeScreen.addChild(challengingModeButton); var practiceModeButton = new Text2('Practice Mode', { size: 100, fill: 0x87CEEB // Light blue color for practice mode }); practiceModeButton.anchor.set(0.5, 0.5); practiceModeButton.x = 2048 / 2; practiceModeButton.y = 2732 / 2 - 500; // Move above the easy mode button gameModeScreen.addChild(practiceModeButton); var endlessModeButton = new Text2('Endless Mode', { size: 100, fill: 0xFF69B4 // Pink color for endless mode }); endlessModeButton.anchor.set(0.5, 0.5); endlessModeButton.x = 2048 / 2; endlessModeButton.y = 2732 / 2 + 500; gameModeScreen.addChild(endlessModeButton); var backButton = new Text2('Back', { size: 100, fill: 0xFFFFFF // White color for back button }); backButton.anchor.set(0.5, 0.5); backButton.x = 2048 / 2; backButton.y = 2732 / 2 + 700; gameModeScreen.addChild(backButton); backButton.down = function (x, y, obj) { console.log("Back button pressed!"); gameModeScreen.visible = false; self.visible = true; // Show the menu screen again }; game.addChild(gameModeScreen); easyModeButton.down = function (x, y, obj) { console.log("Easy Mode selected!"); gameModeScreen.visible = false; game.startGame('easy'); }; normalModeButton.down = function (x, y, obj) { console.log("Normal Mode selected!"); gameModeScreen.visible = false; game.startGame('normal'); }; timeAttackModeButton.down = function (x, y, obj) { console.log("Time Attack Mode selected!"); gameModeScreen.visible = false; game.startGame('timeAttack'); }; challengingModeButton.down = function (x, y, obj) { console.log("Challenging Mode selected!"); gameModeScreen.visible = false; game.startGame('challenging'); }; practiceModeButton.down = function (x, y, obj) { console.log("Practice Mode selected!"); gameModeScreen.visible = false; game.startGame('practice'); }; endlessModeButton.down = function (x, y, obj) { console.log("Endless Mode selected!"); gameModeScreen.visible = false; game.startGame('endless'); }; }; }); // NPC class var NPC = Container.expand(function () { var self = Container.call(this); // Attach head var head = self.attachAsset('playerHead', { anchorX: 0.5, anchorY: 0.5, y: -60 }); // Attach body var body = self.attachAsset('playerBody', { anchorX: 0.5, anchorY: 0.5 }); // Attach arms var leftArm = self.attachAsset('playerArm', { anchorX: 0.5, anchorY: 0.5, x: -25, y: -20 }); var rightArm = self.attachAsset('playerArm', { anchorX: 0.5, anchorY: 0.5, x: 25, y: -20 }); // Attach legs var leftLeg = self.attachAsset('playerLeg', { anchorX: 0.5, anchorY: 0.5, x: -10, y: 40 }); var rightLeg = self.attachAsset('playerLeg', { anchorX: 0.5, anchorY: 0.5, x: 10, y: 40 }); self.speed = 10; // Set NPC speed to match enemy speed self.update = function () { if (!menuScreen.visible && game.currentMode) { // Random movement logic: NPC moves to random locations if (!self.targetX || !self.targetY || Math.abs(self.x - self.targetX) < 5 && Math.abs(self.y - self.targetY) < 5) { self.targetX = Math.random() * 2048; self.targetY = Math.random() * 2732; } var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } } }; }); // Joystick controls // The game engine will automatically load the required assets // Player class var Player = Container.expand(function () { var self = Container.call(this); // Attach head var head = self.attachAsset('playerHead', { anchorX: 0.5, anchorY: 0.5, y: -60 }); // Attach body var body = self.attachAsset('playerBody', { anchorX: 0.5, anchorY: 0.5 }); // Attach arms var leftArm = self.attachAsset('playerArm', { anchorX: 0.5, anchorY: 0.5, x: -25, y: -20 }); var rightArm = self.attachAsset('playerArm', { anchorX: 0.5, anchorY: 0.5, x: 25, y: -20 }); // Attach legs var leftLeg = self.attachAsset('playerLeg', { anchorX: 0.5, anchorY: 0.5, x: -10, y: 40 }); var rightLeg = self.attachAsset('playerLeg', { anchorX: 0.5, anchorY: 0.5, x: 10, y: 40 }); self.energy = 100; // Initial energy level self.tired = false; // Initial tired state self.update = function () { // Decrease energy over time self.energy -= 0.1; if (self.energy <= 0) { self.tired = true; // Set tired state when energy is depleted console.log("Player is tired and cannot move!"); return; // Skip movement if player is tired } if (self.tired) { return; // Skip movement if player is tired } // Allow player to kill NPCs in Become Enemy Mode if (game.currentMode === 'becomeEnemy') { for (var i = 0; i < npcs.length; i++) { if (self.intersects(npcs[i])) { console.log("NPC killed by player!"); npcs[i].destroy(); npcs.splice(i, 1); } } } // Decrease energy over time self.energy -= 0.1; if (self.energy <= 0) { self.tired = true; // Set tired state when energy is depleted console.log("Player is tired and cannot move!"); return; } // Check if player intersects with the shed if (self.intersects(shed)) { console.log("Player touched the shed!"); // Logic to refill the generator if (!generator.isOn) { generator.energy = 100; // Refill generator energy console.log("Generator refilled!"); } } }; }); // Shed class var Shed = Container.expand(function () { var self = Container.call(this); var shedBase = self.attachAsset('houseBase', { anchorX: 0.5, anchorY: 0.5 }); var generator = self.attachAsset('playerBody', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 50 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x191970, // Init game with midnight blue background icon: 'screen' // Set the game icon to be the screen of the game }); /**** * Game Code ****/ // Function to publish the game function publishGame() { console.log("Publishing the game..."); // Add any additional logic needed for publishing // This could include saving game state, uploading to a server, etc. console.log("Game published successfully!"); } // Call the publishGame function when the game is ready to be published publishGame(); // Add a quit button to the top-right corner of the game screen var quitButton = new Text2('Quit', { size: 100, fill: 0xFFFFFF }); quitButton.anchor.set(1, 0); // Anchor to the top-right corner quitButton.x = 2048; // Position at the right edge quitButton.y = 0; // Position at the top edge LK.gui.topRight.addChild(quitButton); // Define the quit button functionality quitButton.down = function (x, y, obj) { console.log("Quit button pressed!"); // Logic to quit the game, e.g., return to the main menu or close the game menuScreen.visible = true; // Show the menu screen again game.currentMode = null; // Reset the current game mode }; // Initialize and display the menu screen var menuScreen = game.addChild(new MenuScreen()); menuScreen.visible = true; game.currentMode = null; // Track the current game mode // Function to start the game game.startGame = function (mode) { // Initialize game elements here if needed menuScreen.visible = false; // Hide the menu screen game.currentMode = mode; // Set the current game mode if (mode === 'easy') { console.log("Starting Easy Mode..."); game.setBackgroundColor(0x00ff00); // Change background to green // Add easy mode specific initialization logic } else if (mode === 'normal') { console.log("Starting Normal Mode..."); // Add normal mode specific initialization logic } else if (mode === 'timeAttack') { console.log("Starting NIGHTMARE MODE..."); game.setBackgroundColor(0xff0000); // Change background to red // Add time attack mode specific initialization logic } else if (mode === 'challenging') { console.log("Starting Challenging Mode..."); game.setBackgroundColor(0xff8c00); // Change background to orange // Increase enemy speed by 10x compared to NIGHTMARE MODE for (var i = 0; i < enemies.length; i++) { enemies[i].speed = 200; // Assuming NIGHTMARE MODE speed is 20 } } else if (mode === 'practice') { console.log("Starting Practice Mode..."); game.setBackgroundColor(0x87ceeb); // Change background to light blue // Remove all existing enemies in practice mode for (var i = 0; i < enemies.length; i++) { enemies[i].destroy(); } enemies = []; } else if (mode === 'becomeEnemy') { console.log("Starting Become Enemy Mode..."); // Remove all existing enemies for (var i = 0; i < enemies.length; i++) { enemies[i].destroy(); } enemies = []; // Transform player into an enemy player.destroy(); player = game.addChild(new Enemy()); player.x = 2048 / 2; player.y = 2732 / 2; } // Add other game initialization logic if necessary }; // Initialize joystick // Blood texture color // Blood texture color // Blood texture color // Function to detect if the device is mobile function isMobileDevice() { return typeof navigator !== 'undefined' && /Mobi|Android/i.test(navigator.userAgent); } var joystick; if (isMobileDevice()) { joystick = game.addChild(new Joystick()); joystick.x = 2048 - 150; // Position joystick at the bottom right of the screen joystick.y = 2732 - 150; // Position joystick at the bottom right of the screen } // Add a clock display to the game var clockTxt = new Text2('00:00', { size: 100, fill: 0xFFFFFF }); clockTxt.anchor.set(0.5, 0); LK.gui.top.addChild(clockTxt); // Add 'Survive until 06:00 am' text at the bottom of the screen var surviveText = new Text2('Survive until 06:00 am', { size: 100, fill: 0xFFFFFF }); surviveText.anchor.set(0.5, 1); surviveText.x = 2048 / 2; surviveText.y = 2732; LK.gui.bottom.addChild(surviveText); // Add player to the game var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 / 2; var house = game.addChild(new House()); house.x = 2048 / 2; house.y = 2732 / 2; // Add NPCs to the game var npcs = []; for (var i = 0; i < 19; i++) { var npc = game.addChild(new NPC()); npc.x = house.x; // Position NPCs inside the house npc.y = house.y; npcs.push(npc); } // Add 10 NPCs every 11 seconds var npcAddInterval = LK.setInterval(function () { if (!menuScreen.visible) { for (var i = 0; i < 30; i++) { var newNpc = game.addChild(new NPC()); newNpc.x = house.x; // Position new NPC inside the house newNpc.y = house.y; npcs.push(newNpc); } } }, 11000); // Update the clock every second var startTime = Date.now(); LK.setInterval(function () { if (!menuScreen.visible && !game.paused && game.currentMode) { var elapsedTime = Math.floor((Date.now() - startTime) / 1000); var minutes = Math.floor(elapsedTime / 60); var seconds = elapsedTime % 60; clockTxt.setText((minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds); // Check if the clock reaches 06:00 and the mode is not endless if (minutes === 6 && seconds === 0 && game.currentMode !== 'endless') { // Display 'YOU WIN!' asset var youWinAsset = LK.getAsset('YOUWIN', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); LK.gui.center.addChild(youWinAsset); // Show game over. The game will be automatically paused while game over is showing. LK.showGameOver(); } } }, 1000); // Add mouse movement control for player game.move = function (x, y, obj) { if (!menuScreen.visible && game.currentMode) { player.x = x; player.y = y; } }; var enemies = []; var enemy = game.addChild(new Enemy()); enemy.x = Math.random() * 2048; enemy.y = Math.random() * 2732; enemies.push(enemy); // Track time for increasing enemy speed var lastSpeedIncreaseTime = Date.now(); // Track time for stopping the player var lastStopTime = Date.now(); // Game update function game.update = function () { // Stop the player every 10 seconds if (Date.now() - lastStopTime >= 10000) { player.tired = true; console.log("Player stops for a moment!"); LK.setTimeout(function () { player.tired = false; console.log("Player can move again!"); }, 1000); // Player stops for 1 second lastStopTime = Date.now(); } if (menuScreen.visible) { return; // Do not update game elements if the menu screen is visible } // Increase speed of all enemies every 10 seconds if (Date.now() - lastSpeedIncreaseTime >= 10000) { for (var i = 0; i < enemies.length; i++) { enemies[i].speed = (enemies[i].speed || 7) + 10; // Initialize speed if undefined and increase by 10 } lastSpeedIncreaseTime = Date.now(); } // Game logic goes here generator.update(); // Check if player is inside the house if (player.intersects(house)) { // Logic to make the player feel cold // For example, decrease player's health or display a message console.log("Player feels cold inside the house!"); // Implement logic to encourage player to leave the house // This could be a visual effect, sound, or health decrease } // Check for collisions between player and enemies for (var i = 0; i < enemies.length; i++) { if (player.intersects(enemies[i])) { // Flash screen red for 2 seconds (2000ms) to show player is killed LK.effects.flashScreen(0xff3333, 2000); // Add killing animation var killingAnimation = LK.getAsset('playerBody', { anchorX: 0.5, anchorY: 0.5, x: player.x, y: player.y }); game.addChild(killingAnimation); LK.effects.flashObject(killingAnimation, 0xff0000, 1000, function () { killingAnimation.destroy(); }); // Show game over. The game will be automatically paused while game over is showing. LK.showGameOver(); break; } for (var j = 0; j < npcs.length; j++) { if (npcs[j].intersects(enemies[i])) { // NPC is killed by enemy console.log("NPC killed by enemy!"); npcs[j].destroy(); npcs.splice(j, 1); } } } // Increase enemy count by 1 every 10 seconds with a maximum of 1 enemy var enemyIncreaseInterval = LK.setInterval(function () { if (!menuScreen.visible && enemies.length < 1 && game.currentMode !== 'becomeEnemy' && game.currentMode !== 'practice') { var newEnemy = game.addChild(new Enemy()); newEnemy.x = Math.random() * 2048; newEnemy.y = Math.random() * 2732; enemies.push(newEnemy); } }, 10000); }; // Initialize the bloodMoon object var bloodMoon = LK.getAsset('bloodMoon', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 200 }); game.addChild(bloodMoon); // Animate the bloodmoon to move across the sky bloodMoon.x -= 0.5; // Move the bloodmoon slowly to the left if (bloodMoon.x < -bloodMoon.width / 2) { bloodMoon.x = 2048 + bloodMoon.width / 2; // Reset position to the right side of the screen } // Add a glow effect to the bloodmoon LK.effects.flashObject(bloodMoon, 0xff0000, 2000, function () { LK.effects.flashObject(bloodMoon, 0x8b0000, 2000); }); var house = game.addChild(new House()); house.x = 2048 / 2; house.y = 2732 / 2; // Add a shed with a generator inside to the game var shed = game.addChild(new Shed()); shed.x = 500; // Position the shed at a specific location shed.y = 2000; // Position the shed at a specific location // Add a generator inside the shed var generator = shed.addChild(new Generator()); generator.x = 0; // Center the generator inside the shed generator.y = 50; // Position the generator inside the shed // Keyboard controls for WASD movement are not supported in this environment
/****
* Classes
****/
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
// Attach head
var head = self.attachAsset('enemyHead', {
anchorX: 0.5,
anchorY: 0.5,
y: -70
});
// Attach body
var body = self.attachAsset('enemyBody', {
anchorX: 0.5,
anchorY: 0.5
});
// Attach arms
var leftArm = self.attachAsset('enemyArm', {
anchorX: 0.5,
anchorY: 0.5,
x: -45,
y: -20
});
var rightArm = self.attachAsset('enemyArm', {
anchorX: 0.5,
anchorY: 0.5,
x: 45,
y: -20
});
// Attach legs
var leftLeg = self.attachAsset('enemyLeg', {
anchorX: 0.5,
anchorY: 0.5,
x: -20,
y: 60
});
var rightLeg = self.attachAsset('enemyLeg', {
anchorX: 0.5,
anchorY: 0.5,
x: 20,
y: 60
});
self.tired = false;
self.energy = 100; // Initial energy level
self.update = function () {
// Decrease energy over time
self.energy -= 0.1; // Decrease energy over time
if (self.energy <= 0) {
self.tired = true; // Set tired state when energy is depleted
}
// Logic to make the enemy slow down when tired
if (self.tired) {
speed = 3; // Reduce speed when tired
}
// Enemy movement logic to chase the player or NPCs
if (!menuScreen.visible && game.currentMode) {
var target = player;
var minDistance = Math.sqrt(Math.pow(player.x - self.x, 2) + Math.pow(player.y - self.y, 2));
// Find the closest NPC
for (var i = 0; i < npcs.length; i++) {
var npc = npcs[i];
var npcDistance = Math.sqrt(Math.pow(npc.x - self.x, 2) + Math.pow(npc.y - self.y, 2));
if (npcDistance < minDistance) {
minDistance = npcDistance;
target = npc;
}
}
var dx = target.x - self.x;
var dy = target.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var speed = game.currentMode === 'easy' ? 10 : game.currentMode === 'challenging' ? 200 : game.currentMode === 'timeAttack' ? 30 : 20; // Adjust speed for challenging mode
if (distance > 0) {
var newX = self.x + dx / distance * speed;
var newY = self.y + dy / distance * speed;
// Check if the new position would intersect with the house
self.x = newX;
self.y = newY;
if (self.intersects(house)) {
if (Math.abs(dx) > Math.abs(dy)) {
self.y += (dy > 0 ? 1 : -1) * speed;
} else {
self.x += (dx > 0 ? 1 : -1) * speed;
}
}
}
}
};
});
// Generator class
var Generator = Container.expand(function () {
var self = Container.call(this);
var generatorGraphic = self.attachAsset('playerBody', {
anchorX: 0.5,
anchorY: 0.5
});
self.isOn = false; // Initial state of the generator
self.energy = 100; // Initial energy level of the generator
self.toggle = function () {
self.isOn = !self.isOn;
console.log("Generator is now " + (self.isOn ? "ON" : "OFF"));
if (self.isOn && self.energy > 0) {
self.energy -= 0.1; // Decrease energy over time
console.log("Generator energy: " + self.energy.toFixed(1) + "/100");
if (self.energy <= 0) {
self.isOn = false; // Turn off the generator when energy is depleted
console.log("Generator is now OFF due to energy depletion");
}
}
};
self.update = function () {
if (self.isOn && self.energy > 0) {
self.energy -= 0.1; // Decrease energy over time
console.log("Generator energy: " + self.energy.toFixed(1) + "/100");
if (self.energy <= 0) {
self.isOn = false; // Turn off the generator when energy is depleted
console.log("Generator is now OFF due to energy depletion");
}
}
};
});
// House class
var House = Container.expand(function () {
var self = Container.call(this);
var houseBase = self.attachAsset('houseBase', {
anchorX: 0.5,
anchorY: 0.5
});
var houseRoof = self.attachAsset('houseRoof', {
anchorX: 0.5,
anchorY: 1.0,
y: -75
});
// Attach door
var houseDoor = self.attachAsset('houseBase', {
anchorX: 0.5,
anchorY: 0.5,
width: 80,
height: 150,
color: 0x654321,
y: 75
});
});
// Joystick class
var Joystick = Container.expand(function () {
var self = Container.call(this);
var joystickButton = self.attachAsset('joystickButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.active = false;
self.startX = 0;
self.startY = 0;
self.down = function (x, y, obj) {
self.active = true;
self.startX = x;
self.startY = y;
};
self.move = function (x, y, obj) {
if (self.active) {
var dx = x - self.startX;
var dy = y - self.startY;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
var speed = 5; // Adjust speed as necessary
player.x += dx / distance * speed;
player.y += dy / distance * speed;
}
self.startX = x;
self.startY = y;
}
};
self.up = function (x, y, obj) {
self.active = false;
};
});
// MenuScreen class
var MenuScreen = Container.expand(function () {
var self = Container.call(this);
var titleText = new Text2('Night of the Massacre', {
size: 150,
fill: 0xFF0000,
// Change color to red for a scarier look
font: "'Creepster', 'Arial Black', Tahoma" // Use a scary font
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 2732 / 2 - 650; // Position title above the start game button
self.addChild(titleText);
var surviveTextMenu = new Text2('SURVIVE UNTIL 6 AM', {
size: 100,
fill: 0xFFFFFF
});
surviveTextMenu.anchor.set(0.5, 0.5);
surviveTextMenu.x = 2048 / 2;
surviveTextMenu.y = 2732 / 2 + 300; // Move further below the house
self.addChild(surviveTextMenu);
var startButton = new Text2('start game', {
size: 150,
fill: 0xFFFFFF
});
startButton.anchor.set(0.5, 0.5);
startButton.x = 2048 / 2;
startButton.y = 2732 / 2 - 500; // Position the start button further from the house
self.addChild(startButton);
startButton.down = function (x, y, obj) {
console.log("Start Game button pressed!");
self.visible = false; // Hide the menu screen
// Create a game mode selection screen
var gameModeScreen = new Container();
gameModeScreen.visible = true;
var easyModeButton = new Text2('Easy Mode', {
size: 100,
fill: 0x00FF00 // Green color for easy mode
});
easyModeButton.anchor.set(0.5, 0.5);
easyModeButton.x = 2048 / 2;
easyModeButton.y = 2732 / 2 - 300; // Move further above the normal mode button
gameModeScreen.addChild(easyModeButton);
var normalModeButton = new Text2('Normal Mode', {
size: 100,
fill: 0xFFFFFF
});
normalModeButton.anchor.set(0.5, 0.5);
normalModeButton.x = 2048 / 2;
normalModeButton.y = 2732 / 2 - 100;
gameModeScreen.addChild(normalModeButton);
var timeAttackModeButton = new Text2('NIGHTMARE MODE', {
size: 100,
fill: 0xFF0000 // Change font color to red
});
timeAttackModeButton.anchor.set(0.5, 0.5);
timeAttackModeButton.x = 2048 / 2;
timeAttackModeButton.y = 2732 / 2 + 100;
gameModeScreen.addChild(timeAttackModeButton);
var challengingModeButton = new Text2('IMPOSSIBLE MODE', {
size: 100,
fill: 0xFF8C00 // Orange color for impossible mode
});
challengingModeButton.anchor.set(0.5, 0.5);
challengingModeButton.x = 2048 / 2;
challengingModeButton.y = 2732 / 2 + 300;
gameModeScreen.addChild(challengingModeButton);
var practiceModeButton = new Text2('Practice Mode', {
size: 100,
fill: 0x87CEEB // Light blue color for practice mode
});
practiceModeButton.anchor.set(0.5, 0.5);
practiceModeButton.x = 2048 / 2;
practiceModeButton.y = 2732 / 2 - 500; // Move above the easy mode button
gameModeScreen.addChild(practiceModeButton);
var endlessModeButton = new Text2('Endless Mode', {
size: 100,
fill: 0xFF69B4 // Pink color for endless mode
});
endlessModeButton.anchor.set(0.5, 0.5);
endlessModeButton.x = 2048 / 2;
endlessModeButton.y = 2732 / 2 + 500;
gameModeScreen.addChild(endlessModeButton);
var backButton = new Text2('Back', {
size: 100,
fill: 0xFFFFFF // White color for back button
});
backButton.anchor.set(0.5, 0.5);
backButton.x = 2048 / 2;
backButton.y = 2732 / 2 + 700;
gameModeScreen.addChild(backButton);
backButton.down = function (x, y, obj) {
console.log("Back button pressed!");
gameModeScreen.visible = false;
self.visible = true; // Show the menu screen again
};
game.addChild(gameModeScreen);
easyModeButton.down = function (x, y, obj) {
console.log("Easy Mode selected!");
gameModeScreen.visible = false;
game.startGame('easy');
};
normalModeButton.down = function (x, y, obj) {
console.log("Normal Mode selected!");
gameModeScreen.visible = false;
game.startGame('normal');
};
timeAttackModeButton.down = function (x, y, obj) {
console.log("Time Attack Mode selected!");
gameModeScreen.visible = false;
game.startGame('timeAttack');
};
challengingModeButton.down = function (x, y, obj) {
console.log("Challenging Mode selected!");
gameModeScreen.visible = false;
game.startGame('challenging');
};
practiceModeButton.down = function (x, y, obj) {
console.log("Practice Mode selected!");
gameModeScreen.visible = false;
game.startGame('practice');
};
endlessModeButton.down = function (x, y, obj) {
console.log("Endless Mode selected!");
gameModeScreen.visible = false;
game.startGame('endless');
};
};
});
// NPC class
var NPC = Container.expand(function () {
var self = Container.call(this);
// Attach head
var head = self.attachAsset('playerHead', {
anchorX: 0.5,
anchorY: 0.5,
y: -60
});
// Attach body
var body = self.attachAsset('playerBody', {
anchorX: 0.5,
anchorY: 0.5
});
// Attach arms
var leftArm = self.attachAsset('playerArm', {
anchorX: 0.5,
anchorY: 0.5,
x: -25,
y: -20
});
var rightArm = self.attachAsset('playerArm', {
anchorX: 0.5,
anchorY: 0.5,
x: 25,
y: -20
});
// Attach legs
var leftLeg = self.attachAsset('playerLeg', {
anchorX: 0.5,
anchorY: 0.5,
x: -10,
y: 40
});
var rightLeg = self.attachAsset('playerLeg', {
anchorX: 0.5,
anchorY: 0.5,
x: 10,
y: 40
});
self.speed = 10; // Set NPC speed to match enemy speed
self.update = function () {
if (!menuScreen.visible && game.currentMode) {
// Random movement logic: NPC moves to random locations
if (!self.targetX || !self.targetY || Math.abs(self.x - self.targetX) < 5 && Math.abs(self.y - self.targetY) < 5) {
self.targetX = Math.random() * 2048;
self.targetY = Math.random() * 2732;
}
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
}
};
});
// Joystick controls
// The game engine will automatically load the required assets
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
// Attach head
var head = self.attachAsset('playerHead', {
anchorX: 0.5,
anchorY: 0.5,
y: -60
});
// Attach body
var body = self.attachAsset('playerBody', {
anchorX: 0.5,
anchorY: 0.5
});
// Attach arms
var leftArm = self.attachAsset('playerArm', {
anchorX: 0.5,
anchorY: 0.5,
x: -25,
y: -20
});
var rightArm = self.attachAsset('playerArm', {
anchorX: 0.5,
anchorY: 0.5,
x: 25,
y: -20
});
// Attach legs
var leftLeg = self.attachAsset('playerLeg', {
anchorX: 0.5,
anchorY: 0.5,
x: -10,
y: 40
});
var rightLeg = self.attachAsset('playerLeg', {
anchorX: 0.5,
anchorY: 0.5,
x: 10,
y: 40
});
self.energy = 100; // Initial energy level
self.tired = false; // Initial tired state
self.update = function () {
// Decrease energy over time
self.energy -= 0.1;
if (self.energy <= 0) {
self.tired = true; // Set tired state when energy is depleted
console.log("Player is tired and cannot move!");
return; // Skip movement if player is tired
}
if (self.tired) {
return; // Skip movement if player is tired
}
// Allow player to kill NPCs in Become Enemy Mode
if (game.currentMode === 'becomeEnemy') {
for (var i = 0; i < npcs.length; i++) {
if (self.intersects(npcs[i])) {
console.log("NPC killed by player!");
npcs[i].destroy();
npcs.splice(i, 1);
}
}
}
// Decrease energy over time
self.energy -= 0.1;
if (self.energy <= 0) {
self.tired = true; // Set tired state when energy is depleted
console.log("Player is tired and cannot move!");
return;
}
// Check if player intersects with the shed
if (self.intersects(shed)) {
console.log("Player touched the shed!");
// Logic to refill the generator
if (!generator.isOn) {
generator.energy = 100; // Refill generator energy
console.log("Generator refilled!");
}
}
};
});
// Shed class
var Shed = Container.expand(function () {
var self = Container.call(this);
var shedBase = self.attachAsset('houseBase', {
anchorX: 0.5,
anchorY: 0.5
});
var generator = self.attachAsset('playerBody', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 50
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x191970,
// Init game with midnight blue background
icon: 'screen' // Set the game icon to be the screen of the game
});
/****
* Game Code
****/
// Function to publish the game
function publishGame() {
console.log("Publishing the game...");
// Add any additional logic needed for publishing
// This could include saving game state, uploading to a server, etc.
console.log("Game published successfully!");
}
// Call the publishGame function when the game is ready to be published
publishGame();
// Add a quit button to the top-right corner of the game screen
var quitButton = new Text2('Quit', {
size: 100,
fill: 0xFFFFFF
});
quitButton.anchor.set(1, 0); // Anchor to the top-right corner
quitButton.x = 2048; // Position at the right edge
quitButton.y = 0; // Position at the top edge
LK.gui.topRight.addChild(quitButton);
// Define the quit button functionality
quitButton.down = function (x, y, obj) {
console.log("Quit button pressed!");
// Logic to quit the game, e.g., return to the main menu or close the game
menuScreen.visible = true; // Show the menu screen again
game.currentMode = null; // Reset the current game mode
};
// Initialize and display the menu screen
var menuScreen = game.addChild(new MenuScreen());
menuScreen.visible = true;
game.currentMode = null; // Track the current game mode
// Function to start the game
game.startGame = function (mode) {
// Initialize game elements here if needed
menuScreen.visible = false; // Hide the menu screen
game.currentMode = mode; // Set the current game mode
if (mode === 'easy') {
console.log("Starting Easy Mode...");
game.setBackgroundColor(0x00ff00); // Change background to green
// Add easy mode specific initialization logic
} else if (mode === 'normal') {
console.log("Starting Normal Mode...");
// Add normal mode specific initialization logic
} else if (mode === 'timeAttack') {
console.log("Starting NIGHTMARE MODE...");
game.setBackgroundColor(0xff0000); // Change background to red
// Add time attack mode specific initialization logic
} else if (mode === 'challenging') {
console.log("Starting Challenging Mode...");
game.setBackgroundColor(0xff8c00); // Change background to orange
// Increase enemy speed by 10x compared to NIGHTMARE MODE
for (var i = 0; i < enemies.length; i++) {
enemies[i].speed = 200; // Assuming NIGHTMARE MODE speed is 20
}
} else if (mode === 'practice') {
console.log("Starting Practice Mode...");
game.setBackgroundColor(0x87ceeb); // Change background to light blue
// Remove all existing enemies in practice mode
for (var i = 0; i < enemies.length; i++) {
enemies[i].destroy();
}
enemies = [];
} else if (mode === 'becomeEnemy') {
console.log("Starting Become Enemy Mode...");
// Remove all existing enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].destroy();
}
enemies = [];
// Transform player into an enemy
player.destroy();
player = game.addChild(new Enemy());
player.x = 2048 / 2;
player.y = 2732 / 2;
}
// Add other game initialization logic if necessary
};
// Initialize joystick
// Blood texture color
// Blood texture color
// Blood texture color
// Function to detect if the device is mobile
function isMobileDevice() {
return typeof navigator !== 'undefined' && /Mobi|Android/i.test(navigator.userAgent);
}
var joystick;
if (isMobileDevice()) {
joystick = game.addChild(new Joystick());
joystick.x = 2048 - 150; // Position joystick at the bottom right of the screen
joystick.y = 2732 - 150; // Position joystick at the bottom right of the screen
}
// Add a clock display to the game
var clockTxt = new Text2('00:00', {
size: 100,
fill: 0xFFFFFF
});
clockTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(clockTxt);
// Add 'Survive until 06:00 am' text at the bottom of the screen
var surviveText = new Text2('Survive until 06:00 am', {
size: 100,
fill: 0xFFFFFF
});
surviveText.anchor.set(0.5, 1);
surviveText.x = 2048 / 2;
surviveText.y = 2732;
LK.gui.bottom.addChild(surviveText);
// Add player to the game
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 / 2;
var house = game.addChild(new House());
house.x = 2048 / 2;
house.y = 2732 / 2;
// Add NPCs to the game
var npcs = [];
for (var i = 0; i < 19; i++) {
var npc = game.addChild(new NPC());
npc.x = house.x; // Position NPCs inside the house
npc.y = house.y;
npcs.push(npc);
}
// Add 10 NPCs every 11 seconds
var npcAddInterval = LK.setInterval(function () {
if (!menuScreen.visible) {
for (var i = 0; i < 30; i++) {
var newNpc = game.addChild(new NPC());
newNpc.x = house.x; // Position new NPC inside the house
newNpc.y = house.y;
npcs.push(newNpc);
}
}
}, 11000);
// Update the clock every second
var startTime = Date.now();
LK.setInterval(function () {
if (!menuScreen.visible && !game.paused && game.currentMode) {
var elapsedTime = Math.floor((Date.now() - startTime) / 1000);
var minutes = Math.floor(elapsedTime / 60);
var seconds = elapsedTime % 60;
clockTxt.setText((minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds);
// Check if the clock reaches 06:00 and the mode is not endless
if (minutes === 6 && seconds === 0 && game.currentMode !== 'endless') {
// Display 'YOU WIN!' asset
var youWinAsset = LK.getAsset('YOUWIN', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
LK.gui.center.addChild(youWinAsset);
// Show game over. The game will be automatically paused while game over is showing.
LK.showGameOver();
}
}
}, 1000);
// Add mouse movement control for player
game.move = function (x, y, obj) {
if (!menuScreen.visible && game.currentMode) {
player.x = x;
player.y = y;
}
};
var enemies = [];
var enemy = game.addChild(new Enemy());
enemy.x = Math.random() * 2048;
enemy.y = Math.random() * 2732;
enemies.push(enemy);
// Track time for increasing enemy speed
var lastSpeedIncreaseTime = Date.now();
// Track time for stopping the player
var lastStopTime = Date.now();
// Game update function
game.update = function () {
// Stop the player every 10 seconds
if (Date.now() - lastStopTime >= 10000) {
player.tired = true;
console.log("Player stops for a moment!");
LK.setTimeout(function () {
player.tired = false;
console.log("Player can move again!");
}, 1000); // Player stops for 1 second
lastStopTime = Date.now();
}
if (menuScreen.visible) {
return; // Do not update game elements if the menu screen is visible
}
// Increase speed of all enemies every 10 seconds
if (Date.now() - lastSpeedIncreaseTime >= 10000) {
for (var i = 0; i < enemies.length; i++) {
enemies[i].speed = (enemies[i].speed || 7) + 10; // Initialize speed if undefined and increase by 10
}
lastSpeedIncreaseTime = Date.now();
}
// Game logic goes here
generator.update();
// Check if player is inside the house
if (player.intersects(house)) {
// Logic to make the player feel cold
// For example, decrease player's health or display a message
console.log("Player feels cold inside the house!");
// Implement logic to encourage player to leave the house
// This could be a visual effect, sound, or health decrease
}
// Check for collisions between player and enemies
for (var i = 0; i < enemies.length; i++) {
if (player.intersects(enemies[i])) {
// Flash screen red for 2 seconds (2000ms) to show player is killed
LK.effects.flashScreen(0xff3333, 2000);
// Add killing animation
var killingAnimation = LK.getAsset('playerBody', {
anchorX: 0.5,
anchorY: 0.5,
x: player.x,
y: player.y
});
game.addChild(killingAnimation);
LK.effects.flashObject(killingAnimation, 0xff0000, 1000, function () {
killingAnimation.destroy();
});
// Show game over. The game will be automatically paused while game over is showing.
LK.showGameOver();
break;
}
for (var j = 0; j < npcs.length; j++) {
if (npcs[j].intersects(enemies[i])) {
// NPC is killed by enemy
console.log("NPC killed by enemy!");
npcs[j].destroy();
npcs.splice(j, 1);
}
}
}
// Increase enemy count by 1 every 10 seconds with a maximum of 1 enemy
var enemyIncreaseInterval = LK.setInterval(function () {
if (!menuScreen.visible && enemies.length < 1 && game.currentMode !== 'becomeEnemy' && game.currentMode !== 'practice') {
var newEnemy = game.addChild(new Enemy());
newEnemy.x = Math.random() * 2048;
newEnemy.y = Math.random() * 2732;
enemies.push(newEnemy);
}
}, 10000);
};
// Initialize the bloodMoon object
var bloodMoon = LK.getAsset('bloodMoon', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 200
});
game.addChild(bloodMoon);
// Animate the bloodmoon to move across the sky
bloodMoon.x -= 0.5; // Move the bloodmoon slowly to the left
if (bloodMoon.x < -bloodMoon.width / 2) {
bloodMoon.x = 2048 + bloodMoon.width / 2; // Reset position to the right side of the screen
}
// Add a glow effect to the bloodmoon
LK.effects.flashObject(bloodMoon, 0xff0000, 2000, function () {
LK.effects.flashObject(bloodMoon, 0x8b0000, 2000);
});
var house = game.addChild(new House());
house.x = 2048 / 2;
house.y = 2732 / 2;
// Add a shed with a generator inside to the game
var shed = game.addChild(new Shed());
shed.x = 500; // Position the shed at a specific location
shed.y = 2000; // Position the shed at a specific location
// Add a generator inside the shed
var generator = shed.addChild(new Generator());
generator.x = 0; // Center the generator inside the shed
generator.y = 50; // Position the generator inside the shed
// Keyboard controls for WASD movement are not supported in this environment