Permalink
Browse files

Add LeapMotion as a new player controller!

  • Loading branch information...
StefanoOrdine committed Nov 8, 2015
1 parent bc9928f commit 10861546a5e178539d72ad8fb4947a9f82511b26
@@ -113,6 +113,8 @@ update = ->
playerMovement()
# Firing?
if (leapMotionController.handIsOpen && player.alive)
fireBullet()
if (fireButton.isDown && player.alive)
fireBullet()
@@ -132,20 +134,23 @@ setupExplosion = (explosion)->
playerMovement = ->
maxVelocity = 500
if (cursors.left.isDown && player.body.velocity.x > -maxVelocity)
# Move to the left
player.body.velocity.x -= 20
else if (cursors.right.isDown && player.body.velocity.x < maxVelocity)
# Move to the right
player.body.velocity.x += 20
if (leapMotionController.enabled)
player.body.position.x = leapMotionController.handPalmPositionX * 1024
else
# Slow down
if (player.body.velocity.x > 0)
player.body.velocity.x -= 4
else if (player.body.velocity.x < 0)
player.body.velocity.x += 4
if (cursors.left.isDown && player.body.velocity.x > -maxVelocity)
# Move to the left
player.body.velocity.x -= 20
else if (cursors.right.isDown && player.body.velocity.x < maxVelocity)
# Move to the right
player.body.velocity.x += 20
else
# Slow down
if (player.body.velocity.x > 0)
player.body.velocity.x -= 4
else if (player.body.velocity.x < 0)
player.body.velocity.x += 4
fireBullet = ->
if (game.time.now > bulletTime)
@@ -0,0 +1,12 @@
leapMotionController = {}
Leap.loop(function(frame) {
if(frame.hands.length) {
leapMotionController.enabled = true;
leapMotionController.handPalmPositionX = (frame.hands[0].palmPosition[0] + 255) / 512.0;
leapMotionController.handIsOpen = frame.hands[0].grabStrength < 0.5;
}
else {
leapMotionController.enabled = false;
}
});
@@ -6,6 +6,8 @@ html
meta name="ROBOTS" content="NOODP"
meta name="viewport" content="width=device-width, initial-scale=1"
title= title
script src="//js.leapmotion.com/leap-0.6.4.js"
script src="//js.leapmotion.com/leap-plugins-0.1.11.js"
= stylesheet_link_tag :application, media: 'all'
= csrf_meta_tags
body class=body_class

0 comments on commit 1086154

Please sign in to comment.