Commit 1d3cfc38 by BellCodeEditor

save project

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