Commit 1d3cfc38 by BellCodeEditor

save project

parent c4bf1e9d
Showing with 51 additions and 43 deletions
...@@ -9,10 +9,10 @@ class Block (pygame.sprite.Sprite): ...@@ -9,10 +9,10 @@ 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 Wu(pygame.sprite.Sprite): class Wukong(pygame.sprite.Sprite):
def __init__(self , image): def __init__(self , image1):
super().__init__() super().__init__()
self.image = image self.image = image1
self.rect = self.image.get_rect() self.rect = self.image.get_rect()
self.rect.x = 150 self.rect.x = 150
self.rect.y = 400 self.rect.y = 400
...@@ -36,14 +36,15 @@ pygame.display.set_caption("一只猴的回家路") ...@@ -36,14 +36,15 @@ pygame.display.set_caption("一只猴的回家路")
index = 0 index = 0
heroLength = len(hero) heroLength = len(hero)
state = "runing" state = "runing"
y = 400
t = 30 t = 30
d = 30 d = 30
f = 30 f = 30
v = 30
block_list = pygame.sprite.Group() block_list = pygame.sprite.Group()
time = 0 time = 0
road_x = 0 road_x = 0
bg_x = 0 bg_x = 0
wukong = Wukong(hero[0])
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:
...@@ -61,13 +62,13 @@ while True: ...@@ -61,13 +62,13 @@ while True:
#w #w
if state == "up" : if state == "up" :
if t > 0: if t > 0:
y -= t wukong.rect.y -= t
t -= 2 t -= 2
else: else:
state = "down" state = "down"
if state == "down" : if state == "down" :
if t <= 30: if t <= 30:
y += t wukong.rect.y += t
t += 2 t += 2
else: else:
state = "runing" state = "runing"
...@@ -75,28 +76,28 @@ while True: ...@@ -75,28 +76,28 @@ while True:
#s #s
if state == "s" : if state == "s" :
if d > 0: if d > 0:
y += d wukong.rect.y += d
d -= 2 d -= 2
else: else:
state = "e" state = "e"
if state == "e" : if state == "e" :
if d <= 30: if d <= 30:
y -= t wukong.rect.y -= t
d += 2 d += 2
f -= 2 f -= 2
else: else:
state = "f" state = "f"
if state == "f" : if state == "f" :
if f <= 30: if f <= 30:
y += f wukong.rect.y += f
f += 2 f += 2
else: else:
y = 400 wukong.rect.y = 400
state = "runing" state = "runing"
#d #d
if state == "d" : if state == "d" :
if d > 0: if d > 0:
y -= d wukong.rect.y -= d
d -= 2 d -= 2
else: else:
state = "q" state = "q"
...@@ -108,39 +109,46 @@ while True: ...@@ -108,39 +109,46 @@ while True:
state = "o" state = "o"
if state == "o": if state == "o":
if f <= 30: if f <= 30:
y += f wukong.rect.y += f
f += 2 f += 2
else: else:
y = 400 wukong.rect.y = 400
state = "runing" state = "runing"
# #
screen.blit(background, (bg_x, 0)) if gameState == True:
screen.blit(road, (road_x, 500)) wukong.image = hero[index]
screen.blit(hero[index], (150, y)) screen.blit(background, (bg_x, 0))
screen.blit(road, (road_x, 500))
screen.blit(wukong.image, (wukong.rect.x, wukong.rect.y))
bg_x -= 1 bg_x -= 1
if bg_x <= -1000: if bg_x <= -1000:
bg_x = 0 bg_x = 0
road_x -= 8 road_x -= 8
if road_x <= -1000: if road_x <= -1000:
road_x = 0 road_x = 0
time += 1 time += 1
if time >= 60 : if time >= 60 :
time = 0 time = 0
wyf = random.randint(0,5) wyf = random.randint(0,5)
if wyf > 2: if wyf > 2:
ob = Block(bush,cacti ,bush) ob = Block(bush,cacti ,bush)
block_list.add(ob) block_list.add(ob)
for sprit in block_list: for sprit in block_list:
sprit.rect.x -= 8 sprit.rect.x -= 8
screen.blit(sprit.image,(sprit.rect.x , sprit.rect.y)) screen.blit(sprit.image,(sprit.rect.x , sprit.rect.y))
if sprit.rect.x <= 0-sprit.rect.width: if sprit.rect.x <= 0-sprit.rect.width:
sprit.kill() sprit.kill()
if state == "runing": if pygame.sprite.collide_rect(wukong,sprit):
index += 1 over = pygame.image.load('gameover.png')
if index > 4: screen.blit(over,(400,200))
index = 0 gameState = False
# 刷新画面
pygame.display.update() if state == "runing":
FPS.tick(60) index += 1
\ No newline at end of file if index > 4:
index = 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