Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

StackOverflow10461993

By: a guest on May 5th, 2012  |  syntax: Java  |  size: 0.62 KB  |  views: 121  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }