/**** * 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 obstacle and set its starting position var obstacle = game.addChild(new Obstacle()); obstacle.x = 2048 / 2; obstacle.y = 0; // Position the obstacle at the top of the screen // Update function to handle game logic game.update = function () { // Move the obstacle obstacle.move(); // Check if the chicken collides with the obstacle if (chicken.intersects(obstacle)) { // Game over LK.showGameOver(); } };
===================================================================
--- original.js
+++ change.js
@@ -1,55 +1,80 @@
-/****
+/****
* 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 (direction) {
- if (direction === 'left') {
- self.x -= self.speed;
- } else if (direction === 'right') {
- self.x += self.speed;
- }
- };
+ 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
+ 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);
- }
+ if (command === 'left' || command === 'right') {
+ chicken.move(command);
+ }
}
// Simulate voice command input (for demonstration purposes)
-var simulatedCommands = ['left', 'right', 'left', 'right'];
+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;
+ handleVoiceCommand(simulatedCommands[commandIndex]);
+ commandIndex = (commandIndex + 1) % simulatedCommands.length;
}, 2000);
+// Initialize obstacle and set its starting position
+var obstacle = game.addChild(new Obstacle());
+obstacle.x = 2048 / 2;
+obstacle.y = 0; // Position the obstacle at the top of the screen
// Update function to handle game logic
game.update = function () {
- // Game logic can be added here
+ // Move the obstacle
+ obstacle.move();
+ // Check if the chicken collides with the obstacle
+ if (chicken.intersects(obstacle)) {
+ // Game over
+ LK.showGameOver();
+ }
};
\ No newline at end of file