Commit 9908e13e by BellCodeEditor

auto save

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