Commit e17be852 by BellCodeEditor

save project

parent 80dd7fff
Showing with 20 additions and 3 deletions
...@@ -4,6 +4,7 @@ from pygame import locals ...@@ -4,6 +4,7 @@ from pygame import locals
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
x,y=240,120 x,y=240,120
setheading="right"
l=[(180,90),(180,120),(210,120),(x,y)] l=[(180,90),(180,120),(210,120),(x,y)]
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
...@@ -21,7 +22,23 @@ while True: ...@@ -21,7 +22,23 @@ while True:
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
x+=30 elif event.type==locals.KEYDOWN:
if event.key==locals.K_RIGHT and setheading!='left':
setheading='right'
if event.key==locals.K_LEFT and setheading!='right':
setheading='left'
if event.key==locals.K_DOWN and setheading!='up':
setheading='down'
if event.key==locals.K_UP and setheading!='down':
setheading='up'
if setheading=="right":
x+=30
elif setheading=="left":
x-=30
elif setheading=="up":
y-=30
else:
y+=30
l.append((x,y)) l.append((x,y))
l.pop(0) l.pop(0)
# 将背景图画上去 # 将背景图画上去
...@@ -38,4 +55,4 @@ while True: ...@@ -38,4 +55,4 @@ while True:
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
shi.tick(3) shi.tick(5)
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment