Commit 7b11d8dd by BellCodeEditor

auto save

parent 25f12fbd
Showing with 129 additions and 15 deletions
......@@ -3,6 +3,14 @@ from pygame import locals
import random
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时钟,控制游戏速度(帧数)
# 载入图片
......@@ -13,14 +21,14 @@ cacti = pygame.image.load('cacti.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")]
index = 0
o_list=pygame.sprite.Group()
jst=1
y=400
t=30
o=random.choice([stone,cacti,bush])
rect=o.get_rect()
rect.x=1000
rect.y=500-rect.height
road_x=0
pygame.display.set_caption("wukong")
road_x=0
time=0
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -47,19 +55,28 @@ while True:
else:
t=30
jst=1
screen.blit(background, (0, 0))
screen.blit(road, (0, 500))
road_x-=8
if road_x<=-1000:
road_x=0
screen.blit(background, (road_x, 0))
screen.blit(road, (road_x, 500))
screen.blit(wukong, (150, y))
if rect.x<0-rect.width:
rect.x=1000
o=random.choice([stone,cacti,bush])
rect=o.get_rect()
rect.x=1000
rect.y=500-rect.height
rect.x-=8
time+=1
if time >60:
time=0
num=random.randint(0,10)
if num>5:
o=Block(stone,cacti,bush)
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:
index+=1
if index==5:
......@@ -68,3 +85,100 @@ while True:
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