HTML5 for Games
Table of Contents
- 1 HTML5 for Games
- 2 html5
- 3 libraries
- 4 games and stuff
- 4.1 classes of web based games
- 4.2 Glitch
- 4.3 word² (née scrabb.ly)
- 4.4 Canvas Rider
- 4.5 freeciv.net
- 4.6 Quake II GWT
- 4.7 canvas-based
- 4.8 emulation
- 4.9 Asteroids
- 4.10 Echo Bazaar
- 4.11 Kingdom of Loathing
- 4.12 Nethax
- 4.13 ForumWarz
- 4.14 interactive fiction
- 4.15 node.js canvas implementation
- 4.16 0boxer
- 5 (meta)
1 HTML5 for Games
Joshua Sled <jsled@asynchronous.org>
- http://asynchronous.org/
- software author
- currently at Oracle (MySQL)
- VAGUE
- Open-Source enthusiast
2 html5
2.1 canvas
-
scriptable drawing surface
- 2d, 3d contexts
-
2d javascript api
- stroke, line styling; shadowing
- rectangles, paths, splines
- transformations (scale, rotate, translate, arbitrary 2d transform matrix)
- compositing (alpha value, compositing operations)
- focus management (no support)
- text, images, pixel manipulation
-
3d api
- webgl = opengl es 2.0 + enumerated extensions
- no scene graph or higher-level api
- http://code.google.com/p/explorercanvas/, IE9
- code example
2.2 <audio>, <video>
<audio src=foo.mp3 controls=false autoplay=true/>
<video src=foo.mp4 controls=true preload=true/>
<video controls autoplay>
<source src='video.mp4'
type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
<source src='video.ogv'
type='video/ogg; codecs="theora, vorbis"'>
<embed clsid=""flash""/>
</video>
2.2.1 common audio/video DOM API
- src attribute
- ready state, network state, preload, buffered
- time, duration, start offset, playback rate
- load(), play(), pause()
-
timed tracks, cues
- subtitles, captions, descriptions, chapters, metadata
- cues can be used to play isolated sections from a larger file
2.2.2 audio mozilla data api proposal
- https://wiki.mozilla.org/Audio_Data_API
- http://ajaxian.com/archives/spectrum-visualization-with-the-html5-audio-data-api
<audio src="song.ogg" controls="true"
onaudiowritten="audioWritten(event);" />
<?javascript
function audioWritten(event) {
var spectrum = event.mozSpectrum;
var specSize = spectrum.length, magnitude;
// Clear the canvas before drawing spectrum
ctx.clearRect(0,0, canvas.width, canvas.height);
for (var i = 0; i < specSize; i++) {
var zoomMultiplier = 4000;
magnitude = spectrum.item(i) * zoomMultiplier;
// Draw rectangle bars for each frequency bin
ctx.fillRect(i * 4, canvas.height, 3, -magnitude);
}
}
?>
2.3 @font-face
- yay real typography!
- boo format soup!
- boo browser brokeness!
<?css
@font-face {
font-family: 'Graublau Web';
src: url('GraublauWeb.eot');
src: local('☺'),
url("GraublauWeb.woff") format("woff"),
url("GraublauWeb.otf") format("opentype"),
url("GraublauWeb.svg#grablau") format("svg");
}
?>
2.4 css3 features
- rbga
- border-radius
- CSS Gradients
-
CSS Transforms
- rotate, skew, scale
- CSS Transitions
- CSS Animations
2.5 local storage
2.5.1 WebStorage
- key,value pairs
- keys are strings
- values are strings (!)
- 5MB
<?javascript localstorage['are we running?'] = true; localstorage['gameboard[' + x + '][' + y + ']'] = value; ?>
2.5.2 Web SQL DB (deprecated)
-
SQL store
- SQLite store
- safari, opera, webkit
-
deprecated
- spec process problems
- being "SQL"-based
2.5.3 Indexed DB API
- object store
- versioned, typed schema
- javascript (idl+event) interface
<?javascript
var request = window.indexedDB.open("CandyDB",
"My candy store database");
request.onsuccess = function(event) {
request = event.result.
objectStore("kids").openCursor();
request.onsuccess = function(event) {
var cursor = event.result;
if (!cursor) { return; /* no more results */ }
var element = document.createElement("div");
element.textContent = cursor.value.name;
document.getElementById("kidList").appendChild(element);
cursor.continue();
};
};
?>
2.6 geolocation
- yay GPS
<?javascript
navigator.geolocation.getCurrentPosition(callback);
navigator.geolocation.watchPosition(callback);
navigator.geolocation.getCurrentPosition(callback, onerror,
{maximumAge: ..., timeout: ...,
enableHighAccuracy: ...});
?>
2.7 messaging
2.7.1 xhr, comet
-
http-based
- request-response
- unidirectional
-
comet
- long poll
- hack to allow server-pushed messages
2.7.2 websockets
- bidirectional message-passing endpoints
-
event-driven
- onopen, onclose, onerror, onmessage
<?javascript
ws = new WebSocket('ws://example.org/updates');
ws.onmessage(function (evt) {
var msg = jsonParse(evt.data);
if (msg.error) { /* ... */ return; }
$('<div class="message"/>')
.text(msg.body)
.appendTo('#messageScroll');
});
$('FORM#userInput').submit(function (e) {
var $textInput = $(this)
.find('INPUT[name=textline]');
ws.send($textInput.val());
$textInput.val('');
});
?>
2.8 webworkers
- threads
-
same postMessage, onmessage event-driven
messaging api
- creator can postMessage to worker
- worker can postMessage to creator
<?javascript
compute = new Worker('heavylifting.js');
compute.onmessage(function (evt) {
// ...
});
compute.postMessage('ready');
?>
2.9 offline apps/cache manifest
<html manifest="app.manifest"> <link rel=stylesheet href="app.css"> <script src="app.js"></script> ... app.manifest: CACHE.MANIFEST app.js app.css
2.10 not covered
- section, nav, aside, header, footer, article
-
new forms
-
input types
- telephone, url, email, date/time, number, range, color,
- datalist, keygen, progress, meter, output, device
-
input types
- details, summary
- menu, command
- link types
- microdata
- History
- Undo
- Drag and Drop
3 libraries
3.1 sfxr.js
- http://vocamus.net/dave/?p=1166
-
8-bit sound effects
- "explosion", "jump", "laster shoot", "pickup coin", "powerup"
- generates .wav files
- js demo
- FireFox 4 Audio Data api
3.2 box2d physics engine
-
box2d
- C++ rigid-body simulation engine
- shapes, bodies, constraints, fixtures, joints
-
does not draw
- mapping of screen assets to box2d objects
- step world, get new coordinates
- iterate objects, draw to canvas
-
http://box2d-js.sourceforge.net/index2.html
- a port of box2d C++ engine
- requires prototype.js, IECanvas
-
http://box2d.thinkpixellab.com/
- a clone of the sf.net one
- uses Closure Compiler ("found a lot of bugs in the original javascript")
3.3 processing.js
- http://processingjs.org/
- javascript implementation of Processing
-
Processing is a language and framework
for visual interactions.
- setup()
- draw()
- mouseMoved(), keyPressed(), …
- 2d: primitives, curves, text, color, drawing control, shapes
-
3d: box, sphere, lights, camera
- coordinate systems
- material properties
- text, fonts
- Processing Tower Defense
3.4 GameQuery
- http://gamequery.onaluf.org/
- jQuery classes for 2d games
-
features
-
multi layer-sprite animations
- dom, not canvas
- sprite hierarchies (grouping)
- collision detection
-
swappable sound support
-
http://www.schillmania.com/projects/soundmanager2/
- html5, flash fallback
-
http://www.schillmania.com/projects/soundmanager2/
- periodic callbacks
- keyboard state tracking
- MIT license
-
multi layer-sprite animations
- not quite great coding
- api: http://gamequery.onaluf.org/api.php
- demos: http://gamequery.onaluf.org/demos.php
3.5 Akihabara
- http://www.kesiev.com/akihabara/
-
html5/javascript/modern browser game framework
- safari, chrome, firefox, opera, konqueror, IE9 beta, iPhone/iPad, Wii, Android
-
gamebox
- grouped objects moving simultaneously
- collisions
- rendering and moving objects
- keyboard handling
- double-buffering
- FSEs
- load/unload persistent data handling
- audio api
-
gamecycle
- generic game cycle: intro, menus, crossfading between stages/lifes, gameover and ending
-
toys
- screen titles
- hud handling
- jumping characters
- z-indexed objects
- bullets, sparks
- staff roll/credits
- bonus screens
- dialogues
-
utility code
- math (moving objects, path following)
- "touchpad/fretboard" for touch devices
- bunches of demos
-
no high-level docs
- documented code
3.6 Effect Games
-
http://www.effectgames.com/effect/
- "Free online tools for building, sharing and playing browser-based games. Your games may include sound effects, music, and multiple layers of parallax-scrolling tiles and sprites".
- DOM, not Canvas
- fully abstracted engine
-
web based builder
- metadata, asset handling, keyboard mapping, level definition
- geometry, collision detection
- sprites and tiles
- fonts, audio, video
- level editor
3.6.1 demo: Super Mario Bros (+Chrome, +FF3.6.12)
3.6.2 demo: Crystal Galaxy (+Chrome, +FF3.6.12)
3.6.3 "My HTML5/CSS3 Browser Wish List"
- fullscreen any DOM element
- audio/video live streaming
- audio stereo panning
- programmatic audio generation (FireFox Audio Data API)
- record audio/video from line input, webcam (coming?)
- screenshot DOM elements
- DOM element composite operation
- Specify Interpolation Algorithm for CSS Transforms
- CSS Distort Transform
- Hardware accel for (specific) DOM objects
- DOM Redraw Control
- HTML5 audio/video src caching
- Human Interface Device (HID) Access
- Accelerated Byte Array
- Canvas Pixel Access
- Progress Events for Form Submits and XHR POST
- Native Hierarchical Menus
- WebKit: fix HTML5 audio
- WebKit: text field spellcheck disable
- Firefox: CSS Masks
3.7 Rocket Engine
- http://rocketpack.fi/engine/
- Multi-platform
-
bunches of features
- sprites
- orthographic/isometric tile rendering
- audio
- collision detection
- pathfinding
- ai state machines
- "Rocket Builder" web based editor
-
"Rocket Network" hosting infrastructure
- "MMO-grade scaling"
- analytics
- "socially connected"
- "Transparent client-server model"
- beta?
4 games and stuff
4.1 classes of web based games
- hypertextual games
- html container including dom/canvas
- html container for only dom/canvas / fully interactive
- flash
4.2 Glitch
- http://glitch.com/
- massively-multiplayer
- browser based
- "built in the spirit of the web"
- demo video
4.3 word² (née scrabb.ly)
- wordsquared.com
- multiplayer scrabble-style game
- jQuery, html5 client
- WebSockets
- node.js server-side
-
MongoDB
- geospatially indexed dataset
- 3rd-party infrastructure (Pusher) to send json messages for game state updates
- since both client and server are js, some game rules can be pushed to the client for execution (and re-evaluation on the server side, of course).
- http://mozillalabs.com/gaming/2010/10/14/massive-fun-building-scrabb-ly/
4.4 Canvas Rider
- http://canvasrider.com/
- good mix of hypertext and interactive content
- interactive level creation
- social level sharing
- simple canvas-based game
4.5 freeciv.net
- http://www.freeciv.net/
- freeciv engine fork
- single player, multiplayer
- html5 canvas &c.
- Affero GPL v3
4.6 Quake II GWT
4.7 canvas-based
- http://canvasdemos.com
- http://www.reddit.com/r/programming/comments/dqpdo/roundup_of_games_using_html5_canvas/
- http://html5games.com/
-
Sudoku : http://html5games.com/2010/11/html5-sudoku/
- offline storage
-
Torus : http://www.benjoffe.com/code/games/torus/
- Tetris-like around a circular base
-
Orbium : http://html5games.com/games/orbium/
- web/mobile, simple puzzle game
-
Rawkets : http://www.rawkets.com/
- asteroids-like, websockets, multiplayer, twitter auth
4.8 emulation
4.8.1 JSNES
- http://benfirshman.com/projects/jsnes/
- NES emulator in javascript
4.8.2 JSGB (JavaScript GameBoy)
4.8.3 JavaScript GameBoy color
4.8.4 Making jsGB (GameBoy emulator in js)
- not the same as above
- http://imrannazar.com/GameBoy-Emulation-in-JavaScript
- Series of posts providing overview of pieces
-
CPU
- js emulation
-
Memory
- rom loading through "asynch file requests"
-
GPU timings
- canvas
-
Graphics
- game boy graphics handling
-
Integration
- putting pieces together
-
Input
- keystroke handling, event handling
- Sprites
- Interrupts
4.9 Asteroids
4.10 Echo Bazaar
4.11 Kingdom of Loathing
- http://www.kingdomofloathing.com/
- An Adventurer is You!
4.12 Nethax
4.13 ForumWarz
4.14 interactive fiction
- http://ifcomp.org/comp10/results.html
-
http://code.google.com/p/parchment
- open source web-based Z-machine interpreter
- typography, css, HTML
- offline-storage
- http://inform7.com/
4.15 node.js canvas implementation
- http://www.learnboost.com/introducing-node-canvas-server-side-html5-canvas-api/
- used to backfill functionality for old browsers, exported PDFs
4.16 0boxer
- http://www.0boxer.com/
- game mechanics for gmail
- infinitely-pervasive game mechanics
- Jesse Schell's DICE 2010 talk
5 (meta)
5.1 demo/example links
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#examples
http://spaceparanoids.net/2010/12/shopvac/
http://vocamus.net/dave/?p=1166
http://box2d.thinkpixellab.com/
http://gamequery.onaluf.org/tutorials/1/step3.php#enemiesmov
http://www.kesiev.com/akihabara/demo/game-tlol.html
http://effectgames.com/effect/games/mariodemo/
http://www.benjoffe.com/code/games/torus/
http://benfirshman.com/projects/jsnes/
http://www.big-ape.net/nethax/
http://echobazaar.failbettergames.com/
http://www.kingdomofloathing.com/
http://ifcomp.org/comp10/results.html
http://code.google.com/p/parchment
http://inform7.com/learn/eg/bronze/source.html
http://fury.com/2010/02/jesse-shells-mindblowing-talk-on-the-future-of-games-dice-2010/
5.1.1 other
5.2 the attic
5.2.1 jsGameSoup
- http://mccormick.cx/projects/jsGameSoup/
-
What it provides:
- Cross browser event handling
- Rudimentary polygon collision detection
- Auto-init to launch code attached to a specific HTML canvas
- Game entity management
-
Game objects implement method-driven interface
- draw()
- key press, pointer movement, collision-detect
-
Game objects register with core engine
- entity list/scene graph
- engine takes over canvas, starts looping and drawing.
- LGPL
- 2009; seems abandoned
5.2.2 Aves Engine
- http://ajaxian.com/archives/aves-game-engine
- kinda cool looking isometric game engine
- bought by Zynga. Web site now gone. :/
5.2.3 Agent 008 Ball
- http://blog.nerdplusart.com/archives/creating-an-html5-game
- ball renering in canvas
- audio element for sound effects
- typography using @font-face, font-embedding
5.2.4 color cycling effect
Date: 2010-12-08 10:06:27 EST
HTML generated by org-mode 6.36c in emacs 23