Я получил этот код из учебника, но я добавил кое-что, чтобы сделать его своим собственным. Некоторое время назад я возился и сумел сделать управляемый объект изображением. Поэтому я мог перемещать изображение по экрану с помощью W A S D , но я изменил его и забыл, как его исправить сейчас и не может blit
вывести его на экран. Это просто прямоугольник, который я могу перемещать по экрану. Как мне сделать изображение снова?
import pygame
pygame.init()
win = pygame.display.set_mode((500,500))
pygame.display.set_caption("Altoria")
mc_front = pygame.image.load('bernie front.jpg')
mc_front = pygame.transform.scale(mc_front, (100, 160))
block = pygame.image.load('block.png')
block = pygame.transform.scale(block,(100,60))
block_x = 100
block_y = 50
x = 50
y = 400
width = 40
height = 60
vel = 20
run = True
while run:
win.blit(block, [block_x, block_y])
pygame.display.update()
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_a] and x > vel: # Making sure the top left position of our character is greater than our vel so we never move off the screen.
x -= vel
if keys[pygame.K_d] and x < 500 - vel - width: # Making sure the top right corner of our character is less than the screen width - its width
x += vel
if keys[pygame.K_w] and y > vel: # Same principles apply for the y coordinate
y -= vel
if keys[pygame.K_s] and y < 500 - height - vel:
y += vel
win.fill((0,0,0))
pygame.draw.rect(win, (250,0,0), (x, y, width, height))
pygame.display.update()
pygame.quit()