Commit 8baf804f by BellCodeEditor

save project

parent 90196acc
Showing with 93 additions and 96 deletions
...@@ -12,6 +12,14 @@ class Block(pygame.sprite.Sprite): ...@@ -12,6 +12,14 @@ class Block(pygame.sprite.Sprite):
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
screen = pygame.display.set_mode((1000, 600),pygame.RESIZABLE) screen = pygame.display.set_mode((1000, 600),pygame.RESIZABLE)
FPS = pygame.time.Clock() FPS = pygame.time.Clock()
pygame.display.set_caption('酷跑') pygame.display.set_caption('酷跑')
...@@ -43,6 +51,7 @@ background_x=0 ...@@ -43,6 +51,7 @@ background_x=0
word2=0 word2=0
nub1=0 nub1=0
nub =0 nub =0
gamestate=True
y = 400 y = 400
...@@ -56,103 +65,91 @@ while True: ...@@ -56,103 +65,91 @@ while True:
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = 'up' jumpState = 'up'
if jumpState == 'up': wukong = Player(hero[index])
if JumpSpeed > 0: if gamestate:
y -= JumpSpeed if jumpState == 'up':
JumpSpeed-=2 if JumpSpeed > 0:
y -= JumpSpeed
else: JumpSpeed-=2
jumpState = 'down'
else:
jumpState = 'down'
if jumpState == 'down':
if JumpSpeed <= 30:
y += JumpSpeed if jumpState == 'down':
JumpSpeed+=2 if JumpSpeed <= 30:
y += JumpSpeed
JumpSpeed+=2
else:
jumpState = 'runing'
JumpSpeed=30
y=400
if jumpState != 'up' and jumpState!='down':
index += 1
else: else:
jumpState = 'runing' index =1
JumpSpeed=30
y=400 if index == 5:
index = 0
if jumpState != 'up' and jumpState!='down':
index += 1
else:
index =1 road_x-=8
if road_x==-1000:
if index == 5: road_x=0
index = 0 background_x-=2
wukong = hero[index] if background_x==-1000:
background_x=0
nub1+=1
road_x-=8 if nub1==50:
if road_x==-1000: word2+=1
road_x=0 nub1=0
background_x-=2 rectNub=word2
if background_x==-1000:
background_x=0 if word2/2==int(word2/2):
nub1+=1 nub=random.choice([1,2,3,4])
if nub1==50:
word2+=1
nub1=0 screen.blit(background, (background_x, 0))
rectNub=word2 screen.blit(road, (road_x,500))
screen.blit(wukong.image, (150,y))
if word2/2==int(word2/2): scoreWord=word.render(info+str(word2),True,(255,255,255))
nub=random.choice([1,2,3,4]) screen.blit(scoreWord, (730,10))
time+=1
screen.blit(background, (background_x, 0)) if time==50:
screen.blit(road, (road_x,500)) time=0
screen.blit(wukong, (150,y)) r=random.randint(0,100)
scoreWord=word.render(info+str(word2),True,(255,255,255)) if r>40:
screen.blit(scoreWord, (730,10)) o=Block(stone,cacti,apple)
block_list.add(o)
time+=1
if time==50: for prop in block_list:
time=0 prop.rect.x-=8
r=random.randint(0,100) screen.blit(prop.image,(prop.rect.x,prop.rect.y))
if r>40: if pygame.sprite.collide_rect(wukong,prop):
o=Block(stone,cacti,apple) gamestate=
block_list.add(o) if prop.rect.x <= 0-prop.rect.width:
prop.kill()
# for prop in block_list:
# prop.rect.x-=8 #if rectNub >= 9 and rect1.x<600 and rect1.x>300 and i==2:
# screen.blit(prop.image,(prop.rect.x,prop.rect.y)) # if rect2.x <= 0-rect2.width and nub==2:
# if pygame.sprite.collide_rect(wukong,prop): # o2=random.choice([stone,cacti,apple])
# break # rect2=o2.get_rect()
# if prop.rect.x <= 0-prop.rect.width: # rect2.x=1000
# prop.kill() # rect2.y=500-rect2.height
#rect2.x-=8
#if rectNub >= 9 and rect1.x<600 and rect1.x>300 and i==2: #if i==2:
# if rect2.x <= 0-rect2.width and nub==2: # screen.blit(o2,(rect2.x,rect2.y))
# o2=random.choice([stone,cacti,apple])
# rect2=o2.get_rect() # 刷新画面
# rect2.x=1000
# rect2.y=500-rect2.height
#rect2.x-=8 pygame.display.update()
#if i==2: FPS.tick(60)
# screen.blit(o2,(rect2.x,rect2.y))
# 刷新画面
pygame.display.update()
FPS.tick(50)
while 1:
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
if event.type == locals.KEYDOWN:
if event.key == locals.K_SPACE:
exit()
screen.blit(background,(0,0))
screen.blit(gameover,(400,100))
scoreWord2=word.render('按下空格键以继续',True,(255,255,255))
screen.blit(scoreWord2, (450,500))
scoreWord2=word.render('SCORES:'+str(word2),True,(0,0,0))
screen.blit(scoreWord2, (400,300))
pygame.display.update()
FPS.tick(50)
......
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