Commit 1fde446e by BellCodeEditor

save project

parent b6278a34
Showing with 71 additions and 53 deletions
...@@ -10,6 +10,15 @@ class Block(pygame.sprite.Sprite): ...@@ -10,6 +10,15 @@ 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
y=400
class Block2(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
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
zaw_list=pygame.sprite.Group() zaw_list=pygame.sprite.Group()
...@@ -29,15 +38,15 @@ pygame.display.set_caption('悟空酷跑') ...@@ -29,15 +38,15 @@ pygame.display.set_caption('悟空酷跑')
a=0 a=0
t=30 t=30
zaw=Block(stone,cacti,apple) zaw=Block(stone,cacti,apple)
wukong_1=hero[0] wukong_1=Block2(hero[0])
wukong='running' wukong='running'
y=400
#z=random.choice([stone,cacti,apple]) #z=random.choice([stone,cacti,apple])
#rect=stone.get_rect() #rect=stone.get_rect()
#z_x=1000 #z_x=1000
time=0 time=0
road_x=0 road_x=0
bg_x=0 bg_x=0
gameover=False
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,56 +55,65 @@ while True: ...@@ -46,56 +55,65 @@ while True:
if event.type==locals.KEYDOWN: if event.type==locals.KEYDOWN:
if event.key==locals.K_SPACE and wukong=='running': if event.key==locals.K_SPACE and wukong=='running':
wukong='up' wukong='up'
if wukong=='up':
if t>0:
y-=t
t-=2
else:
wukong='down'
if wukong=='down':
if t<=30:
y+=t
t+=2
else:
wukong='running'
t=30
#y=400
if wukong=='running': if gameover==False:
wukong_1=hero[a] if wukong=='running':
a+=1 wukong_1=Block2(hero[a])
if a>=5: a+=1
a=0 if a>=5:
# 将背景图画上去 a=0
screen.blit(background, (bg_x, 0)) if wukong=='up':
screen.blit(road, (road_x, 500)) if t>0:
screen.blit(wukong_1, (150, y)) y-=t
wukong_1.rect.y=y
#z_x-=8 t-=2
road_x-=8 else:
bg_x-=1 wukong='down'
#if zaw.rect.x<= 0-zaw.rect.width: if wukong=='down':
time+=1 if t<=30:
if time>=60: y+=t
time=0 wukong_1.rect.y=y
num=random.randint(0,50) t+=2
if num>20: else:
zaw=Block(stone,cacti,apple) wukong='running'
zaw_list.add(zaw) t=30
for i in zaw_list: #y=400
i.rect.x-=8
screen.blit(i.image, (i.rect.x, 500-i.rect.height))
if i.rect.x<=0-i.rect.width:
i.kill()
#z=random.choice([stone,cacti,apple])
#rect=stone.get_rect() # 将背景图画上去
#z_x=1000 screen.blit(background, (bg_x, 0))
screen.blit(road, (road_x, 500))
screen.blit(wukong_1.image, (150, y))
#z_x-=8
road_x-=8
bg_x-=1
#if zaw.rect.x<= 0-zaw.rect.width:
time+=1
if time>=60:
time=0
num=random.randint(0,50)
if num>20:
zaw=Block(stone,cacti,apple)
zaw_list.add(zaw)
for i in zaw_list:
i.rect.x-=8
screen.blit(i.image, (i.rect.x, 500-i.rect.height))
if i.rect.x<=0-i.rect.width:
i.kill()
if pygame.sprite.collide_rect(wukong_1,i):
gmover=pygame.image.load('gameover.png')
screen.blit(gmover,(400,250))
gameover=True
#z=random.choice([stone,cacti,apple])
#rect=stone.get_rect()
#z_x=1000
if road_x<-1000: if road_x<-1000:
road_x=0 road_x=0
if bg_x<-1000: if bg_x<-1000:
bg_x=0 bg_x=0
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(60)
\ No newline at end of file \ 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