Commit 87163497 by BellCodeEditor

save project

parent f227fe3d
Showing with 32 additions and 11 deletions
...@@ -12,9 +12,16 @@ class Block(pygame.sprite.Sprite): ...@@ -12,9 +12,16 @@ class Block(pygame.sprite.Sprite):
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数
pygame.display.set_caption("悟空酷跑") 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') # 背景 background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路 road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头 stone = pygame.image.load('stone.png') # 石头
...@@ -25,13 +32,15 @@ hero = [pygame.image.load('hero1.png'), ...@@ -25,13 +32,15 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'), pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'), pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')] pygame.image.load('hero5.png')]
lu_x=0 lu_x=0
shan_x=0 shan_x=0
index = 0 index = 0
y = 400 y = 400
jumpState = "runing" jumpState = "runing"
t = 30 t = 30
aa=Block(bush,cacti,stone) aa=Block(bush,cacti,stone)
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -42,7 +51,7 @@ while True: ...@@ -42,7 +51,7 @@ while True:
if jumpState == "runing": if jumpState == "runing":
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = "up" jumpState = "up"
if gamestate ==True
if jumpState == "up": # 起跳状态 if jumpState == "up": # 起跳状态
if t > 0: if t > 0:
y -= t y -= t
...@@ -58,7 +67,7 @@ while True: ...@@ -58,7 +67,7 @@ while True:
t =30 t =30
# 悟空造型 # 悟空造型
wukong = hero[index] wukong = Player(hero[index])
if jumpState == "runing": # 跑步状态下 if jumpState == "runing": # 跑步状态下
index += 1 index += 1
if index >= 5: if index >= 5:
...@@ -78,10 +87,22 @@ while True: ...@@ -78,10 +87,22 @@ while True:
# 创建障碍物对象 # 创建障碍物对象
aa=Block(bush,cacti,stone) aa=Block(bush,cacti,stone)
aa.rect.x -= 8 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)) screen.blit(aa.image, (aa.rect.x, aa.rect.y))
# 刷新画面 if sprite.rect.x < =0-sprite.rect.width:
pygame.display.update() sprite.kill()
FPS.tick(60) if pygame.sprite.collide_rect(wukong,sprite):
gameover=pygame.image.load('gameover.png')
\ No newline at end of file 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