Commit b8245204 by BellCodeEditor

save project

parent d4ce2f64
Showing with 28 additions and 17 deletions
...@@ -13,44 +13,46 @@ cacti = pygame.image.load('cacti.png') # 仙人掌 ...@@ -13,44 +13,46 @@ cacti = pygame.image.load('cacti.png') # 仙人掌
apple = pygame.image.load('bush.png') # 灌木丛 apple = pygame.image.load('bush.png') # 灌木丛
hero = pygame.image.load('hero1.png') hero = pygame.image.load('hero1.png')
index = 0 index = 0
heros=[pygame.image.load('hero1.png'), heros=[
pygame.image.load('hero1.png'),
pygame.image.load('hero2.png'), pygame.image.load('hero2.png'),
pygame.image.load('hero3.png'), pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'), pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')] pygame.image.load('hero5.png')]
y=400 y=400
herostatus="running" herostatus="running"
t=30
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type==locals.KEYDOWN: if event.type==locals.KEYDOWN:
if event.key==locals.K_SPACE: if event.key==locals.K_SPACE:
if herostatus=="running": if herostatus=="running":
herostatus="jumping" herostatus="jumping"
print(1)
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if herostatus=="jumping": if herostatus=="jumping":
y=y-5
if y<150: if t>0:
y=y-t
t=t-2
else:
herostatus="down" herostatus="down"
elif herostatus=="down": elif herostatus=="down":
y=y+5 if t<=30:
if y>400: y=y+t
t=t+2
else:
t=30
herostatus="running" herostatus="running"
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(road, (0, 500)) screen.blit(road, (0, 500))
screen.blit(heros[index], (150, y)) screen.blit(heros[index], (150, y))
print(y) if herostatus=="running":
index=index+1 index=index+1
if index>4: if index>4:
index=0 index=0
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(15) FPS.tick(60)
s=30
b=0
while True:
s=s-2
b=b+s
if s<0:
break
print(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