Advertisement
Guest User

StackOverflow10461993

a guest
May 5th, 2012
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. import org.newdawn.slick.Image;
  2. import org.newdawn.slick.Input;
  3.  
  4. /**
  5.  *
  6.  */
  7. public class SO10461993Test {
  8.    
  9.     private Image image;
  10.     private float x;
  11.     private float y;
  12.    
  13.     public SO10461993Test(Image image) {
  14.         this.image = image;
  15.         x = 300;
  16.         y = 400;
  17.     }
  18.    
  19.     public void update(Input input, float delta) {
  20.         float mouseX = input.getMouseX();
  21.         float mouseY = input.getMouseY();
  22.         float xDistance = mouseX - x;
  23.         float yDistance = mouseY - y;
  24.         double angleToTurn = Math.toDegrees(Math.atan2(yDistance, xDistance));
  25.         image.setRotation((float)angleToTurn);
  26.     }
  27.  
  28.     public void draw() {
  29.         image.draw(x, y);
  30.     }  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement