I have only been learning pygame for a few weeks mainly following different arcade style game tutorials. Have adapted a pong game and am trying to insert two delays, one when ball hits border (edge of screen behind paddle) then a reset and time delay before the ball starts moving again from the centre. This way the players can see where the ball contacted the edge of screen and then have all sprites reset to their original position before moving off again.
This is the current code:
class Paddle(pygame.sprite.Sprite):
def reset(self):
paddleA.rect.x = 20
paddleA.rect.y = 200
paddleB.rect.x = 670
paddleB.rect.y = 200
class Ball(pygame.sprite.Sprite):
def reset(self):
ball.rect.x = 345
ball.rect.y = 195
pygame.time.delay(1000)
self.velocity = [randint(4,8), randint(-8,8)]
def hit(self):
self.velocity = 0
pygame.time.delay(500)
asl = pygame.sprite.Group()
asl.add(paddleA)
asl.add(paddleB)
asl.add(BorderA)
asl.add(BorderB)
asl.add(ball)
while GameOn:
asl.update()
if pygame.sprite.collide_mask(ball, BorderA):
scoreB+=1
ball.hit()
paddleA.reset()
paddleB.reset()
ball.reset()
if pygame.sprite.collide_mask(ball, BorderB):
scoreA+=1
ball.hit()
paddleA.reset()
paddleB.reset()
ball.reset()
My guess is there needs to be an update in there, but I have tried adding asl.update() and pygame.display.flip() in a couple of different spots to try and get it to reset the sprites before going to the second time.delay but it never works, the delay just lasts longer and the ball still moves as soon as it moves back to the centre.