CoodeVerse Physics Ball Bounce Game is a free, downloadable HTML5 Canvas JavaScript physics game. Features: realistic gravity simulation (vy += 0.5 per frame), bounce coefficient 0.75, air friction 0.99, glowing trail effects (15-position trail array), radial gradient ball rendering with shine, 3-lives system, score tracking, start and game-over screens, requestAnimationFrame game loop, and full touch/mouse event support. Built with zero JavaScript libraries or frameworks — pure vanilla HTML CSS JS. Free to download, modify, and use. Perfect for learning JavaScript game development, HTML5 Canvas physics, and requestAnimationFrame animation.
Free
Physics Ball Bounce Game updated for 2026 — play in browser, download ZIP, full Canvas JS source →
Play & Download →
The CoodeVerse Physics Ball Bounce Game is a free, playable and downloadable HTML5 Canvas physics game built with pure vanilla JS. Click or tap to launch colourful balls from the screen — each obeys realistic gravity, bounce (coefficient 0.75), and air friction. Balls leave glowing trail effects and are rendered with radial gradient shine. You have 3 lives — lose one each time a ball exits the bottom. Full source code is free to download with no sign-up required.
Tech Stack
HTML5 Canvas + JS
Price
$0 — Free Forever
Libraries
None — Vanilla only
Lives
3 per game
Controls
Mouse + Touch
Sign-up
None required
Welcome! CoodeVerse Physics Ball Bounce Game is 100% free — full HTML CSS JS Canvas source code, no sign-up, instant download.
Free Physics Ball Bounce Game — HTML CSS JS Canvas with Gravity, Trail Effects & Lives System
Free downloadable HTML5 Canvas physics ball bounce game. Built with vanilla JavaScript — realistic gravity, bounce coefficient 0.75, friction, glowing trail effects, radial gradient balls, 3 lives system, score tracking, and touch/mouse controls. No libraries. Download full source code free.
Physics Ball Bounce Game
Updated March 2026
Windows Tip: After downloading the ZIP, right-click the folder → Properties → check "Unblock" (if visible) → Apply → OK. This removes the "file came from another computer" warning so everything works perfectly!
Applied each frame: vy += 0.5. Velocity increases downward every frame, mimicking Earth's gravitational acceleration. Adjust the value to change how "heavy" balls feel.
Bounce Coefficient
bounce = 0.75 — multiplied when a ball hits a wall or ceiling, reversing and reducing velocity. 0.75 means 75% energy retained — realistic gradual decay.
Air Friction
vx *= 0.99 / vy *= 0.99 — multiplied each frame to simulate air resistance, slowly bringing balls to rest horizontally.
Trail Effect
Past positions stored in this.trail[] (max 15). Redrawn each frame with decreasing opacity and radius, creating the glowing comet trail.
Radial Gradient
ctx.createRadialGradient() with a white highlight point at (x-10, y-10) fading to the ball's colour — produces the shiny 3D sphere effect.
requestAnimationFrame
The animate() function calls itself via requestAnimationFrame — syncs to 60fps display refresh, pauses when tab is hidden, and is smoother than setInterval.
How to Build a Physics Ball Bounce Game in JavaScript
1
Create a full-screen HTML5 Canvas
Add <canvas id="canvas"> to HTML. Set body { margin:0; overflow:hidden; }. Use a resize function to match canvas width/height to window dimensions.
2
Build the Ball class
Define a Ball class with x, y, vx, vy, radius, color, trail[]. Add update() for physics and draw() for rendering.
3
Implement physics in update()
Each frame: vy += gravity, vx *= friction, x += vx, y += vy. Detect wall and ceiling collisions, reverse velocity with bounce multiplier. Check if ball fell off bottom.
4
Draw with radial gradient and trail
Push position to trail array each frame. Draw trail as fading transparent circles. Use createRadialGradient for the shiny ball. Add a small white arc for the shine spot.
5
Add game loop and controls
Call requestAnimationFrame(animate) for the smooth 60fps loop. Listen for click and touchstart to launch balls. Use Math.atan2 to calculate launch angle toward the click point.
Create a Canvas element, get its 2D context, then in a requestAnimationFrame loop: apply gravity (vy += 0.5), update position (x += vx, y += vy), detect wall collisions (if x < radius or x > canvas.width - radius, reverse vx), and draw the ball with ctx.arc(). Multiply velocity by a bounce coefficient (0.75) on each collision to simulate energy loss.
A game loop is a function that runs repeatedly to update game state and redraw the screen. The best approach in JavaScript is requestAnimationFrame(animate) — it runs before each browser repaint (60fps), pauses when the tab is hidden to save resources, and produces smoother animation than setInterval or setTimeout.
Listen for the touchstart event on the canvas: canvas.addEventListener("touchstart", handler). In the handler, read touch coordinates from e.touches[0].clientX and e.touches[0].clientY. Also add touch-action: none to the body CSS to prevent default scroll behaviour. The CoodeVerse Physics Ball Bounce Game supports both touch and click events.
Gravity is simulated by adding a constant value to the vertical velocity (vy) each frame — e.g. vy += 0.5. This causes vertical velocity to increase every frame, making objects accelerate downward just like real gravity. Combined with friction and a bounce coefficient, it produces realistic ball physics.
Yes. The CoodeVerse Physics Ball Bounce Game is a beginner-to-intermediate JavaScript project. It demonstrates core Canvas API concepts, OOP with classes, physics simulation, game state management, and event handling. Pair it with CoodeVerse's free JavaScript course for full understanding.
Frequently Asked Questions
Is this physics ball game free to download?
Yes. 100% free — no account, no payment, no sign-up. Download the full ZIP and use it for any personal or commercial project under CC BY 4.0.
What does the bounce coefficient 0.75 mean?
When a ball hits a wall or ceiling, its velocity is reversed and multiplied by 0.75 — meaning it retains 75% of its speed after each bounce. This simulates energy loss realistically, causing balls to gradually come to rest rather than bouncing forever.
How do I change the ball colours?
Edit the colors array in the launchBall function: ["#ff6b6b","#4ecdc4","#45b7d1","#f9ca24","#f3722c","#5f27cd"]. Replace any hex values with your preferred colours. Each ball randomly picks from this array on launch.
How do I add more lives to the game?
Change let lives = 3 to any number in both the variable declaration and the startGame() reset function. The UI will automatically display the updated count.
Can I add sound effects to this game?
Yes. Use the Web Audio API: create an AudioContext, generate oscillator nodes for bounce and launch sounds. Alternatively use new Audio('sound.mp3').play() in the collision detection section of update().
How do I make balls collide with each other?
Add a ball-vs-ball collision check: loop all ball pairs, calculate distance between centres using Math.hypot(b1.x-b2.x, b1.y-b2.y), and if distance < b1.radius + b2.radius, apply elastic collision velocity exchange formulas. This is an intermediate physics extension of this project.
Can this game be added to my portfolio?
Absolutely. This project demonstrates Canvas 2D API, OOP with JS classes, physics simulation, requestAnimationFrame game loops, and event handling — all highly valued frontend and game developer portfolio skills.
How do I increase gravity or make balls bouncier?
Increase gravity (e.g. 1.0) for heavier feel. Increase bounce (e.g. 0.9) for bouncier balls (closer to 1 = less energy loss). Decrease friction (e.g. 0.995) for balls that slide longer horizontally. Experiment with these three constants to completely change the game feel.