I´m trying to make a game where you fly a jet in it, that is controlled via mouse. Right now its flying directly at the mouse. So it means that it is working, but right now i want to make it go via turn(<value>) to the mouse so that this doesn´t happen.
this is my code right now:
this is my code right now:
public class Jet extends Actor
{
private int mouseX;
private int mouseY;
public int timer = 0;
/**
* Act - tut, was auch immer Jet tun will. Diese Methode wird aufgerufen,
* sobald der 'Act' oder 'Run' Button in der Umgebung angeklickt werden.
*/
public void act()
{
move(4);
setRotation();
}
private void setRotation()
{
if(Greenfoot.mouseMoved(null) || Greenfoot.mouseDragged(null)) {
MouseInfo mouse = Greenfoot.getMouseInfo();
mouseX = mouse.getX();
mouseY = mouse.getY();
}
if (timer > 0) {
timer--;
}
if(timer == 0) {
timer = 3;
setRotation(pointTo(mouseX,mouseY));
}
}
public int pointTo(int x, int y)
{
int dX = x - getX();
int dY = y - getY();
double rotation = Math.atan2(dY, dX);
rotation = Math.toDegrees(rotation);
return (int)rotation;
}
}

