Commit 087dd5e3 by BellCodeEditor

save project

parent d14ac1aa
Showing with 24 additions and 10 deletions
......@@ -5,6 +5,7 @@ block_list=pygame.sprite.Group()
time=0
D=0
F=0
H=True
pygame.init() # 初始化
class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3):
......@@ -13,7 +14,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=400
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -43,28 +50,30 @@ while True:
if jumpState == "runing":
if event.key == locals.K_SPACE:
jumpState = "up"
wukong = Player(hero[index])
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
if H == True:
if jumpState == "up": # 起跳状态
if t > 0:
y -= t
t -= 2
wukong.rect.y=y
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
t += 2
wukong.rect.y=y
else:
jumpState = "runing"
t =30
# 悟空造型
wukong = hero[index]
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
# 将背景图画上去
F-=2
if F<=-1000:
F=0
......@@ -73,7 +82,7 @@ while True:
if D<=-1000:
D=0 # 远处背景
screen.blit(road, (D, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空
screen.blit(wukong.image, (150, y)) # 悟空
time+=1
if time>=60:
......@@ -86,7 +95,12 @@ while True:
sprite.rect.x -= 8
screen.blit(sprite.image, (sprite.rect.x, sprite.rect.y))
if sprite.rect.x <= 0-sprite.rect.width:
sprite.kill() # 障碍物消失
sprite.kill()
if pygame.sprite.collide_rect(wukong,sprite):
S=pygame.image.load('gameover.png')
screen.blit(S, (400, 200))
H=False
# 障碍物消失
# 创建障碍物对象
......
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