本文整理汇总了Python中Scene.Scene.move方法的典型用法代码示例。如果您正苦于以下问题:Python Scene.move方法的具体用法?Python Scene.move怎么用?Python Scene.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scene.Scene
的用法示例。
在下文中一共展示了Scene.move方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Scene import Scene [as 别名]
# 或者: from Scene.Scene import move [as 别名]
def main():
# 初始化
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("T-Rex Rush-公众号: Charles的皮卡丘")
clock = pygame.time.Clock()
# 得分
score = 0
# 加载一些素材
jump_sound = pygame.mixer.Sound("./music/jump.wav")
jump_sound.set_volume(6)
die_sound = pygame.mixer.Sound("./music/die.wav")
die_sound.set_volume(6)
pygame.mixer.init()
pygame.mixer.music.load("./music/bg_music.mp3")
pygame.mixer.music.set_volume(0.6)
pygame.mixer.music.play(-1)
font = pygame.font.Font('./font/simkai.ttf', 20)
# 实例化
dinosaur = Dinosaur(WIDTH, HEIGHT)
scene = Scene(WIDTH, HEIGHT)
plants = pygame.sprite.Group()
pteras = pygame.sprite.Group()
# 产生障碍物事件
GenPlantEvent = pygame.constants.USEREVENT + 0
pygame.time.set_timer(GenPlantEvent, 1500)
GenPteraEvent = pygame.constants.USEREVENT + 1
pygame.time.set_timer(GenPteraEvent, 5000)
# 游戏是否结束了
running = True
# 是否可以产生障碍物flag
flag_plant = False
flag_ptera = False
t0 = time.time()
# 主循环
while running:
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
pygame.quit()
if event.type == GenPlantEvent:
flag_plant = True
if event.type == GenPteraEvent:
if score > 50:
flag_ptera = True
key_pressed = pygame.key.get_pressed()
if key_pressed[pygame.K_SPACE]:
dinosaur.is_jumping = True
jump_sound.play()
screen.fill(BACKGROUND)
time_passed = time.time() - t0
t0 = time.time()
# 场景
scene.move()
scene.draw(screen)
# 小恐龙
dinosaur.is_running = True
if dinosaur.is_jumping:
dinosaur.be_afraid()
dinosaur.jump(time_passed)
dinosaur.draw(screen)
# 障碍物-植物
if random.random() < sigmoid(score) and flag_plant:
plant = Plant(WIDTH, HEIGHT)
plants.add(plant)
flag_plant = False
for plant in plants:
plant.move()
if dinosaur.rect.left > plant.rect.right and not plant.added_score:
score += 1
plant.added_score = True
if plant.rect.right < 0:
plants.remove(plant)
continue
plant.draw(screen)
# 障碍物-飞龙
if random.random() < sigmoid(score) and flag_ptera:
if len(pteras) > 1:
continue
ptera = Ptera(WIDTH, HEIGHT)
pteras.add(ptera)
flag_ptera = False
for ptera in pteras:
ptera.move()
if dinosaur.rect.left > ptera.rect.right and not ptera.added_score:
score += 5
ptera.added_score = True
if ptera.rect.right < 0:
pteras.remove(ptera)
continue
ptera.draw(screen)
# 碰撞检测
if pygame.sprite.spritecollide(dinosaur, plants, False) or pygame.sprite.spritecollide(dinosaur, pteras, False):
die_sound.play()
running = False
# 显示得分
score_text = font.render("Score: "+str(score), 1, (0, 0, 0))
screen.blit(score_text, [10, 10])
pygame.display.flip()
clock.tick(60)
#.........这里部分代码省略.........