Ive made this 'game' where you can fire an aibility (a fire ball for instance) from the player towards the mouse (to the point where the mouse was at the time of casting/fireing/shooting the ball), now Id like to know how I could implement it so that if it reaches its destination that it stops, and also how I could make it travel in the direction of the mouse but for a ciurtant distance only.
Here's the code for the fire ball thing:
life += 0.05f;
float dx = (mx - x);
float dy = ((Launcher.GAME_HEIGHT - my) - y);
double direct = Math.atan2(dy, dx);
xv = (float) (spd * Math.cos(direct));
yv = (float) (spd * Math.sin(direct));
x += xv;
y += yv;
Note: xv and yv are velocities, and mx and my are the mouse x and y