Commit e95b6668 by BellCodeEditor

save project

parent 690cc02e
Showing with 17 additions and 1 deletions
...@@ -5,6 +5,7 @@ import random ...@@ -5,6 +5,7 @@ import random
pygame.init() pygame.init()
x,y=240,120 x,y=240,120
# 创建一个窗口 # 创建一个窗口
s="right"
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
t=pygame.time.Clock() t=pygame.time.Clock()
# 背景 # 背景
...@@ -18,8 +19,23 @@ while True: ...@@ -18,8 +19,23 @@ while True:
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
elif event.type==locals.KEYDOWN:
if event.key==locals.K_RIGHT and s !='left' :
s='right'
if event.key==locals.K_LEFT and s !='right' :
s='left'
if event.key==locals.K_UP and s !='down' :
s='up'
if event.key==locals.K_DOWN and s !='up' :
s='down'
if s=='right':
x+=30 x+=30
elif s=='left':
x-=30
elif s=='down':
y+=30
else :
y-=30
p.append((x,y)) p.append((x,y))
p.pop(0) p.pop(0)
t.tick(3) t.tick(3)
......
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