/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Enemy Ball class var EnemyBall = Container.expand(function () { var self = Container.call(this); // colorType: 'red', 'blue', 'orange', 'pink' self.init = function (colorType, speed, angle) { self.colorType = colorType; var assetId = colorType + 'Ball'; var ball = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.radius = ball.width / 2; self.speed = speed; self.angle = angle; // in radians }; self.update = function () { self.x += Math.cos(self.angle) * self.speed; self.y += Math.sin(self.angle) * self.speed; // Bounce off walls if (self.x - self.radius < 0 && Math.cos(self.angle) < 0) { self.angle = Math.PI - self.angle; self.x = self.radius; } if (self.x + self.radius > 2048 && Math.cos(self.angle) > 0) { self.angle = Math.PI - self.angle; self.x = 2048 - self.radius; } if (self.y - self.radius < 0 && Math.sin(self.angle) < 0) { self.angle = -self.angle; self.y = self.radius; } if (self.y + self.radius > 2732 && Math.sin(self.angle) > 0) { self.angle = -self.angle; self.y = 2732 - self.radius; } }; return self; }); // Super Ball (player) class var SuperBall = Container.expand(function () { var self = Container.call(this); var ball = self.attachAsset('superBall', { anchorX: 0.5, anchorY: 0.5 }); self.radius = ball.width / 2; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Not visible, as the money pile image will cover the background }); /**** * Game Code ****/ // Money pile tile image // Game variables // Add a tiled money image background to simulate a pile of money var moneyBg = LK.getAsset('moneyPile', { anchorX: 0, anchorY: 0, x: 0, y: 0, width: 2048, height: 2732, tile: true // This will tile the image to fill the background }); game.addChildAt(moneyBg, 0); // Add as the bottom-most layer // Super Ball (player) // Enemy Balls var superBall; var enemyBalls = []; var dragNode = null; var level = 1; var ballsLeft = 0; var scoreTxt; // Ball color types var colorTypes = ['red', 'blue', 'orange', 'pink']; // Score/balls left display scoreTxt = new Text2('Balls Left: 0', { size: 110, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Score counter display var scoreCounterTxt = new Text2('Score: 0', { size: 90, fill: 0x00FFCC }); // Move anchor to left (0,1) and position at bottom left, leaving space for menu (100px) and a little padding scoreCounterTxt.anchor.set(0, 1); scoreCounterTxt.x = 110; // Leave space for menu (100px) and a little padding scoreCounterTxt.y = 0; LK.gui.bottomLeft.addChild(scoreCounterTxt); // Timer display var timerTxt = new Text2('19.0', { size: 110, fill: 0xFFD700 }); timerTxt.anchor.set(0.5, 0); timerTxt.y = 120; // Place below the score LK.gui.top.addChild(timerTxt); var timerValue = 19.0; var timerInterval = null; var timerActive = false; // Helper: spawn enemy balls for current level function spawnEnemyBalls(level) { // Remove any existing balls for (var i = 0; i < enemyBalls.length; ++i) { enemyBalls[i].destroy(); } enemyBalls = []; // Number of balls increases with level var numBalls = 6 + (level - 1) * 2; if (numBalls > 24) numBalls = 24; ballsLeft = numBalls; scoreTxt.setText('Balls Left: ' + ballsLeft); for (var i = 0; i < numBalls; ++i) { var colorType = colorTypes[i % colorTypes.length]; var speed = 6 + level * 1.2 + Math.random() * 2; // slightly random speed var angle = Math.random() * Math.PI * 2; var ball = new EnemyBall(); ball.init(colorType, speed, angle); // Place balls randomly, but not too close to center var safeRadius = 400; var x, y; do { x = 300 + Math.random() * (2048 - 600); y = 300 + Math.random() * (2732 - 600); } while (Math.abs(x - 1024) < safeRadius && Math.abs(y - 1366) < safeRadius); ball.x = x; ball.y = y; enemyBalls.push(ball); game.addChild(ball); } } // Helper: start/restart game function startGame() { level = 1; LK.setScore(0); if (typeof scoreCounterTxt !== "undefined") { scoreCounterTxt.setText('Score: 0'); } if (superBall) superBall.destroy(); superBall = new SuperBall(); superBall.x = 1024; superBall.y = 1366; game.addChild(superBall); spawnEnemyBalls(level); // Reset and start timer timerValue = 19.0; timerTxt.setText(timerValue.toFixed(1)); timerActive = true; if (timerInterval) { LK.clearInterval(timerInterval); } timerInterval = LK.setInterval(function () { if (!timerActive) return; timerValue -= 0.1; if (timerValue < 0) timerValue = 0; timerTxt.setText(timerValue.toFixed(1)); if (timerValue <= 0) { timerActive = false; LK.clearInterval(timerInterval); LK.showGameOver(); } }, 100); } // Dragging logic function handleMove(x, y, obj) { if (dragNode) { // Clamp to game area var r = dragNode.radius; var nx = x, ny = y; if (nx < r) nx = r; if (nx > 2048 - r) nx = 2048 - r; if (ny < r) ny = r; if (ny > 2732 - r) ny = 2732 - r; dragNode.x = nx; dragNode.y = ny; } } game.move = handleMove; game.down = function (x, y, obj) { // Only allow drag if touch is inside superBall var dx = x - superBall.x; var dy = y - superBall.y; if (dx * dx + dy * dy <= superBall.radius * superBall.radius) { dragNode = superBall; handleMove(x, y, obj); } }; game.up = function (x, y, obj) { dragNode = null; }; // Main update loop game.update = function () { // Move enemy balls for (var i = enemyBalls.length - 1; i >= 0; --i) { var ball = enemyBalls[i]; ball.update(); // Collision with superBall var dx = ball.x - superBall.x; var dy = ball.y - superBall.y; var distSq = dx * dx + dy * dy; var minDist = ball.radius + superBall.radius; if (distSq <= minDist * minDist) { // Destroy ball ball.destroy(); enemyBalls.splice(i, 1); ballsLeft -= 1; LK.setScore(LK.getScore() + 1); scoreTxt.setText('Balls Left: ' + ballsLeft); scoreCounterTxt.setText('Score: ' + LK.getScore()); // Flash effect LK.effects.flashObject(superBall, 0xffffff, 200); // Win condition if (ballsLeft === 0) { // Infinite levels: always increase level and respawn balls level += 1; LK.setTimeout(function () { spawnEnemyBalls(level); // Reset timer for new round timerValue = 19.0; timerTxt.setText(timerValue.toFixed(1)); timerActive = true; if (typeof scoreCounterTxt !== "undefined") { scoreCounterTxt.setText('Score: ' + LK.getScore()); } if (timerInterval) { LK.clearInterval(timerInterval); } timerInterval = LK.setInterval(function () { if (!timerActive) return; timerValue -= 0.1; if (timerValue < 0) timerValue = 0; timerTxt.setText(timerValue.toFixed(1)); if (timerValue <= 0) { timerActive = false; LK.clearInterval(timerInterval); LK.showGameOver(); } }, 100); }, 700); } } } }; // Start game startGame();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Enemy Ball class
var EnemyBall = Container.expand(function () {
var self = Container.call(this);
// colorType: 'red', 'blue', 'orange', 'pink'
self.init = function (colorType, speed, angle) {
self.colorType = colorType;
var assetId = colorType + 'Ball';
var ball = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.radius = ball.width / 2;
self.speed = speed;
self.angle = angle; // in radians
};
self.update = function () {
self.x += Math.cos(self.angle) * self.speed;
self.y += Math.sin(self.angle) * self.speed;
// Bounce off walls
if (self.x - self.radius < 0 && Math.cos(self.angle) < 0) {
self.angle = Math.PI - self.angle;
self.x = self.radius;
}
if (self.x + self.radius > 2048 && Math.cos(self.angle) > 0) {
self.angle = Math.PI - self.angle;
self.x = 2048 - self.radius;
}
if (self.y - self.radius < 0 && Math.sin(self.angle) < 0) {
self.angle = -self.angle;
self.y = self.radius;
}
if (self.y + self.radius > 2732 && Math.sin(self.angle) > 0) {
self.angle = -self.angle;
self.y = 2732 - self.radius;
}
};
return self;
});
// Super Ball (player) class
var SuperBall = Container.expand(function () {
var self = Container.call(this);
var ball = self.attachAsset('superBall', {
anchorX: 0.5,
anchorY: 0.5
});
self.radius = ball.width / 2;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Not visible, as the money pile image will cover the background
});
/****
* Game Code
****/
// Money pile tile image
// Game variables
// Add a tiled money image background to simulate a pile of money
var moneyBg = LK.getAsset('moneyPile', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
width: 2048,
height: 2732,
tile: true // This will tile the image to fill the background
});
game.addChildAt(moneyBg, 0); // Add as the bottom-most layer
// Super Ball (player)
// Enemy Balls
var superBall;
var enemyBalls = [];
var dragNode = null;
var level = 1;
var ballsLeft = 0;
var scoreTxt;
// Ball color types
var colorTypes = ['red', 'blue', 'orange', 'pink'];
// Score/balls left display
scoreTxt = new Text2('Balls Left: 0', {
size: 110,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Score counter display
var scoreCounterTxt = new Text2('Score: 0', {
size: 90,
fill: 0x00FFCC
});
// Move anchor to left (0,1) and position at bottom left, leaving space for menu (100px) and a little padding
scoreCounterTxt.anchor.set(0, 1);
scoreCounterTxt.x = 110; // Leave space for menu (100px) and a little padding
scoreCounterTxt.y = 0;
LK.gui.bottomLeft.addChild(scoreCounterTxt);
// Timer display
var timerTxt = new Text2('19.0', {
size: 110,
fill: 0xFFD700
});
timerTxt.anchor.set(0.5, 0);
timerTxt.y = 120; // Place below the score
LK.gui.top.addChild(timerTxt);
var timerValue = 19.0;
var timerInterval = null;
var timerActive = false;
// Helper: spawn enemy balls for current level
function spawnEnemyBalls(level) {
// Remove any existing balls
for (var i = 0; i < enemyBalls.length; ++i) {
enemyBalls[i].destroy();
}
enemyBalls = [];
// Number of balls increases with level
var numBalls = 6 + (level - 1) * 2;
if (numBalls > 24) numBalls = 24;
ballsLeft = numBalls;
scoreTxt.setText('Balls Left: ' + ballsLeft);
for (var i = 0; i < numBalls; ++i) {
var colorType = colorTypes[i % colorTypes.length];
var speed = 6 + level * 1.2 + Math.random() * 2; // slightly random speed
var angle = Math.random() * Math.PI * 2;
var ball = new EnemyBall();
ball.init(colorType, speed, angle);
// Place balls randomly, but not too close to center
var safeRadius = 400;
var x, y;
do {
x = 300 + Math.random() * (2048 - 600);
y = 300 + Math.random() * (2732 - 600);
} while (Math.abs(x - 1024) < safeRadius && Math.abs(y - 1366) < safeRadius);
ball.x = x;
ball.y = y;
enemyBalls.push(ball);
game.addChild(ball);
}
}
// Helper: start/restart game
function startGame() {
level = 1;
LK.setScore(0);
if (typeof scoreCounterTxt !== "undefined") {
scoreCounterTxt.setText('Score: 0');
}
if (superBall) superBall.destroy();
superBall = new SuperBall();
superBall.x = 1024;
superBall.y = 1366;
game.addChild(superBall);
spawnEnemyBalls(level);
// Reset and start timer
timerValue = 19.0;
timerTxt.setText(timerValue.toFixed(1));
timerActive = true;
if (timerInterval) {
LK.clearInterval(timerInterval);
}
timerInterval = LK.setInterval(function () {
if (!timerActive) return;
timerValue -= 0.1;
if (timerValue < 0) timerValue = 0;
timerTxt.setText(timerValue.toFixed(1));
if (timerValue <= 0) {
timerActive = false;
LK.clearInterval(timerInterval);
LK.showGameOver();
}
}, 100);
}
// Dragging logic
function handleMove(x, y, obj) {
if (dragNode) {
// Clamp to game area
var r = dragNode.radius;
var nx = x,
ny = y;
if (nx < r) nx = r;
if (nx > 2048 - r) nx = 2048 - r;
if (ny < r) ny = r;
if (ny > 2732 - r) ny = 2732 - r;
dragNode.x = nx;
dragNode.y = ny;
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
// Only allow drag if touch is inside superBall
var dx = x - superBall.x;
var dy = y - superBall.y;
if (dx * dx + dy * dy <= superBall.radius * superBall.radius) {
dragNode = superBall;
handleMove(x, y, obj);
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Main update loop
game.update = function () {
// Move enemy balls
for (var i = enemyBalls.length - 1; i >= 0; --i) {
var ball = enemyBalls[i];
ball.update();
// Collision with superBall
var dx = ball.x - superBall.x;
var dy = ball.y - superBall.y;
var distSq = dx * dx + dy * dy;
var minDist = ball.radius + superBall.radius;
if (distSq <= minDist * minDist) {
// Destroy ball
ball.destroy();
enemyBalls.splice(i, 1);
ballsLeft -= 1;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText('Balls Left: ' + ballsLeft);
scoreCounterTxt.setText('Score: ' + LK.getScore());
// Flash effect
LK.effects.flashObject(superBall, 0xffffff, 200);
// Win condition
if (ballsLeft === 0) {
// Infinite levels: always increase level and respawn balls
level += 1;
LK.setTimeout(function () {
spawnEnemyBalls(level);
// Reset timer for new round
timerValue = 19.0;
timerTxt.setText(timerValue.toFixed(1));
timerActive = true;
if (typeof scoreCounterTxt !== "undefined") {
scoreCounterTxt.setText('Score: ' + LK.getScore());
}
if (timerInterval) {
LK.clearInterval(timerInterval);
}
timerInterval = LK.setInterval(function () {
if (!timerActive) return;
timerValue -= 0.1;
if (timerValue < 0) timerValue = 0;
timerTxt.setText(timerValue.toFixed(1));
if (timerValue <= 0) {
timerActive = false;
LK.clearInterval(timerInterval);
LK.showGameOver();
}
}, 100);
}, 700);
}
}
}
};
// Start game
startGame();
Make it a blue ball with a evil face. In-Game asset. High contrast. No shadows
A red ball with a evil face. In-Game asset. High contrast. No shadows
A orange ball with a evil smile. #2d
A pink ball with a evil smile. In-Game asset. High contrast. No shadows
A green super hero ball. In-Game asset. High contrast. No shadows