Commit 7b11d8dd by BellCodeEditor

auto save

parent 25f12fbd
Showing with 130 additions and 16 deletions
...@@ -3,6 +3,14 @@ from pygame import locals ...@@ -3,6 +3,14 @@ from pygame import locals
import random import random
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时钟,控制游戏速度(帧数)
# 载入图片 # 载入图片
...@@ -13,14 +21,14 @@ cacti = pygame.image.load('cacti.png') # 仙人掌 ...@@ -13,14 +21,14 @@ cacti = pygame.image.load('cacti.png') # 仙人掌
bush = pygame.image.load('bush.png') # 灌木丛 bush = pygame.image.load('bush.png') # 灌木丛
hero = [pygame.image.load("hero1.png"),pygame.image.load("hero2.png"),pygame.image.load("hero3.png"),pygame.image.load("hero4.png"),pygame.image.load("hero5.png")] hero = [pygame.image.load("hero1.png"),pygame.image.load("hero2.png"),pygame.image.load("hero3.png"),pygame.image.load("hero4.png"),pygame.image.load("hero5.png")]
index = 0 index = 0
o_list=pygame.sprite.Group()
jst=1 jst=1
y=400 y=400
t=30 t=30
o=random.choice([stone,cacti,bush]) road_x=0
rect=o.get_rect()
rect.x=1000
rect.y=500-rect.height
pygame.display.set_caption("wukong") pygame.display.set_caption("wukong")
road_x=0
time=0
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:
...@@ -47,19 +55,28 @@ while True: ...@@ -47,19 +55,28 @@ while True:
else: else:
t=30 t=30
jst=1 jst=1
road_x-=8
screen.blit(background, (0, 0)) if road_x<=-1000:
screen.blit(road, (0, 500)) road_x=0
screen.blit(background, (road_x, 0))
screen.blit(road, (road_x, 500))
screen.blit(wukong, (150, y)) screen.blit(wukong, (150, y))
if rect.x<0-rect.width: time+=1
rect.x=1000 if time >60:
o=random.choice([stone,cacti,bush]) time=0
rect=o.get_rect() num=random.randint(0,10)
rect.x=1000 if num>5:
rect.y=500-rect.height o=Block(stone,cacti,bush)
rect.x-=8 o_list.add(o)
for i in o_list:
i.rect.x-=8
screen.blit(i.image,(i.rect.x,i.rect.y))
if i.rect.x<=0-i.rect.x:
i.kill()
# 刷新画面 # 刷新画面
screen.blit(o,(rect.x,rect.y))
if jst==1: if jst==1:
index+=1 index+=1
if index==5: if index==5:
...@@ -67,4 +84,101 @@ while True: ...@@ -67,4 +84,101 @@ while True:
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