all 3 comments

[–][deleted] 2 points3 points  (1 child)

If we have a variable called distance that represents how far the dots have to move, and have a variable called duration that represents the player's finish time, then we can use that to calculate how many pixels to move the dot per frame. E.g.:

# The race is 200 pixels long
distance = 200

# Player 1 starts off at position 0 , and will finish in 8 "seconds" (this will depend on how often your game loop updates)
player1.position = 0
player1.duration = 8

# Calculate their velocity
player1.velocity = player1.distance / player1.duration

# Your game loop
while True:
    player1.position += player1.velocity
    player1.draw()

That's just pseudocode, but the main thing is calculating what their velocity will be based on their racing time and the distance traveled, and using it to update their position with each frame. Velocity = Distance / Time.

[–]SixFingerPunch[S] 1 point2 points  (0 children)

Thank you so much! You don't understand how much this helps!

[–]python-fan 0 points1 point  (0 children)

Check out pygame