在python上移动点

2024-06-09 09:43:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道如何在屏幕上移动一个点。就像经典的蠕虫游戏。 选择的键是w代表上s下a代表左,d代表右。 我使用的是python2.5.4

另外,我是一条Python


Tags: 游戏屏幕代表蠕虫经典
1条回答
网友
1楼 · 发布于 2024-06-09 09:43:29

您可以从pygame使用!在

this是由pygame制作的简单的蛇游戏!在

或者使用以下代码:

import sys, pygame
pygame.init()
size = width, height = 800, 400
screen = pygame.display.set_mode(size)
position=[20,20]
white=[255,255,255]

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            loop=False
        if event.type==pygame.KEYDOWN:
            if event.key==pygame.D_KEY:
                position[0]+=20


    screen.fill(white)
    pygame.draw.circle(screen,[255,0,0],position,100,3)
    pygame.display.flip()

pygame.quit()

相关问题 更多 >