Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
in swipeAnim, separate the target setting and the asset movement
Code edit (6 edits merged)
Please save this source code
User prompt
in swipeAnim, update the rotation of the asset toward the target
User prompt
in swipeAnim, alternate the targetX each time between these values: 1*game.width *0.25 2*game.width *0.25 3*game.width *0.25
Code edit (1 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
implement swipeAnim, bt adding the swipe asset and make it move infinetly from ball to the center of the screen
Code edit (1 edits merged)
Please save this source code
User prompt
implement animateScore with wdith and height grow and restore of scoreTxt
Code edit (7 edits merged)
Please save this source code
User prompt
animate scoreTxt when player scores
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
add a little label "Score" above the scoreTxt
Code edit (1 edits merged)
Please save this source code
User prompt
in animateTimer make size bump
User prompt
in animateTimer make size increase then decrease each sec
User prompt
in handleTimer , when time is under 5, animate timerTxt width and height
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: timerInterval is not defined' in or related to this line: 'LK.clearInterval(timerInterval); // Stop the timer when it reaches 0' Line Number: 321
Code edit (2 edits merged)
Please save this source code
User prompt
in handleTimer , when timer is < 5,, change text fill to red
===================================================================
--- original.js
+++ change.js
@@ -225,14 +225,21 @@
var minShootSpeed = 30;
var timerInterval = null;
var timerOriginalWeigth = 94; // 1 number
var timerOriginalHeight = 174;
+var isScoreAnimating = false;
+var previousScore = 0;
+var originalScoreWidth = 94;
+var originalScoreHeight = 174;
/* ********************************************************************************* */
/* ******************************* INPUT HANDLERS ********************************** */
/* ********************************************************************************* */
game.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
startPosition = pos;
+ if (!isGameRunning) {
+ isGameRunning = true;
+ }
});
game.on('up', function (obj) {
if (startPosition && !ball.isMoving) {
var endPosition = obj.event.getLocalPosition(game);
@@ -308,11 +315,13 @@
hoop.hoopBorderLeft.alpha = 0;
hoop.hoopBorderRight.alpha = 0;
}
hoop.setPosition(game.width / 2, 1024); // Position the hoop at the top center
- isGameRunning = true;
}
function handleTimer() {
+ if (!isGameRunning) {
+ return;
+ }
timerSeconds -= 1; // Decrement the timer by one second
timerTxt.setText(timerSeconds.toString()); // Update the timer display with conditional color change
var animateTimer = null;
if (timerSeconds <= 5 && timerSeconds > 0) {
@@ -414,25 +423,38 @@
confetti.animate(); // Animate confetti
});
}
function animateScore() {
+ if (isScoreAnimating) {
+ LK.clearInterval(scoreAnimationInterval);
+ // Resotre previous score temporarly for correct size
+ scoreTxt.setText(previousScore.toString());
+ scoreTxt.width = originalScoreWidth;
+ scoreTxt.height = originalScoreHeight;
+ scoreTxt.setText(score.toString());
+ previousScore = score;
+ }
+ isScoreAnimating = true;
var scoreSizeDirection = 1;
- var originalScoreWidth = scoreTxt.width;
- var originalScoreHeight = scoreTxt.height;
- var maxScoreSize = 200; // Maximum size to grow to
- var minScoreSize = 150; // Minimum size to shrink to
+ originalScoreWidth = scoreTxt.width;
+ originalScoreHeight = scoreTxt.height;
+ var maxScoreSize = 300; // Maximum size to grow to
+ var minScoreSize = 100; // Minimum size to shrink to
var scoreAnimationInterval = LK.setInterval(function () {
scoreTxt.width += scoreSizeDirection * 5; // Adjust width by 5 pixels per frame
scoreTxt.height += scoreSizeDirection * 5; // Adjust height by 5 pixels per frame
// Reverse direction if the score text reaches max or min size
if (scoreTxt.width >= maxScoreSize || scoreTxt.height >= maxScoreSize || scoreTxt.width <= minScoreSize || scoreTxt.height <= minScoreSize) {
scoreSizeDirection *= -1;
}
// Restore original size and clear interval when animation is done
- if (scoreTxt.width === originalScoreWidth && scoreTxt.height === originalScoreHeight) {
+ if (scoreTxt.width <= originalScoreWidth && scoreTxt.height <= originalScoreHeight) {
LK.clearInterval(scoreAnimationInterval);
+ scoreTxt.width = originalScoreWidth;
+ scoreTxt.height = originalScoreHeight;
+ isScoreAnimating = false;
}
- }, 16); // Run every 16ms (~60FPS)
+ }, 20); // Run every 16ms (~60FPS)
}
function moveHoop() {
//console.log("moveHoop...");
// Initiate gradual movement of the hoop to a new random position within the game boundaries
@@ -526,8 +548,42 @@
}, 200);
}
}, 1); // Run every 16ms (~60FPS)
}
+function swipeAnim() {
+ // Don't show while game is running
+ if (isGameRunning) {
+ return;
+ }
+ // Create and configure the swipe asset
+ var swipeAsset = LK.getAsset('swipe', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: ball.x,
+ // Start at the ball's position
+ y: ball.y
+ });
+ game.addChild(swipeAsset);
+ // Animate the swipe asset moving towards the center of the screen
+ var targetX = game.width / 2;
+ var targetY = game.height / 2;
+ LK.on('tick', function () {
+ // Calculate the direction vector towards the center
+ var directionX = targetX - swipeAsset.x;
+ var directionY = targetY - swipeAsset.y;
+ var magnitude = Math.sqrt(directionX * directionX + directionY * directionY);
+ var normalizedDirectionX = directionX / magnitude;
+ var normalizedDirectionY = directionY / magnitude;
+ // Move the swipe asset towards the center
+ swipeAsset.x += normalizedDirectionX * 5; // Adjust speed as necessary
+ swipeAsset.y += normalizedDirectionY * 5;
+ // Reset position to ball's position if it reaches or overshoots the center
+ if (Math.abs(swipeAsset.x - targetX) < 5 && Math.abs(swipeAsset.y - targetY) < 5) {
+ swipeAsset.x = ball.x;
+ swipeAsset.y = ball.y;
+ }
+ });
+}
/* ********************************************************************************* */
/* ********************************** MAIN LOOP ************************************ */
/* ********************************************************************************* */
LK.on('tick', function () {