• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    JavaScript
  • Created over 9 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

"Behind Asteroids, The Dark Side" is a JS13K entry for 2015 โ€“ winner in Desktop, Mobile and Community categories

Behind Asteroids, The Dark Side

PLAY โ€“ entry

Synopsis

Ever wondered what is happening under the hood of an Asteroids Arcade machine? I can tell you: A greedy evil 25ยข money maker engine.

Context

This is an entry for js13kGames, goal is to make a web game in less than 13k zipped of JavaScript. Theme was "Reversed".

Inspiration

Best quote ever

"Not bad for a 35 years old system. 35 years old. Things don't get better than this. They don't get better than this. Look at this picture, you know what, even HD can't be this clear, crystal clear, razor sharp, wonderful vector graphics. Sorry there is nothing like it. nothing like it. What a terrific game."

Special thanks

  • mrspeaker for his support, testing and English help.

Game versions

The game both works for mobile and desktop but the gameplay varies. The desktop version is a touch typing game where the mobile version is a simple touch game. If you are not good at typing on keyboards, just prefer the mobile version.

On mobile (especially for iOS Safari), please use Add to Home screen for better experience.


The Game

Behind Asteroids is a game about throwing asteroids to people playing "Asteroids" on an arcade machine. Like in Asteroids game, player have 3 extra lifes. The goal is to make the player lose and try to earn as much coins as possible. When a player lose, another come and put a new coin in the arcade.

There are different game mechanism involved, they get introduced in first levels and get harder and harder to use:

  • The Asteroids have an aiming centered in the spaceship that varies the throw velocity
  • The Asteroids aiming rotates (Player >2)
  • The "RED" area in the aiming that make you fail the throw (Player >3)
  • The UFO bonus that you get after sending asteroids without failing to throw an asteroid (Player >4)

Game Over

Everytime the player is reaching 10'000 points, he wins a new extra life, You lose if player reaches 5 lifes.

Continue

Game is saved every time a player entered and can be continued later.


Tech overview

Making of the post-processing effects pipeline

Here is an non exhaustive summary of what's going on with the WebGL post-processing effects.

Because this is a 2D game, a subset of WebGL is used here: we just use 2 triangles that cover the whole surface in order to just focus in writing fragment shaders.

primitives are down on a simple 2D Canvas

with classical Canvas 2D code but also using the 3 color channels (RED, GREEN, BLUE) independently to split objects into different classes...

A laser shader draws it to monochrome

It sums up the 3 color channels. The BLUE channel, used for the bullets, gets accentuated in a factor that depends on the screen position. This intends to recreate the various intensity of a vector monitor.

The result of this shader is also blurred:

the player shader is rendered

The player and it environment (that will be reflected in the screen) is procedurally generated in a shader.

The shader code is a bit crazy right now probably because of all animations, but the drawing is not so complex: this is just about drawing ovale and squircle shapes and also some gradients for the lightning.

We don't directly use this image in the game, it is visually not very realist, but if we blur it a lot (and even more on X axis) to recreate a reflection style, it becomes quite interesting:

The objective is to find an equilibrium between seeing it a bit in background but not too much. Also note that the hands are moving during a game, this is very subtile to see but it is part of the environment.

a Glare shader effects is added

Glare is obtained by applying a large directional blur. It is only applied on bright objects (basically just bullets).

Result with some persistence

The final Game shader combines 5 textures:

uniform sampler2D G; // game
uniform sampler2D R; // persistence
uniform sampler2D B; // blur
uniform sampler2D L; // glare
uniform sampler2D E; // env (player)

The blur texture is used as a way to make the glowing effect (multiplying with a blue color). The persistence texture stores the previous blur texture to accumulate motion blur over time.

Finally, we just put the UI canvas on top of the game canvas

Font drawing

Code is here

Feedbacks on developing a JS13K game

Don't start with JS*K tricks

