===================================================================
--- original.js
+++ change.js
@@ -21,15 +21,23 @@
if (self.isMoving) {
self.x += self.speedX;
self.y += self.speedY;
self.speedY += 0.98; // Gravity effect
- // Check for boundary collisions and reverse speed accordingly
+ // Check for boundary collisions, reverse speed, and lose points
if (self.x <= 0 || self.x >= game.width) {
self.speedX *= -1;
+ score -= 1; // Deduct points when hitting horizontal boundaries
+ scoreTxt.setText(score.toString()); // Update score display
}
- if (self.y <= 0 || self.y >= game.height) {
+ if (self.y <= 0) {
self.speedY *= -1;
+ score -= 1; // Deduct points when hitting the top boundary
+ scoreTxt.setText(score.toString()); // Update score display
}
+ // Allow the ball to fall off the bottom without reversing speed or losing points
+ if (self.y >= game.height) {
+ self.speedY *= -1;
+ }
}
};
self.reset = function () {
self.x = game.width / 2;