Commit e1a56324 by BellCodeEditor

auto save

parent 8a23fdb0
Showing with 27 additions and 14 deletions
...@@ -10,6 +10,16 @@ class Block(pygame.sprite.Sprite): ...@@ -10,6 +10,16 @@ class Block(pygame.sprite.Sprite):
self.rect.x=1000 self.rect.x=1000
self.rect.y=500-self.rect.height self.rect.y=500-self.rect.height
pygame.init() # 初始化 pygame.init() # 初始化
class player(pygame.sprite.Sprite):
def __init__(self,image):
super().__init__()
self.image=image
self.rect=self.image.get_rect()
self.rect.x=150
self.rect.y=400
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
...@@ -25,7 +35,6 @@ hero = [pygame.image.load('hero1.png'), ...@@ -25,7 +35,6 @@ hero = [pygame.image.load('hero1.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')]
lu_x=0 lu_x=0
shan_x=0 shan_x=0
index = 0 index = 0
...@@ -58,9 +67,9 @@ while True: ...@@ -58,9 +67,9 @@ while True:
else: else:
jumpState = "runing" jumpState = "runing"
t =30 t =30
gamestate=True
# 悟空造型 # 悟空造型
wukong = hero[index] wukong = Player(hero[index])
if jumpState == "runing": # 跑步状态下 if jumpState == "runing": # 跑步状态下
index += 1 index += 1
if index >= 5: if index >= 5:
...@@ -74,21 +83,25 @@ gamestate=True ...@@ -74,21 +83,25 @@ gamestate=True
if lu_x <-1000: if lu_x <-1000:
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.image, (150, y)) # 悟空
time+=1
if time >=60: if obstacle.rect.x <= 0-obstacle.rect.width: # 障碍物消失
time+=1 # 创建障碍物对象
if time>=60:
time=0 time=0
num=random.randint(0,50) num=random.randint(0,50)
if num>20: if num>20:
obstacle=Block(bush,cacti,st) obstacle=Block(bush,cacti,stone)
if obstacle.rect.x <= 0-obstacle.rect.width: # 障碍物消失 block_list.add(obstacle)
# 创建障碍物对象
obstacle=Block(bush,stone,cacti)
block_list.add(obstacle)
for sprite in block_list: for sprite in block_list:
sprite.rect..x-=8 sprite.rect.x-=8
screen.blit(sprite) screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
screen.blit(obstacle.image,(obstacle.rect.x,obstacle.rect.y)) if sprite
obstacle=Block(bush,stone,cacti)
obstacle.rect.x-=8
screen.blit(obstacle.image,(obstacle.rect.x,obstacle.rect.y))
screen.blit(aa.image, (aa.rect.x, aa.rect.y)) screen.blit(aa.image, (aa.rect.x, aa.rect.y))
......
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