Commit 90e2733e by BellCodeEditor

save project

parent 80718b16
Showing with 15 additions and 8 deletions
......@@ -11,9 +11,9 @@ class Block (pygame.sprite.Sprite):
self.rect.y = 500 - self.rect.height
class Wukong(pygame.sprite.Sprite):
def __init__(self , image):
def __init__(self , image1 ):
super().__init__()
self.image = image
self.image = image1
self.rect = self.image.get_rect()
self.rect.x = 150
self.rect.y = 400
......@@ -41,7 +41,8 @@ block_lite = pygame.sprite.Group()
time = 0
road_x = 0
bg_x = 0
Wukong = Wukong(hero[1])
wukong = Wukong(hero[1])
gameState=True
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -54,20 +55,20 @@ while True:
if jumpState == "up": # 起跳状态
if t > 0:
y -= t
wukong.rect.y -= t
t -= 2
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
wukong.rect.y += t
t += 2
else:
jumpState = "runing"
t =30
if gameState == True:
# 悟空造型
wukong = hero[index]
wukong.image = hero[index]
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
......@@ -75,7 +76,7 @@ while True:
# 将背景图画上去
screen.blit(background, (bg_x, 0)) # 远处背景
screen.blit(road, (road_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空
screen.blit(wukong.image, (wukong.rect.x, wukong.rect.y)) # 悟空
bg_x -= 1
if bg_x <= -1000:
......@@ -91,11 +92,16 @@ while True:
if gai > 2:
obstacle = Block(stone , cacti , bush)
block_lite.add(obstacle)
for sprit in block_lite:
sprit.rect.x -= 8
screen.blit(sprit.image, (sprit.rect.x, sprit.rect.y))
if sprit.rect.x <= 0-sprit.rect.width:
sprit.kill()
if pygame.sprite.collide_rect(wukong,obstacle):
over = pygame.image.load('gameover.png')
screen.blit(over, (400,200))
gameState = False
# 刷新画面
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