1

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

2

Using trigonometry to handle the movimentation function.

Thumbs up

3

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

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up

4

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

Thumbs up

5

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.

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up

6

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

7

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

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up

8

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

Thumbs up

9

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

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up

10

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

Thumbs up

11

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

Thumbs up

12

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?

Thumbs up

13

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.

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up