/**** * Classes ****/ //<Write entity 'classes' with empty functions for important behavior here> var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.x += self.speedX; self.y += self.speedY; if (self.x < 0 || self.x > 2048) { self.speedX *= -1; } if (self.y < 0 || self.y > 2732) { self.speedY *= -1; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ //<Assets used in the game will automatically appear here> // Initialize variables var ball = game.addChild(new Ball()); ball.x = 1024; ball.y = 1366; ball.speedX = 5; ball.speedY = 5; var randomNumber = Math.floor(Math.random() * 100) + 1; var guessText = new Text2('Guess a number between 1 and 100.', { size: 100, fill: "#ffffff" }); guessText.anchor.set(0.5, 0); LK.gui.top.addChild(guessText); var inputText = new Text2('Your guess: ', { size: 100, fill: "#ffffff" }); inputText.anchor.set(0.5, 0); LK.gui.center.addChild(inputText); var resultText = new Text2('', { size: 100, fill: "#ffffff" }); resultText.anchor.set(0.5, 0); LK.gui.bottom.addChild(resultText); // Function to handle user input function handleInput(guess) { if (guess === randomNumber) { resultText.setText("You win!"); } else { resultText.setText("Try again."); } } // Simulate user input for demonstration purposes var simulatedGuesses = [50, 75, 85, 95, randomNumber]; var currentGuessIndex = 0; var guessInterval = LK.setInterval(function () { if (currentGuessIndex < simulatedGuesses.length) { var guess = simulatedGuesses[currentGuessIndex]; inputText.setText('Your guess: ' + guess); handleInput(guess); currentGuessIndex++; } else { LK.clearInterval(guessInterval); } }, 2000);
===================================================================
--- original.js
+++ change.js
@@ -1,17 +1,43 @@
/****
-* Initialize Game
+* Classes
****/
-//<Assets used in the game will automatically appear here>
//<Write entity 'classes' with empty functions for important behavior here>
+var Ball = Container.expand(function () {
+ var self = Container.call(this);
+ var ballGraphics = self.attachAsset('ball', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ self.x += self.speedX;
+ self.y += self.speedY;
+ if (self.x < 0 || self.x > 2048) {
+ self.speedX *= -1;
+ }
+ if (self.y < 0 || self.y > 2732) {
+ self.speedY *= -1;
+ }
+ };
+});
+
+/****
+* Initialize Game
+****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
+//<Assets used in the game will automatically appear here>
// Initialize variables
+var ball = game.addChild(new Ball());
+ball.x = 1024;
+ball.y = 1366;
+ball.speedX = 5;
+ball.speedY = 5;
var randomNumber = Math.floor(Math.random() * 100) + 1;
var guessText = new Text2('Guess a number between 1 and 100.', {
size: 100,
fill: "#ffffff"