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
===================================================================
--- original.js
+++ change.js
@@ -1,56 +1,57 @@
-/****
+/****
* 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;
- };
+ 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;
- };
+ 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;
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
var ball = game.addChild(new Ball());
var hoop = game.addChild(new Hoop());
var scoreTxt = new Text2('0', {
- size: 150,
- fill: "#ffffff"
+ size: 150,
+ fill: "#ffffff"
});
LK.gui.top.addChild(scoreTxt);
// Set initial positions
ball.reset();
@@ -58,25 +59,25 @@
// 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;
+ 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();
- }
- // 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();
- }
+ ball.move();
+ // Check for collision with hoop
+ if (ball.intersects(hoop)) {
+ score += 1;
+ scoreTxt.setText(score.toString());
+ ball.reset();
+ }
+ // 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();
+ }
});
\ No newline at end of file