User prompt
make the npc move to every place
User prompt
make the NPC walking and can killed by enemy
User prompt
make a NPC shape like player
User prompt
decrease the "night of the massacre" word
User prompt
change the game logo to scary
User prompt
decrease enemy max to 5
User prompt
make the player stop every 10 seconds
User prompt
decrease enemy spawn rate
User prompt
max enemy limit 10
User prompt
make the enemy increased 1 by 1 every 5 seconds
User prompt
add enemy by 1 every 5 seconds
User prompt
remove leaderboard
User prompt
make the enemy speed increase by 10 every seconds
User prompt
make the enemy stop when the game not started
User prompt
display leaderboard button after dead
User prompt
add leaderboard by who have many time at the clock
User prompt
save the game
User prompt
increase enemy crowd by 1 every 10 seconds
User prompt
increase enemy every 10 seconds
User prompt
increase enemy's speed by 10 every 1 seconds
User prompt
make the player stop when he is tired
User prompt
make the enemy not stop
User prompt
increase enemy speed by 1 every seconds
User prompt
make the enemy speed increase to 10 every 10 seconds
User prompt
make the enemy not stuck at the house
/**** * 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 stop moving when tired if (self.tired) { return; } // Enemy movement logic to chase the player var dx = player.x - self.x; var dy = player.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); var speed = 7; // Speed at which the enemy chases the player 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)) { // Prevent enemy from entering the house if (self.intersects(house)) { return; } // If intersecting, find an alternative path if (Math.abs(dx) > Math.abs(dy)) { // Try moving vertically self.y += (dy > 0 ? 1 : -1) * speed; } else { // Try moving horizontally self.x += (dx > 0 ? 1 : -1) * speed; } } } }; }); // GasCan class var GasCan = Container.expand(function () { var self = Container.call(this); var gasCanGraphic = self.attachAsset('playerBody', { anchorX: 0.5, anchorY: 0.5 }); gasCanGraphic.tint = 0xff0000; // Set color to red }); // 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; player.x += dx * 0.5; // Reduce speed by half player.y += dy * 0.5; // Reduce speed by half 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: 200, fill: "#ffffff" }); titleText.anchor.set(0.5, 0.5); titleText.x = 2048 / 2; titleText.y = 800; self.addChild(titleText); var startButton = new Text2('Start Game', { size: 150, fill: "#ffffff" }); startButton.anchor.set(0.5, 0.5); startButton.x = 2048 / 2; startButton.y = 2732 / 2 - 300; // Position the start button at the top of the house self.addChild(startButton); startButton.down = function (x, y, obj) { console.log("Start Game button pressed!"); self.visible = false; // Hide the menu screen game.startGame(); // Call the start game function }; }); // 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.update = function () { // Player movement logic with delay if (self.tired) { return; // Skip movement if player is tired } // 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; } for (var i = 0; i < shotguns.length; i++) { if (self.intersects(shotguns[i])) { // Logic to prevent player from grabbing the shotgun console.log("Player cannot grab the shotgun!"); } } // Check if player intersects with the gas can if (self.intersects(gasCan)) { console.log("Player grabbed the gas can!"); self.energy = 100; // Replenish player energy self.tired = false; // Reset tired state // Logic to remove the gas can from the game gasCan.destroy(); // Recreate the gas can after refilling the generator LK.setTimeout(function () { gasCan = game.addChild(new GasCan()); gasCan.x = shed.x + 300; // Move the gas can further away from the shed gasCan.y = shed.y + 150; // Adjust the y position accordingly }, 5000); // Reappear after 5 seconds // Logic to refill the generator if (!generator.isOn) { generator.energy = 100; // Refill generator energy console.log("Generator refilled!"); } } // 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 }); }); // Shotgun class var Shotgun = Container.expand(function () { var self = Container.call(this); var shotgunGraphic = self.attachAsset('playerBody', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Rotate the shotgun towards the player var dx = player.x - self.x; var dy = player.y - self.y; self.rotation = Math.atan2(dy, dx); // Fire logic: Check if the player is within a certain range and fire var distanceToPlayer = Math.sqrt(dx * dx + dy * dy); if (distanceToPlayer < 500) { // Example range // Logic to fire at the player console.log("Shotgun fires at the player!"); // Implement firing effect or damage logic here } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x191970 // Init game with midnight blue background }); /**** * Game Code ****/ // Initialize and display the menu screen var menuScreen = game.addChild(new MenuScreen()); menuScreen.visible = true; // Function to start the game game.startGame = function () { // Initialize game elements here if needed menuScreen.visible = false; // Hide the menu screen // Add other game initialization logic if necessary }; // Initialize joystick // Blood texture color // Blood texture color // Blood texture color var joystick = game.addChild(new Joystick()); joystick.x = 150; // Position joystick on the screen joystick.y = 2582; // Near the bottom of the screen // Add a clock display to the game var clockTxt = new Text2('00:00', { size: 100, fill: "#ffffff" }); clockTxt.anchor.set(0.5, 0); LK.gui.top.addChild(clockTxt); // Add player to the game var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 / 2; // Update the clock every second var startTime = Date.now(); LK.setInterval(function () { if (!menuScreen.visible) { 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); } }, 1000); // Add mouse movement control for player game.move = function (x, y, obj) { if (!menuScreen.visible) { 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(); // Game update function game.update = function () { if (menuScreen.visible) { return; // Do not update game elements if the menu screen is visible } // Check if 10 seconds have passed if (Date.now() - lastSpeedIncreaseTime >= 10000) { // Increase speed of all enemies for (var i = 0; i < enemies.length; i++) { enemies[i].speed += 1; // Increase speed by 1 } // Update the last speed increase time 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])) { if (shotguns.length === 0) { // Enemy dies if player has grabbed the shotgun enemies[i].destroy(); enemies.splice(i, 1); } else { // Flash screen red for 1 second (1000ms) to show player is killed LK.effects.flashScreen(0xff0000, 1000); // Show game over. The game will be automatically paused while game over is showing. LK.showGameOver(); break; } } } // Reappear enemies after a delay if (enemies.length === 0) { LK.setTimeout(function () { if (enemies.length < 1) { // Ensure only one enemy is added var newEnemy = game.addChild(new Enemy()); newEnemy.x = Math.random() * 2048; newEnemy.y = Math.random() * 2732; enemies.push(newEnemy); } }, 5000); // Reappear after 5 seconds } }; // Add a bloodmoon to the game var bloodMoon = LK.getAsset('bloodMoon', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 200 }); game.addChild(bloodMoon); 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 // Add a gas can near the shed var gasCan = game.addChild(new GasCan()); gasCan.x = shed.x + 300; // Move the gas can further away from the shed gasCan.y = shed.y + 150; // Adjust the y position accordingly // Add a single shotgun near the house var shotguns = []; var shotgun = game.addChild(new Shotgun()); shotgun.x = 200; // Position the shotgun at x position 200 shotgun.y = 1500; // Position the shotgun at a specific y location shotguns.push(shotgun); // Set an interval for the shotgun to check for firing LK.setInterval(function () { shotgun.update(); }, 1000); // Check every second // 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 stop moving when tired
if (self.tired) {
return;
}
// Enemy movement logic to chase the player
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var speed = 7; // Speed at which the enemy chases the player
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)) {
// Prevent enemy from entering the house
if (self.intersects(house)) {
return;
}
// If intersecting, find an alternative path
if (Math.abs(dx) > Math.abs(dy)) {
// Try moving vertically
self.y += (dy > 0 ? 1 : -1) * speed;
} else {
// Try moving horizontally
self.x += (dx > 0 ? 1 : -1) * speed;
}
}
}
};
});
// GasCan class
var GasCan = Container.expand(function () {
var self = Container.call(this);
var gasCanGraphic = self.attachAsset('playerBody', {
anchorX: 0.5,
anchorY: 0.5
});
gasCanGraphic.tint = 0xff0000; // Set color to red
});
// 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;
player.x += dx * 0.5; // Reduce speed by half
player.y += dy * 0.5; // Reduce speed by half
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: 200,
fill: "#ffffff"
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 800;
self.addChild(titleText);
var startButton = new Text2('Start Game', {
size: 150,
fill: "#ffffff"
});
startButton.anchor.set(0.5, 0.5);
startButton.x = 2048 / 2;
startButton.y = 2732 / 2 - 300; // Position the start button at the top of the house
self.addChild(startButton);
startButton.down = function (x, y, obj) {
console.log("Start Game button pressed!");
self.visible = false; // Hide the menu screen
game.startGame(); // Call the start game function
};
});
// 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.update = function () {
// Player movement logic with delay
if (self.tired) {
return; // Skip movement if player is tired
}
// 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;
}
for (var i = 0; i < shotguns.length; i++) {
if (self.intersects(shotguns[i])) {
// Logic to prevent player from grabbing the shotgun
console.log("Player cannot grab the shotgun!");
}
}
// Check if player intersects with the gas can
if (self.intersects(gasCan)) {
console.log("Player grabbed the gas can!");
self.energy = 100; // Replenish player energy
self.tired = false; // Reset tired state
// Logic to remove the gas can from the game
gasCan.destroy();
// Recreate the gas can after refilling the generator
LK.setTimeout(function () {
gasCan = game.addChild(new GasCan());
gasCan.x = shed.x + 300; // Move the gas can further away from the shed
gasCan.y = shed.y + 150; // Adjust the y position accordingly
}, 5000); // Reappear after 5 seconds
// Logic to refill the generator
if (!generator.isOn) {
generator.energy = 100; // Refill generator energy
console.log("Generator refilled!");
}
}
// 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
});
});
// Shotgun class
var Shotgun = Container.expand(function () {
var self = Container.call(this);
var shotgunGraphic = self.attachAsset('playerBody', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Rotate the shotgun towards the player
var dx = player.x - self.x;
var dy = player.y - self.y;
self.rotation = Math.atan2(dy, dx);
// Fire logic: Check if the player is within a certain range and fire
var distanceToPlayer = Math.sqrt(dx * dx + dy * dy);
if (distanceToPlayer < 500) {
// Example range
// Logic to fire at the player
console.log("Shotgun fires at the player!");
// Implement firing effect or damage logic here
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x191970 // Init game with midnight blue background
});
/****
* Game Code
****/
// Initialize and display the menu screen
var menuScreen = game.addChild(new MenuScreen());
menuScreen.visible = true;
// Function to start the game
game.startGame = function () {
// Initialize game elements here if needed
menuScreen.visible = false; // Hide the menu screen
// Add other game initialization logic if necessary
};
// Initialize joystick
// Blood texture color
// Blood texture color
// Blood texture color
var joystick = game.addChild(new Joystick());
joystick.x = 150; // Position joystick on the screen
joystick.y = 2582; // Near the bottom of the screen
// Add a clock display to the game
var clockTxt = new Text2('00:00', {
size: 100,
fill: "#ffffff"
});
clockTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(clockTxt);
// Add player to the game
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 / 2;
// Update the clock every second
var startTime = Date.now();
LK.setInterval(function () {
if (!menuScreen.visible) {
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);
}
}, 1000);
// Add mouse movement control for player
game.move = function (x, y, obj) {
if (!menuScreen.visible) {
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();
// Game update function
game.update = function () {
if (menuScreen.visible) {
return; // Do not update game elements if the menu screen is visible
}
// Check if 10 seconds have passed
if (Date.now() - lastSpeedIncreaseTime >= 10000) {
// Increase speed of all enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].speed += 1; // Increase speed by 1
}
// Update the last speed increase time
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])) {
if (shotguns.length === 0) {
// Enemy dies if player has grabbed the shotgun
enemies[i].destroy();
enemies.splice(i, 1);
} else {
// Flash screen red for 1 second (1000ms) to show player is killed
LK.effects.flashScreen(0xff0000, 1000);
// Show game over. The game will be automatically paused while game over is showing.
LK.showGameOver();
break;
}
}
}
// Reappear enemies after a delay
if (enemies.length === 0) {
LK.setTimeout(function () {
if (enemies.length < 1) {
// Ensure only one enemy is added
var newEnemy = game.addChild(new Enemy());
newEnemy.x = Math.random() * 2048;
newEnemy.y = Math.random() * 2732;
enemies.push(newEnemy);
}
}, 5000); // Reappear after 5 seconds
}
};
// Add a bloodmoon to the game
var bloodMoon = LK.getAsset('bloodMoon', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 200
});
game.addChild(bloodMoon);
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
// Add a gas can near the shed
var gasCan = game.addChild(new GasCan());
gasCan.x = shed.x + 300; // Move the gas can further away from the shed
gasCan.y = shed.y + 150; // Adjust the y position accordingly
// Add a single shotgun near the house
var shotguns = [];
var shotgun = game.addChild(new Shotgun());
shotgun.x = 200; // Position the shotgun at x position 200
shotgun.y = 1500; // Position the shotgun at a specific y location
shotguns.push(shotgun);
// Set an interval for the shotgun to check for firing
LK.setInterval(function () {
shotgun.update();
}, 1000); // Check every second
// Keyboard controls for WASD movement are not supported in this environment