webdevpuneet.com

Space Blaster Game: Diving Aliens, Bosses and Power-Ups

Space Blaster Arcade Game · Games · Plain HTML, CSS & JS · Live preview

CategoryGames

About this UI Snippet

Space Blaster: Swooping Alien Formations, a Mothership Boss and Arcade Game Feel

Screenshot of the Space Blaster Arcade Game snippet rendered live

Space Blaster is a vertical arcade shooter in the style of Galaga: alien formations fly onto the screen along curved paths, sway in place, and break off one by one to dive-bomb your ship. This snippet builds the complete game on one HTML5 <canvas> with no libraries and no image files. It plays with the arrow keys or A and D and Space, with on-screen buttons, or by dragging a finger on the game, which moves the ship under your finger and fires automatically.

Formations that fly in, sway and dive

Every alien has a slot in a formation whose centre slowly drifts from side to side. A new wave starts with each alien following a quadratic Bézier curve from off-screen to its slot, staggered by a few hundredths of a second, so the formation streams in. Once in place, aliens fire now and then (shooters aim at you, tanks fire a three-way spread) and, a few at a time, break into a dive: a curve that starts at the alien, swings sideways and ends just past your ship's position below the screen. A diving alien that misses you reappears at the top and drops back into its slot. Hitting a diver is worth double, and the number of simultaneous divers, the dive rate and the fire rate all grow with the wave.

Three alien types and a mothership

Green grunts take one hit, purple shooters two and orange tanks four; each is pixel art with two animation frames, pre-rendered into small off-screen canvases (plus a white copy for the hit flash) so drawing dozens of them costs only a drawImage each. Every fifth wave is a mothership boss with a health bar: it sweeps across the top and cycles through a rotating ring of bullets, aimed three-shot bursts, and launching kamikaze grunts. Destroying it scores 1000 plus 100 per wave and drops two power-ups.

Power-ups, combos and game feel

Destroyed aliens sometimes drop a capsule: double shot, a three-way spread, rapid fire, a shield that absorbs one hit, or a rare extra life. Weapons last ten seconds, shown as timer bars along the bottom. Kills in quick succession build a combo, and every five raise the score multiplier, up to x4. Explosions combine additive particles, an expanding shockwave ring, screen shake and a filtered-noise boom from the Web Audio API; the background is a three-layer parallax starfield over a slowly scrolling nebula, and clearing a wave triggers a hyperspace streak. The ship banks as it moves, has a flickering engine flame, and blinks while it is invulnerable after a hit.

Fair and readable

The ship's hitbox is a 9-pixel circle, smaller than the drawing, and enemy bullets are bright glowing orbs so they read clearly against the stars. Losing a life clears the enemy bullets and gives two seconds of invulnerability. The game pauses on P, Escape, the pause button or a tab switch, sound can be muted, and the best score is saved in localStorage.

What's included

Features

Galaga-style alien formations that fly in along Bézier curves, sway, and dive at the player in curved swoops
Three pixel-art alien types with two-frame animation and white hit flashes, pre-rendered to off-screen canvases
A mothership boss every fifth wave with a health bar and three attack patterns
Double, spread and rapid-fire weapons, a shield and extra lives as falling power-ups with timer bars
A combo multiplier up to x4 and double points for shooting divers
Additive particle explosions, shockwave rings, screen shake and a hyperspace streak between waves
Parallax starfield over a scrolling nebula, a banking ship with an engine flame
Keyboard, on-screen buttons and drag-to-move with auto-fire for touch
Web Audio lasers, noise-burst explosions and alarms, with a mute button and pause
Best score saved in localStorage with try/catch

Step by step

How to Use

  1. 1
    LaunchPress Launch. Move with the arrow keys or A and D (or the on-screen arrows) and hold Space or FIRE to shoot. On a phone, drag on the game: the ship follows your finger and fires automatically.
  2. 2
    Break the formationAliens stream in and take their places. Grunts take one hit, shooters two and tanks four. Shooters aim at you, tanks fire spreads.
  3. 3
    Watch for diversAliens break away and swoop at your ship. Dodge them or shoot them mid-dive for double points; a diver that touches you costs a life.
  4. 4
    Grab power-upsCatch falling capsules: D for double shot, S for a spread, R for rapid fire, a shield, or a heart for an extra life. Weapons last ten seconds.
  5. 5
    Build a comboKill aliens in quick succession: every five quick kills raise the multiplier, up to x4.
  6. 6
    Beat the mothershipEvery fifth wave a mothership with a health bar fires rings, aimed bursts and kamikaze grunts. Take it down for a big bonus and two power-ups.

Real-world uses

Common Use Cases

Learning curved enemy movement
Quadratic Bézier paths for entering and diving, plus a drifting formation slot, are a compact way to get lively enemy motion without physics.
A shoot-'em-up starter
Waves, a boss, power-ups and a combo system are separated into small functions, so new enemy types, weapons or bosses slot in easily.
Pixel art and juice on canvas
Sprites from strings of characters, additive glows, shockwaves and screen shake show how to make a canvas game feel punchy with no assets.
A touch-friendly arcade template
Drag-to-move with auto-fire makes a shooter comfortable on a phone, alongside keyboard and button controls.
An interactive 404 page or loading screen
A quick, self-contained arcade game works as a distraction on an error page, like the Asteroids Game.

Got questions?

Frequently Asked Questions

Each alien follows a quadratic Bézier curve. When a wave starts the curve goes from a point off-screen, through a control point on the other side, to the alien's slot in the formation. A dive goes from the alien's current position, through a random point beside it, to just below your ship. After a dive the alien reappears above the screen and slides back into its slot.

