Commit 25acad74 by BellCodeEditor

save project

parent 037c7d48
Showing with 9 additions and 27 deletions
...@@ -8,9 +8,8 @@ class Block(pygame.sprite.Sprite): ...@@ -8,9 +8,8 @@ class Block(pygame.sprite.Sprite):
self.image=random.choice([image1,image2,image3]) self.image=random.choice([image1,image2,image3])
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.heig self.rect.y=500-self.rect.height
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时钟,控制游戏速度(帧数)
...@@ -34,8 +33,6 @@ jumpState = "runing" ...@@ -34,8 +33,6 @@ jumpState = "runing"
t = 30 t = 30
aa=Block(bush,cacti,stone) aa=Block(bush,cacti,stone)
Block_list=pygame.sprite.Group()
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -46,16 +43,6 @@ while True: ...@@ -46,16 +43,6 @@ while True:
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 gamestate==True:
if jumpState == "up": # 起跳状态 if jumpState == "up": # 起跳状态
if t > 0: if t > 0:
y -= t y -= t
...@@ -70,7 +57,12 @@ if gamestate==True: ...@@ -70,7 +57,12 @@ if gamestate==True:
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:
...@@ -86,18 +78,8 @@ if gamestate==True: ...@@ -86,18 +78,8 @@ if gamestate==True:
# 创建障碍物对象 # 创建障碍物对象
aa=Block(bush,cacti,stone) aa=Block(bush,cacti,stone)
aa.rect.x -= 8 aa.rect.x -= 8
time+=1
if time>=60:
time=0
num=random.randint(0,50)
if num>20:
obstacle=Block(bush,cacti,stone)
Block_list.add
if pygame.sprite.collide_rect(wukong,sprite):
gemeover = pygame.image.load('gameover.png')
screen.blit(gameover,(400,200))
gamestate=Flase
screen.blit(aa.image, (aa.rect.x, aa.rect.y)) screen.blit(aa.image, (aa.rect.x, aa.rect.y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
......
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