Skip to content

Commit

Permalink
more work
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeetienne committed Dec 24, 2011
1 parent 10a3e9b commit 53cd0ea
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions js/lib/microphysics.virtualjoystickAccelerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
vphy.VirtualJoystickAccelerator = vphy.Class({
__extends__ : vphy.Accelerator,
__init__ : function(args){
var params = vphy.extend({
}, args);
this.bodies = params.bodies;
this.joystick = params.joystick;
this.acceleration = params.acceleration;
},
perform : function(){
var joystick = this.joystick;
var acc = this.acceleration;
var key = {
right : joystick.right(),
up : joystick.up(),
left : joystick.left(),
down : joystick.down()
};
// TODO do something like device orientation
// something which takes advantage of the analogic part
for(var i = 0; i < this.bodies.length; i++){
var body = this.bodies[i];
if( key.right ) body.accelerate(+acc,0,0);
if( key.left ) body.accelerate(-acc,0,0);
if( key.up ) body.accelerate(0,0,-acc);
if( key.down ) body.accelerate(0,0,+acc);
}
}
});

0 comments on commit 53cd0ea

Please sign in to comment.