How to make one object move after another?

import random
WIDTH = 500
HEIGHT = 500
bg = Actor('bg_space')
platform = Actor('platforma')
ball = Actor('ball')
a=random.randint(-2,2)
b=random.randint(3,4)
platform1=Actor("platforma1")
def draw():
    screen.clear()
    bg.draw()
    platform.draw()
    ball.draw()
    platform1.draw()
def update():
    global a
    ball.left=ball.left+a
    if (ball.left>WIDTH-35) or (ball.left<0):
        a=-a
    global b
    ball.top=ball.top+b
    if (ball.top<0):
        quit()
    if ball.left==platform.left and ball.top==platform.top:
        b=-b
        a=-a
    if (ball.colliderect(platform)):
        a=-a + random.randint(-3,3)
        b=-b
    if (ball.colliderect(platform1)):
        a=-a + random.randint(-3,3)
        b=-b
    if ball.top>HEIGHT:
        quit()
        
ball.pos=250,250
platform1.pos=250,40
platform.pos=250,485
def on_mouse_move(pos):
        platform.left=pos[0]
        platform.top=460    

Game

How can I make the upper platform move horizontally along the horizontal coordinates of the ball? I want to create a game like ping pong but endless I would like to ask you to explain the code if possible.



Read more here: https://stackoverflow.com/questions/67010679/how-to-make-one-object-move-after-another

Content Attribution

This content was originally published by SlazZzor at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: