Commit 3e19ca65 by BellCodeEditor

save project

parent 09a3b034
Showing with 10 additions and 10 deletions
...@@ -10,8 +10,7 @@ class Block(pygame.sprite.Sprite): ...@@ -10,8 +10,7 @@ class Block(pygame.sprite.Sprite):
self.image = random.choice([image1,image2,image3]) self.image = random.choice([image1,image2,image3])
self.rect = self.image.get_rect() self.rect = self.image.get_rect()
self.rect.x = 1000 self.rect.x = 1000
self.rect.y =500-rect.height self.rect.y =500-self.rect.height
pygame.display.set_caption("悟空酷跑") pygame.display.set_caption("悟空酷跑")
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
...@@ -33,7 +32,7 @@ wukong_y=400 ...@@ -33,7 +32,7 @@ wukong_y=400
rode_x=0 rode_x=0
background_x=0 background_x=0
t=30 t=30
obstacle = Block([bush,cacti,stone]) obstacle = Block(bush,cacti,stone)
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -43,6 +42,9 @@ while True: ...@@ -43,6 +42,9 @@ while True:
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if event.key == locals.K_SPACE and jumpState=="runing": if event.key == locals.K_SPACE and jumpState=="runing":
jumpState="up" jumpState="up"
if event.type == locals.MOUSEBUTTONDOWN:
if jumpState=="runing":#event.m == locals.BUTTON_LEFT and
jumpState="up"
if jumpState=="up": if jumpState=="up":
if t>0: if t>0:
...@@ -71,13 +73,11 @@ while True: ...@@ -71,13 +73,11 @@ while True:
screen.blit(road, (rode_x, 500)) screen.blit(road, (rode_x, 500))
screen.blit(wukong, (150, wukong_y)) screen.blit(wukong, (150, wukong_y))
if rect.x<=0-rect.width: if obstacle.rect.x<=0-obstacle.rect.width:
obstacle = random.choice([bush,cacti,stone]) obstacle = Block(bush,cacti,stone)
rect=obstacle.get_rect()
rect.x = 1000 screen.blit(obstacle.image, (obstacle.rect.x, obstacle.rect.y))
rect.y =500-rect.height obstacle.rect.x -= 8
screen.blit(obstacle, (rect.x, rect.y))
rect.x -= 8
rode_x=rode_x-8 rode_x=rode_x-8
background_x -= 5 background_x -= 5
# 刷新画面 # 刷新画面
......
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