Commit a39f9a31 by BellCodeEditor

save project

parent 749f661f
Showing with 12 additions and 7 deletions
...@@ -18,7 +18,8 @@ hero = [pygame.image.load('hero1.png'), ...@@ -18,7 +18,8 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero5.png')] pygame.image.load('hero5.png')]
index = 0 index = 0
State='running' State='running'
y=400 y=400
t=30
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -26,18 +27,21 @@ while True: ...@@ -26,18 +27,21 @@ while True:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type==locals.KEYDOWN: if event.type==locals.KEYDOWN:
if event.key==locals.K_SPACE: if event.key==locals.K_SPACE and State=='running':
State='up' State='up'
if State=='up': if State=='up':
if y>150: if t>0:
y-=10 y-=t
t-=2
else: else:
State='down' State='down'
if State=='down': if State=='down':
if y<400: if y<400:
y+=10 y+=t
t+=2
else: else:
State='running' State='running'
t=30
...@@ -48,7 +52,8 @@ while True: ...@@ -48,7 +52,8 @@ while True:
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(road, (0, 500)) screen.blit(road, (0, 500))
screen.blit(hero[index], (150, y)) screen.blit(hero[index], (150, y))
index+=1 if State=='running':
index+=1
if index>len(hero)-1: if index>len(hero)-1:
index=0 index=0
# 刷新画面 # 刷新画面
......
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