Commit 87163497 by BellCodeEditor

save project

parent f227fe3d
Showing with 29 additions and 7 deletions
......@@ -12,9 +12,16 @@ class Block(pygame.sprite.Sprite):
pygame.init() # 初始化
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数
pygame.display.set_caption("悟空酷跑")
# 载入图片
class pyayer(pygame.sprite.Sprite):
def __int__(self,imsge)
super().__init__()
self.imag = image
self.rect = self.image.get__rect()
self.rect.x=150
self.rect.y=400
background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头
......@@ -25,9 +32,11 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
lu_x=0
shan_x=0
index = 0
y = 400
jumpState = "runing"
t = 30
......@@ -42,7 +51,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
......@@ -58,7 +67,7 @@ while True:
t =30
# 悟空造型
wukong = hero[index]
wukong = Player(hero[index])
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
......@@ -78,10 +87,22 @@ while True:
# 创建障碍物对象
aa=Block(bush,cacti,stone)
aa.rect.x -= 8
time+=1
if time>=60:
num=random.randint(0,50)
if num>20:
obstacle=block_list
for sprite in block_list:
sprite.rect.x-=8
screen.blit(aa.image, (aa.rect.x, aa.rect.y))
# 刷新画面
pygame.display.update()
FPS.tick(60)
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
pygame.display.update()
FPS.tict(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