/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var FallingBall = Container.expand(function (colorIndex) {
var self = Container.call(this);
var ballColors = ['redBall', 'blueBall', 'greenBall', 'yellowBall', 'purpleBall', 'orangeBall'];
var ballAssetNames = ballColors[colorIndex];
var ballGraphics = self.attachAsset(ballAssetNames, {
anchorX: 0.5,
anchorY: 0.5
});
self.colorIndex = colorIndex;
self.speed = fallSpeed;
self.tapped = false;
self.down = function (x, y, obj) {
if (self.tapped) return;
self.tapped = true;
if (self.colorIndex === targetColorIndex) {
// Correct color tapped
LK.setScore(LK.getScore() + 1);
scoreText.setText(LK.getScore());
LK.getSound('correctTap').play();
// Flash effect
LK.effects.flashObject(self, 0xffffff, 300);
// Remove from array and destroy
for (var i = fallingBalls.length - 1; i >= 0; i--) {
if (fallingBalls[i] === self) {
fallingBalls.splice(i, 1);
break;
}
}
self.destroy();
} else {
// Wrong color tapped - game over
LK.getSound('wrongTap').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
};
self.update = function () {
self.y += self.speed;
// Check if ball reached bottom
if (self.y > 2732 + 50) {
// If this was the target color, game over
if (self.colorIndex === targetColorIndex && !self.tapped) {
LK.showGameOver();
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x001122
});
/****
* Game Code
****/
var fallingBalls = [];
var targetColorIndex = 0;
var fallSpeed = 3;
var spawnTimer = 0;
var spawnRate = 90; // Spawn every 90 ticks (1.5 seconds at 60fps)
var colorChangeTimer = 0;
var colorChangeRate = 600; // Change color every 10 seconds
var difficultyTimer = 0;
var ballColors = ['red', 'blue', 'green', 'yellow', 'purple', 'orange'];
var ballColorValues = [0xff0000, 0x0066ff, 0x00ff00, 0xffff00, 0x9900ff, 0xff6600];
// Create target color display
var targetColorDisplay = game.addChild(LK.getAsset('targetColorBox', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 150
}));
targetColorDisplay.tint = ballColorValues[targetColorIndex];
// Create target color text
var targetColorText = new Text2('Tap: ' + ballColors[targetColorIndex].toUpperCase(), {
size: 48,
fill: 0x000000
});
targetColorText.anchor.set(0.5, 0.5);
targetColorText.x = 2048 / 2;
targetColorText.y = 150;
game.addChild(targetColorText);
// Create score display
var scoreText = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
scoreText.y = 50;
function spawnRandomBall() {
var randomColor = Math.floor(Math.random() * 6);
var newBall = new FallingBall(randomColor);
// Random x position
newBall.x = Math.random() * (2048 - 100) + 50;
newBall.y = -50;
fallingBalls.push(newBall);
game.addChild(newBall);
}
function changeTargetColor() {
var oldColor = targetColorIndex;
// Make sure we don't pick the same color
do {
targetColorIndex = Math.floor(Math.random() * 6);
} while (targetColorIndex === oldColor);
targetColorDisplay.tint = ballColorValues[targetColorIndex];
targetColorText.setText('Tap: ' + ballColors[targetColorIndex].toUpperCase());
// Flash effect on color change
LK.effects.flashObject(targetColorDisplay, 0xffffff, 500);
}
game.update = function () {
// Spawn balls
spawnTimer++;
if (spawnTimer >= spawnRate) {
spawnRandomBall();
spawnTimer = 0;
}
// Change target color periodically
colorChangeTimer++;
if (colorChangeTimer >= colorChangeRate) {
changeTargetColor();
colorChangeTimer = 0;
}
// Increase difficulty over time
difficultyTimer++;
if (difficultyTimer >= 1800) {
// Every 30 seconds
if (fallSpeed < 8) {
fallSpeed += 0.5;
}
if (spawnRate > 30) {
spawnRate -= 5;
}
difficultyTimer = 0;
}
// Clean up balls that have gone off screen
for (var i = fallingBalls.length - 1; i >= 0; i--) {
var ball = fallingBalls[i];
if (ball.y > 2732 + 100) {
ball.destroy();
fallingBalls.splice(i, 1);
}
}
// Update ball speeds
for (var j = 0; j < fallingBalls.length; j++) {
fallingBalls[j].speed = fallSpeed;
}
};
// Initialize first target color change after 3 seconds
LK.setTimeout(function () {
changeTargetColor();
}, 3000); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,164 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var FallingBall = Container.expand(function (colorIndex) {
+ var self = Container.call(this);
+ var ballColors = ['redBall', 'blueBall', 'greenBall', 'yellowBall', 'purpleBall', 'orangeBall'];
+ var ballAssetNames = ballColors[colorIndex];
+ var ballGraphics = self.attachAsset(ballAssetNames, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.colorIndex = colorIndex;
+ self.speed = fallSpeed;
+ self.tapped = false;
+ self.down = function (x, y, obj) {
+ if (self.tapped) return;
+ self.tapped = true;
+ if (self.colorIndex === targetColorIndex) {
+ // Correct color tapped
+ LK.setScore(LK.getScore() + 1);
+ scoreText.setText(LK.getScore());
+ LK.getSound('correctTap').play();
+ // Flash effect
+ LK.effects.flashObject(self, 0xffffff, 300);
+ // Remove from array and destroy
+ for (var i = fallingBalls.length - 1; i >= 0; i--) {
+ if (fallingBalls[i] === self) {
+ fallingBalls.splice(i, 1);
+ break;
+ }
+ }
+ self.destroy();
+ } else {
+ // Wrong color tapped - game over
+ LK.getSound('wrongTap').play();
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ };
+ self.update = function () {
+ self.y += self.speed;
+ // Check if ball reached bottom
+ if (self.y > 2732 + 50) {
+ // If this was the target color, game over
+ if (self.colorIndex === targetColorIndex && !self.tapped) {
+ LK.showGameOver();
+ }
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x001122
+});
+
+/****
+* Game Code
+****/
+var fallingBalls = [];
+var targetColorIndex = 0;
+var fallSpeed = 3;
+var spawnTimer = 0;
+var spawnRate = 90; // Spawn every 90 ticks (1.5 seconds at 60fps)
+var colorChangeTimer = 0;
+var colorChangeRate = 600; // Change color every 10 seconds
+var difficultyTimer = 0;
+var ballColors = ['red', 'blue', 'green', 'yellow', 'purple', 'orange'];
+var ballColorValues = [0xff0000, 0x0066ff, 0x00ff00, 0xffff00, 0x9900ff, 0xff6600];
+// Create target color display
+var targetColorDisplay = game.addChild(LK.getAsset('targetColorBox', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 2048 / 2,
+ y: 150
+}));
+targetColorDisplay.tint = ballColorValues[targetColorIndex];
+// Create target color text
+var targetColorText = new Text2('Tap: ' + ballColors[targetColorIndex].toUpperCase(), {
+ size: 48,
+ fill: 0x000000
+});
+targetColorText.anchor.set(0.5, 0.5);
+targetColorText.x = 2048 / 2;
+targetColorText.y = 150;
+game.addChild(targetColorText);
+// Create score display
+var scoreText = new Text2('0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+scoreText.y = 50;
+function spawnRandomBall() {
+ var randomColor = Math.floor(Math.random() * 6);
+ var newBall = new FallingBall(randomColor);
+ // Random x position
+ newBall.x = Math.random() * (2048 - 100) + 50;
+ newBall.y = -50;
+ fallingBalls.push(newBall);
+ game.addChild(newBall);
+}
+function changeTargetColor() {
+ var oldColor = targetColorIndex;
+ // Make sure we don't pick the same color
+ do {
+ targetColorIndex = Math.floor(Math.random() * 6);
+ } while (targetColorIndex === oldColor);
+ targetColorDisplay.tint = ballColorValues[targetColorIndex];
+ targetColorText.setText('Tap: ' + ballColors[targetColorIndex].toUpperCase());
+ // Flash effect on color change
+ LK.effects.flashObject(targetColorDisplay, 0xffffff, 500);
+}
+game.update = function () {
+ // Spawn balls
+ spawnTimer++;
+ if (spawnTimer >= spawnRate) {
+ spawnRandomBall();
+ spawnTimer = 0;
+ }
+ // Change target color periodically
+ colorChangeTimer++;
+ if (colorChangeTimer >= colorChangeRate) {
+ changeTargetColor();
+ colorChangeTimer = 0;
+ }
+ // Increase difficulty over time
+ difficultyTimer++;
+ if (difficultyTimer >= 1800) {
+ // Every 30 seconds
+ if (fallSpeed < 8) {
+ fallSpeed += 0.5;
+ }
+ if (spawnRate > 30) {
+ spawnRate -= 5;
+ }
+ difficultyTimer = 0;
+ }
+ // Clean up balls that have gone off screen
+ for (var i = fallingBalls.length - 1; i >= 0; i--) {
+ var ball = fallingBalls[i];
+ if (ball.y > 2732 + 100) {
+ ball.destroy();
+ fallingBalls.splice(i, 1);
+ }
+ }
+ // Update ball speeds
+ for (var j = 0; j < fallingBalls.length; j++) {
+ fallingBalls[j].speed = fallSpeed;
+ }
+};
+// Initialize first target color change after 3 seconds
+LK.setTimeout(function () {
+ changeTargetColor();
+}, 3000);
\ No newline at end of file
blue ball. In-Game asset. 2d. High contrast. No shadows
greenBall. In-Game asset. 2d. High contrast. No shadows
orangeBall. In-Game asset. 2d. High contrast. No shadows
purpleBall. In-Game asset. 2d. High contrast. No shadows
redBall. In-Game asset. 2d. High contrast. No shadows
yellowBall. In-Game asset. 2d. High contrast. No shadows