/****
* 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 = 1;
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 = 7;
for (var i = 0; i < buckets.length; i++) {
if (buckets[i].intersects(self)) {
if (self.color === puzzleSequence[currentPuzzleIndex] && buckets[i].color === self.color) {
currentPuzzleIndex++;
if (currentPuzzleIndex >= puzzleSequence.length) {
currentPuzzleIndex = 0; // Reset sequence if completed
score += 10; // Bonus for completing the sequence
LK.getSound('Yes').play(); // Play achievement sound effect
}
LK.getSound('Poof').play();
if (self.color.includes('Bonus')) {
score += 5;
LK.getSound('Yes').play(); // Assuming 'Yes' is the sound ID for the positive sound effect
} else {
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 + balls.filter(function (ball) {
return ball.color === self.color && ball.settled;
}).length * self.height;
self.settled = true;
} else {
LK.effects.flashObject(self, 0xffffff, 500);
LK.getSound('GameEnd').play();
self.destroy();
balls.splice(balls.indexOf(self), 1);
}
break;
} else {
currentPuzzleIndex = 0; // Reset sequence on incorrect match
score -= 5; // Deduct points for incorrect match
scoreTxt.setText(score); // Update score display
LK.effects.flashScreen(0xff0000, 1000);
var levelTxt = new Text2('Level 2', {
size: 200,
fill: 0xFFFFFF,
fontWeight: 'bold'
});
levelTxt.anchor.set(0.5, 0.5);
levelTxt.x = 2048 / 2;
levelTxt.y = 2732 / 2;
game.addChild(levelTxt);
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;
});
// Removed duplicate BonusBlueBall definition
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 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', {
loop: true
});
// Display the sequence 'Red, Blue, Green, Blue, Red' in small font on the screen
var sequenceTxt = new Text2('Red, Blue, Green, Blue, Red', {
size: 50,
// Small font size
fill: 0xFFFFFF // White color
});
sequenceTxt.anchor.set(0.5, 0); // Center horizontally, top edge
sequenceTxt.x = 2048 / 2; // Center horizontally
sequenceTxt.y = 100; // Position near the top
LK.gui.top.addChild(sequenceTxt);
var balls = [];
var buckets = [];
var score = 0;
var puzzleSequence = ['Red', 'Blue', 'Green', 'Blue', 'Red']; // Define a new sequence of colors for level two
var currentPuzzleIndex = 0; // Track the current position in the sequence
var scoreBackground = LK.getAsset('scoreBackground', {
width: 400,
height: 200,
color: 0x800000,
// Maroon color
alpha: 0.5,
// Semi-transparent for glass-like effect
anchorX: 0.5,
anchorY: 0
});
LK.gui.top.addChild(scoreBackground);
var scoreTxt = new Text2('0', {
size: 150,
fill: 0x800000,
// Bold maroon color
fontWeight: 'bold' // Set font weight to bold
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Add a timer display at the top right
var timerTxt = new Text2('0:00', {
size: 150,
fill: 0xFFFF00,
// Glass-like yellow color
fontWeight: 'bold',
// Set font weight to bold
alpha: 0.5 // Semi-transparent for glass-like effect
});
timerTxt.anchor.set(1, 0); // Anchor to the top right
LK.gui.topRight.addChild(timerTxt);
// Update the timer every second
var startTime = Date.now();
LK.setInterval(function () {
var elapsedTime = Math.floor((Date.now() - startTime) / 1000);
var minutes = Math.floor(elapsedTime / 60);
var seconds = elapsedTime % 60;
timerTxt.setText(minutes + ':' + (seconds < 10 ? '0' : '') + seconds);
// Increase the speed of falling balls by one when the time hits 60 seconds
if (elapsedTime === 60) {
balls.forEach(function (ball) {
ball.speed += 1;
});
}
// Level 2 starts at 120 seconds
if (elapsedTime === 120) {
balls.forEach(function (ball) {
ball.speed += 3; // Increase speed further for level 2
});
Ball.prototype.speed += 3; // Increase base speed for new balls
if (LK.ticks % 15 === 0) {
// Increase spawn rate for level 2
spawnBall();
}
// Removed rotation speed increase
}
}, 1000);
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;
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++) {
// Removed rotation to stop buckets from rotating
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 % 120 === 0) {
spawnBall();
}
}
var bonusBallExists = balls.some(function (ball) {
return ball.color && ball.color.includes('Bonus');
});
};
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.