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?

Thumbs up

Using trigonometry to handle the movimentation function.

Thumbs up

Trig with doubles for the position. If you need to use integer precision for the UI, you'd have to round.

Thumbs up

@CAE, whats the disadvantages on rounding the new values of the vectors?

Thumbs up

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.

Thumbs up

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?

Thumbs up

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)).

Thumbs up

Thank you, i haven't think on it, and magnitude also works on this case?

Thumbs up

Yeah, the magnitude and the length are effectively the same, for these purposes.

Thumbs up

Aprone's coding tutorial?  Where is it?  Never saw it.

Thumbs up

http://forum.audiogames.net/viewtopic.p … 58&p=2

Thumbs up