===================================================================
--- original.js
+++ change.js
@@ -1,51 +1,51 @@
-/****
+/****
* Classes
-****/
+****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Ball class to represent falling balls
var Ball = Container.expand(function (color) {
- var self = Container.call(this);
- var ballGraphics = self.attachAsset(color + 'Ball', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.color = color;
- self.speed = 5; // Speed of falling balls
- self.update = function () {
- self.y += self.speed;
- };
+ var self = Container.call(this);
+ var ballGraphics = self.attachAsset(color + 'Ball', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.color = color;
+ self.speed = 5; // Speed of falling balls
+ self.update = function () {
+ self.y += self.speed;
+ };
});
// Bucket class to represent buckets at the bottom
var Bucket = Container.expand(function (color, xPosition) {
- var self = Container.call(this);
- var bucketGraphics = self.attachAsset(color + 'Bucket', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.color = color;
- self.x = xPosition;
- self.y = 2600; // Position buckets at the bottom
+ var self = Container.call(this);
+ var bucketGraphics = self.attachAsset(color + 'Bucket', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.color = color;
+ self.x = xPosition;
+ self.y = 2600; // Position buckets at the bottom
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize arrays and variables
var balls = [];
var buckets = [];
var score = 0;
var scoreTxt = new Text2('0', {
- size: 150,
- fill: 0xFFFFFF
+ size: 150,
+ fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create buckets
@@ -53,68 +53,72 @@
buckets.push(game.addChild(new Bucket('blue', 1024)));
buckets.push(game.addChild(new Bucket('green', 1536)));
// Function to spawn a new ball
function spawnBall() {
- var colors = ['red', 'blue', 'green'];
- var color = colors[Math.floor(Math.random() * colors.length)];
- var newBall = new Ball(color);
- newBall.x = Math.random() * 2048;
- newBall.y = 0;
- balls.push(newBall);
- game.addChild(newBall);
+ var colors = ['red', 'blue', 'green'];
+ var color = colors[Math.floor(Math.random() * colors.length)];
+ var newBall = new Ball(color);
+ newBall.x = Math.random() * 2048;
+ newBall.y = 0;
+ balls.push(newBall);
+ game.addChild(newBall);
}
// Handle game update
game.update = function () {
- for (var i = balls.length - 1; i >= 0; i--) {
- balls[i].update();
- // Check if ball is in a bucket
- for (var j = 0; j < buckets.length; j++) {
- if (balls[i].intersects(buckets[j])) {
- if (balls[i].color === buckets[j].color) {
- score++;
- scoreTxt.setText(score);
- } else {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
- balls[i].destroy();
- balls.splice(i, 1);
- break;
- }
- }
- // Remove balls that fall off the screen
- if (balls[i] && balls[i].y > 2732) {
- balls[i].destroy();
- balls.splice(i, 1);
- }
- }
- // Spawn a new ball every 60 ticks
- if (LK.ticks % 60 === 0) {
- spawnBall();
- }
+ for (var i = balls.length - 1; i >= 0; i--) {
+ balls[i].update();
+ // Check if ball is in a bucket
+ for (var j = 0; j < buckets.length; j++) {
+ if (balls[i].intersects(buckets[j])) {
+ if (balls[i].color === buckets[j].color) {
+ score++;
+ scoreTxt.setText(score);
+ } else {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ balls[i].destroy();
+ balls.splice(i, 1);
+ break;
+ }
+ }
+ // Remove balls that fall off the screen
+ if (balls[i] && balls[i].y > 2732) {
+ balls[i].destroy();
+ balls.splice(i, 1);
+ }
+ }
+ // Spawn a new ball every 60 ticks
+ if (LK.ticks % 60 === 0) {
+ spawnBall();
+ }
};
// Handle touch/mouse events to direct balls
game.down = function (x, y, obj) {
- for (var i = 0; i < balls.length; i++) {
- if (balls[i].containsPoint({
- x: x,
- y: y
- })) {
- balls[i].x = x;
- balls[i].y = y;
- }
- }
+ for (var i = 0; i < balls.length; i++) {
+ if (balls[i].intersects({
+ x: x,
+ y: y,
+ width: 1,
+ height: 1
+ })) {
+ balls[i].x = x;
+ balls[i].y = y;
+ }
+ }
};
game.move = function (x, y, obj) {
- for (var i = 0; i < balls.length; i++) {
- if (balls[i].containsPoint({
- x: x,
- y: y
- })) {
- balls[i].x = x;
- balls[i].y = y;
- }
- }
+ for (var i = 0; i < balls.length; i++) {
+ if (balls[i].intersects({
+ x: x,
+ y: y,
+ width: 1,
+ height: 1
+ })) {
+ balls[i].x = x;
+ balls[i].y = y;
+ }
+ }
};
game.up = function (x, y, obj) {
- // No specific action needed on release
+ // No specific action needed on release
};
\ No newline at end of file
A red ball with the words bonus. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A Green ball written bonus. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Metallic marron clear background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.