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
===================================================================
--- original.js
+++ change.js
@@ -1,91 +1,91 @@
-/****
+/****
* 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: 100,
- // Initial width
- height: 100,
- // 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
- });
+ 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
+ });
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize score and targets array
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"
+ 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);
- }
+ 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
- }
- });
- // End game when time is up
- if (Date.now() >= gameEndTime) {
- LK.showGameOver();
- }
+ // 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
+ }
+ });
+ // End game when time is up
+ if (Date.now() >= gameEndTime) {
+ 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);
+ LK.clearInterval(spawnTimer);
});
\ No newline at end of file