User prompt
Make the font for the time look glass like color yellow
User prompt
Replicate the RedBonusBall logic to the GreenBonusBall logic
User prompt
The game is still ending
User prompt
Examine and rectify all the methods for GreenBonusBall to prevent game over
User prompt
Rectify the drop method of the GreenBonusBall
User prompt
When the time hits 60, increase the speed of falling balls by one
User prompt
Correct overlapping logic
User prompt
For every bonus ball that enters the correct bucket, add five points to the score and add a sound that says either Yes or Way to go
User prompt
Play background music
User prompt
Remove the background from the timer
User prompt
The font for the timer should be 10
User prompt
Add a glass like background for the timer
User prompt
The timer and the score font color should be bold maroon
User prompt
Add a time at the top right part of the game canvas on the same level as the scores
User prompt
Add a glass like maroon background for the the score part
User prompt
The GreenBonusBall is collected by the GreenBucket
User prompt
Remove the BonusBlueBall class and all it's dependants
User prompt
Please fix the bug: 'ReferenceError: BonusBlueBall is not defined' in or related to this line: 'var newBlueBonusBall = new BonusBlueBall();' Line Number: 345
User prompt
Collect the BlueBonusBall
User prompt
Please fix the bug: 'ReferenceError: BonusBlueBall is not defined' in or related to this line: 'var newBlueBonusBall = new BonusBlueBall();' Line Number: 345
User prompt
Make all the necessary corrections
User prompt
As long as the ball enters the correct bucket let it settle there instead of bursting or disappear
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: BonusBlueBall is not defined' in or related to this line: 'var newBlueBonusBall = new BonusBlueBall();' Line Number: 343
User prompt
BlueBonusBall is collected by Blue bucket
/****
* Classes
****/
var Ball = Container.expand(function (color) {
var self = Container.call(this);
self.attachAsset(color + 'Ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.color = color;
self.speed = 2;
self.dragging = false;
self.dragStartX = 0;
self.dragStartY = 0;
self.update = function () {
if (!self.dragging) {
self.y += self.speed;
}
if (self.x < 40) {
self.x = 40;
}
if (self.x > 2008) {
self.x = 2008;
}
};
self.startDrag = function (x, y) {
self.dragging = true;
self.dragStartX = x - self.x;
self.dragStartY = y - self.y;
self.speed = 0;
};
self.drag = function (x, y) {
if (self.dragging) {
self.x = x - self.dragStartX;
self.y = y - self.dragStartY;
}
};
self.stopDrag = function () {
self.dragging = false;
self.drop();
};
self.drop = function () {
self.speed = 5;
for (var i = 0; i < buckets.length; i++) {
if (buckets[i].intersects(self)) {
if ((self.color === 'Red' || self.color === 'RedBonus') && buckets[i].color === 'Red' || (self.color === 'Blue' || self.color === 'BlueBonus') && buckets[i].color === 'Blue' || (self.color === 'Green' || self.color === 'GreenBonus') && buckets[i].color === 'Green') {
LK.getSound('Poof').play();
score++;
scoreTxt.setText(score);
if (self.color === 'Blue' && buckets[i].color === 'Blue' || self.color === 'Green' && buckets[i].color === 'Green' || self.color === 'Red' && buckets[i].color === 'Red') {
self.speed = 0;
self.y = buckets[i].y - buckets[i].height / 2 + self.height / 2;
self.settled = true;
} else {
LK.effects.flashObject(self, 0xffffff, 500);
LK.getSound('GameEnd').play();
self.destroy();
balls.splice(balls.indexOf(self), 1);
}
break;
} else {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
}
};
self.intersects = function (obj) {
return obj.x >= self.x - self.width / 2 && obj.x <= self.x + self.width / 2 && obj.y >= self.y - self.height / 2 && obj.y <= self.y + self.height / 2;
};
return self;
});
var RedBonusBall = Ball.expand(function () {
var self = Ball.call(this, 'RedBonus');
self.drop = function () {
self.speed = 5;
for (var i = 0; i < buckets.length; i++) {
if (self.intersects(buckets[i])) {
if (buckets[i].color === 'Red') {
score += 20;
LK.getSound('Poof').play();
scoreTxt.setText(score);
for (var j = 0; j < balls.length; j++) {
if (balls[j].color === 'Red' && balls[j].settled) {
balls[j].destroy();
balls.splice(j, 1);
j--;
}
}
LK.getSound('GameEnd').play();
LK.effects.flashObject(buckets[i], 0xff0000, 500); // Flash the RedBucket to indicate explosion
LK.effects.flashObject(self, 0xffffff, 500);
self.destroy();
balls.splice(balls.indexOf(self), 1);
break;
}
}
}
};
return self;
});
var GreenBonusBall = Ball.expand(function () {
var self = Ball.call(this, 'GreenBonus');
self.drop = function () {
self.speed = 5;
for (var i = 0; i < buckets.length; i++) {
if (self.intersects(buckets[i])) {
if (buckets[i].color === 'Green') {
score += 10;
LK.getSound('Poof').play();
scoreTxt.setText(score);
for (var j = 0; j < balls.length; j++) {
if (balls[j].color === 'Green' && balls[j].settled) {
balls[j].destroy();
balls.splice(j, 1);
j--;
}
}
self.speed = 0;
self.y = buckets[i].y - buckets[i].height / 2 + self.height / 2;
self.settled = true;
// Removed GameEnd sound to continue the game without ending it
break;
}
}
}
for (var i = 0; i < buckets.length; i++) {
if (self.intersects(buckets[i])) {
if (buckets[i].color === 'Green') {
score += 10;
LK.getSound('Poof').play();
scoreTxt.setText(score);
for (var j = 0; j < balls.length; j++) {
if (balls[j].color === 'Green' && balls[j].settled) {
balls[j].destroy();
balls.splice(j, 1);
j--;
}
}
LK.effects.flashObject(self, 0xffffff, 500);
self.destroy();
balls.splice(balls.indexOf(self), 1);
// Continue the game without ending it
break;
}
}
}
};
return self;
});
// Removed duplicate BonusBlueBall definition
var BlueBonusBall = Ball.expand(function () {
var self = Ball.call(this, 'BlueBonus');
self.drop = function () {
self.speed = 5;
for (var i = 0; i < buckets.length; i++) {
if (self.intersects(buckets[i])) {
if (buckets[i].color === 'Blue') {
score += 20;
LK.getSound('Poof').play();
scoreTxt.setText(score);
for (var j = 0; j < balls.length; j++) {
if (balls[j].color === 'Blue' && balls[j].settled) {
balls[j].destroy();
balls.splice(j, 1);
j--;
}
}
LK.effects.flashObject(buckets[i], 0x0000ff, 500); // Flash the BlueBucket to indicate explosion
LK.effects.flashObject(self, 0xffffff, 500);
self.destroy();
balls.splice(balls.indexOf(self), 1);
// Continue the game without ending it
return;
}
}
}
};
return self;
});
var BlueBall = Ball.expand(function () {
var self = Ball.call(this, 'Blue');
self.drop = function () {
self.speed = 5;
for (var i = 0; i < buckets.length; i++) {
if (self.intersects(buckets[i])) {
if (buckets[i].color === 'Blue') {
score += 1;
LK.getSound('Poof').play();
scoreTxt.setText(score);
self.speed = 0;
self.y = buckets[i].y - buckets[i].height / 2 + self.height / 2 + balls.filter(function (ball) {
return ball.color === 'Blue' && ball.settled;
}).length * self.height;
self.settled = true;
LK.getSound('GameEnd').play();
break;
} else if (buckets[i].color === 'Blue' && self.color === 'BlueBonus') {
score += 10;
LK.getSound('Poof').play();
scoreTxt.setText(score);
self.destroy();
balls.splice(balls.indexOf(self), 1);
break;
}
}
}
};
return self;
});
var BonusBall = Container.expand(function () {
var self = Container.call(this);
self.update = function () {
// Define the update behavior for BonusBall
};
return self;
});
var Bucket = Container.expand(function (color, xPosition) {
var self = Container.call(this);
self.attachAsset(color + 'Bucket', {
anchorX: 0.5,
anchorY: 0.5
});
self.color = color;
self.x = xPosition;
self.y = 2600;
self.intersects = function (obj) {
return obj.x >= self.x - self.width / 2 && obj.x <= self.x + self.width / 2 && obj.y >= self.y - self.height / 2 && obj.y <= self.y + self.height / 2;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x40E0D0 // Turquoise background
});
/****
* Game Code
****/
// Play cool music in the background at all times
LK.playMusic('Cool');
var balls = [];
var buckets = [];
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var bucketWidth = 350; // Width of the bucket
var bucketSpacing = (2048 - 3 * bucketWidth) / 4; // Calculate spacing between buckets
buckets.push(game.addChild(new Bucket('Blue', bucketSpacing + bucketWidth / 2, 2600)));
buckets.push(game.addChild(new Bucket('Green', 2 * bucketSpacing + 1.5 * bucketWidth, 2600)));
buckets.push(game.addChild(new Bucket('Red', 3 * bucketSpacing + 2.5 * bucketWidth, 2600)));
function spawnBall() {
var colors = ['Red', 'Blue', 'Green'];
var newBall;
if (Math.random() < 0.1) {
// 10% chance to spawn a bonus ball
newBall = new BonusBall();
} else {
var color = colors[Math.floor(Math.random() * colors.length)];
newBall = new Ball(color);
}
var bucketPositions = [400, 1024, 1648]; // x-positions of the buckets
var randomOffset = (Math.random() - 0.5) * 200; // Random offset to allow some variation
newBall.x = bucketPositions[Math.floor(Math.random() * bucketPositions.length)] + randomOffset;
newBall.y = 0;
balls.push(newBall);
game.addChild(newBall);
}
game.update = function () {
for (var i = balls.length - 1; i >= 0; i--) {
balls[i].update();
for (var j = 0; j < buckets.length; j++) {
if (balls[i].intersects(buckets[j])) {
if (balls[i].color === buckets[j].color || balls[i].color === 'RedBonus' && buckets[j].color === 'Red') {
score++;
scoreTxt.setText(score);
if (balls[i].color === 'Blue' && buckets[j].color === 'Blue') {
balls[i].speed = 0;
balls[i].y = buckets[j].y - buckets[j].height / 2 + balls[i].height / 2;
balls[i].settled = true;
} else {
balls[i].destroy();
balls.splice(i, 1);
}
break;
} else if (buckets[j].color === 'Green' && (balls[i].color === 'Blue' || balls[i].color === 'Red') || buckets[j].color === 'Blue' && (balls[i].color === 'Green' || balls[i].color === 'Red') || buckets[j].color === 'Red' && (balls[i].color === 'Green' || balls[i].color === 'Blue')) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
} else {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
}
if (balls[i] && balls[i].y > 2600) {
balls[i].destroy();
balls.splice(i, 1);
}
}
Ball.prototype.speed = score >= 30 ? 5 : 2 + Math.floor(LK.ticks / 3600); // Increase speed to 5 after 30 points, otherwise increase by 1 every minute
if (score >= 40) {
if (LK.ticks % 30 === 0) {
// Increase spawn rate after score reaches 40
spawnBall();
}
} else {
if (LK.ticks % 60 === 0) {
spawnBall();
}
}
var bonusBallExists = balls.some(function (ball) {
return ball.color && ball.color.includes('Bonus');
});
if (!bonusBallExists) {
if (Math.random() < 0.005) {
// 1% chance every tick for BlueBonusBall
var newBlueBonusBall = new BonusBlueBall();
newBlueBonusBall.x = Math.random() * 2048;
newBlueBonusBall.y = 0;
balls.push(newBlueBonusBall);
game.addChild(newBlueBonusBall);
} else if (Math.random() < 0.005) {
// 1% chance every tick for GreenBonusBall
var newGreenBonusBall = new GreenBonusBall();
newGreenBonusBall.x = Math.random() * 2048;
newGreenBonusBall.y = 0;
balls.push(newGreenBonusBall);
game.addChild(newGreenBonusBall);
} else if (Math.random() < 0.005) {
// 1% chance every tick for RedBonusBall
var newRedBonusBall = new RedBonusBall();
newRedBonusBall.x = Math.random() * 2048;
newRedBonusBall.y = 0;
balls.push(newRedBonusBall);
game.addChild(newRedBonusBall);
}
}
};
game.down = function (x, y) {
for (var i = 0; i < balls.length; i++) {
if (balls[i].intersects({
x: x,
y: y
})) {
balls[i].startDrag(x, y);
break;
}
}
};
game.move = function (x, y) {
for (var i = 0; i < balls.length; i++) {
if (balls[i].dragging) {
balls[i].drag(x, y);
}
}
};
game.up = function () {
for (var i = 0; i < balls.length; i++) {
if (balls[i].dragging) {
balls[i].stopDrag();
}
}
};
// Attach event listeners for dragging
game.on('pointerdown', game.down);
game.on('pointermove', game.move);
game.on('pointerup', game.up);
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.