Commit d69364fb by BellCodeEditor

save project

parent df70cfbf
Showing with 57 additions and 38 deletions
...@@ -4,12 +4,19 @@ import random ...@@ -4,12 +4,19 @@ import random
pygame.init() # 初始化 pygame.init() # 初始化
class Block(pygame,sprite,Sprite): class Block(pygame,sprite,Sprite):
def_init_(self,imaga1,image2,image3): def_init_(self,imaga1,imaga2,imaga3):
supere()._init_() supere()._init_()
self.image = random.choice([image1,image2,image3]) self.image = random.choice([image1,image2,image3])
self.rect = self.imef.image.get_rect() self.rect = self.imef.image.get_rect()
self.rect.x= 1000 self.rect.x= 1000
self.rect.y =500 - self.rect.height self.rect.y =500 - self.rect.height
class Player(pygame,sprite,Sprite):
def_init_(self,image):
super()._init_()
self.image = image
self.rect = self.imef.image.get_rect()
self.rect.x = 150
self.rect.y = 400
def (self, parameter_list): def (self, parameter_list):
raise NotImplementedError raise NotImplementedError
...@@ -28,6 +35,8 @@ hero = [pygame.image.load('hero1.png'), ...@@ -28,6 +35,8 @@ 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')]
index = 0 index = 0
y = 400 y = 400
jumpState = "runing" jumpState = "runing"
...@@ -37,6 +46,8 @@ rect = obstacle.get_rect() ...@@ -37,6 +46,8 @@ rect = obstacle.get_rect()
rect.x = 1000 rect.x = 1000
rect.y = 500 - rect.height rect.y = 500 - rect.height
time=0 time=0
gamestate = True
block_list =pygame.sprite.infog rope() block_list =pygame.sprite.infog rope()
while True: while True:
...@@ -49,46 +60,54 @@ while True: ...@@ -49,46 +60,54 @@ while True:
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = "up" jumpState = "up"
if jumpState == "up": # 起跳状态 if gamestate == True:
if t > 0: if jumpState == "up": # 起跳状态
y -= t if t > 0:
t -= 2 y -= t
else: wukong.rest.y = y
jumpState = "down" t -= 2
if jumpState == "down": # 降落状态 else:
if t <= 30: jumpState = "down"
y += t if jumpState == "down": # 降落状态
t += 2 if t <= 30:
else: y += t
jumpState = "runing" wukong.rest.y = y
t =30 t += 2
else:
jumpState = "runing"
t =30
# 悟空造型 # 悟空造型
wukong = hero[index] wukong = hero[index]
if jumpState == "runing": # 跑步状态下 if jumpState == "runing": # 跑步状态下
index += 1 index += 1
if index >= 5: if index >= 5:
index = 0 index = 0
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) # 远处背景 screen.blit(background, (0, 0)) # 远处背景
screen.blit(road, (0, 500)) # 路 screen.blit(road, (0, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空 screen.blit(wukong, (150, y)) # 悟空
#if rect.x <= 0-rect.width: # 障碍物消失 #if rect.x <= 0-rect.width: # 障碍物消失
# 创建障碍物对象 # 创建障碍物对象
time += 1 time += 1
if time >= 60: if time >= 60:
r=randon.randint(0,100) r=randon.randint(0,100)
if r>40: if r>40:
obstacle = Block(bush,cacti,stome) obstacle = Block(bush,cacti,stome)
block_list.add(obstacle) block_list.add(obstacle)
time = 0 time = 0
for prop in block_list: for prop in block_list:
prop.rect.x -= 8 prop.rect.x -= 8
screen.blit(porp.image,(porp,rect.x,porp.rect.y)) screen.blit(porp.image,(porp,rect.x,porp.rect.y))
if porp.rect.x<=0-prop.rect.widh: if porp.rect.x<=0-prop.rect.widh:
pop.kill() sprite.kill()
# 刷新画面 if pygame.sprite.collide_rest(kuong,sprite):
pygame.display.update() gameover = pygame.image.load('gameover.png')
FPS.tick(60) screen.blit(gameoer,(400,200))
\ No newline at end of file gamestate = False
# 刷新画面
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