/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Chicken class to represent the player character var Chicken = Container.expand(function () { var self = Container.call(this); var chickenGraphics = self.attachAsset('chicken', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; // Default speed for the chicken // Method to move the chicken based on voice input self.move = function (command) { if (command === 'left') { self.x -= self.speed; } else if (command === 'right') { self.x += self.speed; } else if (command === 'jump') { self.y -= self.speed * 10; // Make the chicken jump } }; }); // Obstacle class to represent the obstacles that the chicken needs to jump over var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; // Default speed for the obstacle // Method to move the obstacle self.move = function () { self.y += self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb // Sky blue background }); /**** * Game Code ****/ // Initialize chicken and set its starting position var chicken = game.addChild(new Chicken()); chicken.x = 2048 / 2; chicken.y = 2732 - 150; // Position the chicken near the bottom of the screen // Function to handle voice commands function handleVoiceCommand(command) { if (command === 'left' || command === 'right') { chicken.move(command); } } // Simulate voice command input (for demonstration purposes) var simulatedCommands = ['left', 'right', 'jump', 'right']; var commandIndex = 0; // Simulate receiving voice commands every 2 seconds LK.setInterval(function () { handleVoiceCommand(simulatedCommands[commandIndex]); commandIndex = (commandIndex + 1) % simulatedCommands.length; }, 2000); // Initialize an array to hold multiple obstacles var obstacles = []; // Add a new obstacle to the array every 2 seconds LK.setInterval(function () { var obstacle = game.addChild(new Obstacle()); obstacle.x = Math.random() * 2048; // Randomize the x position of the obstacle obstacle.y = 0; // Position the obstacle at the top of the screen obstacles.push(obstacle); }, 2000); // Update function to handle game logic game.update = function () { // Move all obstacles and check for collisions with the chicken for (var i = 0; i < obstacles.length; i++) { var obstacle = obstacles[i]; obstacle.move(); if (chicken.intersects(obstacle)) { // Game over LK.showGameOver(); } } // Create an obstacle and set its starting position var obstacle = game.addChild(new Obstacle()); obstacle.x = Math.random() * 2048; // Randomize the x position of the obstacle obstacle.y = 0; // Position the obstacle at the top of the screen obstacles.push(obstacle); };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Chicken class to represent the player character
var Chicken = Container.expand(function () {
var self = Container.call(this);
var chickenGraphics = self.attachAsset('chicken', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5; // Default speed for the chicken
// Method to move the chicken based on voice input
self.move = function (command) {
if (command === 'left') {
self.x -= self.speed;
} else if (command === 'right') {
self.x += self.speed;
} else if (command === 'jump') {
self.y -= self.speed * 10; // Make the chicken jump
}
};
});
// Obstacle class to represent the obstacles that the chicken needs to jump over
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5; // Default speed for the obstacle
// Method to move the obstacle
self.move = function () {
self.y += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb // Sky blue background
});
/****
* Game Code
****/
// Initialize chicken and set its starting position
var chicken = game.addChild(new Chicken());
chicken.x = 2048 / 2;
chicken.y = 2732 - 150; // Position the chicken near the bottom of the screen
// Function to handle voice commands
function handleVoiceCommand(command) {
if (command === 'left' || command === 'right') {
chicken.move(command);
}
}
// Simulate voice command input (for demonstration purposes)
var simulatedCommands = ['left', 'right', 'jump', 'right'];
var commandIndex = 0;
// Simulate receiving voice commands every 2 seconds
LK.setInterval(function () {
handleVoiceCommand(simulatedCommands[commandIndex]);
commandIndex = (commandIndex + 1) % simulatedCommands.length;
}, 2000);
// Initialize an array to hold multiple obstacles
var obstacles = [];
// Add a new obstacle to the array every 2 seconds
LK.setInterval(function () {
var obstacle = game.addChild(new Obstacle());
obstacle.x = Math.random() * 2048; // Randomize the x position of the obstacle
obstacle.y = 0; // Position the obstacle at the top of the screen
obstacles.push(obstacle);
}, 2000);
// Update function to handle game logic
game.update = function () {
// Move all obstacles and check for collisions with the chicken
for (var i = 0; i < obstacles.length; i++) {
var obstacle = obstacles[i];
obstacle.move();
if (chicken.intersects(obstacle)) {
// Game over
LK.showGameOver();
}
}
// Create an obstacle and set its starting position
var obstacle = game.addChild(new Obstacle());
obstacle.x = Math.random() * 2048; // Randomize the x position of the obstacle
obstacle.y = 0; // Position the obstacle at the top of the screen
obstacles.push(obstacle);
};