(点击图片进入关卡)
然而,游戏逻辑并不需要最后一个 nextPotionIn 。 我们仅将它用于 UI 所以玩家可以看到下一次药水产生的时间。当然,我们可以显示 game.spawnPotionTime 但玩家不清楚,因为他们必须比较当前时间和生成时间。 相反,我们会显示到下一个药水的剩余时间。
def spawnMunchkins():
munchkin1 = game.spawnXY("munchkin", 2, 12)
munchkin2 = game.spawnXY("munchkin", 2, 56)
munchkin1.behavior = "AttacksNearest"
munchkin2.behavior = "AttacksNearest"
def spawnThrowers():
thrower1 = game.spawnXY("thrower", 2, 16)
thrower1.behavior = "AttacksNearest"
thrower2 = game.spawnXY("thrower", 2, 52)
thrower2.behavior = "AttacksNearest"
def spawnPotion():
game.spawnXY("potion-large", 46, 34)
game.addSurviveGoal(20)
game.munchkinSpawnTime = 0
game.throwerSpawnTime = 0
game.potionSpawnTime = 6
game.nextPotionIn = 0
ui.track(game, "time")
ui.track(game, "nextPotionIn")
player = game.spawnPlayerXY("duelist", 40, 34);
player.maxSpeed = 15
def updateTimers():
if game.time > game.munchkinSpawnTime:
game.munchkinSpawnTime = game.munchkinSpawnTime + 6
spawnMunchkins()
if game.time > game.potionSpawnTime:
player.say("药水在这!")
game.potionSpawnTime = game.potionSpawnTime + 6
spawnPotion()
if game.time > game.throwerSpawnTime:
game.throwerSpawnTime = game.throwerSpawnTime + 9
spawnThrowers()
game.nextPotionIn = game.potionSpawnTime - game.time
while True:
updateTimers()