Commit a3ea6f77 by BellCodeEditor

auto save

parent 9d7c1465
Showing with 49 additions and 14 deletions
...@@ -3,6 +3,7 @@ from pygame import locals ...@@ -3,6 +3,7 @@ from pygame import locals
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 # 创建一个窗口
time=0
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption('悟空酷跑')#标题 pygame.display.set_caption('悟空酷跑')#标题
...@@ -16,15 +17,33 @@ pygame.image.load('hero2.png'), ...@@ -16,15 +17,33 @@ pygame.image.load('hero2.png'),
pygame.image.load('hero3.png'), pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'), pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')] pygame.image.load('hero5.png')]
# obstate = random.choice([bush,stone,cacti])
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
road_x = 0
bg = 0
index = 0 index = 0
y=400 y=400
jumpState = 'running' jumpState = 'running'
t=30 t=30
obstate = random.choice([bush,stone,cacti]) # rect = obstate.get_rect()
rect = obstate.get_rect() # rect.x = 1000
rect.x = 1000 # rect.y = 500 - rect.height
rect.y = 500 - rect.height block_list = pygame.sprite.Group()
# obstate = Block(bush,cacti,stone)
while True: while True:
road_x-=8
bg-=20
if road_x==-1000:
road_x=0
if bg==-1000:
bg=0
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
...@@ -51,18 +70,33 @@ while True: ...@@ -51,18 +70,33 @@ while True:
else: else:
y=400 y=400
jumpState='running' jumpState='running'
if rect.x<= 0-rect.width:
obstate = random.choice([bush,stone,cacti])
rect = obstate.get_rect()
rect.x = 1000
rect.y = 500 - rect.height
rect.x-=8
# 将背景图画上去 # if rect.x<= 0-rect.width:
screen.blit(background, (0, 0)) # obstate = random.choice([bush,stone,cacti])
screen.blit(road, (0, 500)) # rect = obstate.get_rect()
# rect.x = 1000
# rect.y = 500 - rect.height
# rect.x-=8
screen.blit(background, (bg,0))
screen.blit(road, (road_x,500))
screen.blit(wukong, (150, y)) screen.blit(wukong, (150, y))
screen.blit(obstate,(rect.x,rect.y)) time+=1
if time%25 == 0:
r = random.randint(0,100)
if r>30:
obstate = Block(bush,cacti,stone)
block_list.add(obstate)
for prop in block_list:
prop.rect.x-=8
screen.blit(prop.image,(prop.rect.x,prop.rect.y))
print(prop.rect.x)
if prop.rect.x<=0-prop.rect.width:
prop.kill()
# if obstate.rect.x<=0-obstate.rect.width:
# obstate = Block(bush,cacti,stone)
# obstate.rect.x -=8
# 将背景图画上去
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(60)
\ No newline at end of file

34.7 KB | W: | H:

40.1 KB | W: | H:

road.png
road.png
road.png
road.png
  • 2-up
  • Swipe
  • Onion skin
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