Commit a7b3f50c by BellCodeEditor

save project

parent 639d26db
Showing with 32 additions and 4 deletions
...@@ -6,6 +6,7 @@ pygame.init() # 初始化 ...@@ -6,6 +6,7 @@ pygame.init() # 初始化
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 载入图片 # 载入图片
pygame.display.set_caption("Monkey King Running Game")
background = pygame.image.load('bg.png') # 背景 background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路 road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头 stone = pygame.image.load('stone.png') # 石头
...@@ -17,20 +18,46 @@ hero = [pygame.image.load('hero1.png'), ...@@ -17,20 +18,46 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero4.png'), pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')] pygame.image.load('hero5.png')]
high = 30
a = 0 #悟空造型变量
a = 0 kingy = 400
jump = "running"
wjump =
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:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type == locals.KEYDOWN:
if event.key == locals.K_ESCAPE:
exit()
if jump == "running":
if event.key == locals.K_SPACE:
jump = "up"
if jump == "up":
if high >= 0:
kingy -= high
high -= 2
else:
jump = "down"
if jump == "down":
if high <= 30:
kingy += high
high += 2
else:
jump = "running"
high = 30
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(road, (0, 500)) screen.blit(road, (0, 500))
screen.blit(hero[a], (150, 400)) screen.blit(hero[a], (150, kingy))
if a <=3: if a <=3:
a+=1 a+=1
else: else:
...@@ -39,5 +66,5 @@ while True: ...@@ -39,5 +66,5 @@ while True:
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(30)
import pygame import pygame
\ 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