Code edit (3 edits merged)
Please save this source code
User prompt
place the timer under the score
User prompt
add a start text on top of the button, center it on the button
Code edit (1 edits merged)
Please save this source code
User prompt
if count down is NaN display 30
User prompt
if count down is NaN display 0
User prompt
if the count down hits 0 game over
User prompt
make the timer an text object
User prompt
add a count down from 30 seconds that starts on game start
User prompt
add a start game button
User prompt
fix the timer so that it updates
User prompt
the timers beginning value should be 30 seconds
User prompt
the timer should use the duration of the var gameduration
User prompt
set the timer to 30 seconds
User prompt
the timer should be a text element
User prompt
expand the game
Code edit (1 edits merged)
Please save this source code
Initial prompt
aim trainer v2
/**** * Classes ****/ // Assets will be automatically created based on usage in the code. // Target class var Target = Container.expand(function () { var self = Container.call(this); // Initialize target with a shape asset var targetGraphics = self.attachAsset('target', { anchorX: 0.5, anchorY: 0.5, shape: 'ellipse', width: 200, // Initial width height: 200, // Initial height color: 0xff0000 // Red color }); // Method to decrease the size of the target self.shrink = function () { if (targetGraphics.width > 20 && targetGraphics.height > 20) { // Minimum size check targetGraphics.width -= 1; targetGraphics.height -= 1; } else { self.destroy(); // Destroy target if it's too small } }; // Method to handle target click self.on('down', function () { LK.setScore(LK.getScore() + 1); // Increase score self.destroy(); // Destroy target after click }); }); // Timer class var Timer = Container.expand(function () { var self = Container.call(this); // Initialize timer with a text asset var timerGraphics = new Text2('30', { size: 50, fill: "#ffffff" }); self.addChild(timerGraphics); timerGraphics.anchor.set(0.5, 0.5); timerGraphics.x = self.width / 2; timerGraphics.y = self.height / 2; // Method to decrease the timer self.tick = function () { if (parseInt(timerGraphics.text) > 0) { timerGraphics.text = (parseInt(timerGraphics.text) - 1).toString(); } else { self.destroy(); // Destroy timer if it's 0 } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize timer var timer = new Timer(); timer.x = 2048 / 2; // Center the timer horizontally timer.y = 50; // Position the timer at the top of the screen game.addChild(timer); // Add timer to the game var targets = []; var gameDuration = 30000; // 30 seconds in milliseconds var targetSpawnInterval = 500; // 0.5 seconds in milliseconds var gameEndTime = Date.now() + gameDuration; // Calculate game end time // Create score display var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); LK.gui.top.addChild(scoreTxt); // Add score display to the top-center of the screen // Function to spawn targets function spawnTarget() { if (Date.now() < gameEndTime) { // Check if game time is not over var target = new Target(); // Random position within game area target.x = Math.random() * (2048 - 100) + 50; // Avoid spawning on the edges target.y = Math.random() * (2732 - 100) + 50; // Avoid spawning on the edges game.addChild(target); targets.push(target); } } // Game tick event LK.on('tick', function () { // Update score display scoreTxt.setText(LK.getScore().toString()); // Shrink targets targets.forEach(function (target, index) { target.shrink(); if (!target.parent) { // Check if target has been destroyed targets.splice(index, 1); // Remove target from array } }); // Update timer every second if (LK.ticks % 60 == 0) { timer.tick(); } // End game when timer is 0 if (!timer.parent) { LK.showGameOver(); } }); // Spawn targets at intervals var spawnTimer = LK.setInterval(spawnTarget, targetSpawnInterval); // Clear interval on game over to stop spawning targets LK.on('gameOver', function () { LK.clearInterval(spawnTimer); });
===================================================================
--- original.js
+++ change.js
@@ -35,17 +35,16 @@
// Timer class
var Timer = Container.expand(function () {
var self = Container.call(this);
// Initialize timer with a text asset
- var timerGraphics = self.attachAsset('timer', {
- anchorX: 0.5,
- anchorY: 0.5,
- text: '30',
- style: {
- fill: '#ffffff',
- fontSize: 50
- }
+ var timerGraphics = new Text2('30', {
+ size: 50,
+ fill: "#ffffff"
});
+ self.addChild(timerGraphics);
+ timerGraphics.anchor.set(0.5, 0.5);
+ timerGraphics.x = self.width / 2;
+ timerGraphics.y = self.height / 2;
// Method to decrease the timer
self.tick = function () {
if (parseInt(timerGraphics.text) > 0) {
timerGraphics.text = (parseInt(timerGraphics.text) - 1).toString();