Every fifth wave (5, 10, 15...). Its health is 50 plus 12 per wave, and it cycles through a ring of bullets, three aimed spread bursts, and launching two kamikaze grunts. It gets faster at switching patterns on later waves.

D gives a double shot and S a three-way spread, each for ten seconds (the newest replaces the other). R doubles the fire rate for ten seconds and can stack with either. The shield absorbs one hit, and the heart adds a life (up to five). Aliens drop a capsule 7% of the time and the mothership always drops two.

Grunts are 10, shooters 20 and tanks 40 points, doubled if the alien was diving, then multiplied by your combo (1 plus one for every five quick kills, up to x4). Each hit on the mothership is 5 points and destroying it is 1000 plus 100 per wave.

Yes. Drag anywhere on the game and the ship follows your finger and fires automatically, or use the arrow and FIRE buttons. The game pauses by itself when you switch tabs.

Each alien frame is drawn once into a tiny off-screen canvas (plus a white copy for the hit flash). Drawing the formation is then one drawImage per alien instead of dozens of fillRect calls, which keeps the frame rate steady with many enemies, particles and bullets on screen.

Copy & paste

Source Code

<div class="game-card">
  <div class="game-header">
    <div class="game-title">
      <span class="game-icon">🚀</span>
      <h2>Space Blaster</h2>
    </div>
    <div class="stat-badges">
      <span class="badge">Wave <b id="wave">1</b></span>
      <span class="badge">Best <b id="best-score">0</b></span>
    </div>
  </div>

  <div class="canvas-wrap">
    <canvas id="game-canvas" width="360" height="440"></canvas>
    <div class="hud">
      <span id="hud-score">0</span>
      <span class="lives" id="hud-lives">❤️❤️❤️</span>
    </div>
    <div class="overlay" id="start-overlay">
      <div class="overlay-card">
        <p class="overlay-title">Space Blaster</p>
        <p class="overlay-sub">Aliens fly in, then dive at you. Blast them, grab power-ups for double, spread and rapid fire, and survive the mothership every 5th wave.</p>
        <button class="btn btn-primary" id="btn-start">Launch</button>
      </div>
    </div>
    <div class="overlay hidden" id="pause-overlay">
      <div class="overlay-card">
        <p class="overlay-title">Paused</p>
        <button class="btn btn-primary" id="btn-resume">Resume</button>
      </div>
    </div>
    <div class="overlay hidden" id="gameover-overlay">
      <div class="overlay-card">
        <p class="overlay-title" id="over-title">Game Over</p>
        <p class="overlay-sub" id="final-score">Score 0</p>
        <p class="overlay-best" id="best-msg"></p>
        <button class="btn btn-primary" id="btn-retry">Play again</button>
      </div>
    </div>
  </div>

  <div class="controls">
    <div class="dpad">
      <button class="ctrl-btn" id="btn-left" aria-label="Move left">◀</button>
      <button class="ctrl-btn" id="btn-right" aria-label="Move right">▶</button>
    </div>
    <div class="mid-btns">
      <button class="mini-btn" id="btn-pause" type="button" aria-label="Pause">⏸</button>
      <button class="mini-btn" id="btn-mute" type="button" aria-label="Sound on" aria-pressed="false">🔊</button>
    </div>
    <button class="fire-btn" id="btn-fire" aria-label="Fire">FIRE</button>
  </div>

  <p class="hint-text">← → / A D to move, hold Space to fire · or drag on the game (auto-fire) · P to pause</p>
</div>

Extend with AI

Take This Snippet Further With AI

Paste this snippet's HTML, CSS and JS into an AI assistant like Claude and ask it to explain the Bézier entry and dive paths, the formation slots, the boss attack cycle and the power-up system. It is a good base to extend: ask for a tractor-beam alien that captures your ship (as in Galaga), a bomb that clears the screen, ship upgrades bought between waves, a two-player mode, gamepad support, or a port to a React component with the game state in a ref. Treat it as a working prototype to question and rebuild.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build a complete Galaga-style vertical shooter on an HTML5 canvas in plain HTML, CSS and JavaScript, with no libraries and no image files.

Requirements:
- A ship at the bottom that moves left and right (arrow keys, A and D, on-screen buttons, or dragging on the canvas, which also auto-fires) and shoots with Space or a FIRE button, with a banking tilt and an engine flame.
- Waves of aliens in a formation whose centre drifts side to side. Each alien enters along a quadratic Bézier curve with a staggered delay, then fires now and then and breaks off into curved dives toward the ship, returning to its slot from the top if it misses. Dive count, dive rate and fire rate grow with the wave.
- Three alien types (1, 2 and 4 hit points) drawn as two-frame pixel art from strings, pre-rendered to off-screen canvases with a white hit-flash copy. Shooters aim at the player, tanks fire spreads.
- A mothership boss every fifth wave with a health bar and three rotating attacks: a ring of bullets, aimed spread bursts, and kamikaze grunts.
- Power-up capsules (double shot, spread, rapid fire, shield, extra life) with timer bars, a combo multiplier up to x4, double points for diving aliens, and a boss bonus.
- Additive particle explosions, shockwave rings, screen shake, a parallax starfield over a scrolling nebula and a hyperspace streak between waves. Invulnerability blink after a hit, a small circular ship hitbox, wave and warning banners.
- Web Audio sound (lasers, noise-burst explosions, alarms) with a mute button, pause on P, a button and tab switch, and the best score in localStorage (with try/catch).

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.