I'm trying to make my first real time game.
I'm having problems with the movements using the mouse though. If close to theX axis, the player is moving fine, but if close to the Y axis(going southwards) he moves fast even though I'm taking into consideration the x coordinates.
Edit: I rewritten the code following your advice and the answer below. I hope it's better written now.
if(input.isMousePressed(Input.MOUSE_LEFT_BUTTON))
{
mousex = input.getAbsoluteMouseX();
mousey = input.getAbsoluteMouseY();
if(mousex<= gc.getWidth()/2f)
mousex = x - (gc.getWidth()/2f - mousex);
else
mousex = x + (mousex - gc.getWidth()/2f);
if(mousey<= gc.getHeight()/2f)
mousey = y - (gc.getHeight()/2f - mousey); // calculate the x and y needed to move to
else
mousey = y + (mousey - gc.getHeight()/2f); // mousex and mousey in relation to the map and not screen position
// because screen scrolls
System.out.println("mousex: "+mousex+"mousey: "+ mousey);
int delta_x=(int) (mousex-x);
int delta_y=(int) (mousey-y);
double rotangle = Math.atan2(delta_y,delta_x);
double rot = Math.toDegrees(rotangle);
if(rot==0)
rot=0.1;
texture.setRotation((float) rot+90);
}
if( (Math.abs(x-mousex)>1))
{
this.moveForward(0.2f, texture.getRotation(), delta, null);
}
else
if( (Math.abs(y-mousey)>1))
{
this.moveForward(0.2f, texture.getRotation(), delta, null);
}
else
this.setX(mousex);
}
