09. 【JavaScript】 I Built a Complete Shooting Game Using Only SVG (No Canvas)

tags: [JavaScript, SVG, Web, Beginner]


🎮 What Does It Do?

I built a complete mini shooting game using only SVG.

This is a DOM-friendly shooting game
for people who feel that “Canvas looks a bit intimidating…”.


🎮 Controls


🤔 Why SVG Instead of Canvas?

Canvas works by drawing pixels, which means:

It’s hard to interact with individual bullets or enemies afterward.

SVG, on the other hand, is DOM-based:

👉 For learning, teaching, and understanding game structure, SVG is extremely powerful.


🧩 Core Idea: DOM Manipulation (Example)

Bullets are created as <circle> elements,
and movement is achieved by simply updating coordinates (cx, cy).

const bullet = document.createElementNS(
  "http://www.w3.org/2000/svg",
  "circle"
);

bullet.setAttribute("cx", x);
bullet.setAttribute("cy", y);
bullet.setAttribute("r", 3);
svg.appendChild(bullet);

// Movement: just update `cy`
bullet.setAttribute("cy", y - 5);

💡 No redraw loop like Canvas is required.


▶️ Live Demo (Playable)

👇 Click here to play
https://samizo-aitl.github.io/qiita-articles/demos/svg-shooter/

Opens in a new tab


✅ Summary

Planned additions include:


🔜 Continuation of This Game

This article (09) focuses on showing that:

A complete game can be built using SVG (DOM) alone.

The series continues as follows:

👉 If you just want to play, jump straight to 12
👉 If you want to learn how it’s built, check out 10 / 11 as well