BomberJS

How do I run it?

The server is written in JavaScript and uses node.js. To run it, get hold of a build of node.js for your platform and run:

node server.js

which will give you a Bomberman server running on http://localhost:8000/

How do I play?

Click here to join the game

What is it?

One day, it'll be Atomic Bomberman written in Javascript using Websockets and NodeJS.

Right now, it's four copies of Eric Cartman chasing each other around an HTML DIV tag.

NodeJS Websocket documentation

nodejs/node-websocket-server/docs/index.html

How The Game Works

The server runs an instance of BomberServer.

BomberServer contains exactly one BomberGame. A BomberGame represents the current state of a particular game, where state is defined as:

A collection of players, each responsible for its' own state

The current state of the level (terrain, power-ups)

The game scores

A player's state is the player's LOCATION and VELOCITY.

Each connected client runs a timing loop, and each client is the source of truth for that player. This is naive from a security perspective because clients can be spoofed, but we don't care about that right now.

Events

Events happen on the client, in response to user input or gameplay. They're sent to the server, which broadcasts them to all other clients.

When an event is broadcast, we'll also transmit certain "snapshot" data about the state of the game, to keep multiple clients in sync.

Events are JSON objects encoded as:

{
    type: [string],
    data: [json-data]
}

where the JSON-data varies with the event type.

join-game
A client has connected to the game. The server needs to send them the current game state (map, players, and scores), a spawn location, a color, and a player ID. The client should draw the map based on the game state, spawn the new player at the specified location, and start listening for events.

Format: { type: 'join-game', data: { player: [player], game: [game] }}
change-direction
A client has started or stopped moving, or changed the direction they're moving in. Raised in response to input events (keypresses), and collisions (client running into walls, arena limits, or hitting another player)

Format: { type: 'changed-direction', data { id: [player.id], position: [player.position], velocity: [player.velocity] } }
drop-bomb
A client has dropped a bomb. Event must encode the location where the bomb was dropped.
bomb-explodes
A bomb dropped by a client has exploded. Event must encode which bomb it is.
player-died
Each client is responsible for detecting whether an explosion has killed the player and notifying the server when this occurs. Bombs don't move, and death is caused by proximity - so it makes sense to use the local client state to decide whether a player's died or not.

Each client must listen for the following events transmitted by the server:

player-joined
A new player has joined the game. Data will encode the new player's name, color, ID and spawn point.

{ type: 'player-joined', data: { id: player.id, color: player.color, position: player.position, name: player.name} }
game-init
The clients' request to join the server was accepted. Data contains the initial game state.
player-changed-direction
A player changed direction (or stopped moving). This will also include the map coordinates where the change happened, and so provides syncing of client/server state.
bomb-dropped
A player dropped a bomb. The client must draw a bomb at the specified coordinates and start the countdown timing loop.