0
import pygame, sys
pygame.init()

class Person:
    def __init__(self, screen):
        self.player = pygame.image.load('person.png')
        self.x = 400
        self.y = 300
        self.screen = screen
        self.speed = 5

    def draw(self):
        self.screen.blit(self.player, (self.x, self.y))

    def move(self):
        keys = pygame.key.get_pressed()
        if keys[pygame.K_LEFT]:
            self.x -= self.speed

class Game:
    def __init__(self):
        self.size = [600,900]
        self.screen = pygame.display.set_mode(self.size)
        pygame.display.set_caption("Game")
        self.person = Person(self.screen)

    def run(self):
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()
                elif event.type == pygame.K_DOWN:
                    self.person.move()

            self.screen.fill((255,255,255))
            self.person.draw()
            pygame.display.update()

if __name__ == '__main__':
    game = Game()
    game.run()

1 ответ 1

0

Вместо pygame.K_DOWN нужно написать pygame.KEYDOWN.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.