A question from the Game Development 2: 1.Guard Duty level. I wrote game.spawnXY instead of hero.spawnXY but it is still working as it should (this is why I did not notice the difference in the code at first). So I am wondering, since both of them works in this code, what is the difference between using hero.spawn and game.spawn when it comes to adding a hero to the game?
I wrote:
def soldierLogic():
while True:
enemy = soldier.findNearestEnemy()
if enemy:
soldier.attack(enemy)
else:
soldier.moveXY(42, 48)
This assigns your spawned unit to the soldier variable.
soldier = game.spawnXY(“soldier”, 42, 48)
soldier.on(“spawn”, soldierLogic
I compared with:
HINT 1
def soldierLogic():
while True:
enemy = soldier.findNearestEnemy()
if enemy:
soldier.attack(enemy)
soldier = hero.spawnXY(“soldier”, 42, 48)
soldier.on(“spawn”, soldierLogic)