Commit 26ec9eb7 by BellCodeEditor

save project

parent 018270b6
Showing with 63 additions and 49 deletions
...@@ -9,8 +9,16 @@ class Block(pygame.sprite.Sprite): ...@@ -9,8 +9,16 @@ 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 p(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
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
gs=True
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("悟空酷跑")
...@@ -43,53 +51,59 @@ while True: ...@@ -43,53 +51,59 @@ 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 gs==True:
if jumpState == "up": # 起跳状态
if t > 0:
y -= t
p.image.rect.y=y
t -= 2
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
p.image.rect.y=y
t += 2
else:
jumpState = "runing"
t =30
# 悟空造型
wukong = hero[index]
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
# 将背景图画上去
shan_x -=2
if shan_x <-1000:
shan_x=0
screen.blit(background, (shan_x, 0)) # 远处背景
lu_x -=8
if lu_x <-1000:
lu_x=0
screen.blit(road, (lu_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空
if jumpState == "up": # 起跳状态 #if aa.rect.x <= 0-aa.rect.width: # 障碍物消失
if t > 0: # 创建障碍物对象
y -= t
t -= 2
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
t += 2
else:
jumpState = "runing"
t =30
# 悟空造型
wukong = hero[index]
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
# 将背景图画上去
shan_x -=2
if shan_x <-1000:
shan_x=0
screen.blit(background, (shan_x, 0)) # 远处背景
lu_x -=8
if lu_x <-1000:
lu_x=0
screen.blit(road, (lu_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空
#if aa.rect.x <= 0-aa.rect.width: # 障碍物消失
# 创建障碍物对象
time+=1 time+=1
if time>=50: if time>=50:
time=0 time=0
rs=random.randint(0,100) rs=random.randint(0,100)
if rs>45: if rs>45:
aa=Block(bush,cacti,stone) aa=Block(bush,cacti,stone)
block_list.add(aa) block_list.add(aa)
for prep in block_list: for prep in block_list:
prep.rect.x-=8 prep.rect.x-=8
screen.blit(prep.image, (prep.rect.x, prep.rect.y)) screen.blit(prep.image, (prep.rect.x, prep.rect.y))
if prep.rect.x<=0-prep.rect.width: if prep.rect.x<=0-prep.rect.width:
prep.kill() prep.kill()
# 刷新画面 if pygame.sprite.collide_rect(wukong,prep):
pygame.display.update() o=pygame.image.load("gamemover.png")
FPS.tick(50) screen.blit(gameover(500,300))
\ No newline at end of file gs=False
# 刷新画面
pygame.display.update()
FPS.tick(50)
\ 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