import pygame
import random
WIDHT = 800
HEIGHT = 800
BLACK = (0,0,0)
WHITE = (255, 255, 255)
COLO = (random.randint(0,255),
random.randint(0,255),
random.randint(0,255))
speed = 5
x, y = 0, 0
pygame.init()
screen = (pygame.display.set_mode((WIDHT, HEIGHT)))
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
key = pygame.key.get_pressed()
if key[pygame.K_w]:
if y - speed - 15 >= 0:
y -= speed
if key[pygame.K_a]:
if x - speed - 5 >= 0:
x -= speed
if key[pygame.K_s]:
if y + speed + 20 <= HEIGHT:
y += speed
if key[pygame.K_d]:
if x + speed + 20 + 5 <= WIDHT:
x += speed
x_house = x + 20
y_house = y + 20
while y_house < HEIGHT:
y += 9.8
# speed_fall = speed_f = 9.8
# if event.type == pygame.KEYUP:
# if event.key == pygame.K_w:
# while y + 20 != HEIGHT:
# y += speed_f
# speed += speed_fall
screen.fill((0,0,0))
pygame.draw.rect( #сам домик
screen,
COLO,
(x, y, 20, 20)
)
pygame.draw.polygon(screen, #крыша
COLO,
[(x - 5, y), (x_house + 5, y), (x + 10, y - 15)])
pygame.draw.rect(screen, #окно
BLACK,
(x + 5, y + 5, 10, 10))
pygame.draw.line(screen, #рама
COLO,
(x + 5, y + 5), (x + 15, y + 15), 3)
pygame.draw.line(screen,
COLO,
(x + 15, y + 5), (x + 5, y + 15), 3)
pygame.display.flip() #обновление
pygame.quit()