ruby gosu moving image to the direction is pointed at -


i have been trying make image move direction pointed at.
keeps moving in random directions :(
cant figure out why...

here's code:
require 'gosu'

class game < gosu::window def initialize super(1280, 720, true) @image = gosu::image.from_text ':', 100 @ang = 1 @x = 640 - @image.width @y = 360 - @image.height end def update @sngx = (10.0/math.cos(@ang.to_f)).to_i @sngy = (10.0/math.sin(@ang.to_f)).to_i @n = gosu::image.from_text @ang.to_s, 50 end def draw @image.draw_rot @x, @y, 0, @ang @n.draw 0, 0, 0 end def button_down id close if id == gosu::kbescape if id == gosu::kbe @ang += 10 end if id == gosu::kbq @ang -= 10 end if id == gosu::kbw @x += @sngx @y += @sngy end end end

game.new.show

it not behave random.

i'd bet issue math trigonometric functions expect values in radians not grads, @sngx , @sngy assigned extreme results.

from ruby docs math::cos:

computes cosine of x (expressed in radians). returns float in range -1.0..1.0

hope know how convert grads radians.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -