pygame简单小游戏 移动小球

键盘a,d,s,w移动小球

需要安装pygame cmd里输入pip install pygame

import pygame
import sys

pygame.init()
screen = pygame.display.set_mode((400, 300))
x, y = 200, 150

while True:
    pygame.time.delay(20)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
    keys = pygame.key.get_pressed()
    if keys[pygame.K_a]:
        x -= 5
    if keys[pygame.K_d]:
        x += 5
    if keys[pygame.K_w]:
        y -= 5
    if keys[pygame.K_s]:
        y += 5
    screen.fill((0, 0, 0))
    pygame.draw.circle(screen, (0, 250, 100), (x, y), 50)
    pygame.display.update()

 

posted @ 2021-08-25 10:15  KevinLikesCoding  阅读(293)  评论(0编辑  收藏  举报