My first point is about NOT doing any JavaScript tricks to save more bytes until you are at the last days of the competitions and if it happens you actually are >13k (really, 13K zipped is plenty of room for making a game even if not "bytes optimized").

So, you want your game to run first. And even if you have a first version, you might improve it, so keeping your code readable and maintainable is very important.

Don't fear beginning with libraries!

Unlike some recommendations I've seen previously about making JS13K games, I think you can afford starting with some libraries. Just keep in mind to not be too much tied to these libraries so you can eventually remove them.

My point is, the process of making a game is very long and you want to be as productive as possible to prototype and add game features.

In my game I've used stack.gl libraries for making the post processing effects, and I only port my code back to raw WebGL when I was really sure it was done. I was very productive working on these effects and was not stuck by crazy code.

When I was sure of the post-processing pipeline, I've then replaced usage of these libraries by tiny utility functions specific for my needs.

Make your game visually debuggable

When developing a game, especially an AI, it is important to debug. And by debug I mean displaying hidden game logic. The problem of console.logging things is it is difficult to picture it with the game for a given instant.

You want to see vectors and AI decisions to be able to tweak game parameters and improve the game.

See in this video one display I've used when debugging the AI

I have avoided "OO-style" to functional style

There is no "Objects" in my game, I've gone away from the classical prototype / OO way of doing games.

What I've used is just arrays. This is both a technical choice (going more FP) and a way to save more bytes (a minifier can't rename fields of objects, [0], [1], ... are obviously saving bytes especially when zipped).

Array as data structure

So instead of objects, I've used array like a tuple. For instance, the spaceship state is [x, y, velx, vely, rot] and asteroids state is an array of [x, y, rot, vel, shape, lvl].

All my game state is in state.js and "tuple types" are all documented.

Taking this approach, you better have to design your game state first so you don't change this over time (this is the cons of this approach, indexes are not really readable and maintainable).

Also you should try to make your tuple looking like the same so you can share some code for different types (x, y is always the 2 first values in my tuples).

Embrace Functions

Instead of object methods, I just have a lot of functions. For instance, I have drawAsteroid(asteroid).

Some functions are generic so you can re-use them for different needs. I've found a very nice way of implementing "behaviors" of objects:

// code from the update loop
euclidPhysics(spaceship);
asteroids.forEach(polarPhysics);
ufos.forEach(euclidPhysics);
bullets.forEach(euclidPhysics);
particles.forEach(polarPhysics);

ufos.forEach(applyUFOlogic);
incomingObjects.forEach(applyIncLogic);

particles.forEach(applyLife);
loopOutOfBox(spaceship);
asteroids.forEach(
  // conditional behavior !!
  playingSince > 0 && !awaitingContinue && !gameOver ?
  destroyOutOfBox : loopOutOfBox);
ufos.forEach(loopOutOfBox);
bullets.forEach(applyLife);
bullets.forEach(loopOutOfBox);

Also, it is easy to pass function as a value:

// code from the render loop
renderCollection(asteroids, drawAsteroid);
renderCollection(ufos, drawUFO);
renderCollection(bullets, drawBullet);
renderCollection(particles, drawParticle);

Build system

The build system is dedicated to JS13K and made with a few simple scripts. It is able to copy assets, concat all files, minify the GLSL code, minify the JavaScript, zip the result and give size information.

Things are a bit specific to my need but remain very simple, modular and powerful, you could easily fork it.

dev

npm run liveserver
npm run watch

prod

npm run build

More Repositories

1

gl-react

gl-react โ€“ React library to write and compose WebGL shaders
JavaScript
2,866
star
2

react-native-view-shot

Snapshot a React Native view and save it to an image
JavaScript
2,420
star
3

gl-react-native-v2

DEPRECATED, Please migrate to latest version of gl-react-native that works nicely with expo-gl and unimodules
Java
1,937
star
4

bezier-easing

cubic-bezier implementation for your JavaScript animation easings โ€“ MIT License
JavaScript
1,660
star
5

diaporama

image/video/content slideshow engine providing high quality animation effects including Kenburns Effect and GLSL Transitions.
JavaScript
798
star
6

gl-transition-libs

libraries to run GL Transitions and source code of
JavaScript
756
star
7

illuminated.js

Illuminated.js โ€“ 2D lights and shadows rendering engine for HTML5 applications
JavaScript
421
star
8

bezier-easing-editor

Cubic Bezier Curve editor made with React & SVG
JavaScript
325
star
9

deprecated-glsl.js

NOT MAINTAINED prefer the use of http://stack.gl or gl-react โ€“ a light Javascript & GLSL library for vizualisation and game purposes (2D or 3D).
JavaScript
286
star
10

gl-react-v2

DEPRECATED =>
JavaScript
265
star
11

gl-react-image-effects

[WIP] universal image app that uses different gl-react components
JavaScript
225
star
12

wavegl

Generate Audio in the GPU and pipe to the Audio Card.
JavaScript
190
star
13

deprecated-flexible-nav

NOT MAINTAINED โ€“ Improve your navigation experience - this jQuery lib improves a webpage navigation and helps to visualize different sections. of a document, an article,.. any web page.
CoffeeScript
159
star
14

gl-react-dom-v2

WebGL bindings for React to implement complex effects over images and content, in the descriptive VDOM paradigm
JavaScript
138
star
15

diaporama-maker

[BETA] An image slideshow editor โ€“ including KenBurns effect and GLSL Transitions. (performed with diaporama)
JavaScript
99
star
16

qrloop

Encode a big binary blob to a loop of QR codes
TypeScript
90
star
17

transitions.glsl.io

WE HAVE MOVED TO
JavaScript
89
star
18

play2vim

Play framework vim plugin
Vim Script
81
star
19

playpainter

A simple Play 2 framework, Canvas and WebSocket experiment where many users can paint their draws simultaneously on a Canvas.
JavaScript
77
star
20

screenshot-webservice

UNMAINTAINED โ€“ Screenshot Webservice is an open-source REST web service to perform web page screenshots.
Scala
71
star
21

playCLI

Play Framework Iteratees + UNIX pipe library
Scala
70
star
22

kenburns

Ken Burns effect for DOM, Canvas2D, WebGL
JavaScript
66
star
23

gl-react-image

Universal gl-react Image that implements resizeMode in OpenGL
JavaScript
59
star
24

dta

Drone Tank Arena is a BattleZone-like FPS made in WebGL made during 7dfps contest.
JavaScript
59
star
25

gre

https://greweb.me/
Rust
57
star
26

zound-live

ZOUND live
JavaScript
56
star
27

ipo

easing library allowing to describe complex easings in JSON
JavaScript
55
star
28

zound

Zound, a PlayFramework 2 audio streaming experiment using Iteratees
Scala
53
star
29

multi-slider

React component for multiple values slider (allocate values)
JavaScript
49
star
30

reactjsconf2016

Example used in gl-react's talk at React.js conf 2016
JavaScript
46
star
31

json-beautify

JSON.stringify with fixed maximum character width.
JavaScript
40
star
32

gl-react-blur

Universal gl-react multi-pass gaussian Blur effect with configurable intensity
JavaScript
38
star
33

one-day-one-plot

=> now merged into https://github.com/gre/gre
Rust
37
star
34

beez

100% web real-time audio experiment using smartphones as effect controller. (tech: Android Chrome + WebRTC + Web Audio API)
JavaScript
35
star
35

deprecated-qajax

NOT MAINTAINED โ€“ this library was fun but hey, you can just use https://github.com/github/fetch now :) โ€“ Minimal Promise ajax library based on Q
JavaScript
35
star
36

glsl-transitions

OUTDATED โ€“ please migrate to gl-transitions
JavaScript
30
star
37

same-game-gravity

The Same Game Gravity Desktop version code - licence GPL v3
JavaScript
30
star
38

gl-react-dom-static-container

StaticContainer for gl-react-dom: render the Surface once, snapshot it and release the WebGL context
JavaScript
30
star
39

json2d

Express vectorial content in JSON using canvas2d directives
JavaScript
28
star
40

smoothstep

the smoothstep() function
JavaScript
26
star
41

webaudio-hooks

web audio & midi VS react hooks
JavaScript
26
star
42

glsl-transition

DEPRECATED โ€“ new project =>
JavaScript
21
star
43

zpeech

ZPeech, vowel formant analysis experiment with Web Audio API
JavaScript
21
star
44

jscrush

Minimal version of a JSCrusher to be used for js#k golf contest.
JavaScript
20
star
45

diaporama-react

Diaporama component for React
JavaScript
19
star
46

deprecated-gl-react-inspector

DEPRECATED it will be in gre/gl-react monolithic repo
JavaScript
18
star
47

js1k-starter

A convenient JS1K starter with livereload, jscrushing, multifiles support, shader minification, env code splitting
HTML
16
star
48

WebAppBuilder

Important note: I'm working on a more Makefile compliant way for WebAppBuilder (like i've done in some of my recent libs) | using Rakefile and ant are good alternatives | a lightweight Makefile to build a web app project for multiple platforms. This is a mashup of existing cool stuff like : a small template system (Mustache), SASS with Compass, Javascript minimizer, ...
JavaScript
16
star
49

react-native-webgl-view-shot

React Native WebGL extension to rasterize a view as a GL Texture.
Java
15
star
50

memocart

MEMO CART โ€“ lowrezjam 2017 โ€“ game
JavaScript
13
star
51

deprecated-qretry

UNMAINTAINEDโ€“ Promise retry system for Q
JavaScript
13
star
52

timelapse

js13kgames submission - Timelapse, a psychedelic rhythm game - Web Audio API + WebGL (GLSL)
JavaScript
12
star
53

audio-notes

Note frequencies for equal-tempered scale
JavaScript
12
star
54

jardin

[STATUS: project paused. no time to maintain] gre's personal gardening data & tools
JavaScript
11
star
55

webgltexture-loader

load & cache various kind of WebGLTexture with an extensible and loosely coupled system
JavaScript
11
star
56

DEPRECATED_react-native-view-shot-example

DEPRECATED โ€“ see updated example in https://github.com/gre/react-native-view-shot (example folder)
JavaScript
11
star
57

deprecated-qimage

UNMAINTAINED no need for a lib, see https://twitter.com/greweb/status/675620261232836608 โ€“ Simple Promise Image Loader based on Q
JavaScript
10
star
58

diaporama-recorder

Client side library to record a diaporama and obtain a stream of frames
JavaScript
10
star
59

kenburns-editor

React component to edit a Kenburns effect
JavaScript
10
star
60

ibex

the entry hosted on js13k is broken, please go on ->
JavaScript
10
star
61

glsl-uniforms-editor

UNMAINTAINED โ€“ React component with inputs to edit uniforms of a GLSL shader
JavaScript
9
star
62

sliding-window

sliding-window is an unidimensional chunk allocation / free system.
JavaScript
8
star
63

glsl-transition-vignette-grid

OUTDATED โ€“ renders a grid of glsl-transition-vignette efficiently (cached + pull of WebGL canvas)
JavaScript
8
star
64

chess-game

NOT MAINTAINED โ€“ A sample Chess Game made with HTML5 and CSS3 and targeting multi plateform. (made for "HTML5 Game Most Wanted") - the game is not fully finished but illustrates some concepts explained in the book
JavaScript
8
star
65

twitbot

a Clojure twitter bot engine that uses Google Spreadsheet as a sentence database, made for educational purpose
Clojure
7
star
66

livedraw

livedraw is a real-time collaborative pen plotter stream experience (e.g. twitch)
HTML
7
star
67

gl-react-contrast-saturation-brightness

Universal gl-react which combines Contrast, Saturation and Brightness effects
JavaScript
7
star
68

HTML5-File-Uploader

Asynchronous file upload, using html5 drag and drop if supported. Example with play! framework
JavaScript
6
star
69

gl-react-hue-rotate

Universal gl-react Hue Rotate effect
JavaScript
6
star
70

zampling

a simple audio editor built with Web Audio API
JavaScript
6
star
71

playCLI-examples

Presentation slides and Examples for playCLI
Scala
6
star
72

gl-react-color-matrix

Universal gl-react effect to apply 4x4 rgba color matrix on a content
JavaScript
6
star
73

glsl-transition-examples

OUTDATED โ€“ GLSL Transition Examples
CSS
6
star
74

glsl-transition-vignette

OUTDATED โ€“ A React component which display a GLSL Transition as a vignette (with hover and click controls)
JavaScript
6
star
75

deprecated-qanimationframe

DEPRECATED just use requestAnimationFrameโ€“ Promisified requestAnimationFrame with Q
JavaScript
6
star
76

workshop-gl-react-expo

JavaScript
5
star
77

Battle-Brushes

HTML5 Canvas game - brushes try to paint the best surface on screen
JavaScript
5
star
78

same-game

a same game in HTML canvas
JavaScript
5
star
79

ld29

Anthill, a game made for LudumDare 29
JavaScript
5
star
80

glsldoc

a JSON-structured documentation of all WebGL GLSL predefined functions, constants, types, qualifiers,...
5
star
81

blazing-race

Blazing Race is a HTML5 against-the-clock platform game where you control a fireball with your mouse and you try to light candles.
JavaScript
5
star
82

ld25

Ludum Dare 25 "You are the Villain" submission - HTML5 game
JavaScript
5
star
83

deprecated-kenburns-webgl

DEPRECATED use [email protected] โ€“ Ken Burns effect โ€“ webgl implementation
JavaScript
5
star
84

backbone-extend-standalone

Standalone version of Backbone's extend
JavaScript
4
star
85

Play-completion

a bash completion for Play! Framework
4
star
86

react-json2d

JavaScript
4
star
87

morpion-solitaire

A morpion solitaire game implementation in C using ncurses.
C
4
star
88

audio-chunks

slice/append/insert/subset/copy operations on AudioBuffer linked-list chunks
JavaScript
4
star
89

shape-editor

A graphic editor in Java made for an university project.
Java
3
star
90

rect-crop

Crop a dimension in a viewport: Compute a rectangle from a zoom ratio and a center point while preserving the dimension ratio.
JavaScript
3
star
91

rect-clamp

Constraint a Rectangle into another by preserving the ratio.
JavaScript
3
star
92

bezier-easing-picker

React component which allows to pick predefined bezier curve
JavaScript
3
star
93

deprecated-kenburns-dom

DEPRECATED use [email protected] โ€“ Ken Burns effect โ€“ DOM implementation
JavaScript
3
star
94

gl-react-negative

Universal gl-react negative effect
JavaScript
3
star
95

Bee--Hornets-and-flowers

A WebWorkers and Canvas demo. You control the bee and have to consume flowers pollen and avoid hornets collision.
JavaScript
3
star
96

deprecated-kenburns-core

DEPRECATED use [email protected] โ€“ Ken Burns effect โ€“ core
JavaScript
3
star
97

rust-generative-web-setup-example

JavaScript
3
star
98

js13k-2017

AMAZ3D is a game, made in a few days for js13k 2017 gamejam.
JavaScript
3
star
99

ld41

Tetrikaruga โ€“ entry for LD41 gamejam
JavaScript
3
star
100

ld28

LudumDare 28 - You Only Get One
JavaScript
3
star