User prompt
point and time text has to be upper center of game
User prompt
combo text has to be bottom of the game
User prompt
make combo system
User prompt
Please fix the bug: 'mixedBtn is not defined' in or related to this line: 'mixedBtn.x = 0;' Line Number: 456
User prompt
make the toggles bottom of the start menu.
User prompt
make a new toggle. this one mixes all diffculties. in one game every diffculty can appear.
User prompt
make a main menu option that enables enemy vibration. that makes game harder
User prompt
main menu "start" text needs to be white. and a black outline.
User prompt
add different background assets and choose one of them randomly everytime
User prompt
Please fix the bug: 'Uncaught ReferenceError: Enemy is not defined' in or related to this line: 'var target = new Enemy();' Line Number: 96
User prompt
seperate the enemy assets from "box" assets. i want to change them.
User prompt
and make it blurry
User prompt
make background opacity %50
User prompt
i want a background asset
User prompt
i want hard difficulty with red color. enemys will be red too. like the other different diffculties
User prompt
delete "hard"
User prompt
you have to change it to red
User prompt
hard enemy must be red
User prompt
make in game enemy color same with the difficultie color
User prompt
these assets have to be in game
User prompt
i want 3 new assets of "easy" "mid" and "hard" boxes
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'fill')' in or related to this line: 'this.children[1].style.fill = selected ? '#ffffff' : '#e0e0e0';' Line Number: 347
User prompt
make a main menu. there we can pick easy-mid-hard difficulties.
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'feedbackTxt.style.fill = '#' + color.toString(16).padStart(6, '0');' Line Number: 187
Code edit (1 edits merged)
Please save this source code
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Target class: represents a tappable target var Target = Container.expand(function () { var self = Container.call(this); // Randomize size (between 120 and 220 px) var minSize = 120; var maxSize = 220; var size = minSize + Math.floor(Math.random() * (maxSize - minSize + 1)); // Randomize color var colors = [0xff3b3b, 0x3b9cff, 0x3bff6a, 0xffe23b, 0xff3bda, 0x3bffd7]; var color = colors[Math.floor(Math.random() * colors.length)]; // Use ellipse for target var targetAsset = self.attachAsset('targetShape', { width: size, height: size, color: color, shape: 'ellipse', anchorX: 0.5, anchorY: 0.5 }); // Store size for hit detection self.size = size; // Used to prevent double tap self.isActive = true; // Animate in (pop effect) targetAsset.scaleX = 0.6; targetAsset.scaleY = 0.6; tween(targetAsset, { scaleX: 1, scaleY: 1 }, { duration: 120, easing: tween.elasticOut }); // Called when target is tapped self.down = function (x, y, obj) { if (!self.isActive) return; self.isActive = false; // Animate out (shrink and fade) tween(targetAsset, { scaleX: 0.2, scaleY: 0.2, alpha: 0 }, { duration: 120, easing: tween.cubicIn, onFinish: function onFinish() { if (self.onHit) self.onHit(); self.destroy(); } }); }; // Called when target times out (missed) self.miss = function () { if (!self.isActive) return; self.isActive = false; // Animate out (fade) tween(targetAsset, { alpha: 0 }, { duration: 120, easing: tween.cubicIn, onFinish: function onFinish() { if (self.onMiss) self.onMiss(); self.destroy(); } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x181c24 }); /**** * Game Code ****/ // Game settings var GAME_TIME = 30; // seconds var TARGET_LIFETIME = 900; // ms before target disappears var TARGET_SPAWN_DELAY = 200; // ms between targets (after hit/miss) var MIN_TARGETS = 1; var MAX_TARGETS = 1; // Only one target at a time for MVP // State var score = 0; var timeLeft = GAME_TIME; var timerInterval = null; var targetTimeout = null; var currentTarget = null; var gameActive = false; // Score display var scoreTxt = new Text2('0', { size: 120, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Timer display var timerTxt = new Text2(GAME_TIME + '', { size: 90, fill: 0xFFD700 }); timerTxt.anchor.set(0.5, 0); LK.gui.top.addChild(timerTxt); timerTxt.y = scoreTxt.height * 0.9; // Center score and timer horizontally, with timer below score scoreTxt.x = LK.gui.top.width / 2; timerTxt.x = LK.gui.top.width / 2; // Feedback text (shows "Miss!" or "+1") var feedbackTxt = new Text2('', { size: 120, fill: 0xFF3B3B }); feedbackTxt.anchor.set(0.5, 0.5); feedbackTxt.visible = false; LK.gui.center.addChild(feedbackTxt); // Helper: spawn a new target at a random position function spawnTarget() { // Remove previous target if any if (currentTarget) { currentTarget.destroy(); currentTarget = null; } // Create new target var target = new Target(); // Randomize position, keep fully inside screen and away from top-left 100x100 var margin = 80; var minX = margin + target.size / 2; var maxX = 2048 - margin - target.size / 2; var minY = margin + target.size / 2 + 100; // avoid top 100px var maxY = 2732 - margin - target.size / 2; target.x = minX + Math.random() * (maxX - minX); target.y = minY + Math.random() * (maxY - minY); // Attach hit/miss handlers target.onHit = function () { score += 1; LK.setScore(score); scoreTxt.setText(score + ''); showFeedback('+1', 0x3bff6a); scheduleNextTarget(); }; target.onMiss = function () { showFeedback('Miss!', 0xff3b3b); scheduleNextTarget(); }; // Add to game game.addChild(target); currentTarget = target; // Set up timeout for missing the target if (targetTimeout) LK.clearTimeout(targetTimeout); targetTimeout = LK.setTimeout(function () { if (currentTarget) { currentTarget.miss(); currentTarget = null; } }, TARGET_LIFETIME); } // Helper: show feedback text at center function showFeedback(text, color) { feedbackTxt.setText(text); feedbackTxt.style.fill = '#' + color.toString(16).padStart(6, '0'); feedbackTxt.visible = true; feedbackTxt.alpha = 1; tween(feedbackTxt, { alpha: 0 }, { duration: 500, easing: tween.cubicOut, onFinish: function onFinish() { feedbackTxt.visible = false; } }); } // Helper: schedule next target after a short delay function scheduleNextTarget() { if (targetTimeout) LK.clearTimeout(targetTimeout); targetTimeout = LK.setTimeout(function () { if (gameActive) spawnTarget(); }, TARGET_SPAWN_DELAY); } // Start the game function startGame() { score = 0; LK.setScore(0); scoreTxt.setText('0'); timeLeft = GAME_TIME; timerTxt.setText(timeLeft + ''); feedbackTxt.visible = false; gameActive = true; // Remove any lingering target if (currentTarget) { currentTarget.destroy(); currentTarget = null; } // Start timer if (timerInterval) LK.clearInterval(timerInterval); timerInterval = LK.setInterval(function () { if (!gameActive) return; timeLeft -= 0.1; if (timeLeft < 0) timeLeft = 0; timerTxt.setText(Math.ceil(timeLeft) + ''); if (timeLeft <= 0) { endGame(); } }, 100); // Spawn first target spawnTarget(); } // End the game function endGame() { gameActive = false; if (timerInterval) LK.clearInterval(timerInterval); if (targetTimeout) LK.clearTimeout(targetTimeout); if (currentTarget) { currentTarget.destroy(); currentTarget = null; } // Show game over (handled by LK) LK.showGameOver(); } // Game tap handler: if tap is not on a target, show miss feedback game.down = function (x, y, obj) { if (!gameActive) return; // If tap is not on the target, count as miss if (currentTarget) { // Convert tap to target local coordinates var local = currentTarget.toLocal(game.toGlobal({ x: x, y: y })); var dx = local.x; var dy = local.y; var r = currentTarget.size / 2; if (dx * dx + dy * dy > r * r) { // Missed the target currentTarget.miss(); currentTarget = null; } // else: handled by target.down } }; // Start game on first frame LK.setTimeout(function () { startGame(); }, 200); // Clean up on game over (reset state) game.on('destroy', function () { gameActive = false; if (timerInterval) LK.clearInterval(timerInterval); if (targetTimeout) LK.clearTimeout(targetTimeout); if (currentTarget) { currentTarget.destroy(); currentTarget = null; } }); // No need for update loop for MVP // Prevent elements in top-left 100x100 // (Handled by spawnTarget margin and minY)
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Target class: represents a tappable target
var Target = Container.expand(function () {
var self = Container.call(this);
// Randomize size (between 120 and 220 px)
var minSize = 120;
var maxSize = 220;
var size = minSize + Math.floor(Math.random() * (maxSize - minSize + 1));
// Randomize color
var colors = [0xff3b3b, 0x3b9cff, 0x3bff6a, 0xffe23b, 0xff3bda, 0x3bffd7];
var color = colors[Math.floor(Math.random() * colors.length)];
// Use ellipse for target
var targetAsset = self.attachAsset('targetShape', {
width: size,
height: size,
color: color,
shape: 'ellipse',
anchorX: 0.5,
anchorY: 0.5
});
// Store size for hit detection
self.size = size;
// Used to prevent double tap
self.isActive = true;
// Animate in (pop effect)
targetAsset.scaleX = 0.6;
targetAsset.scaleY = 0.6;
tween(targetAsset, {
scaleX: 1,
scaleY: 1
}, {
duration: 120,
easing: tween.elasticOut
});
// Called when target is tapped
self.down = function (x, y, obj) {
if (!self.isActive) return;
self.isActive = false;
// Animate out (shrink and fade)
tween(targetAsset, {
scaleX: 0.2,
scaleY: 0.2,
alpha: 0
}, {
duration: 120,
easing: tween.cubicIn,
onFinish: function onFinish() {
if (self.onHit) self.onHit();
self.destroy();
}
});
};
// Called when target times out (missed)
self.miss = function () {
if (!self.isActive) return;
self.isActive = false;
// Animate out (fade)
tween(targetAsset, {
alpha: 0
}, {
duration: 120,
easing: tween.cubicIn,
onFinish: function onFinish() {
if (self.onMiss) self.onMiss();
self.destroy();
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181c24
});
/****
* Game Code
****/
// Game settings
var GAME_TIME = 30; // seconds
var TARGET_LIFETIME = 900; // ms before target disappears
var TARGET_SPAWN_DELAY = 200; // ms between targets (after hit/miss)
var MIN_TARGETS = 1;
var MAX_TARGETS = 1; // Only one target at a time for MVP
// State
var score = 0;
var timeLeft = GAME_TIME;
var timerInterval = null;
var targetTimeout = null;
var currentTarget = null;
var gameActive = false;
// Score display
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Timer display
var timerTxt = new Text2(GAME_TIME + '', {
size: 90,
fill: 0xFFD700
});
timerTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(timerTxt);
timerTxt.y = scoreTxt.height * 0.9;
// Center score and timer horizontally, with timer below score
scoreTxt.x = LK.gui.top.width / 2;
timerTxt.x = LK.gui.top.width / 2;
// Feedback text (shows "Miss!" or "+1")
var feedbackTxt = new Text2('', {
size: 120,
fill: 0xFF3B3B
});
feedbackTxt.anchor.set(0.5, 0.5);
feedbackTxt.visible = false;
LK.gui.center.addChild(feedbackTxt);
// Helper: spawn a new target at a random position
function spawnTarget() {
// Remove previous target if any
if (currentTarget) {
currentTarget.destroy();
currentTarget = null;
}
// Create new target
var target = new Target();
// Randomize position, keep fully inside screen and away from top-left 100x100
var margin = 80;
var minX = margin + target.size / 2;
var maxX = 2048 - margin - target.size / 2;
var minY = margin + target.size / 2 + 100; // avoid top 100px
var maxY = 2732 - margin - target.size / 2;
target.x = minX + Math.random() * (maxX - minX);
target.y = minY + Math.random() * (maxY - minY);
// Attach hit/miss handlers
target.onHit = function () {
score += 1;
LK.setScore(score);
scoreTxt.setText(score + '');
showFeedback('+1', 0x3bff6a);
scheduleNextTarget();
};
target.onMiss = function () {
showFeedback('Miss!', 0xff3b3b);
scheduleNextTarget();
};
// Add to game
game.addChild(target);
currentTarget = target;
// Set up timeout for missing the target
if (targetTimeout) LK.clearTimeout(targetTimeout);
targetTimeout = LK.setTimeout(function () {
if (currentTarget) {
currentTarget.miss();
currentTarget = null;
}
}, TARGET_LIFETIME);
}
// Helper: show feedback text at center
function showFeedback(text, color) {
feedbackTxt.setText(text);
feedbackTxt.style.fill = '#' + color.toString(16).padStart(6, '0');
feedbackTxt.visible = true;
feedbackTxt.alpha = 1;
tween(feedbackTxt, {
alpha: 0
}, {
duration: 500,
easing: tween.cubicOut,
onFinish: function onFinish() {
feedbackTxt.visible = false;
}
});
}
// Helper: schedule next target after a short delay
function scheduleNextTarget() {
if (targetTimeout) LK.clearTimeout(targetTimeout);
targetTimeout = LK.setTimeout(function () {
if (gameActive) spawnTarget();
}, TARGET_SPAWN_DELAY);
}
// Start the game
function startGame() {
score = 0;
LK.setScore(0);
scoreTxt.setText('0');
timeLeft = GAME_TIME;
timerTxt.setText(timeLeft + '');
feedbackTxt.visible = false;
gameActive = true;
// Remove any lingering target
if (currentTarget) {
currentTarget.destroy();
currentTarget = null;
}
// Start timer
if (timerInterval) LK.clearInterval(timerInterval);
timerInterval = LK.setInterval(function () {
if (!gameActive) return;
timeLeft -= 0.1;
if (timeLeft < 0) timeLeft = 0;
timerTxt.setText(Math.ceil(timeLeft) + '');
if (timeLeft <= 0) {
endGame();
}
}, 100);
// Spawn first target
spawnTarget();
}
// End the game
function endGame() {
gameActive = false;
if (timerInterval) LK.clearInterval(timerInterval);
if (targetTimeout) LK.clearTimeout(targetTimeout);
if (currentTarget) {
currentTarget.destroy();
currentTarget = null;
}
// Show game over (handled by LK)
LK.showGameOver();
}
// Game tap handler: if tap is not on a target, show miss feedback
game.down = function (x, y, obj) {
if (!gameActive) return;
// If tap is not on the target, count as miss
if (currentTarget) {
// Convert tap to target local coordinates
var local = currentTarget.toLocal(game.toGlobal({
x: x,
y: y
}));
var dx = local.x;
var dy = local.y;
var r = currentTarget.size / 2;
if (dx * dx + dy * dy > r * r) {
// Missed the target
currentTarget.miss();
currentTarget = null;
}
// else: handled by target.down
}
};
// Start game on first frame
LK.setTimeout(function () {
startGame();
}, 200);
// Clean up on game over (reset state)
game.on('destroy', function () {
gameActive = false;
if (timerInterval) LK.clearInterval(timerInterval);
if (targetTimeout) LK.clearTimeout(targetTimeout);
if (currentTarget) {
currentTarget.destroy();
currentTarget = null;
}
});
// No need for update loop for MVP
// Prevent elements in top-left 100x100
// (Handled by spawnTarget margin and minY)