/**** * Classes ****/ // Assets will be automatically created based on usage in the code. // Person class var Person = Container.expand(function () { var self = Container.call(this); // Attach person asset var personGraphics = self.attachAsset('person', { anchorX: 0.5, anchorY: 0.5 }); // Flag to indicate if this person has the magic hat self.hasMagicHat = false; // Method to give the magic hat to this person self.giveMagicHat = function () { self.hasMagicHat = true; // Change the person's color to indicate they have the magic hat personGraphics.tint = 0xFFFF00; // Yellow color }; // Method to remove the magic hat from this person self.removeMagicHat = function () { self.hasMagicHat = false; // Reset the person's color personGraphics.tint = 0xFFFFFF; // White color }; // Method to turn this person into a zombie self.turnIntoZombie = function () { // Change the person's color to indicate they are a zombie personGraphics.tint = 0x00FF00; // Green color }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize an array to keep track of all persons var persons = []; // Create a few persons and add them to the game for (var i = 0; i < 5; i++) { var person = new Person(); person.x = Math.random() * 2048; // Random position within the game area width person.y = Math.random() * 2732; // Random position within the game area height game.addChild(person); persons.push(person); // Add event listener to pass the magic hat on tap person.on('down', function (obj) { var tappedPerson = obj.target; if (tappedPerson.hasMagicHat) { // Find the next person to pass the hat to var nextPersonIndex = (persons.indexOf(tappedPerson) + 1) % persons.length; var nextPerson = persons[nextPersonIndex]; tappedPerson.removeMagicHat(); nextPerson.giveMagicHat(); } }); } // Initially give the magic hat to the first person persons[0].giveMagicHat(); // Create a timer to turn the person with the magic hat into a zombie after a delay var zombieTimer = LK.setInterval(function () { for (var i = 0; i < persons.length; i++) { if (persons[i].hasMagicHat) { persons[i].turnIntoZombie(); // Stop the timer as the game ends when someone turns into a zombie LK.clearInterval(zombieTimer); break; } } }, 5000); // 5 seconds delay // Note: This is a simplified version of the game. Additional features like score tracking, game restart, and more complex interactions can be added as needed.
/****
* Classes
****/
// Assets will be automatically created based on usage in the code.
// Person class
var Person = Container.expand(function () {
var self = Container.call(this);
// Attach person asset
var personGraphics = self.attachAsset('person', {
anchorX: 0.5,
anchorY: 0.5
});
// Flag to indicate if this person has the magic hat
self.hasMagicHat = false;
// Method to give the magic hat to this person
self.giveMagicHat = function () {
self.hasMagicHat = true;
// Change the person's color to indicate they have the magic hat
personGraphics.tint = 0xFFFF00; // Yellow color
};
// Method to remove the magic hat from this person
self.removeMagicHat = function () {
self.hasMagicHat = false;
// Reset the person's color
personGraphics.tint = 0xFFFFFF; // White color
};
// Method to turn this person into a zombie
self.turnIntoZombie = function () {
// Change the person's color to indicate they are a zombie
personGraphics.tint = 0x00FF00; // Green color
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize an array to keep track of all persons
var persons = [];
// Create a few persons and add them to the game
for (var i = 0; i < 5; i++) {
var person = new Person();
person.x = Math.random() * 2048; // Random position within the game area width
person.y = Math.random() * 2732; // Random position within the game area height
game.addChild(person);
persons.push(person);
// Add event listener to pass the magic hat on tap
person.on('down', function (obj) {
var tappedPerson = obj.target;
if (tappedPerson.hasMagicHat) {
// Find the next person to pass the hat to
var nextPersonIndex = (persons.indexOf(tappedPerson) + 1) % persons.length;
var nextPerson = persons[nextPersonIndex];
tappedPerson.removeMagicHat();
nextPerson.giveMagicHat();
}
});
}
// Initially give the magic hat to the first person
persons[0].giveMagicHat();
// Create a timer to turn the person with the magic hat into a zombie after a delay
var zombieTimer = LK.setInterval(function () {
for (var i = 0; i < persons.length; i++) {
if (persons[i].hasMagicHat) {
persons[i].turnIntoZombie();
// Stop the timer as the game ends when someone turns into a zombie
LK.clearInterval(zombieTimer);
break;
}
}
}, 5000); // 5 seconds delay
// Note: This is a simplified version of the game. Additional features like score tracking, game restart, and more complex interactions can be added as needed.