Commit 3321ceb0 by BellCodeEditor

save project

parent 4b658832
Showing with 76 additions and 85 deletions
File added
...@@ -2,8 +2,10 @@ import pygame ...@@ -2,8 +2,10 @@ import pygame
from pygame import locals from pygame import locals
import random import random
bg=pygame.display.set_mode((1000,600)) screen=pygame.display.set_mode((1000,600))
FPS=pygame.time.Clock()
pygame.display.set_caption("悟空酷跑") pygame.display.set_caption("悟空酷跑")
gameover = pygame.image.load('gameover.png')
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') # 石头
...@@ -39,97 +41,86 @@ time=0 ...@@ -39,97 +41,86 @@ time=0
t=30 t=30
jumpstate="run" jumpstate="run"
lu=road.get_rect() lu=road.get_rect()
lu.x=0 lu_x=0
bg_x=0 bg_x=0
gamestate= True gamestate= "True"
jingling_list=pygame.sprite.Group() jingling_list=pygame.sprite.Group()
'''my_font=pygame.font.Font('STKAITI.TTF',18)'''
#my_font=pygame.font.Font('STKAITI.TTF',18)
while True: while True:
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 event.key == K_up: if event.key == locals.K_UP:
if jumpstate == "up": if jumpstate == "run":
y-=t jumpstate="up"
t-2
if t<=0: if gamestate == "True":
jumpstate="down" bg_x-=8 #背景向左移动,到屏幕边缘返回原点
if jumpstate == "down": screen.blit(background,(bg_x,0))
y+=t if bg_x<=-1000:
t+2 bg_x=0
if t>=30:
jumpstate="run" lu_x-=8
screen.blit(road,(lu_x,500))
if lu_x<=-1000:
lu_x=0
bg_x-=8 #背景向左移动,到屏幕边缘返回原点
screen.blit(background,(bg_x,0))
if bg_x<=1000:
bg_x=0
lu_x-=8
screen.blit(rode,(lu_x,200))
if lu_x<=1000:
lu_x=0
obstacle.rect.x-=8
screen.blit(obstacle,(obstacle.rect.x,200))
wukong=Wukong(hero[index])
if jumpstate == "up":
if t>=0:
y-=t
wukong.rect.y=y
t-=2
else:
jumpstate="down"
if jumpstate == "down":
if t<=30:
y+=t
wukong.rect.y=y
t+=2
else:
jumpstate="run"
t=30
if jumpstate == "run":
index+=1
if index>=4:
index=0
screen.blit(wukong.image,(wukong.rect.x,wukong.rect.y))
time+=1
if time>=60:
time=0
yun=random.randint(0,50)
if yun>10:
obstacle=Block(stone,cacti,bush)
jingling_list.add(obstacle)
for sprite in jingling_list:
sprite.rect.x-=8
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if sprite.rect.x<0-sprite.rect.width:
sprite.kill()
if pygame.sprite.collide_rect(wukong,sprite):
screen.blit(gameover,(300,200))
gamestate = "False"
else:
if wukong.rect.x>sprite.rect.x+sprite.rect.width:
score+=sprite.score
sprite.score=0
#fenshu=my_font.render("分数"+score,True,(255,255,255))
#screen.blit(fenshu,(900,0))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(60)
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