Commit d69364fb by BellCodeEditor

save project

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