/**** * 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 balls = []; var level = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]; for (var i = 0; i < level.length; i++) { for (var j = 0; j < level[i].length; j++) { if (level[i][j] === 1) { var ball = game.addChild(new Ball()); ball.x = j * 204.8; ball.y = i * 273.2; ball.speedX = (Math.random() - 0.5) * 10; ball.speedY = (Math.random() - 0.5) * 10; balls.push(ball); } } } 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
@@ -32,15 +32,20 @@
****/
//<Assets used in the game will automatically appear here>
// Initialize variables
var balls = [];
-for (var i = 0; i < 200; i++) {
- var ball = game.addChild(new Ball());
- ball.x = Math.random() * 2048;
- ball.y = Math.random() * 2732;
- ball.speedX = (Math.random() - 0.5) * 10;
- ball.speedY = (Math.random() - 0.5) * 10;
- balls.push(ball);
+var level = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]];
+for (var i = 0; i < level.length; i++) {
+ for (var j = 0; j < level[i].length; j++) {
+ if (level[i][j] === 1) {
+ var ball = game.addChild(new Ball());
+ ball.x = j * 204.8;
+ ball.y = i * 273.2;
+ ball.speedX = (Math.random() - 0.5) * 10;
+ ball.speedY = (Math.random() - 0.5) * 10;
+ balls.push(ball);
+ }
+ }
}
var randomNumber = Math.floor(Math.random() * 100) + 1;
var guessText = new Text2('Guess a number between 1 and 100.', {
size: 100,