Commit 087f85bf by BellCodeEditor

save project

parent fca4196f
Showing with 20 additions and 8 deletions
...@@ -8,12 +8,19 @@ class Block(pygame.sprite.Sprite): ...@@ -8,12 +8,19 @@ class Block(pygame.sprite.Sprite):
self.rect=self.image.get_rect() self.rect=self.image.get_rect()
self.rect.x=1000 self.rect.x=1000
self.rect.y=500-self.rect.height self.rect.y=500-self.rect.height
class Player(pygame.sprite.Sprite):
def __init__(self,image):
super().__init__()
self.rect=self.image.get.rect()
self.rect.x=150
self.rect.y=400
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("悟空酷跑")
time=0 time=0
gamestate=True
# 载入图片 # 载入图片
background = pygame.image.load('bg.png') # 背景 background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路 road = pygame.image.load('road.png') # 路
...@@ -42,6 +49,12 @@ while True: ...@@ -42,6 +49,12 @@ while True:
if jumpState == "runing": if jumpState == "runing":
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = "up" jumpState = "up"
# 悟空造型
wukong = hero[index]
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
if jumpState == "up": # 起跳状态 if jumpState == "up": # 起跳状态
if t > 0: if t > 0:
y -= t y -= t
...@@ -55,12 +68,6 @@ while True: ...@@ -55,12 +68,6 @@ while True:
else: else:
jumpState = "runing" jumpState = "runing"
t =30 t =30
# 悟空造型
wukong = hero[index]
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
# 将背景图画上去 # 将背景图画上去
shan_x -=2 shan_x -=2
if shan_x <-1000: if shan_x <-1000:
...@@ -74,15 +81,19 @@ while True: ...@@ -74,15 +81,19 @@ while True:
time=time+1 time=time+1
if time>=60: if time>=60:
r=random.randint(0,50) r=random.randint(0,50)
if r>40: if r>20:
ob=Block(bush,cacti,stone) ob=Block(bush,cacti,stone)
block_list.add(ob) block_list.add(ob)
time=0 time=0
for prop in block_list: for prop in block_list:
prop.rect.x=prop.rect.x-8 prop.rect.x=prop.rect.x-8
screen.blit(prop.image,(prop.x,prop.y)) screen.blit(prop.image,(prop.x,prop.y))
if prop.rect.x<=0-prop.rect.width: if prop.rect.x<=0-prop.rect.width:
prop.kill() prop.kill()
if pygame.sprite.Sprite(wukong,sprite):
gameover=pygame.image.load("gameover.png")
screen.blit(gameover,(400,200))
gamestate=False
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(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