Commit 24182f9b by BellCodeEditor

save project

parent e1a92d85
Showing with 27 additions and 10 deletions
......@@ -6,6 +6,13 @@ pygame.init() # 初始化
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption('悟空酷跑')
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
class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3):
super().__init__()
......@@ -15,6 +22,7 @@ class Block(pygame.sprite.Sprite):
self.rect.y=500-self.rect.height
# 载入图片
# gameover = pygame.image.load('gameover.png')
background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头
......@@ -32,6 +40,7 @@ t=30
road_x=8
bg_x=0
time=0
gamestate=True
# obstacle=Block(stone,cacti,bush)
block_list=pygame.sprite.Group()
......@@ -44,26 +53,28 @@ while True:
if jumpstate == 'running':
if event.key==locals.K_w:
jumpstate='up'
wukong=Player(hero[index])
if gamestate==True:
if jumpstate =='up':
if t>0:
y-=t
wukong.rect.y=y
t-=2
else:
jumpstate='down'
if jumpstate == 'down':
if t <=30:
y+=t
wukong.rect.y=y
t+=2
else:
jumpstate='running'
t=30
wukong = hero[index]
index+=1
if index==5:
index=0
if y < 400 and y>150:
wukong=hero[3]
bg_x-=1
if bg_x <=-1000:
bg_x=0
......@@ -79,21 +90,27 @@ while True:
if num>=40:
obstacle=Block(bush,stone,cacti)
block_list.add(obstacle)
time=0
screen.blit(background, (bg_x, 0))
for prop in block_list:
for sprite in block_list:
sprite.rect.x-=8
prop.rect.x-=8
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if sprite.rect.x<= 0-sprite.rect.width:
sprite.kill()
screen.blit(prop.image,(prop.rect.x,prop.rect.y))
if prop.rect.x<=0-prop.rect.width:
prop.kill()
if pygame.sprite.collide_rect(wukong,sprite):
gameover=pygame.image.load('gameover.png')
screen.blit(gameover,(400,200))
gamestate=False
# 将背景图画上去
screen.blit(road, (road_x, 500))
screen.blit(wukong, (150, y))
screen.blit(wukong.image, (150, y))
#screen.blit(.image,(prop.rect.x,prop.rect.y))
# obstacle.rect.x-=8
......
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