Commit 3012a24e by BellCodeEditor

save project

parent ea4945bf
Showing with 18 additions and 20 deletions
......@@ -5,7 +5,7 @@ pygame.init() # 初始化
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption("嗨害害")
pygame.display.set_caption("嗨害害")#标题
# 载入图片
background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路
......@@ -18,8 +18,8 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]#悟空
index = 0
y = 400
t = 30
y = 400#y坐标
t = 30#跳跃增减的值
Status = "running"#悟空的初始状态
while True:
......@@ -28,33 +28,30 @@ while True:
# 接收到退出事件后退出程序
exit()
#当空格被按下
if event.type == locals.KEYDOWN:
if event.key == locals.K_SPACE:
Status = "jump"
if Status == "jump":
if t > 0:
if event.type == locals.KEYDOWN:#当按键被按下
if event.key == locals.K_SPACE:#当空格键被按下
Status = "jump"#悟空状态切换
if Status == "jump":#当状态为jump时
if t > 0:#向上跳
y-=t
t-=2
else:
Status = "down"
if Status == "down":
if t <= 30:
if Status == "down":#当状态为down时
if t <= 30:#向下降
y+=t
t+=2
else:
Status = "running"
wukong = hero[index]
index +=1
if index > 4:
Status = "running"#悟空状态切换
wukong = hero[index]#悟空的跑步造型切换
index +=1#下一个造型
if index > 4:#造型变为第1个造型
index = 0
# 将背景图画上去
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
screen.blit(wukong, (150, y))
screen.blit(background, (0, 0))#背景
screen.blit(road, (0, 500))#路
screen.blit(wukong, (150, y))#悟空
# 刷新画面
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