Commit c8b63a9f by BellCodeEditor

save project

parent a9db6bf0
Showing with 17 additions and 4 deletions
...@@ -10,7 +10,7 @@ class Block(pygame.sprite.Sprite): ...@@ -10,7 +10,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
#obstacle=Block(importpygame)
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
...@@ -35,6 +35,9 @@ t = 30 ...@@ -35,6 +35,9 @@ t = 30
# rect.x = 1000 # rect.x = 1000
# rect.y = 500 - rect.height # rect.y = 500 - rect.height
obstacle = Block(bush,stone,cacti) obstacle = Block(bush,stone,cacti)
pygame
time = 0
list=pygame.sprite.Group()
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -44,6 +47,7 @@ while True: ...@@ -44,6 +47,7 @@ while True:
if jumpState == "runing": if jumpState == "runing":
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = "up" jumpState = "up"
if jumpState == "up": # 起跳状态 if jumpState == "up": # 起跳状态
if t > 0: if t > 0:
...@@ -68,9 +72,18 @@ while True: ...@@ -68,9 +72,18 @@ while True:
# 将背景图画上去 # 将背景图画上去
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))
obstacle.rect.x-=8 if time>=60:
screen.blit(obstacle.image,(obstacle.rect.x,obstacle.rect.y)) time=0
num = random.randint(0,50)
if num >20:
obstacle=Block(bush,carti,stone)
list.add(obstacle)
for sprite in list:
sprite.rect.x-=8
screen.blit(sprite.image(sprite.rcet.x.sprite.rect.y))
if sprite.rect.x<=0-sprite.rect.width:
sprite.skill()
# if rect.x <= 0-rect.width: # 障碍物消失 # if rect.x <= 0-rect.width: # 障碍物消失
# # 创建障碍物对象 # # 创建障碍物对象
# obstacle = random.choice([bush,stone,cacti]) # obstacle = random.choice([bush,stone,cacti])
......
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