Commit f40a308e by BellCodeEditor

save project

parent 4dd6ff52
Showing with 17 additions and 8 deletions
......@@ -8,9 +8,16 @@ class Block(pygame.sprite.Sprite):
self.rect = self.image.get_rect()
self.rect.x = 1000
self.rect.y = 500 - self.rect.width
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
block_list = pygame.sprite.Group()
gameover = True
pygame.init() # 初始化
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
......@@ -36,8 +43,8 @@ obstacle = Block(bush,stone,cacti)
road_x = 0
bg_x = 0
while True:
if gameover == True:
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
......@@ -60,10 +67,8 @@ while True:
else:
jumpState = "runing"
t =30
# 悟空造型
wukong = hero[index]
if jumpState == "runing": # 跑步状态下
wukong = Player(hero[index])
if jumpState == "runing":
index += 1
if index >= 5:
index = 0
......@@ -76,7 +81,6 @@ while True:
if road_x <= -1000:
road_x = 0
screen.blit(road, (road_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空
time += 1
if time >= 60:
time = 0
......@@ -89,6 +93,10 @@ while True:
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if sprite.rect.x <= 0-sprite.rect.width: # 障碍物消失
sprite.kill()
if pygame.sprite.collide_rect(wukong,sprite):
gameover = pygame.image.load("gameover.png")
screen.blit(gameover,(400,200))
gameover = Flase
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ 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