本文整理匯總了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)
#.........這裏部分代碼省略.........