Results 1 to 3 of 3
- 08-10-2009, 06:19 AM #1Member
- Join Date
- Aug 2009
- Rep Power
Moving objects - setting different speed
Hi, sorry my english.
I'm making a football game in Java. I tried to make it in other languages in the past (delphi and vb6) and in all of them I had the same question which I can't even now solve.
It might be a conceptual one, that's why Im asking here.
I have a class player which calculates where a player should move (an X and Y point) and then through some math calculations I get whether he should move 1 or 0 of X and 1 or 0 of Y to reach that point.
So if my player is on X:200,Y:200 and he has to move to X:400,Y:400, he will move 1 of X and 1 of Y each time my timer is fired until he reaches point 400,400.
To show the player's movement to the user, I have a timer which is launched each 1 ms (it fires an event who moves the player by repainting) and it works fine (I can see my players moving through the screen). But the problem is that even using 1ms my players only move in a normal speed. I can't make my fastest player to move more quickly. I can do this only by moving him 2 by 2 instead 1 by 1 but when you see the player's movement you can see the "jumps" he does.
How can i simulate different speed in player's movement?
Thanks in advance.
- 08-13-2009, 06:57 AM #2Senior Member
- Join Date
- Mar 2009
- Rep Power
The only way is to slow down how quickly the 'normal' speed timer fires.
Very Fast: 1 ms
Fast: 2 ms
Normal: 3 ms
Slow: 4 ms
Very Slow: 5 ms
This will simulate different movement speeds for the players.If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
- 08-14-2009, 02:14 AM #3
What I would do is map the world to a floating point coordinates system (or some sort of adjusted size coordinate system), and just fire the timer off more often. I'm guessing that the x,y that you are using are actual pixels on the window. That makes it so that if someone is going 1 pixel per second, the next fastest person has to be going twice as fast.
Someone going 1.25 and someone going 1.50 would be much more realistic.
- By Krons in forum Advanced JavaReplies: 10Last Post: 04-16-2009, 07:30 AM
- By kalpo in forum NetworkingReplies: 0Last Post: 03-31-2009, 01:20 AM
- By bezudar in forum Advanced JavaReplies: 3Last Post: 11-20-2008, 10:53 AM
- By fred in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:06 PM
- By bbq in forum JDBCReplies: 1Last Post: 06-28-2007, 06:34 PM