Commit b2dd49ef by BellCodeEditor

save project

parent e630520a
Showing with 46 additions and 19 deletions
import pygame import pygame
import time import time
import random
from pygame import locals from pygame import locals
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
i=-1
y=400
tiao = 0
g = 30
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
pygame.display.set_caption('wukongkupao') pygame.display.set_caption('wukongkupao')
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
#变量 #不要动
i=1#造型 #不要动
y=400#y值 #不要动
Status = "running"#状态 #不要动
g = 30 #重力
#不要动
# 载入图片 # 载入图片
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') # 石头
cacti = pygame.image.load('cacti.png') # 仙人掌 cacti = pygame.image.load('cacti.png') # 仙人掌
apple = pygame.image.load('bush.png') # 灌木丛 bush = pygame.image.load('bush.png') # 灌木丛
hero = [pygame.image.load('hero1.png'),pygame.image.load('hero2.png'),pygame.image.load('hero3.png'),pygame.image.load('hero4.png'),pygame.image.load('hero5.png')] hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero2.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
zhang_ai = random.choice([stone,cacti,bush])
rect = zhang_ai.get_rect()
rect.x=1000
rect.y = 500-rect.height
index = 0 index = 0
while True: while True: #不要动
i = i+1 wukong = hero[i] #不要动 #不要动 #不要动#不要动#不要动#不要动#不要动#不要动#不要动
if Status == "running": #不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动
i = i+1 #不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动
if i > 4: if i > 4:
i=0 i=0
wukong = hero[i]
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.type == locals.KEYDOWN:
if Status == "running":
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
tiao = 1 Status = "up"
if tiao == 1: if Status == "up":
if g >= 0: if g >= 0:
y -= g y -= g
g -= 2 g -= 2
else: else: #不要动#不要动#不要动#不要动#不要动#不要动
tiao = 0 Status = "down" #不要动#不要动#不要动#不要动#不要动
if tiao == 0: if Status == "down":
if g <= 30: if g < 30:
y += g +2 y += g +2
g += 2 g += 2
else: else:
tiao = 3 Status = "running"
screen.blit(background, (0, 0))# 将背景图画上去 screen.blit(background, (0, 0))# 将背景图画上去
screen.blit(road, (0, 500))# 将背景图画上去 screen.blit(road, (0, 500))# 将背景图画上去 #不要动#不要动#不要动#不要动#不要动
screen.blit(wukong,(150,y))#悟空的动作 screen.blit(wukong,(150,y))#悟空的动作
if rect.x <= 0-rect.width:
zhang_ai = random.choice([stone,cacti,bush])
rect = zhang_ai.get_rect()
rect.x = 1000
rect.y = 500-rect.height
rect.x -=8
screen.blit(zhang_ai,(rect.x,rect.y))
pygame.display.update()#保存 pygame.display.update()#保存
FPS.tick(60)# 刷新画面 FPS.tick(40)# 刷新画面
\ No newline at end of file \ 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