Commit 1fde446e by BellCodeEditor

save project

parent b6278a34
Showing with 26 additions and 8 deletions
...@@ -10,6 +10,15 @@ class Block(pygame.sprite.Sprite): ...@@ -10,6 +10,15 @@ class Block(pygame.sprite.Sprite):
self.rect=self.image.get_rect() self.rect=self.image.get_rect()
self.rect.x=1000 self.rect.x=1000
self.rect.y=500-self.rect.height self.rect.y=500-self.rect.height
y=400
class Block2(pygame.sprite.Sprite):
def __init__(self,image):
super().__init__()
self.image=image
self.rect=self.image.get_rect()
self.rect.x=150
self.rect.y=400
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
zaw_list=pygame.sprite.Group() zaw_list=pygame.sprite.Group()
...@@ -29,15 +38,15 @@ pygame.display.set_caption('悟空酷跑') ...@@ -29,15 +38,15 @@ pygame.display.set_caption('悟空酷跑')
a=0 a=0
t=30 t=30
zaw=Block(stone,cacti,apple) zaw=Block(stone,cacti,apple)
wukong_1=hero[0] wukong_1=Block2(hero[0])
wukong='running' wukong='running'
y=400
#z=random.choice([stone,cacti,apple]) #z=random.choice([stone,cacti,apple])
#rect=stone.get_rect() #rect=stone.get_rect()
#z_x=1000 #z_x=1000
time=0 time=0
road_x=0 road_x=0
bg_x=0 bg_x=0
gameover=False
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:
...@@ -46,30 +55,35 @@ while True: ...@@ -46,30 +55,35 @@ while True:
if event.type==locals.KEYDOWN: if event.type==locals.KEYDOWN:
if event.key==locals.K_SPACE and wukong=='running': if event.key==locals.K_SPACE and wukong=='running':
wukong='up' wukong='up'
if gameover==False:
if wukong=='running':
wukong_1=Block2(hero[a])
a+=1
if a>=5:
a=0
if wukong=='up': if wukong=='up':
if t>0: if t>0:
y-=t y-=t
wukong_1.rect.y=y
t-=2 t-=2
else: else:
wukong='down' wukong='down'
if wukong=='down': if wukong=='down':
if t<=30: if t<=30:
y+=t y+=t
wukong_1.rect.y=y
t+=2 t+=2
else: else:
wukong='running' wukong='running'
t=30 t=30
#y=400 #y=400
if wukong=='running':
wukong_1=hero[a]
a+=1
if a>=5:
a=0
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (bg_x, 0)) screen.blit(background, (bg_x, 0))
screen.blit(road, (road_x, 500)) screen.blit(road, (road_x, 500))
screen.blit(wukong_1, (150, y)) screen.blit(wukong_1.image, (150, y))
#z_x-=8 #z_x-=8
road_x-=8 road_x-=8
...@@ -87,6 +101,10 @@ while True: ...@@ -87,6 +101,10 @@ while True:
screen.blit(i.image, (i.rect.x, 500-i.rect.height)) screen.blit(i.image, (i.rect.x, 500-i.rect.height))
if i.rect.x<=0-i.rect.width: if i.rect.x<=0-i.rect.width:
i.kill() i.kill()
if pygame.sprite.collide_rect(wukong_1,i):
gmover=pygame.image.load('gameover.png')
screen.blit(gmover,(400,250))
gameover=True
#z=random.choice([stone,cacti,apple]) #z=random.choice([stone,cacti,apple])
#rect=stone.get_rect() #rect=stone.get_rect()
......
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