0
0 Комментариев

import pygame, sys, time
from pygame.locals import *

pygame.init()

WINDOWWIDTH = 400
WINDOWHEIGHT = 400
windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)
pygame.display.set_caption(‘Анимация’)

RIGHT = ‘right’
LEFT = ‘left’

counter = 1
countera = 1

MOVESPEED = 4

BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)

b1 = {‘rect’:pygame.Rect(200, 150, 50, 50), ‘color’:RED, ‘dir’:RIGHT}
boxes = [b1]

basicFont = pygame.font.Font(None, 48)
text1 = basicFont.render(‘..’, 1, BLACK)

text2 = basicFont.render(‘…’, 1, BLACK)

while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()

windowSurface.fill(WHITE)

for b in boxes:
if b[‘dir’] == LEFT:
b[‘rect’].left -= MOVESPEED
if b[‘dir’] == RIGHT:
b[‘rect’].left += MOVESPEED

if b[‘rect’].left < 0:
if b[‘dir’] == LEFT:
windowSurface.blit(text1, (160, 70))
counter += 1
text3 = basicFont.render(str(counter), 1, BLACK)
windowSurface.blit(text3, (10, 10))
pygame.display.flip()
time.sleep(2)
b[‘dir’] = RIGHT
if b[‘dir’] == LEFT:
b[‘dir’] = RIGHT
if b[‘rect’].right > WINDOWWIDTH:
if b[‘dir’] == RIGHT:
windowSurface.blit(text2, (160, 70))
countera += 1
text4 = basicFont.render(str(countera), 1, BLACK)
windowSurface.blit(text4, (10, 10))
pygame.display.flip()
time.sleep(2)
b[‘dir’] = LEFT
if b[‘dir’] == RIGHT:
b[‘dir’] = LEFT

pygame.draw.rect(windowSurface, b[‘color’], b[‘rect’])

for i in range():
if b1 WINDOWWIDTH == 200 :
import time
b1 == time.sleep(10)

pygame.display.update()
time.sleep(0.02)

line 73-76

квадратик должен останавливаться по центру на 10 сек


Добавить комментарий