画面上でドットを移動する方法を知りたいです。ワームと呼ばれる古典的なゲームのように。選択するキーは、上は w、下は a、左は d、右は d です。私はpython 2.5.4を使用しています
PS私はパイソン初心者です
pygameから使えます!
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()