The female ogre on the bottom won’t attack the hero or the archers and soldiers, but I used the onSpawn function for it.
# Create your own game!
# Spawn a hero with spawnHeroXY()
player = game.spawnPlayerXY("samurai", 37, 35)
player.maxSpeed=15
player.maxHealth=300
player.attackDamage=10
# Add at least one goal!
game.addDefeatGoal()
#Tracking
ui.track(game, "defeated")
ui.track(player, "health")
ui.track(player, "collected")
#onSpawn
def onSpawn(event):
while True:
unit = event.target
enemy = unit.findNearestEnemy()
if enemy:
unit.attack(enemy)
game.setActionFor("munchkin", "spawn", onSpawn)
game.setActionFor("thrower", "spawn", onSpawn)
game.setActionFor("skeleton", "spawn", onSpawn)
game.setActionFor("archer", "spawn", onSpawn)
game.setActionFor("soldier", "spawn", onSpawn)
game.setActionFor("ogre-f", "spawn", onSpawn)
#Layout
game.spawnXY("forest", 31, 37)
game.spawnXY("forest", 31, 29)
game.spawnXY("forest", 39, 29)
game.spawnXY("forest", 48, 29)
game.spawnXY("forest", 48, 37)
game.spawnXY("forest", 48, 45)
forest1 = game.spawnXY("forest", 39, 45)
game.spawnXY("forest", 31, 45)
game.spawnXY("forest", 57, 45)
game.spawnXY("forest", 66, 45)
game.spawnXY("forest", 75, 45)
game.spawnXY("forest", 80, 45)
game.spawnXY("forest", 23, 45)
game.spawnXY("forest", 15, 45)
game.spawnXY("forest", 7, 45)
forest4 = game.spawnXY("forest", 1, 45)
forest5=game.spawnXY("forest", 1, 29)
game.spawnXY("forest", 66, 29)
game.spawnXY("forest", 75, 29)
game.spawnXY("forest", 80, 29)
game.spawnXY("forest", 23, 29)
game.spawnXY("forest", 15, 29)
game.spawnXY("forest", 7, 29)
game.spawnXY("forest", 57, 29)
game.spawnXY("forest", 31, 53)
forest2=game.spawnXY("forest", 22, 60)
game.spawnXY("forest", 31, 65)
game.spawnXY("forest", 48, 53)
forest3=game.spawnXY("forest", 56, 59)
game.spawnXY("forest", 48, 65)
game.spawnXY("forest", 31, 22)
game.spawnXY("forest", 31, 15)
game.spawnXY("forest", 31, 9)
game.spawnXY("forest", 31, 2)
game.spawnXY("forest", 48, 22)
game.spawnXY("forest", 48, 15)
game.spawnXY("forest", 48, 9)
game.spawnXY("forest", 48, 2)
#Enemies
game.spawnXY("munchkin", 43, 41)
thrower1=game.spawnXY("thrower", 31, 59)
thrower2=game.spawnXY("thrower", 47, 59)
game.spawnXY("skeleton", 3, 70)
ogref=game.spawnXY("ogre-f", 13, 5)
ogref.attackDamage = 60
ogref.maxSpeed = 14
ogref.maxHealth = 500
#Items
game.spawnXY("chest", 39.5, 12)
game.spawnXY("potion-medium", 22, 53)
game.spawnXY("potion-medium", 22, 67)
game.spawnXY("potion-large", 23, 37)
game.spawnXY("gem", 15, 37)
game.spawnXY("silver-coin", 19, 37)
game.spawnXY("lightstone", 19, 37)
#First Challenge
def onDefeat(event):
defeated = event.target
game.defeated += 1
if game.defeated == 1:
forest1.destroy()
if game.defeated == 3:
forest2.destroy()
forest3.destroy()
game.spawnXY("potion-small", 39, 65)
if game.defeated == 4:
forest4.destroy()
pass
game.setActionFor("munchkin", "defeat", onDefeat)
game.setActionFor("thrower", "defeat", onDefeat)
game.setActionFor("skeleton", "defeat", onDefeat)
game.setActionFor("ogre-f", "defeat", onDefeat)
#Rest Period
def onCollect(event):
item = event.other
if item:
if item.type == "gem":
game.spawnXY("soldier", 3, 22)
game.spawnXY("soldier", 7, 22)
game.spawnXY("archer", 11, 22)
game.spawnXY("archer", 15, 22)
if item.type == "lightstone":
player.attackDamage = 20
player.maxHealth = 500
if item.type == "silver-coin":
forest5.destroy()
player.on("collect", onCollect)