+
+ # Return the current angle of velocity
+ # Often used to rotate the displayed image with the correct angle
+ fun velocity_angle: Float
+ do
+ return atan2(self.vx.to_f, -self.vy.to_f)
+ end
+
+ # Return the angle to target an other sprite
+ fun angle_to(target: Sprite): Float
+ do
+ return atan2((target.x-self.x).to_f, (self.y-target.y).to_f)
+ end
+
+ # Update of vx and vy toward a given angle and magnitude
+ fun set_velocity(angle: Float, maginude: Int)
+ do
+ var magf = maginude.to_f
+ self.vx = (angle.sin * magf).to_i
+ self.vy = (angle.cos * -magf).to_i
+ end
+