Commit effea78b by BellCodeEditor

save project

parent 23e444c6
Showing with 18 additions and 1 deletions
...@@ -20,6 +20,8 @@ hero5= pygame.image.load('hero5.png') ...@@ -20,6 +20,8 @@ hero5= pygame.image.load('hero5.png')
hero=[hero1,hero2,hero3,hero4,hero5] hero=[hero1,hero2,hero3,hero4,hero5]
index = 0 index = 0
a=0 a=0
y=400
runstate="running"
pygame.display.set_caption("悟空酷跑") pygame.display.set_caption("悟空酷跑")
while True: while True:
b=random.randint(60,100) b=random.randint(60,100)
...@@ -27,6 +29,20 @@ while True: ...@@ -27,6 +29,20 @@ while True:
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type==locals.KEYDOWN:
if event.key==locals.K_SPACE:
runstate="up"
if runstate=="up":
if y>150:
y-=5
else:
runstate="down"
if runstate=="down":
if y<400:
y+=5
else:
runstate=="running"
a+=1 a+=1
if a==len(hero)-1: if a==len(hero)-1:
a=0 a=0
...@@ -34,7 +50,7 @@ while True: ...@@ -34,7 +50,7 @@ while True:
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(road, (0, 500)) screen.blit(road, (0, 500))
screen.blit(mode, (150, 400)) screen.blit(mode, (150, y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(b) FPS.tick(b)
\ 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