/phaseball

Primary LanguageJavaScript


Phase Ball

game that has challenges which you solve with math, by moving a ball into a goal along the path of an equation

To contribute to the project, follow these instructions:
https://help.github.com/articles/fork-a-repo

Getting set up

Install Node:

if you have homebrew installed, you can just: brew install node

else:

git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install

Ubuntu install:

  sudo apt-get install nodejs
  sudo apt-get install npm
  sudo npm install -g foreman
  sudo apt-get install nodejs-legacy

Other Platforms:

You can download Node JS from http://nodejs.org/download/. You will also need node foreman which can be installed with npm.

Running

To run the server run first cd to the phaseball directory and run

nf start

If you don't have Node foreman installed you can run it with

node web.js

Code Overview

The web.js server uses the express framework for serving up challenge. See http://expressjs.com/guide.html

The challenge is generated on the server side using Node.js. The server does a string replacement of the challenge before it sends it to the client.

var challenge = <%- JSON.stringify(game) -%>;

The game consists of 2 javascript modules written for requirejs. The modules are used in challenge.html.

The Game module consists of 4 function calls and contains all the game logic such as score and ball movement.

  init(challenge) //Initializes a game for a given challenge generated by the server.
  compileFuncs(dx,dy) //compiles the dx and dy function using mathjs
  gameBalls = update(dt) //updates the positions of the balls for the game and returns a list of gameballs
  (xNext, yNext) = nextP(x,y,dt) //Calculates a next position using eulers method.

The render module consists of 3 functions and is responsible for rendering a canvas. It uses kinectjs to render the game.

  init (gameMod,containerId) //This initializes the rendering for a specific gameModule.
                             //It expects the game has been initialized.
                             //The containerId should be a div element id.
  start(gameMod,scoreFunc)   //This starts the game. This assumes that you have already called compileFuncs.
                             //The scoreFuncs is a callback function for updating the score display.
  stop()                     //This stops the game.