User prompt
add a small flash of text that says “+1” every time there is a score
User prompt
Change the background to a basketball court
User prompt
Make each obstacle have its own radius of damage
User prompt
Make obstacles move in randomly sized circular patterns
User prompt
Allow obstacles to move both clockwise and counterclockwise
User prompt
Obstacles must initially appear at least 3 squares away from the ball
User prompt
Randomize obstacle positions
User prompt
Spread out the obstacles more
User prompt
Make the obstacles only move around inside of the screen limit
User prompt
Make each obstacle move asynchronously
User prompt
Make 9 more obstacles
User prompt
Make the obstacles move around the screen
User prompt
Add obstacles that end the game when hit
User prompt
Randomize the position of the goal each game
Initial prompt
Basketball Bangers
/**** * Classes ****/ // Assets will be automatically generated based on usage in the code. // Ball class for the basketball var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = 0; self.speedY = 0; self.move = function () { self.x += self.speedX; self.y += self.speedY; }; self.reset = function () { self.x = game.width / 2; self.y = game.height - 200; self.speedX = 0; self.speedY = 0; hoop.setPosition(Math.random() * game.width, Math.random() * game.height); }; }); // Hoop class for the basketball hoop var Hoop = Container.expand(function () { var self = Container.call(this); var hoopGraphics = self.attachAsset('hoop', { anchorX: 0.5, anchorY: 0.5 }); self.setPosition = function (x, y) { self.x = x; self.y = y; }; }); // Obstacle class for the game ending obstacles var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var ball = game.addChild(new Ball()); var hoop = game.addChild(new Hoop()); var obstacle = game.addChild(new Obstacle()); obstacle.x = Math.random() * game.width; obstacle.y = Math.random() * game.height; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); LK.gui.top.addChild(scoreTxt); // Set initial positions ball.reset(); hoop.setPosition(game.width / 2, 100); // Score variable var score = 0; // Touch event to launch the ball game.on('down', function (obj) { var pos = obj.event.getLocalPosition(game); var dx = pos.x - ball.x; var dy = pos.y - ball.y; var distance = Math.sqrt(dx * dx + dy * dy); ball.speedX = dx / distance * 10; ball.speedY = dy / distance * 10; }); // Game tick event LK.on('tick', function () { ball.move(); // Check for collision with hoop if (ball.intersects(hoop)) { score += 1; scoreTxt.setText(score.toString()); ball.reset(); } // Check for collision with obstacle if (ball.intersects(obstacle)) { LK.showGameOver(); } // Move the obstacle around the screen obstacle.x += Math.cos(LK.ticks / 60) * 5; obstacle.y += Math.sin(LK.ticks / 60) * 5; // Reset ball if it goes off screen if (ball.y < -50 || ball.y > game.height + 50 || ball.x < -50 || ball.x > game.width + 50) { ball.reset(); } // Wrap obstacle around screen if (obstacle.x < -50) { obstacle.x = game.width + 50; } if (obstacle.x > game.width + 50) { obstacle.x = -50; } if (obstacle.y < -50) { obstacle.y = game.height + 50; } if (obstacle.y > game.height + 50) { obstacle.y = -50; } });
===================================================================
--- original.js
+++ change.js
@@ -90,9 +90,25 @@
// Check for collision with obstacle
if (ball.intersects(obstacle)) {
LK.showGameOver();
}
+ // Move the obstacle around the screen
+ obstacle.x += Math.cos(LK.ticks / 60) * 5;
+ obstacle.y += Math.sin(LK.ticks / 60) * 5;
// Reset ball if it goes off screen
if (ball.y < -50 || ball.y > game.height + 50 || ball.x < -50 || ball.x > game.width + 50) {
ball.reset();
}
+ // Wrap obstacle around screen
+ if (obstacle.x < -50) {
+ obstacle.x = game.width + 50;
+ }
+ if (obstacle.x > game.width + 50) {
+ obstacle.x = -50;
+ }
+ if (obstacle.y < -50) {
+ obstacle.y = game.height + 50;
+ }
+ if (obstacle.y > game.height + 50) {
+ obstacle.y = -50;
+ }
});
\ No newline at end of file