Commit ed30ced7 by BellCodeEditor

save project

parent b7a30bcd
Showing with 1 additions and 66 deletions
...@@ -21,72 +21,7 @@ hero = [pygame.image.load('hero1.png'), ...@@ -21,72 +21,7 @@ hero = [pygame.image.load('hero1.png'),
class Block(pygame.sprite.Sprite): class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3): def __init__(self,image1,image2,image3):
super().__init__() super().__init__()
self.image=random.choice([image1,image2,image3]) self.image=random.choice([image1,image+++++++++++++++++++++
self.rect=self.image.get_rect()
self.rect.x=1000
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
index = 0
y = 400
jumpState = "runing"
t = 30
# +++++++++++++++++++++++
bg_x = 0
road_x = 0
# +++++++++++++++++++++++
obstacle=Block(bush, stone, cacti)
block_list=pygame.sprite.Group()
time=0
num=0
game=True
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type == locals.KEYDOWN:
if jumpState == "runing":
if event.key == locals.K_SPACE:
jumpState = "up"
if game==True:
if jumpState == "up": # 起跳状态
if t > 0:
y -= t
t -= 2
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
t += 2
else:
jumpState = "runing"
t =30
# 悟空造型
wukong = player(hero[index])
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
# 将背景图画上去
# +++++++++++++++++++++++
bg_x -= 30
if bg_x<=-1000:
bg_x = 0
screen.blit(background, (bg_x, 0))
road_x -= 32
if road_x<=-1000:
road_x = 0
screen.blit(road, (road_x, 500))
# +++++++++++++++++++++++
screen.blit(wukong.image, (150, y)) # 悟空 screen.blit(wukong.image, (150, y)) # 悟空
time+=1 time+=1
if time > 30: if time > 30:
......
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