Search code examples
rubylibgosu

Gosu: Making image point to cursor


I'm using Gosu on Ruby 1.9.3 MRI

I have a Player class, with it's own x/y variables, aswell as a Cursor class with the same. Considering the Player and Cursor class don't differ in movement and values are the same, how can I calculate the angle to #draw_rot the player in?

screencap of window Above: screencap of the game window.

The cursor is an image centered on the actual OS cursor, by the way.


Solution

  • The angle between the two objects is:

    angle = Gosu.angle(player.x, player.y, cursor.x, cursor.y)
    

    which is what you can use as the angle when drawing the player with Image::draw_rot