Skip to content

devstopfix/elixoids

Repository files navigation

Elixoids

Asteroids 1979 arcade game engine written in Elixir. Watch the Elixoids movie on Vimeo recorded at a Coding Night. Participants were given one hour to write an AI bot that could pilot a ship and play the game! See the original Arcade Asteroids video.

Elixoids Elixoids

The original UI was rendered by JavaScript asteroids-ui and has had a recent Elm conversion. Audio originall provided by SonicAsteroids before conversion to Web Audio.

Build Status

Build

To run the game on Ubuntu, or on OSX:

brew install elixir
git clone https://github.com/devstopfix/elixoids.git
cd elixoids
mix deps.get

Run

This repo contains the game engine, a webserver, and a recent version of the asteroids-ui.

To start a game use the play script or:

mix run --no-halt

Open the UI in your browser:

open http://localhost:8065/0/game

In the REPL you can start multiple games on the same server:

iex -S mix

{:ok, pid, id} = Elixoids.Game.Supervisor.start_game([asteroids: 16])
{:ok, #PID<0.538.0>, 2}
open http://localhost:8065/2/game
python3 clients/miner.py --name TWO --game 2

The parameters of the game can be alterted in the config.

Clients

Clients subscribe to an event stream from the game via Websockets. The resources available are:

Path Accept Content
/0/graphics application/json Graphics stream
/0/news text/event-stream News stream
/0/ship/PLY application/json Game state for player PLY

News Client

The news stream at http://example.com/0/news is a stream of text lines of the form:

[PLY|ASTEROID] VERB [PLY|ASTEROID]

Example dialogue:

$ curl -H 'Accept: text/event-stream' http://localhost:8065/0/news 2>&1

PLY fires
PLY shot ASTEROID
PLY fires
PLY shot OTH
PLY kills OTH
ASTEROID hit PLY
ASTEROID spotted

This can be used to generate a hi-score table:

elixir --no-halt clients/hiscore.exs http://localhost:8065/0/news

Java Ship Client

See Elixoids Java Client by J Rothwell.

Python Asteroid Miner Client

The CBDR Python client at miner.py will try and shoot the asteroid which is on the most constant bearing with it:

pip3 install websocket-client --user
python3 clients/miner.py --host localhost:8065 --name MCB

Ruby Client

There is a simple Ruby client that shoots the nearest ship:

gem install eventmachine
gem install faye-websocket

export ELIXOIDS_SERVER=rocks.example.com:8065 ruby clients/shoot_nearest_ship.rb

NB The websocket connection can be troublesome on OSX. It will often fail to connect after a reboot. Keep trying and it will eventually connect and stay connected! These scripts will be migrated to Python3.

Graphics Client

Graphics stream can be received at ws://example.com/0/graphics - to be documented - see GraphicsDecoder.elm and asteroids-ui for reference implementations.

While developing the UI you can start a test card game that allows you to prove your rendering:

mix run --no-halt games/testcard.exs

Then connect to ws://localhost:8065/1/game.

Deploy

See the Ubuntu deployment guide to run the game engine on a server.

Licence

This software is published under the MIT License and Copyright ©2019 devstopfix. UI is ©2016 lachok. Audio code is ©2016 jrothwell. Button CSS by ozer.