Неправильный порядок отображения спрайтов в pygame Ссылка на пастбин с кодом: https://pastebin.com/8MMnbaDU import pygame, sys class MyBallClass(pygame.sprite.Sprite): def __init__(self,image_file,speed,location): pygame.sprite.Sprite.__init__(self) self.image=pygame.image.load('football.png') self.image=pygame.transform.scale(self.image,(30,30)) self.rect=self.image.get_rect() self.rect.left, self.rect.top=location self.speed=speed def move(self): global score, score_surf, score_font self.rect=self.rect.move(self.speed) if self.rect.left<0 or self.rect.right>screen.get_width(): self.speed[0]=-self.speed[0] if self.rect.top<=0: self.speed[1]=-self.speed[1] score=score+1 score_surf=score_font.render(str(score),1,(0,0,0))
class MyPaddleClass(pygame.sprite.Sprite): def __init__(self,location=[0,0]): pygame.sprite.Sprite.__init__(self) self.image=pygame.image.load('footballer.png') self.image=pygame.transform.scale(self.image,(150,220)) self.rect=self.image.get_rect() self.rect.left,self.rect.top=location
while running: clock.tick(30) pole_surf=pygame.image.load('pole.png') pole_surf=pygame.transform.scale(pole_surf,(460,320)) pole_rect=pole_surf.get_rect(center=(230,160)) screen.blit(pole_surf,pole_rect) pygame.display.flip() for event in pygame.event.get(): if event.type==pygame.QUIT: running=False elif event.type==pygame.MOUSEMOTION: paddle.rect.centerx=event.pos[0]
if pygame.sprite.spritecollide(paddle, ballGroup, False): myBall.speed[1]=-myBall.speed[1] pygame.display.flip()
myBall.move() if not done: screen.blit(myBall.image, myBall.rect) screen.blit(paddle.image, paddle.rect) screen.blit(score_surf, score_pos) pygame.display.flip() for i in range (lives): width=screen.get_width() screen.blit(myBall.image, [width - 40*i, 20]) pygame.display.flip() pygame.display.flip()