GithubHelp home page GithubHelp logo

rlugojr / planetary-gamejs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from oberhamsi/planetary-gamejs

0.0 1.0 0.0 256 KB

physics game, a gamejs app

Home Page: http://gamejs.org/apps/planetary/

JavaScript 94.48% HTML 5.52%

planetary-gamejs's Introduction

Planetary

A Gamejs.org application built for the Global Game Jam 2011.

Box2d

The game interacts with the box2d code via my custom, small box2d.js module. This module initializes the physics world and provides us with functions to create the handfull of predefined body forms needed.

The ship sprite is the only moving sprite and therefor the only type of object that must update its position according to the box2d simulation. It does so by reading the appropriate values from the box2d body it has attached:

// in Ship.prototype.update
var t = this.b2body.m_xf;
this.rect.left = t.position.x;
this.rect.top = t.position.y;

Compared to the other sprites, ships interact a lot with the physics stuff. For example, I forcefully stop a Ship once it moves really slowly (to avoid boring the player).

Another box2d related class to highlight is the ContactListener. The listener instance gets informed about all collision in the box2d world. The collision results only specify the box2d bodies involved but each of those bodies has a userData object attached. And via that userData the ContactListener can resolve which sprite or other game object the physics body belongs to and what the collision means for the game (e.g., point scored, ship killed).

Touch interfaces & low CPU environment

Planetary runs on the iPad at about 7 frames per second. I took extra care not to deplete the iPad's battery: fps.js keeps an average of the frames rendered per second. Heavy optimizations kick in if the average drops below a certain threshold.

For touch interfaces I am simply re-dispatching touch events as mouse events. The mouse events then get picked up, as usual, by the GameJs event system. This is good enough for simple drag & drop interactions. And that way I didn't even have to modify any of the game's event handlers. The small touch.js module creates the necessary Dom handlers that do the re-dispatching.

The rest of the modules are the usual suspects: actors.js holds the gamejs.sprite.Sprite subclasses - anything visible on the screen - and main.js is mostly model logic and event handling.

planetary-gamejs's People

Contributors

oberhamsi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.