Commit 51185de7 by BellCodeEditor

save project

parent da852cf9
Showing with 13 additions and 4 deletions
import pygame
import random
from pygame import locals
pygame.init() # 初始化
......@@ -9,7 +10,7 @@ FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
y=400
t=30
jump="running"
pygame.display.set_caption("悟空跑障碍赛")
pygame.display.set_caption("悟空是个只因")
background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头
......@@ -22,25 +23,29 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero5.png')]
index=0
obstacle = random.choice([bush,stone,cacti])
rect=obstacle.get_rect()
rect.x = 1000
rect.y = 500-rect.height
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type==locals.KEYDOWN:
if jump=="running":
if event.key==locals.K_SPACE:
jump="up"
if jump=="up":
if y > 0:
if t > 0:
y-=t
t-=2
else:
jump = "down"
if jump=="down":
if y < 30:
if t <= 30:
y +=t
t+=2
else:
......@@ -48,9 +53,13 @@ while True:
t=30
wukong = hero[index]
if jump=="running":
index+=1
if index == 5:
index = 0
if rect.x <= 0-rect.width:
rect.x-=8
screen.blit(obstacle,(rect.x,rect.y))
# 将背景图画上去
screen.blit(background, (0, 0))
......
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