===================================================================
--- original.js
+++ change.js
@@ -75,17 +75,20 @@
// Check for collisions with top and bottom boundaries
if (ball.y - ball.radius <= 0 || ball.y + ball.radius >= game.height) {
ball.velocity.y *= -1;
}
- // Gravity effect from planet
+ // Enhanced gravity effect from planet
var dx = planet.x - ball.x;
var dy = planet.y - ball.y;
var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance < planet.radius + ball.radius) {
- // Simple gravity effect
- var gravity = planet.mass / (distance * distance);
- var gravityX = dx / distance * gravity;
- var gravityY = dy / distance * gravity;
+ var influenceZone = planet.radius * 3; // Define an influence zone where gravity starts affecting the ball
+ if (distance < influenceZone) {
+ // Calculate gravity force with a stronger effect when closer to the planet
+ var gravityStrength = planet.mass / (distance * distance);
+ var normalizedDistance = (influenceZone - distance) / influenceZone;
+ var gravityForce = gravityStrength * normalizedDistance;
+ var gravityX = dx / distance * gravityForce;
+ var gravityY = dy / distance * gravityForce;
ball.velocity.x += gravityX;
ball.velocity.y += gravityY;
}
// Reset ball if it goes off screen
plasma barrier. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
neutron star. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
neutron star, pulsar. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cat eye nebula, cartoon style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
flying saucer, cartoon style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
erase