Commit fa50ce17 by BellCodeEditor

save project

parent 945eeb29
Showing with 64 additions and 51 deletions
...@@ -42,6 +42,7 @@ aa=Block(bush,cacti,stone) ...@@ -42,6 +42,7 @@ aa=Block(bush,cacti,stone)
Block_list=pygame.sprite.Group() Block_list=pygame.sprite.Group()
time=0 time=0
b=0 b=0
gamestate=True
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -51,66 +52,78 @@ while True: ...@@ -51,66 +52,78 @@ while True:
if jumpState == "runing": if jumpState == "runing":
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = "up" jumpState = "up"
if jumpState == "up": # 起跳状态
if t > 0:
y -= t
t -= 2
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
t += 2
else:
jumpState = "runing"
t =30
# 悟空造型
wukong = wu(hero[index]) wukong = wu(hero[index])
if jumpState == "runing": # 跑步状态下 if jumpState == "runing": # 跑步状态下
index += 1 index += 1
if index >= 5: if index >= 5:
index = 0 index = 0
#if aa.rect.x<=0-aa.rect.width: if gamestate==True:
#aa=Block(bush,cacti,stone) if jumpState == "up": # 起跳状态
#aa.rect.x-=8 if t > 0:
y -= t
wukong.rect.y=y
t -= 2
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
wukong.rect.y=y
t += 2
else:
jumpState = "runing"
t =30
# 悟空造型
# wukong = wu(hero[index])
# if jumpState == "runing": # 跑步状态下
# index += 1
# if index >= 5:
# index = 0
#if aa.rect.x<=0-aa.rect.width:
#aa=Block(bush,cacti,stone)
#aa.rect.x-=8
# 将背景图画上去
shan_x-=5
if shan_x<=-1000:
shan_x=0
lu_x-=8
if lu_x<=-1000:
lu_x=0
time+=1
if time>=50:
time=0
b=random.randint(0,40)
if b>20:
aa=Block(bush,cacti,stone)
Block_list.add(aa)
# 将背景图画上去
shan_x-=5
if shan_x<=-1000:
shan_x=0
lu_x-=8
if lu_x<=-1000:
lu_x=0
time+=1
if time>=50:
time=0
b=random.randint(0,40)
if b>20:
aa=Block(bush,cacti,stone)
Block_list.add(aa)
screen.blit(background, (shan_x,0))
screen.blit(road, (lu_x, 500)) # 路
screen.blit(wukong.image, (wukong.rect.x,y)) # 悟空
for c in Block_list:
c.rect.x-=8
screen.blit(c.image, (c.rect.x, c.rect.y))
if c.rect.x<=0-c.rect.width:
c.kill()
screen.blit(background, (shan_x,0))
screen.blit(road, (lu_x, 500)) # 路
screen.blit(wukong.image, (wukong.rect.x,y)) # 悟空
for c in Block_list:
c.rect.x-=8
screen.blit(c.image, (c.rect.x, c.rect.y))
if c.rect.x<=0-c.rect.width:
c.kill()
if pygame.sprite.collide_rect(wukong,c):
gameover=pygame.image.load('gameover.png')
screen.blit(gameover,(400,200))
gamestate=False
# 刷新画面
pygame.display.update() # 刷新画面
FPS.tick(50) pygame.display.update()
\ No newline at end of file FPS.tick(50)
\ 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