Commit 4df3041b by BellCodeEditor

save project

parent 17cd0e11
Showing with 14 additions and 24 deletions
...@@ -11,7 +11,7 @@ class Block(pygame.sprite.Sprite): ...@@ -11,7 +11,7 @@ class Block(pygame.sprite.Sprite):
self.rect = self.image.get_rect() self.rect = self.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 Block(pygame.sprite.Sprite): class Player(pygame.sprite.Sprite):
def __init__(self,image): def __init__(self,image):
super().__init__() super().__init__()
self.image = image self.image = image
...@@ -36,7 +36,6 @@ hero = [pygame.image.load('hero1.png'), ...@@ -36,7 +36,6 @@ hero = [pygame.image.load('hero1.png'),
index = 0 index = 0
bg_x = 0 bg_x = 0
road_x = 0 road_x = 0
lu_x=0
y = 400 y = 400
jumpState = "runing" jumpState = "runing"
t = 30 t = 30
...@@ -65,12 +64,14 @@ while True: ...@@ -65,12 +64,14 @@ while True:
if jumpState == "up": # 起跳状态 if jumpState == "up": # 起跳状态
if t > 0: if t > 0:
y -= t y -= t
wukong.rect.y = y
t -= 2 t -= 2
else: else:
jumpState = "down" jumpState = "down"
if jumpState == "down": # 降落状态 if jumpState == "down": # 降落状态
if t <= 30: if t <= 30:
y += t y += t
wukong.rect.y = y
t += 2 t += 2
else: else:
jumpState = "runing" jumpState = "runing"
...@@ -82,43 +83,31 @@ while True: ...@@ -82,43 +83,31 @@ while True:
bg_x -= 1 bg_x -= 1
if bg_x <=-1000: if bg_x <=-1000:
bg_x=0 bg_x=0
screen.blit(background,(bg_x,0)) screen.blit(background,(bg_x, 0))
road_x -= 8 road_x -= 8
if road_x <-1000: if road_x <-1000:
road_x=0 road_x=0
screen.blit(road, (road_x, 500)) # 远处背景 screen.blit(road, (road_x, 500)) # 远处背景
screen.blit(wukong,image (150, y)) # 悟空
screen.blit(wukong.image, (150, y)) # 悟空
time += 1 time += 1
if time >= 60: if time >= 60:
time = 0 time = 0
num = random.randint(0,50) num = random.randint(0,50)
if r > 20: if num > 20:
obstacle = Block(bush,cacti,stone) obstacle = Block(bush,cacti,stone)
block_list.add(obstacle) 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.image,(sprite.rect.x,sprite.rect.y)) screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if prop.rect.x <= 0-prop.rect.width:# 障碍物消失 if sprite.rect.x <= 0-sprite.rect.width:# 障碍物消失
prop.kill() sprite.kill()
if pygame.sprite.collide_rest(wukong,sprite): if pygame.sprite.collide_rect(wukong,sprite):
gameover = pygame.image.load('gameover.pong') gameover = pygame.image.load('gameover.png')
screen.blit(gameover,(400,200)) screen.blit(gameover,(400,200))
gameover = False gamestate = False
# 创建障碍物对象
#obstacle = random.choice([bush,stone,cacti])
#rect = obstacle.get_rect()
#rect.x = 1000
#rect.y = 500 - rect.height
#rect.x -= 8
#screen.blit(obstacle, (rect.x,rect.y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) 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