Commit e2a88b51 by BellCodeEditor

save project

parent 8f8d478f
Showing with 30 additions and 16 deletions
......@@ -5,12 +5,16 @@ import random
pygame.init() # 初始化
class Block(pygame.sprite.Sprite):
def _init_(self,image1,image2,image3):
super()._init_()
self.image=random.choice([image1,image2,image3])
sef.rect=self.image.get_rect()
self.rect.x=1000
self.rect.y=500-self.rect.height
def __init__(self,image1,image2,image3):
super().__init__()
# 加载障碍物的图片
self.image = random.choice([image1, image2, image3])
# 根据障碍物位图的宽高设置矩形
self.rect = self.image.get_rect()
# 障碍物绘制坐标
self.rect.x = 1000
self.rect.y = 500 - self.rect.height
# 创建一个窗口
screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -26,16 +30,18 @@ hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')]
Block=pygame.sprite.Group()
block_list=pygame.sprite.Group() #Block=pygame.sprite.Group()
bgx=0
index = 0
y = 400
jumpState = "runing"
t = 30
obstacle = Block(bush,cacti,stone)
rect = obstacle.get_rect()
rect.x = 1000
rect.y = 500 - rect.height
# rect = obstacle.get_rect()
# rect.x = 1000
# rect.y = 500 - rect.height
roadx=0
time=0
pygame.display.set_caption('悟空酷跑')
......@@ -78,26 +84,33 @@ while True:
# obstacle=Block(bush,cacti,stone)
# obstacle.rect.x-=8
# screen.blit(obstacle.image, (obstacle.rect.x,obstacle.rect.y))
# roadx-=8
# if roadx<=-1000:
# roadx=0
screen.blit(road,(roadx,500))
roadx -= 8
if roadx<=- 1000:
roadx = 0
screen.blit(road, (roadx, 500))
bgx-=1
if bgx<-1000:
bgx=0
screen.blit(background, (bgx, 0))
screen.blit(wukong, (150, y))
time+=1
if time>=60:
r=random.randint(0,100)
if r>40:
obstacle=Block(bush,cacti,stone)
block_list=add(obstacle)
#block_list=add(obstacle)
block_list.add(obstacle)
time=0
for prop in block_list:
prop.rect.x-=8
screen.blit(prop.image,(prop.rect.x,prop.rect.y))
if prop.rect.x<=0-prop.rect.width:
prop.kill()
# 刷新画面
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