Commit b2dd49ef by BellCodeEditor

save project

parent e630520a
Showing with 50 additions and 23 deletions
import pygame
import time
import random
from pygame import locals
pygame.init() # 初始化
# 创建一个窗口
i=-1
y=400
tiao = 0
g = 30
screen = pygame.display.set_mode((1000, 600))
pygame.display.set_caption('wukongkupao')
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') # 路
stone = pygame.image.load('stone.png') # 石头
cacti = pygame.image.load('cacti.png') # 仙人掌
apple = 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')]
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')]
zhang_ai = random.choice([stone,cacti,bush])
rect = zhang_ai.get_rect()
rect.x=1000
rect.y = 500-rect.height
index = 0
while True:
i = i+1
if i > 4:
i=0
wukong = hero[i]
while True: #不要动
wukong = hero[i] #不要动 #不要动 #不要动#不要动#不要动#不要动#不要动#不要动#不要动
if Status == "running": #不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动
i = i+1 #不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动
if i > 4:
i=0
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()# 接收到退出事件后退出程序
if event.type == locals.KEYDOWN:
if event.key == locals.K_SPACE:
tiao = 1
if tiao == 1:
if Status == "running":
if event.key == locals.K_SPACE:
Status = "up"
if Status == "up":
if g >= 0:
y -= g
g -= 2
else:
tiao = 0
if tiao == 0:
if g <= 30:
else: #不要动#不要动#不要动#不要动#不要动#不要动
Status = "down" #不要动#不要动#不要动#不要动#不要动
if Status == "down":
if g < 30:
y += g +2
g += 2
else:
tiao = 3
Status = "running"
screen.blit(background, (0, 0))# 将背景图画上去
screen.blit(road, (0, 500))# 将背景图画上去
screen.blit(road, (0, 500))# 将背景图画上去 #不要动#不要动#不要动#不要动#不要动
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()#保存
FPS.tick(60)# 刷新画面
\ No newline at end of file
FPS.tick(40)# 刷新画面
\ 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