Commit 937a9fde by BellCodeEditor

save project

parent 88070503
Showing with 16 additions and 9 deletions
...@@ -7,6 +7,7 @@ screen = pygame.display.set_mode((1000, 600)) ...@@ -7,6 +7,7 @@ screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption('悟空酷跑') pygame.display.set_caption('悟空酷跑')
jumpState='runing' jumpState='runing'
y = 400 y = 400
# 载入图片 # 载入图片
background = pygame.image.load('bg.png') # 背景 background = pygame.image.load('bg.png') # 背景
...@@ -16,6 +17,7 @@ cacti = pygame.image.load('cacti.png') # 仙人掌 ...@@ -16,6 +17,7 @@ cacti = pygame.image.load('cacti.png') # 仙人掌
apple = pygame.image.load('bush.png') # 灌木丛 apple = pygame.image.load('bush.png') # 灌木丛
hero = pygame.image.load('hero1.png') hero = pygame.image.load('hero1.png')
i = 0 i = 0
t = 30
hero = [pygame.image.load('hero1.png'), hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero2.png'), pygame.image.load('hero2.png'),
pygame.image.load('hero3.png'), pygame.image.load('hero3.png'),
...@@ -29,23 +31,28 @@ while True: ...@@ -29,23 +31,28 @@ while True:
exit() exit()
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if event.key == locals.K_SPACE: if jumpState == 'runing':
jumpState = 'up' if event.key == locals.K_SPACE:
jumpState = 'up'
if jumpState == 'up': if jumpState == 'up':
if y>150: if t > 0:
y -= 5 y -= t
t -= 2
else: else:
jumpState = 'down' jumpState = 'down'
if jumpState == 'down': if jumpState == 'down':
if y<400: if t <= 30:
y += 5 y += t
t +=2
else: else:
jumpState = 'runing' jumpState = 'runing'
t = 30
wukong = hero[i] wukong = hero[i]
i += 1 if jumpState == 'runing':
if i == 5: i += 1
i = 0 if i >= 5:
i = 0
# 将背景图画上去 # 将背景图画上去
......
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