Skip to content

Instantly share code, notes, and snippets.

@borgar
Last active June 27, 2022 21:03
Show Gist options
  • Save borgar/cb5a3e4188e928800556 to your computer and use it in GitHub Desktop.
Save borgar/cb5a3e4188e928800556 to your computer and use it in GitHub Desktop.
Octopus
license: MIT
height: 578
border: no

Octopus is an experiment at building a game fully contained in a single SVG image. The game simulates Nintendo’s 1981 Game & Watch game Octopus.

The image was traced using a vector drawing program, sanitised and references added to each shape to simulate the LCD. The JavaScript program logic then runs the game. This is fully contained, even down to the simple sound generation.

Excluding the time and alarm set, clicking buttons on the image works and keyboard keys are bound as follows:

← = Left
→ = Right
1 = A
2 = B
⎋ = Time
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8 />
<style>
html, body {
font-family: sans-serif;
margin : 0;
padding : 0;
height: 100%;
}
iframe {
border : 0;
}
</style>
</head>
<body>
<iframe id="octopus" src="octopus.svg"
width="100%" height="100%"
marginwidth="0" marginheight="0" border="0"
scrolling="no"></iframe>
<script>
// This hack transfers key events into the svg driver so
// that user doesn't have to focus in to start playing.
window.addEventListener( 'load', function () {
var xdoc = document.querySelector( '#octopus' ).contentDocument;
window.addEventListener( 'keyup', function ( e ) {
var ev = new CustomEvent( 'Input', { 'detail': { 'key': e.keyCode } });
xdoc.dispatchEvent( ev );
}, false);
}, false);
</script>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment