Commit 909760c6 by BellCodeEditor

save project

parent 17b8b8b5
Showing with 59 additions and 45 deletions
......@@ -11,6 +11,13 @@ class Block(pygame.sprite.Sprite):
shilf.rect=shilf.image.get_rect()
shilf.rect.x=1000
shilf.rect.y=500-shilf.rect.height
class Play(pygame.sprite.Sprite):
def __init__(shilf,image):
super().__init__()
shilf.image=image
shilf.rect=shilf.image.get_rect()
shilf.rect.x=150
shilf.rect.y=400
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -30,13 +37,12 @@ index = 0
y = 400
jumpState = "runing"
t = 30
obstacle = random.choice([bush, stone, cacti])
rect = obstacle.get_rect()
rect.x = 1000
rect.y = 500 - rect.height
blocklist=pygame.sprite.Group()
yxzt=True
dl = 0
bj = 0
time=0
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -46,46 +52,53 @@ while True:
if jumpState == "runing":
if event.key == locals.K_SPACE:
jumpState = "up"
if jumpState == "up": # 起跳状态
if t > 0:
y -= t
t -= 2
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
t += 2
else:
jumpState = "runing"
t =30
# 悟空造型
wukong = hero[index]
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
# 将背景图画上去
bj-=4
if bj<-1000:
bj=0
screen.blit(background, (bj, 0)) # 远处背景
dl-=9
if dl<-1000:
dl=0
screen.blit(road, (dl, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空
if rect.x <= 0-rect.width: # 障碍物消失
# 创建障碍物对象
obstacle = random.choice([bush,stone,cacti])
rect = obstacle.get_rect()
rect.x = 1000
rect.y = 500 - rect.height
rect.x -= 9
screen.blit(obstacle, (rect.x, rect.y))
if yxzt==True:
if jumpState == "up": # 起跳状态
if t > 0:
y -= t
t -= 2
else:
jumpState = "down"
if jumpState == "down": # 降落状态
if t <= 30:
y += t
t += 2
else:
jumpState = "runing"
t =30
# 悟空造型
wukong = Play(hero[index])
if jumpState == "runing": # 跑步状态下
index += 1
if index >= 5:
index = 0
# 将背景图画上去
bj-=4
if bj<-1000:
bj=0
screen.blit(background, (bj, 0)) # 远处背景
dl-=9
if dl<-1000:
dl=0
screen.blit(road, (dl, 500)) # 路
screen.blit(wukong.image, (150, y)) # 悟空
time+=1
if time>=60:
time=0
num=random.randint(0,50)
if num>30:
obstacle=Block(bush,stone,cacti)
blocklist.add(obstacle)
for i in blocklist:
i.rect.x-=8
screen.blit(i.image,(i.rect.x,i.rect.y))
if i.rect.x<0-i.rect.width:
i.kill()
if pygame.sprite.collide_rect(wukong,i):
game = pygame.image.load('gameover.png')
screen.blit(game, (400,200))
yxzt=False
# 刷新画面
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