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.
@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?
Aprone's coding tutorial? Where is it? Never saw it.
CAE, i was thinking on several ways to handle that kind of behaviour on movimentation, but how did you made footsteps on JLA sound every 1.0 tiles based on player's speed?
I don't remember which of round, floor, or ceiling I used for this. I think it was round. I guess the other thing is that, when I'm having something move, I keep the old variables unchanged until the move is confirmed, and use temporary variables for the target position. So it's simple in this case to say if(round(x, 0) != round(tx, 0)) play_footstep(tx, ty); .
If you're doing this with top down or first person or 3d, you'd need to compare the lengths of the vectors instead, otherwise you'd get steps sounding much different when the player moves diagonally. I think that Swamp had this issue for one version early on.