Commit cfd04e41 by BellCodeEditor

save project

parent 044d9ec8
Showing with 18 additions and 8 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random import random
block_list=pygame.sprite.Group()
time=0
D=0 D=0
F=0 F=0
pygame.init() # 初始化 pygame.init() # 初始化
...@@ -32,7 +33,6 @@ index = 0 ...@@ -32,7 +33,6 @@ index = 0
y = 400 y = 400
jumpState = "runing" jumpState = "runing"
t = 30 t = 30
obstacle = Block(stone,cacti,bush)
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -75,12 +75,22 @@ while True: ...@@ -75,12 +75,22 @@ while True:
screen.blit(road, (D, 500)) # 路 screen.blit(road, (D, 500)) # 路
screen.blit(wukong, (150, y)) # 悟空 screen.blit(wukong, (150, y)) # 悟空
if obstacle.rect.x <= 0-obstacle.rect.width: # 障碍物消失 time+=1
# 创建障碍物对象 if time>=60:
time=0
num=random.randint(0,50)
if num>20:
obstacle = Block(bush,stone,cacti) obstacle = Block(bush,stone,cacti)
block_list.add(obstacle)
for sprite in block_list:
sprite.rect.x -= 8
screen.blit(sprite.image, (sprite.rect.x, sprite.rect.y))
if sprite.rect.x <= 0-sprite.rect.width:
sprite.kill() # 障碍物消失
# 创建障碍物对象
obstacle.rect.x -= 8
screen.blit(obstacle.image, (obstacle.rect.x, obstacle.rect.y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(20) FPS.tick(35)
\ No newline at end of file \ 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