Commit a0ed6c23 by BellCodeEditor

auto save

parent 9908e13e
Showing with 11 additions and 24 deletions
...@@ -4,14 +4,6 @@ from random import* ...@@ -4,14 +4,6 @@ from random import*
pygame.init() # 初始化 pygame.init() # 初始化
class Block(pygame.sprite.Sprite):
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)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
...@@ -32,14 +24,12 @@ lu_x=0 ...@@ -32,14 +24,12 @@ lu_x=0
shan_x=0 shan_x=0
index = 0 index = 0
y = 400 y = 400
jumpState = "running" jumpState = "runing"
t = 37 t = 37
zhangaiwu=choice([bush,cacti,stone])#随机获得一个障碍物 zhangaiwu=choice([bush,cacti,stone])#随机获得一个障碍物
#xingzhuang=zhangaiwu.get_rect()#活得障碍物的坐标,宽,高。 xingzhuang=zhangaiwu.get_rect()#活得障碍物的坐标,宽,高。
#xingzhuang.x=1000#使障碍物的x坐标为1000 xingzhuang.x=1000#使障碍物的x坐标为1000
#xingzhuang.y=500-xingzhuang.height#初始化障碍物的y坐标 xingzhuang.y=500-xingzhuang.height#初始化障碍物的y坐标
block_list=pygame.sprite.Group()
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:
...@@ -80,18 +70,14 @@ while True: ...@@ -80,18 +70,14 @@ while True:
lu_x=0 lu_x=0
screen.blit(road, (lu_x, 500)) # 路 screen.blit(road, (lu_x, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空 screen.blit(wukong, (150, y)) # 悟空
zhangaiwu=Block(bush,cacti,stone)
block_list.add(zhangaiwu)
#xingzhuang.x-=8 xingzhuang.x-=8
#if xingzhuang.x <0-xingzhuang.width:#如果障碍物的x if xingzhuang.x <0-xingzhuang.width:#如果障碍物的x
# zhangaiwu=choice([bush,cacti,stone]) zhangaiwu=choice([bush,cacti,stone])
#xingzhuang.y=500-xingzhuang.height#初始化障碍物的y坐标 xingzhuang.y=500-xingzhuang.height#初始化障碍物的y坐标
#xingzhuang.x=1000#使障碍物的x坐标为1000 xingzhuang.x=1000#使障碍物的x坐标为1000
screen.blit(zhangaiwu,(xingzhuang.x,xingzhuang.y)) screen.blit(zhangaiwu,(xingzhuang.x,xingzhuang.y))
for sprite in block_list:
sprite.rect.x-=8
sprite.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) 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