Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -211,9 +211,9 @@
var currentShootBuckets = 0;
var maxSpeed = 100;
var ballPassedAboveHoop = false;
var ballPassedInsideHoop = false;
-var timerSeconds = 60; // Set the initial timer value in seconds
+var timerSeconds = 11; // 60; // Set the initial timer value in seconds
var ball = null;
var hoop = null;
var score = 0;
var startPosition = null;
@@ -221,13 +221,15 @@
// UI
var background = null;
var scoreTxt = null;
var timerTxt = null;
+var timerLabelTxt = null;
var minShootSpeed = 30;
var timerInterval = null;
-var timerOriginalWeigth = 94; // 1 number
+var timerOriginalWeigth = 94; // 1 char
var timerOriginalHeight = 174;
var isScoreAnimating = false;
+var scoreAnimationInterval = null;
var previousScore = 0;
var originalScoreWidth = 94;
var originalScoreHeight = 174;
/* ********************************************************************************* */
@@ -245,9 +247,9 @@
var endPosition = obj.event.getLocalPosition(game);
var speedX = Math.max(Math.min((endPosition.x - startPosition.x) * 0.1, maxSpeed), -maxSpeed);
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 ===========================");
+ //console.log("============================= SHOOT ===========================");
currentShootBuckets = 0;
ball.launch(speedX, speedY);
}
startPosition = null;
@@ -280,12 +282,12 @@
fill: "#006400",
weight: 1000,
dropShadow: true
});
- scoreTxt.anchor.set(0.5, -0.250);
+ scoreTxt.anchor.set(0.5, -0.150);
LK.gui.top.addChild(scoreTxt);
// Timer UI
- var timerLabelTxt = new Text2('Time', {
+ timerLabelTxt = new Text2('Time', {
size: 50,
fill: "#FFFFFF",
weight: 1000,
dropShadow: true
@@ -299,12 +301,10 @@
weight: 1000,
dropShadow: true
});
timerTxt.tint = timerSeconds <= 5 ? 0xff0000 : 0x646464;
- timerTxt.anchor.set(1.15, -0.250);
+ timerTxt.anchor.set(1.10, -0.150);
LK.gui.topRight.addChild(timerTxt);
- console.log("timerOriginalWeigth", timerOriginalWeigth);
- console.log("timerOriginalHeight", timerOriginalHeight);
// Update the timer every second
timerInterval = LK.setInterval(handleTimer, 1000); // Set the interval to update every 1000ms (1 second)
ball = game.addChild(new Ball());
ball.reset();
@@ -324,11 +324,15 @@
}
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 < 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;
@@ -341,8 +345,9 @@
timerTxt.tint = 0x646464;
}
if (timerSeconds <= 0) {
timerTxt.tint = 0x646464;
+ timerLabelTxt.tint = 0x646464;
timerTxt.width = timerOriginalWeigth;
timerTxt.height = timerOriginalHeight;
LK.clearInterval(animateTimer);
LK.clearInterval(timerInterval); // Stop the timer when it reaches 0
@@ -350,42 +355,42 @@
LK.showGameOver(); // Show game over screen
}
}
function handleTopTrigger() {
- console.log("Top trigger. speed", ball.speedY);
+ //console.log("Top trigger. speed", ball.speedY);
hoop.hoopTopTrigger.isHandling = true;
if (ball.speedY > 0) {
ballPassedAboveHoop = true;
}
}
function handleBottomTrigger() {
- console.log("Bottom trigger", ball.speedY.toFixed(2), ball.x.toFixed(2), hoop.hoopBorderLeft.x.toFixed(2), hoop.hoopBorderRight.x.toFixed(2));
+ //console.log("Bottom trigger", ball.speedY.toFixed(2), ball.x.toFixed(2), hoop.hoopBorderLeft.x.toFixed(2), hoop.hoopBorderRight.x.toFixed(2));
hoop.hoopBottomTrigger.isHandling = true;
var leftBorderX = hoop.x + hoop.hoopBorderLeft.x;
var rightBorderX = hoop.x + hoop.hoopBorderRight.x;
if (ballPassedAboveHoop && ball.x > leftBorderX && ball.x < rightBorderX) {
if (ball.speedY > 0) {
- console.log("--------------- SCORE!!! -----------------");
+ //console.log("--------------- SCORE!!! -----------------");
ballPassedInsideHoop = true;
handleScore();
}
} else if (ball.speedY < 0) {
- console.log("touch hoop from bottom");
+ //console.log("touch hoop from bottom");
ball.speedY *= -0.98;
ballPassedAboveHoop = false;
ballPassedInsideHoop = false;
}
}
function handleHoopBorder(border) {
- console.log("handleHoopBorder");
+ //console.log("handleHoopBorder");
border.isHandling = true;
// Check if the ball has hit the left or right border
if (ball.x <= border.x || ball.x >= border.x + border.width) {
ball.speedX *= -1; // Reverse the x direction
}
// Check if the ball has hit the top or bottom border
if (ball.y <= border.y || ball.y >= border.y + border.height) {
- //ball.speedY *= -1; // Reverse the y direction
+ //ball.speedY *= -1; // Reverse the y direction ???
}
}
function resetCollisionHandling() {
//console.log("resetCollisionHandling...");
@@ -405,16 +410,15 @@
function handleScore() {
if (isHandlingScore) {
return;
}
- console.log("handleScore...bounceMultiplier=", bounceMultiplier, "*", currentShootBuckets);
+ //console.log("handleScore...bounceMultiplier=", bounceMultiplier, "*", currentShootBuckets);
isHandlingScore = true;
currentShootBuckets++;
- score += 10 * bounceMultiplier + 10 * bounceMultiplier * (currentShootBuckets - 1); // Add bounce counter to score
+ score += 10 * bounceMultiplier + 10 * bounceMultiplier * (currentShootBuckets - 1) * (currentShootBuckets - 1); // Add bounce counter to score
scoreTxt.setText(score.toString());
animateScore();
- popupBucket(currentShootBuckets > 1);
- //ball.reset();
+ popupBucket(currentShootBuckets - 1);
ballPassedAboveHoop = false; // Reset the condition after scoring
ballPassedInsideHoop = false;
// Create and add confetti effect to the game
var confetti = game.addChild(new Confetti());
@@ -439,9 +443,9 @@
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 () {
+ 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) {
@@ -517,9 +521,9 @@
function popupBucket(isCombo) {
console.log("popupBucket", isCombo);
var popupSpeed = 60;
var popupMaxSize = isCombo ? 4096 : 2048;
- var assetName = isCombo ? 'superCombo' : 'bucket';
+ var assetName = isCombo > 1 ? 'megaCombo' : isCombo ? 'superCombo' : 'bucket';
var bucketAsset = LK.getAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5,
x: game.width / 2,
@@ -554,16 +558,16 @@
// Don't show while game is running
if (isGameRunning) {
return;
}
+ // Start at the ball's position
var startX = ball.x;
var startY = ball.y - 400;
// Create and configure the swipe asset
var swipeAsset = LK.getAsset('swipe', {
anchorX: 0.5,
anchorY: 0.5,
x: startX,
- // Start at the ball's position
y: startY
});
game.addChild(swipeAsset);
// Animate the swipe asset moving towards the center of the screen
@@ -640,11 +644,9 @@
var distanceY = ball.y - hoop.y;
var distance = Math.sqrt(distanceX * distanceX + distanceY * distanceY);
//console.log("Distance between ball and hoop:", distance);
if (distance > 350) {
- // ~hoop heigth/2 + ball/heigth/2
isHandlingScore = false;
resetCollisionHandling();
}
- //scoreTxt.setText(ball.speedY.toFixed(2));
});
initGame();
\ No newline at end of file