Commit f74281f5 by BellCodeEditor

auto save

parent f688b92b
Showing with 35 additions and 61 deletions
...@@ -10,13 +10,6 @@ class Block(pygame.sprite.Sprite): ...@@ -10,13 +10,6 @@ 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.image=image
self.rect=self.image.get_rect()
self.rect.x=150
self.rect.y=400
# 创建一个窗口 # 创建一个窗口
...@@ -41,9 +34,8 @@ jumpState="running" ...@@ -41,9 +34,8 @@ jumpState="running"
t=30 t=30
road_x=0 road_x=0
background_x=0 background_x=0
time=0 obstacle=Block(bush,cacti,stone)
gamestate=True
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:
...@@ -53,57 +45,39 @@ while True: ...@@ -53,57 +45,39 @@ while True:
if jumpState=="running": if jumpState=="running":
if event.key==locals.K_SPACE: if event.key==locals.K_SPACE:
jumpState="up" jumpState="up"
wukong=Player(hero[index]) if jumpState=="up":
if t >0:
y-=t
t-=2
else:
jumpState="down"
if jumpState=="down":
if t <=30:
y+=t
t+=2
else:
jumpState="running"
t=30
wukong=hero[index]
if jumpState=="running": if jumpState=="running":
index+=1 index+=1
if index >=5: if index >=5:
index=0 index=0
if gamestate==True: # 将背景图画上去
if jumpState=="up": background_x-=100
if t >0: if background_x<=-1000:
y-=t background_x=0
t-=2 screen.blit(background, (background_x, 0))
else: road_x-=100
jumpState="down" if road_x<=-1000:
if jumpState=="down": road_x=0
if t <=30: screen.blit(road, (road_x, 500))
y+=t screen.blit(wukong, (150, y))
t+=2 if obstacle.rect.x <= 0-obstacle.rect.width:
else: obstacle=Block(bush,cacti,stone)
jumpState="running" obstacle.rect.x-=8
t=30 screen.blit(obstacle.image,(obstacle.rect.x,obstacle.rect.y))
# 刷新画面
wukong=Player(hero[index]) pygame.display.update()
if jumpState=="running": FPS.tick(90)
index+=1 \ No newline at end of file
if index >=5:
index=0
# 将背景图画上去
background_x-=100
if background_x<=-1000:
background_x=0
screen.blit(background, (background_x, 0))
road_x-=100
if road_x<=-1000:
road_x=0
screen.blit(road, (road_x, 500))
screen.blit(wukong.image, (150, y))
# if obstacle.rect.x <= 0-obstacle.rect.width:
# obstacle=Block(bush,cacti,stone)
# obstacle.rect.x-=8
# screen.blit(obstacle.image,(obstacle.rect.x,obstacle.rect.y))
time+=1
if time>=60:
time=0
num=random.randint(0,50)
if num>20:
obstacle=Block(bush,cacti,stone)
block_list.add(obstacle)
for liu in block_list:
liu.rect.x -=8
screen.blit(liu.image,(liu.rect.x,liu.rect.y))
if liu.rect.x<=0-liu.rect.width:
liu.kill()
# 刷新画面
pygame.display.update()
FPS.tick(90)
\ 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