[SOLVED]CodeCombat | Phase Shift {Python}

Hello! I don’t get any errors for this level, and I don’t know what’s wrong with my code!

# This level is a side-scrolling platform game.
# Read to see how it works. 
# Follow the pattern to add an update handler. 
# Then play the game!

# First, we create the world:
game.spawnXY("desert-platform", 8, 10)
game.spawnXY("desert-platform", 20, 10)
game.spawnXY("desert-platform", 38, 20)
game.spawnXY("desert-platform", 50, 20)
game.spawnXY("desert-platform", 76, 10)
game.spawnXY("desert-platform", 18, 40)
game.spawnXY("desert-platform", 30, 40)

# Now we need a hero:
game.spawnXY("duelist", 10, 18)

# And a generator to randomly spawn coins:
game.spawnXY("generator", 40, 35)
game.setPropertyFor("generator", "spawnType", "gold-coin")
game.setPropertyFor("generator", "spawnRadius", 30)
game.setPropertyFor("generator", "spawnDelay", 1)
game.setPropertyFor("generator", "visible", False)

# We add gravity to the world:
game.setGravity(0, 30)
# And tell the platforms and coins to ignore it:
game.setPropertyFor("desert-platform", "ignoreGravity", True)
game.setPropertyFor("gold-coin", "ignoreGravity", True)

# We can set the speed property for some objects.
# These speeds work, but you can try changing them!
game.setPropertyFor("desert-platform","speed", 5)
game.setPropertyFor("gold-coin","speed", 10)
game.setPropertyFor("duelist", "speed", 20)

# Now that we’ve made the world,
# let’s set up the player controls with events:
game.onInput("space", handler.jump(35, "duelist"))
game.onInput("d", handler.moveRight("duelist"))
game.onInput("a", handler.moveLeft("duelist"))

# We also use events to manage hero behavior.
# The hero stops when he runs into something:
game.setActionFor("duelist", "collide", handler.stop())
# The hero is defeated if he exits the screen:
game.setActionFor("duelist", "exit", handler.defeat())

# Here’s a new kind of event: "update"
# The game updates many times per second,
# So the "update" event is called continuously.
# Here’s an example.
# We want the platforms to continuously move left:
game.setActionFor("desert-platform", "update", handler.moveLeft())

# Your turn! 
# Make it so the coins continuously move right:
game.setActionFor("coin", "update", handler.moveRight())

# When the platforms move off screen, 
# we want them to reappear at the right. 
# That’s called "wrapping". This code makes it happen:

# Finally, we add goals for the game:
# And write directions for the player:
ui.setText("directions", "Collect 10 coins")
ui.setText("directions", "Controls:")
ui.setText("directions", "'A' - move left")
ui.setText("directions", "'D' - move right")
ui.setText("directions", "Space - jump")

Please help!

If it helps, here’s the link to the level:

And here’s what my goals look like:

Screenshot 2021-06-08 2.03.11 PM

“coin” should be “gold-coin”.


Thank you! It worked!

1 Like

I love the description about you, @King_RaiderVII


This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.