Gam Dev 2 Final Project

I did all the steps for the final project but it is still asking me to “include the hero” is there something I am missing? Here is my code

# Create your own game!

# Spawn a player with spawnPlayerXY()
hero = game.spawnXY("knight", 19, 30)
# Add at least one goal!
money = game.addManualGoal("Increase your money!!!")
# Spawn objects into the game with spawnXY()
game.spawnXY("chest", 52, 50)
game.spawnXY("chest", 57, 50)
for i in range(5):
    game.spawnXY("fence", 8*i + 40, 30)
    game.spawnXY("forest", 36, 8*i + 40)
for i in range(10):
    game.spawnXY("captain", 28, 5*i + 10)
    game.spawnXY("thrower", 68, 5*i + 10)

def onSpawn(event):
    while True:
        unit = event.target
        enemy = unit.findNearestEnemy()
        if enemy:
            unit.attack(enemy)

game.setActionFor("captain", "spawn", onSpawn)
game.setActionFor("thrower", "spawn", onSpawn)
game.score = 0

def onCollect(event):
    unit = event.target
    item = event.other
    if item.value:
        game.score = game.score + item.value

hero.on("collect", onCollect)
def checkGoal():
    if game.score > 100:
        game.setGoalState(money, True)
        
# Playomg tje game
while True:
    checkGoal()
    enemy = hero.findNearestEnemy()
    coin = hero.findNearestItem()
    if enemy:
        hero.attack(enemy)
    elif coin:
        hero.attack(coin)
    

There are no errors just I have all of the objectives excpet for include the hero.

Use spawnPlayerXY not spawnXY for the hero

1 Like

use game.spawnPlayerXY() instead of game.spawnXY().