CoodeVerse Cannon Shooter Game is a free, downloadable HTML5 Canvas JavaScript game. Players aim a rotating cannon using Math.atan2, charge a visual power bar (power increments up to 100 on mouse/touch drag), then release to fire a cannonball with projectile motion (vx = Math.cos(angle)*speed, vy = Math.sin(angle)*speed, vy += 0.5 gravity per frame). Includes a 20-point trail effect drawn as a stroked path, 30-particle explosion system on target hit (Particle class with vx/vy, gravity, life decay), circle-circle collision detection with Math.hypot, level progression (targets = 2 + Math.floor(level/3)), score +100 per hit, start and game-over overlays, and full touch/mouse support. Built with zero JavaScript libraries. Free to download and modify.
Free
Cannon Shooter Game updated for 2026 — projectile physics, power bar, particle explosions →
Play & Download →
The CoodeVerse Cannon Shooter Game is a free, playable and downloadable HTML5 Canvas shooting game built with pure vanilla JS. Aim the rotating cannon with your mouse or touch, hold to charge the power bar, then release to fire a cannonball with realistic projectile motion (gravity + angle-based velocity). Hit all colourful targets to advance levels. Features a 20-point trail effect, 30-particle explosions on every hit, +100 score per target, and progressive level difficulty. Full source code is free to download — no sign-up required.
Tech Stack
HTML5 Canvas + JS
Price
$0 — Free Forever
Libraries
None — Vanilla only
Score / Target
+100 points
Controls
Mouse + Touch
Sign-up
None required
Welcome! CoodeVerse Cannon Shooter Game is 100% free — full HTML5 Canvas JS source, no sign-up, instant download.
Free Cannon Shooter Game — HTML5 Canvas JavaScript Projectile Physics, Power Bar, Particle Explosions & Level Progression
Free downloadable HTML5 Canvas cannon shooter game. Built with vanilla JavaScript — projectile motion physics, rotating cannon with ctx.rotate, hold-to-charge power bar, 20-point trail effect, 30-particle explosion system, circle collision with Math.hypot, progressive level system, score tracking, and touch/mouse controls. No libraries. Download full source code free.
Cannon Shooter Game Canvas
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!
Math.atan2(my-cannonY, mx-cannonX) calculates the angle in radians from the cannon to the mouse. ctx.rotate(angle) inside save/restore rotates the cannon barrel to always aim at the cursor.
Power Charge Bar
Increments power (max 100) while the mouse/touch is held. Final speed: 10 + power × 0.3 (range: 10–40 px/frame). CSS div width updates in real time to show charge level.
Projectile Motion
vx = Math.cos(angle) * speed, vy = Math.sin(angle) * speed, then each frame vy += 0.5 (gravity). This creates the parabolic arc of a real cannonball trajectory.
Trail Effect
Past cannonball positions stored in trail[] (max 20). Drawn each frame as a single ctx.stroke() path using moveTo / lineTo — efficient and visually smooth.
Collision Detection
Math.hypot(t.x - ball.x, t.y - ball.y) < t.size + 15 — the Pythagorean distance check for circle-circle overlap. Runs every frame for each active target.
Particle Explosion
30 Particle objects spawn at hit position with random vx/vy. Each frame: gravity applied, life -= 0.02, size *= 0.98. ctx.globalAlpha = life creates fade-out. Filtered out when life ≤ 0.
How to Build a Cannon Shooter Game in JavaScript
1
Set up Canvas and game state
Create a full-screen canvas, get the 2D context. Declare: score, level, angle, power, charging, cannonball, targets[], particles[], isPlaying.
2
Draw the rotating cannon
ctx.save(), ctx.translate(cannonX, cannonY), ctx.rotate(angle), draw barrel rectangles at origin, ctx.restore(). Update angle with Math.atan2 on mouse/touch move.
3
Implement hold-to-charge power bar
On mousedown/touchstart: set charging=true, power=0. On mousemove/touchmove: power = Math.min(power+2, 100), update CSS bar width. On release: call fire().
4
Fire and animate the cannonball
Set vx = Math.cos(angle) * speed, vy = Math.sin(angle) * speed. Each frame: vy += 0.5 (gravity), update position, push to trail[], draw trail as path and ball as filled circle.
5
Add targets, collision, particles, and levels
Spawn Target objects. Check collision with Math.hypot. On hit: spawn 30 Particle objects, increment score, call checkWin(). If all targets hit: advance level, spawn more targets.
Create a canvas, draw a cannon using ctx.save/translate/rotate/restore with Math.atan2 pointing at the mouse. On mousedown, start incrementing a power variable. On mouseup, fire a cannonball object with vx = Math.cos(angle)*speed and vy = Math.sin(angle)*speed. Each frame apply gravity (vy += 0.5) and check circle collision with targets using Math.hypot.
Projectile motion in JavaScript simulates an object launched at an angle and speed, then affected only by gravity. Set vx = Math.cos(angle)*speed and vy = Math.sin(angle)*speed at launch. Each animation frame: vy += gravity (typically 0.5), x += vx, y += vy. The result is a parabolic arc identical to real-world cannonball physics.
Use Math.atan2(mouseY - pivotY, mouseX - pivotX) to get the angle from the pivot to the mouse in radians. Then inside your draw function: ctx.save(), ctx.translate(pivotX, pivotY), ctx.rotate(angle), draw object centred at origin, ctx.restore(). Update the angle variable on each mousemove event.
Create a CSS div with fixed width and a coloured inner div. Set charging=true on mousedown, increment a power variable each frame or mousemove (capped at 100), update inner div width as power+"%". On mouseup, use power to calculate projectile speed and reset to 0. The CSS transition:width property animates the fill smoothly.
After all current targets are destroyed (checked with targets.every(t => t.hit)), increment the level counter and spawn a new set of targets. The Cannon Shooter Game uses count = 2 + Math.floor(level / 3) — so difficulty scales automatically. Display the level in a UI element that updates with each advance.
Frequently Asked Questions
Is this cannon game free to download?
Yes. 100% free — no account, payment, or sign-up. Download the full ZIP with HTML, CSS, and JS. Use and modify freely under CC BY 4.0.
How does the power bar fill speed differ on mobile?
On mouse: power += 2 per mousemove event. On touch: power += 3 per touchmove event (slightly faster to compensate for touch drag friction on mobile screens).
How do I change the cannon fire speed?
Edit the fire() function: const speed = 10 + power * 0.3. Increase the base (10) for faster minimum speed, or increase the multiplier (0.3) for more range between min and max power shots.
Can I add multiple cannonballs at once?
Yes. Change cannonball from a single object to an array cannonballs[]. In fire(), push new balls to the array. In animate(), loop through all active balls. This allows multi-shot, shotgun spread, or burst fire modes.
How do I add sound effects to the cannon game?
Use the Web Audio API to generate explosion and fire sounds. Create an AudioContext, use an OscillatorNode with a short burst for the fire sound, and a GainNode with a sharp attack and decay for explosion effects. Alternatively, use new Audio('boom.mp3').play() on target hit.
How do I make targets move?
Add this.vx = (Math.random() - 0.5) * 3 to the Target constructor. In draw() (or a separate update()), add this.x += this.vx and reverse direction when hitting screen edges: if(this.x < this.size || this.x > canvas.width - this.size) this.vx *= -1.
Can I add this game to my portfolio?
Absolutely. This project demonstrates canvas rotation transforms, projectile physics, particle systems, collision detection, event handling, and OOP with JavaScript classes — all highly valued skills for frontend and game developer portfolios.
What is the Math.hypot used for in this game?
Math.hypot(t.x - ball.x, t.y - ball.y) calculates the straight-line distance between two points using the Pythagorean theorem. If this distance is less than the sum of both radii (t.size + 15), the circles overlap — a collision has occurred. It's more readable than writing Math.sqrt(dx*dx + dy*dy) manually.