===================================================================
--- original.js
+++ change.js
@@ -81,11 +81,9 @@
self.y = game.height - 300;
self.speedX = 0;
self.speedY = 0;
self.isMoving = false;
- if (isGameOver) {
- isLastShotEnded = true;
- }
+ isLastShotEnded = true;
};
});
/* ********************************************************************************* */
/* ******************************** CONFETTI CLASS ********************************* */
@@ -214,9 +212,9 @@
var currentShootBuckets = 0;
var maxSpeed = 100;
var ballPassedAboveHoop = false;
var ballPassedInsideHoop = false;
-var timerSeconds = 6; // Set the initial timer value in seconds
+var timerSeconds = 60; // Set the initial timer value in seconds
var ball = null;
var hoop = null;
var score = 0;
var startPosition = null;
@@ -245,11 +243,8 @@
return;
}
var pos = obj.event.getLocalPosition(game);
startPosition = pos;
- if (!isGameRunning) {
- isGameRunning = true;
- }
});
game.on('up', function (obj) {
if (isGameOver) {
return;
@@ -260,8 +255,12 @@
var speedY = Math.max(Math.min((endPosition.y - startPosition.y) * 0.1, maxSpeed), -maxSpeed);
if (Math.abs(speedX) >= minShootSpeed || Math.abs(speedY) >= minShootSpeed) {
//console.log("============================= SHOOT ===========================");
currentShootBuckets = 0;
+ isLastShotEnded = false;
+ if (!isGameRunning) {
+ isGameRunning = true;
+ }
ball.launch(speedX, speedY);
}
startPosition = null;
}
@@ -332,38 +331,49 @@
function handleTimer() {
if (!isGameRunning) {
return;
}
- timerSeconds -= 1; // Decrement the timer by one second
+ //timerSeconds -= 1; // Decrement the timer by one second
+ timerSeconds -= 1;
+ timerSeconds = timerSeconds < 0 ? 0 : timerSeconds;
timerTxt.setText(timerSeconds.toString()); // Update the timer display with conditional color change
- var animateTimer = null;
- if (timerSeconds < 10) {
- timerTxt.anchor.set(1.6, -0.150);
- }
- if (timerSeconds <= 5 && timerSeconds > 0) {
- var maxTimerLabelSize = 200 + (5 - timerSeconds) * 20;
- timerTxt.tint = 0xff0000;
- timerLabelTxt.tint = 0xff0000;
- // Animate timerTxt width and height
- var growDirection = 1;
- animateTimer = LK.setInterval(function () {
- timerTxt.width += growDirection * 4;
- timerTxt.height += growDirection * 4;
- if (timerTxt.width >= maxTimerLabelSize || timerTxt.height >= maxTimerLabelSize || timerTxt.width <= 100 || timerTxt.height <= 100) {
- growDirection *= -1;
+ if (!isGameOver) {
+ var animateTimer = null;
+ if (timerSeconds > 0) {
+ if (timerSeconds > 5) {
+ timerTxt.tint = 0x646464;
}
- }, 16); // Run every 16ms (~60FPS)
- } else {
- timerTxt.tint = 0x646464;
+ if (timerSeconds < 10) {
+ timerTxt.anchor.set(1.6, -0.150);
+ }
+ if (timerSeconds <= 5) {
+ var maxTimerLabelSize = 200 + (5 - timerSeconds) * 20;
+ timerTxt.tint = 0xff0000;
+ timerLabelTxt.tint = 0xff0000;
+ // Animate timerTxt width and height
+ var growDirection = 1;
+ animateTimer = LK.setInterval(function () {
+ if (timerSeconds <= 0) {
+ LK.clearInterval(animateTimer);
+ return;
+ }
+ timerTxt.width += growDirection * 4;
+ timerTxt.height += growDirection * 4;
+ if (timerTxt.width >= maxTimerLabelSize || timerTxt.height >= maxTimerLabelSize || timerTxt.width <= 100 || timerTxt.height <= 100) {
+ growDirection *= -1;
+ }
+ }, 16); // Run every 16ms (~60FPS)
+ }
+ }
+ if (timerSeconds <= 0) {
+ timerTxt.tint = 0x646464;
+ timerLabelTxt.tint = 0x646464;
+ timerTxt.width = timerOriginalWeigth;
+ timerTxt.height = timerOriginalHeight;
+ LK.clearInterval(animateTimer);
+ isGameOver = true;
+ }
}
- if (timerSeconds <= 0) {
- timerTxt.tint = 0x646464;
- timerLabelTxt.tint = 0x646464;
- timerTxt.width = timerOriginalWeigth;
- timerTxt.height = timerOriginalHeight;
- LK.clearInterval(animateTimer);
- isGameOver = true;
- }
if (isGameOver && isLastShotEnded) {
LK.clearInterval(timerInterval); // Stop the timer when it reaches 0
LK.setScore(score); // Save the final score using the platform's tool
LK.showGameOver(); // Show game over screen
@@ -529,9 +539,9 @@
}
}, 1); // Run every 16ms (~60FPS)
}
function popupBucket(isCombo) {
- console.log("popupBucket", isCombo);
+ //console.log("popupBucket", isCombo);
var popupSpeed = 60;
var popupMaxSize = isCombo ? 4096 : 2048;
var assetName = isCombo > 1 ? 'megaCombo' : isCombo ? 'superCombo' : 'bucket';
var bucketAsset = LK.getAsset(assetName, {
@@ -577,9 +587,11 @@
var swipeAsset = LK.getAsset('swipe', {
anchorX: 0.5,
anchorY: 0.5,
x: startX,
- y: startY
+ y: startY,
+ tint: 0xff0000,
+ alpha: 0
});
game.addChild(swipeAsset);
// Animate the swipe asset moving towards the center of the screen
var targetY = game.height / 2;
@@ -589,9 +601,12 @@
targetXIndex = (targetXIndex + 1) % targetXValues.length;
targetX = targetXValues[targetXIndex];
LK.on('tick', function () {
if (isGameRunning) {
- swipeAsset.destroy();
+ if (swipeAsset) {
+ swipeAsset.destroy();
+ swipeAsset = null;
+ }
return;
}
// Update targetX at the beginning of each tick if necessary
var directionX = targetX - swipeAsset.x;
@@ -611,8 +626,12 @@
targetX = targetXValues[targetXIndex];
swipeAsset.x = startX + (targetX - game.width * 0.5) / 2;
swipeAsset.y = startY;
}
+ if (swipeAsset.alpha == 0) {
+ swipeAsset.tint = 0xffFFFF;
+ swipeAsset.alpha = 1;
+ }
});
}
/* ********************************************************************************* */
/* ********************************** MAIN LOOP ************************************ */