alarm
Задайте вопрос
Информатика
Shaktizil

Неправильный порядок отображения спрайтов в pygameimport pygame, sysclass 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=locationself. speed=speeddef move(self):global score, score_surf, score_fontself. 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+1score_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=locationpygame. init()screen=pygame. display. set_mode([460,320])pygame. display. set_caption('Проект "Футболист"')clock=pygame. time. Clock()myBall=MyBallClass('footballer. png',[10,20],[20,20])ballGroup=pygame. sprite. Group(myBall)paddle=MyPaddleClass([270,150])lives=3;score=0score_font=pygame. font. Font(None,50)score_surf=score_font. render(str(score),1,(0,0,0))score_pos=[10,10];done=False;running=Truepygame. display. flip()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=Falseelif 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()if myBall. rect. top>=screen. get_rect(). bottom:lives=lives-1if lives==0:final_text1="Конец игры"final_text2="Количество очков:" + str(score)ft1_font=pygame. font. Font(None,70)ft1_surf=ft1_font. render(final_text1,1,(255,0,0))ft2_font=pygame. font. Font(None,50)ft2_surf=ft2_font. render(final_text2,1,(255,0,0))screen. blit(ft1_surf,[screen. get. width()/2 - ft1_surf. get_width()/2,100])screen. blit(ft2_surf,[screen. get. width()/2 - ft2_surf. get_width()/2,200])pygame. display. flip()done=Trueelse:pygame. time. delay(5000)myBall. rect. topleft=[50,50] if event. type==pygame. QUIT:running=Falsepygame. quit()

ответы: 1
Зарегистрируйтесь, чтобы добавить ответ
Чтобы ответить необходимо зарегистрироваться.

Другие вопросы: - Информатика

посчитайте ЭТО На початковій зу

4.Внимательно прочитайте код про

Мини конспект на тему Безопасный

В алгоритме, записанном ниже, ис

4. Написать программу решения да

У клас SportResults додайте змін

Контакты
Реклама на сайте