So here's the goal. Before the ball is struck, the player should be able to set the targeted angle which he wants the ball to travel. In other words, there will be a key to press, and then by hitting the arrow keys, a sound will move from left to right, changing the position, the angle as it were. So instead of hitting the ball exactly diagonally, (1,1, 2,2, etc), they might choose an angle that doesn't go straight, but doesn't go exactly diagonally. Maybe the angle means that it would travel more along the Y axis, while still travelling X, just less than it would diagonally., so more straight than left or right. Or maybe the angle is sharper than diagonally, so more horizontally than straight. What would be the most efficient way to handle this?
Using trigonometry to handle the movimentation function.
Trig with doubles for the position. If you need to use integer precision for the UI, you'd have to round.
@CAE, whats the disadvantages on rounding the new values of the vectors?
I would only round them for i/o, since you'd otherwise lose precision and get undesired behavior. You'd probably want to round elsewhere for readability, since the user mostly cares which integer square the object is mostly in, and not if it's really at 1.743981.
Yes of cource, for handling movements based on angle i understud how can i do it with the aprone's coding tutorial, but my problem is playing sounds when the player moves exactly 1.0 from their previous location that the footstep sound was eard, for example every 1.0 that any axis increases. You know any math formula to handle it?
There are a few ways. If the position is a vector, you can store its length before the movement, and compare it to afterward. Or you can keep track of the distance traveled, and when it reaches 1.0, play the sound then.
You can tell when the integer part of a double has changed multiple ways, such as if(floor(oldDistance)!=floor(newDistance)).
Thank you, i haven't think on it, and magnitude also works on this case?
Yeah, the magnitude and the length are effectively the same, for these purposes.
Aprone's coding tutorial? Where is it? Never saw it.