Commit b1df6cd9 by BellCodeEditor

save project

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