Commit f9c0297d by BellCodeEditor

save project

parent f6da6f5f
Showing with 18 additions and 4 deletions
......@@ -9,6 +9,13 @@ 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=450
pygame.init() # 初始化
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
......@@ -35,7 +42,7 @@ time=0
sprites=pygame.sprite.Group()
aa=Block(bush,cacti,stone)
sprites.add(aa)
gamestatue = True
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -45,7 +52,8 @@ while True:
if jumpState == "runing":
if event.key == locals.K_SPACE:
jumpState = "up"
if gamestatue !=True:
continue
if jumpState == "up": # 起跳状态
if t > 0:
y -= t
......@@ -61,11 +69,14 @@ while True:
t =30
# 悟空造型
wukong = hero[index]
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
wukong = Player(hero[index])
wukong.rect.y=y
# 将背景图画上去
shan_x -=2
if shan_x <-1000:
......@@ -75,7 +86,7 @@ while True:
if lu_x <-1000:
lu_x=0
screen.blit(road, (lu_x, 500)) # 路
screen.blit(wukong, (150, y))
screen.blit(wukong.image, (wukong.rect.x, wukong.rect.y))
time+=1
if time>60:
time=0
......@@ -86,6 +97,9 @@ while True:
for sprite in sprites:
sprite.rect.x -= 8
screen.blit(sprite.image, (sprite.rect.x, sprite.rect.y))
if pygame.sprite.collide_rect(wukong,sprite):
screen.blit(pygame.image.load("gameover.png"), (0, 0))
gamestatue = False
if sprite.rect.x <= 0-sprite.rect.width:
sprite.kill() # 悟空
# 刷新画面
......
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