Commit b3c9436d by BellCodeEditor

save project

parent a29e44da
Showing with 35 additions and 5 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import time import time
wukong_state = "running"
pygame.display.set_caption("悟空跑酷") y = 400
suo_ying = 0
#创建窗口 #创建窗口
screen = pygame.display.set_mode((1000,600)) screen = pygame.display.set_mode((1000,600))
pygame.display.set_caption("悟空跑酷")
#导入素材 #导入素材
background_img = pygame.image.load("bg.png") background_img = pygame.image.load("bg.png")
bush_img = pygame.image.load("bush.png") bush_img = pygame.image.load("bush.png")
...@@ -17,16 +19,43 @@ hero4_img = pygame.image.load("hero4.png") ...@@ -17,16 +19,43 @@ hero4_img = pygame.image.load("hero4.png")
hero5_img = pygame.image.load("hero5.png") hero5_img = pygame.image.load("hero5.png")
road_img = pygame.image.load("road.png") road_img = pygame.image.load("road.png")
stone_img = pygame.image.load("stone.png") stone_img = pygame.image.load("stone.png")
#悟空形态列表
hero_list=[hero1_img,hero2_img,hero3_img,hero4_img,hero5_img]
#设置时钟 #设置时钟
FPSCLOCK = pygame.time.Clock() FPSCLOCK = pygame.time.Clock()
#渲染图片 #渲染图片
while True: while True:
for type.event in locals: #收到退出信息结束游戏
if for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
#按下空格悟空状态变成“up”
if event.type == locals.KEYDOWN:
if event.key == locals.K_SPACE:
wukong_state = "up"
#状态为“up”且y>150时悟空向上跳跃,否则悟空状态为“down”
if wukong_state == "up":
if y>150:
y-=5
else:
wukong_state = "down"
#状态为“down”且y<400时向下降落,否则悟空状态为“running”
if wukong_state == "down":
if y<400:
y+=5
else:
wukong_state = "running"
#渲染图片
screen.blit(background_img,(0,0)) screen.blit(background_img,(0,0))
screen.blit(road_img,(0,500)) screen.blit(road_img,(0,500))
screen.blit(hero1_img,(150,400)) screen.blit(hero_list[suo_ying],(150,y))
#悟空造型变换
if suo_ying == 4:
suo_ying = 0
suo_ying += 1
FPSCLOCK.tick(60) FPSCLOCK.tick(60)
#刷新画面 #刷新画面
pygame.display.update() pygame.display.update()
\ 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