[Python] 纯文本查看 复制代码 import pygame
import sys
pygame.init()
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption("移动正方形")
clock = pygame.time.Clock()
black = (0,0,0)
white = (255,255,255)
turtle = pygame.image.load('turtle.png')
spuare_size = 50
spuare_x = 320
spuare_y = 240
while True:
if event in pygame.event.get():
pygame.quit()
sys.exit()
mouse_x,mouse_y = pygame.mouse.get_pos()
keys = pygame.key.get_pressed()
if keys[pygame.K_UP]:
print(len(keys))
print(pygame.K_UP)
spuare_y -= 5
if keys[pygame.K_DOWN]:
spuare_y += 5
if keys[pygame.K_LEFT]:
spuare_x -= 5
if keys[pygame.K_RIGHT]:
print(pygame.K_RIGHT)
spuare_x += 5
screen.fill(white)
screen.blit(turtle,(spuare_x,spuare_y))
pygame.draw.rect(screen,black,(spuare_x,spuare_y,spuare_size,spuare_size))
pygame.display.update()
clock.tick(60) |