Skip to content

Instantly share code, notes, and snippets.

@unstoppablecarl
Created February 18, 2013 20:03
Show Gist options
  • Save unstoppablecarl/4980206 to your computer and use it in GitHub Desktop.
Save unstoppablecarl/4980206 to your computer and use it in GitHub Desktop.
setVelocity: function () {
var difX = ((ig.input.mouse.x - (this.size.x / 2)) - this.pos.x).round();
var difY = ((ig.input.mouse.y - (this.size.y / 2)) - this.pos.y).round();
var max = 100,
maxX = (difX > 0)? max : -max,
maxY = (difY > 0)? max : -max;
this.vel.x += difX * 4;
this.vel.y += difY * 4;
},
decayHandler: function () {
if (this.vel.x > 0){
this.vel.x -= 50;
} else if (this.vel.x < 0){
this.vel.x += 50;
}
if (this.vel.y > 0){
this.vel.y -= 50;
} else if (this.vel.y < 0){
this.vel.y += 50;
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment