Arcade widget

Space Tours Defense

Raiders all the way from Earth orbit to Neptune, and a liner full of tourists behind you. One JavaScript file, no dependencies, drops onto any page in one line.

← → move Space fire P pause M sound On a phone: drag to steer, hold to fire.

Putting it on a page

Copy the file next to your HTML, then add the container and the script. It mounts itself.

<div data-space-tours-game></div>
<script src="space-tours-defense.js"></script>

The widget fills the width of its container and takes a 4:3 box by default. Give the container a height of your own and it uses that instead.

Options

Set them as data attributes on the container, or pass an object to SpaceToursDefense.mount(el, options).

AttributeDefaultWhat it does
data-attracttrue Plays itself, arcade cabinet style, until someone takes the controls. Set to false for a still title screen.
data-soundfalse Sound is off until the player asks for it. The demo run is always silent.
data-lives3Escort ships you start with.
data-aspect4 / 3 Box shape, used only when the container has no height of its own.
data-titleSpace Tours DefenseHeading on the title screen.
data-credit-label
data-credit-href
none Optional credit line under the start button.

It borrows your colors

The game runs inside a shadow root, so nothing leaks either way: the host page cannot restyle it by accident and its own CSS cannot touch the page. What it does read are the custom properties --bg, --line, --text, --gold, --ember, --pulse, --pulse-dim, --danger and --ok, if the page defines them. Otherwise it falls back to the palette you see here.

Behaviour worth knowing

It pauses when it scrolls out of view and when the tab loses focus, so a widget sitting halfway down a page is not quietly burning a laptop battery. It honours prefers-reduced-motion. Keyboard input is only captured while the widget has focus, so arrow keys still scroll the page everywhere else. The high score is kept in localStorage on the visitor's own machine and goes nowhere near a server.