Commit 17b2ac31 by BellCodeEditor

save project

parent 5ee9ead7
Showing with 17 additions and 3 deletions
......@@ -25,6 +25,14 @@ 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
index = 0
y = 400
jumpState = "runing"
......@@ -35,6 +43,7 @@ block_list = pygame.sprite.Group()
road_x = 0
background_x = 0
time = 0
gamestate = True
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -44,7 +53,7 @@ while True:
if jumpState == "runing":
if event.key == locals.K_SPACE:
jumpState = "up"
if gamestate == True:
if jumpState == "up": # 起跳状态
if t > 0:
y -= t
......@@ -60,7 +69,7 @@ while True:
t =30
# 悟空造型
wukong = hero[index]
wukong = Player(hero[index])
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
......@@ -68,7 +77,7 @@ while True:
# 将背景图画上去
screen.blit(background, (background_x, 0)) # 远处背景
screen.blit(road, (road_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空
screen.blit(wukong.image, (150, y)) # 悟空
time +=1
if time >= 60:
time = 0
......@@ -76,11 +85,16 @@ while True:
if num > 20:
obstacle = Block(stone, bush, cacti)
block_list.add(obstacle)
for sprite in block_list:
sprite.rect.x -= 8
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))
gamestate = False
road_x -= 8
if road_x <= -1000:
road_x = 8
......
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