Commit b1df6cd9 by BellCodeEditor

save project

parent ca10315b
Showing with 29 additions and 11 deletions
...@@ -11,10 +11,21 @@ class Block(pygame.sprite.Sprite): ...@@ -11,10 +11,21 @@ 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
class player(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时钟,控制游戏速度(帧数)
# 载入图片 # 载入图片
pygame.display.set_caption("悟空酷跑")
background = pygame.image.load('bg.png') # 背景 background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路 road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头 stone = pygame.image.load('stone.png') # 石头
...@@ -35,6 +46,8 @@ bg_x = 0 ...@@ -35,6 +46,8 @@ bg_x = 0
time = 0 time = 0
#zhuangzhe = Block(stone,cacti,bush) #zhuangzhe = Block(stone,cacti,bush)
block_list = pygame.sprite.Group() block_list = pygame.sprite.Group()
huabu = 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:
...@@ -45,10 +58,18 @@ while True: ...@@ -45,10 +58,18 @@ while True:
if zhuangtai == "running": if zhuangtai == "running":
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
zhuangtai = "up" zhuangtai = "up"
if huabu == True:
wukong = player(hero[index])
if zhuangtai == "running":
index += 1
if index == 5:
index = 0
if zhuangtai == "up": if zhuangtai == "up":
if nu > 0: if nu > 0:
y -= nu y -= nu
wukong.rect.y = y
nu -=2 nu -=2
else: else:
zhuangtai = "down" zhuangtai = "down"
...@@ -56,19 +77,12 @@ while True: ...@@ -56,19 +77,12 @@ while True:
if zhuangtai == "down": if zhuangtai == "down":
if nu <= 30: if nu <= 30:
y += nu y += nu
wukong.rect.y = y
nu += 2 nu += 2
else: else:
zhuangtai = "running" zhuangtai = "running"
nu = 30 nu = 30
wukong = hero[index]
if zhuangtai == "running":
index += 1
if index == 5:
index = 0
bg_x -= 1 bg_x -= 1
if bg_x <= -1000: if bg_x <= -1000:
bg_x = 0 bg_x = 0
...@@ -79,11 +93,12 @@ while True: ...@@ -79,11 +93,12 @@ while True:
road_x = 0 road_x = 0
screen.blit(road, (road_x, 500)) screen.blit(road, (road_x, 500))
# 将背景图画上去 # 将背景图画上去
screen.blit(wukong, (150, y)) screen.blit(wukong.image, (150, y))
# 刷新画面 # 刷新画面
#if zhuangzhe.rect.x <= 0-zhuangzhe.rect.width: #if zhuangzhe.rect.x <= 0-zhuangzhe.rect.width:
#zhuangzhe = Block(stone,cacti,bush) #zhuangzhe = Block(stone,cacti,bush)
# zhuangzhe.rect.x -= 8 #zhuangzhe.rect.x -= 8
time += 1 time += 1
if time >= 60: if time >= 60:
...@@ -97,7 +112,10 @@ while True: ...@@ -97,7 +112,10 @@ while True:
screen.blit(prop.image,(prop.rect.x,prop.rect.y)) screen.blit(prop.image,(prop.rect.x,prop.rect.y))
if prop.rect.x <= 0-prop.rect.width: if prop.rect.x <= 0-prop.rect.width:
prop.kill() prop.kill()
if pygame.sprite.collide_rect(wukong,prop):
gameover = pygame.image.load('gameover.png')
screen.blit(gameover,(400,200))
huabu = False
#screen.blit(zhuangzhe.image, (zhuangzhe.rect.x, zhuangzhe.rect.y)) #screen.blit(zhuangzhe.image, (zhuangzhe.rect.x, zhuangzhe.rect.y))
pygame.display.update() 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