Commit 653c3fb1 by BellCodeEditor

save project

parent c97f957e
Showing with 19 additions and 13 deletions
......@@ -9,15 +9,11 @@ class Block(pygame.sprite.Sprite):
self.rect=self.image.get_rect()
self.rect.x=1000
self.rect.y=500-self.rect.height
pygame.init() # 初始化
self.rect.x=1000
self.rect.y=500-self.rect.height
sflf.score=1
class Player(pygame.sprite.Sprite):
def_init_(self,image):
super()._init_()
def __init__(self,image):
super().__init__()
self.image=image
self.rect=self.image.get_rect()
self.rect.x=150
......@@ -47,6 +43,8 @@ obstacle=Block(bush,cacti,stone)
road_x=0
obstacle_time=0
block_list=pygame.sprite.Group()
gamestate=True
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -56,27 +54,30 @@ while True:
if jumpState == "runing":
if event.key == locals.K_SPACE:
jumpState = "up"
wukong = Player(hero[index])
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
if gamestate==True:
if jumpState == "up": # 起跳状态
if t > 0:
y -= t
t -= 2
wukong.rect.y = y
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
t += 2
wukong.rect.y = y
else:
jumpState = "runing"
t =30
# 悟空造型
wukong = hero[index]
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
# 将背景图画上去
shan_x -=2
if shan_x <-1000:
......@@ -86,7 +87,7 @@ while True:
if lu_x <-1000:
lu_x=0
screen.blit(road, (lu_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空
screen.blit(wukong.image, (150, wukong.rect.y)) # 悟空
obstacle_time+=1
if obstacle_time>60:
......@@ -100,6 +101,11 @@ while True:
screen.blit(sprite_i.image,(sprite_i.rect.x,sprite_i.rect.y))
if sprite_i.rect.x<0-sprite_i.rect.width:
sprite_i.kill()
if pygame.sprite.collide_rect(wukong,obstacle):
gameover=pygame.image.load("gameover.png")
screen.blit(gameoveer,(420,200))
gamestate=False
pygame.display.update()
......
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