-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10a3e9b
commit 53cd0ea
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
}); |