Commit 5fddf660 by BellCodeEditor

auto save

parent 4d36d640
Showing with 69 additions and 19 deletions
......@@ -15,6 +15,19 @@ cacti = pygame.image.load('cacti.png') # 仙人掌
bush = pygame.image.load('bush.png') # 灌木丛
hero = [pygame.image.load('hero1.png'),pygame.image.load('hero2.png'),pygame.image.load('hero3.png'),pygame.image.load('hero4.png'),pygame.image.load('hero5.png')]
if jumpstate=="run":
index += 1
if index == 5:
index = 0
screen.blit(wukong.image, (150,y))
if jumpstate=="up": #跳跃状态
if t>=0:
y-=t
wukong.rect.y = y
t-=2
screen.blit(wukong.image, (150,y))
else:
music=pygame.mixer.sound("")
class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3):
super().__init__()
......@@ -22,15 +35,29 @@ class Block(pygame.sprite.Sprite):
self.rect=self.image.get_rect()
self.rect.x=1000
self.rect.y=500-self.rect.height
self.score=1
class Wukong(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
score=0
index = 0
y = 400
time=0
t=30
jumpstate="run"
obstacle=Block(stone,cacti,bush)
lu=road.get_rect()
lu.x=0
bg_x=0
gamestate= True
jingling_list=pygame.sprite.Group()
my_font=pygame.font.Font('STKAITI.TTF',18)
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -40,40 +67,62 @@ while True:
if event.key == locals.K_SPACE:
if jumpstate=="run":
jumpstate="up"
if gamestate == True:
# 将背景图画上去
obstacle.rect.x-=8
lu.x-=8
bg_x-=1
screen.blit(background, (bg_x, 0))
if bg_x<-1000:
bg_x=0
lu.x-=8
screen.blit(road, (lu.x, 500))
if lu.x<-1000:
lu.x=0
screen.blit(obstacle.image,(obstacle.rect.x,obstacle.rect.y))
#判断是否超出画面左边缘,重新创建障碍物
if obstacle.rect.x<0-obstacle.rect.width:
obstacle=Block(stone,cacti,bush)
if jumpstate=="up": #跳跃状态
if t>=0:
y-=t
t-=2
screen.blit(hero[index], (150, y))
else:
#判断是否超出画面左边缘,重新创建障碍物
wukong=Wukong(hero[index])
jumestate="down"
if jumpstate=="down": #跳跃状态
if t<=30:
y+=t
wukong.rect.y = y
t+=2
screen.blit(hero[index], (150, y))
screen.blit(wukong.image, (150,y))
else:
jumestate="run"
t=30
if jumpstate=="run":
index += 1
if index == 5:
index = 0
screen.blit(hero[index], (150, y))
time+=1
if time>=60:
time=0
yun=random.randint(0,50)
if yun>25:
obstacle=Block(stone,bush,cacti)
jingling_list.add(obstacle)
for sprite in jingling_list:
sprite.rect.x-=8
screen.blit(sprite.image, (sprite.rect.x, sprite.rect.y))
if pygame.sprite.collide_rect(wukong,sprite):
gamewu = pygame.image.load('gameover.png')
screen.blit(gamewu, (400,200))
gamestate = False
if sprite.rect.x<0-sprite.rect.width:
sprite.kill()
else:
if sprite.rect.x-sprite.rect.width<wukong.rect.x:
music.play()
score+=sprite.score
sprite.score=0
text=my_font.render("分数"+str(score),True,(255,255,255))
screen.blit(text,(900,0))
# 刷新画面
pygame.display.update()
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