Code edit (1 edits merged)
Please save this source code
User prompt
in popupMultiplier, don't use scale, use width and height
Code edit (1 edits merged)
Please save this source code
User prompt
call popupMultiplier(value, x, y) at each bounce
Code edit (2 edits merged)
Please save this source code
User prompt
in popupMultiplier, popup the x2 asset at the position x,y. start at with,heigth 1x1 and make it grow until 1024x1024
User prompt
in popupMultiplier, check if value is in possibleValues, if not set it to 999;
Code edit (5 edits merged)
Please save this source code
User prompt
flash the ball at each bounce
User prompt
flash the screen at each bounce
Code edit (7 edits merged)
Please save this source code
User prompt
move the hoop after a shoot even if not scored
Code edit (1 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
don't accept other touch while ball is moving
Code edit (5 edits merged)
Please save this source code
User prompt
reduce ball speed when launched
User prompt
reduce ball speed
Code edit (6 edits merged)
Please save this source code
User prompt
in LK.on('tick', ), after ball.update();, calculate distance between ball and hoop
Code edit (1 edits merged)
Please save this source code
User prompt
in initGame, if !isDebug, set alpha of hoopTriggers to 0
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: handleHoopBorder is not defined' in or related to this line: 'handleHoopBorder();' Line Number: 341
Code edit (3 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -68,9 +68,9 @@
ball.speedX *= -1 * self.wallBounceSpeedRatio;
bounceCounter += 1; // Increment bounce counter
}
// Reset ball when in bottom and its speed is very low
- if (ball.y > game.height * 0.75 && Math.abs(self.speedX) < 1 && Math.abs(self.speedY) < 1) {
+ if (ball.y > game.height * 0.6 && Math.abs(self.speedX) < 5 && Math.abs(self.speedY) < 5) {
self.reset();
}
};
self.reset = function () {
@@ -233,8 +233,9 @@
if (startPosition && !ball.isMoving) {
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);
+ console.log("============================= SHOOT ===========================");
ball.launch(speedX, speedY);
startPosition = null;
}
});
@@ -309,26 +310,18 @@
ballPassedInsideHoop = false;
}
}
function handleHoopBorder(border) {
- console.log("handleHoopBorder ");
+ console.log("handleHoopBorder");
border.isHandling = true;
- // Calcul du vecteur normal
- var dx = ball.x - border.x;
- var dy = ball.y - border.y;
- var normal = normalize({
- x: dx,
- y: dy
- });
- // Calcul du vecteur de réflexion
- var dot = ball.speedX * normal.x + ball.speedY * normal.y;
- var reflection = {
- x: ball.speedX - 2 * dot * normal.x,
- y: ball.speedY - 2 * dot * normal.y
- };
- // Mise à jour de la vitesse de la balle
- ball.speedX = reflection.x * ball.wallBounceSpeedRatio;
- ball.speedY = reflection.y * ball.wallBounceSpeedRatio;
+ // 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
+ }
}
function resetCollisionHandling() {
//console.log("resetCollisionHandling...");
hoop.hoopTopTrigger.isHandling = false;
@@ -361,9 +354,9 @@
confetti.y = 0;
LK.on('tick', function () {
confetti.animate(); // Animate confetti
});
- // Initiate gradual movement of the hoop to a new random position within the game boundaries
+ // Initiate gradual movement of the hoop to a new random position within the game boundaries after every shoot
var targetX = Math.random() * (game.width - hoop.width) + hoop.width / 2;
var targetY = Math.max(Math.random() * (game.height / 2) + 100, 780); // Ensure hoop's Y position does not go below 780
var moveHoopInterval = LK.setInterval(function () {
hoop.x += (targetX - hoop.x) * 0.05; // Move 5% of the distance per tick
@@ -371,13 +364,26 @@
// Check if the hoop is close enough to the target position to stop
if (Math.abs(hoop.x - targetX) < 1 && Math.abs(hoop.y - targetY) < 1) {
hoop.setPosition(targetX, targetY); // Ensure hoop is exactly at target position
LK.clearInterval(moveHoopInterval); // Stop the interval
- console.log("Ok can handle score...");
+ console.log("Hoop moved to new position after shoot...");
isHandlingScore = false;
resetCollisionHandling();
}
}, 16); // Run every 16ms (~60FPS)
+ // Move the hoop after every shoot, regardless of scoring
+ game.on('up', function (obj) {
+ if (startPosition && !ball.isMoving) {
+ 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);
+ console.log("============================= SHOOT ===========================");
+ ball.launch(speedX, speedY);
+ startPosition = null;
+ // Trigger hoop movement after a shoot
+ handleScore();
+ }
+ });
/*
LK.setTimeout(function () {
isHandlingScore = false;
resetCollisionHandling();
@@ -393,21 +399,17 @@
}
ball.update();
if (!hoop.hoopBorderLeft.isHandling && ball.intersects(hoop.hoopBorderLeft)) {
handleHoopBorder(hoop.hoopBorderLeft);
- return;
}
if (!hoop.hoopBorderRight.isHandling && ball.intersects(hoop.hoopBorderRight)) {
handleHoopBorder(hoop.hoopBorderRight);
- return;
}
if (!hoop.hoopTopTrigger.isHandling && ball.intersects(hoop.hoopTopTrigger)) {
handleTopTrigger();
- return;
}
if (!hoop.hoopBottomTrigger.isHandling && ball.intersects(hoop.hoopBottomTrigger)) {
handleBottomTrigger();
- return;
}
// Calculate distance between ball and hoop
var distanceX = ball.x - hoop.x;
var distanceY = ball.y - hoop.y;