Created
August 22, 2015 20:49
-
-
Save jonathanhirz/f03dcf52c69a4780fab6 to your computer and use it in GitHub Desktop.
monster_movement
This file contains hidden or 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
override function update(dt:Float) { | |
velocity.x += acceleration.x * dt; | |
monster.pos.x += velocity.x * dt; | |
velocity.y += acceleration.y * dt; | |
monster.pos.y += velocity.y * dt; | |
if(Luxe.input.inputdown('right')) { | |
acceleration.x = move_speed; | |
} | |
if(Luxe.input.inputdown('left')) { | |
acceleration.x = -move_speed; | |
} | |
if(Luxe.input.inputdown('up')) { | |
acceleration.y = -move_speed; | |
} | |
if(Luxe.input.inputdown('down')) { | |
acceleration.y = move_speed; | |
} | |
if((Luxe.input.inputdown('left') && Luxe.input.inputdown('right')) || ((!Luxe.input.inputdown('left')) && !Luxe.input.inputdown('right'))) { | |
acceleration.x = 0; | |
velocity.x *= dampening_amount; | |
} | |
if((Luxe.input.inputdown('up') && Luxe.input.inputdown('down')) || ((!Luxe.input.inputdown('up')) && !Luxe.input.inputdown('down'))) { | |
acceleration.y = 0; | |
velocity.y *= dampening_amount; | |
} | |
velocity.x = Maths.clamp(velocity.x, -max_speed, max_speed); | |
velocity.y = Maths.clamp(velocity.y, -max_speed, max_speed); | |
} //update |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment