Can someone please help me with freeze tag (python)

Let’s make a game of Freeze Tag!

game.tagged is used to count tagged archers.

game.tagged = 0
ui.track(game, “tagged”)
goal = game.addManualGoal(“Tag all archers.”)

Spawn the archers.

game.spawnXY(“archer”, 12, 52)
game.spawnXY(“archer”, 12, 16)
game.spawnXY(“archer”, 24, 52)
game.spawnXY(“archer”, 24, 16)

player = game.spawnPlayerXY(‘captain’, 68, 24)
player.maxSpeed = 1000

Make the player bigger so it’s easier to tag archers.

player.scale = 2

Set up the archers’ speed and behavior properties onSpawn

def onSpawn(event):
unit = event.target
unit.behavior = “Scampers”
unit.maxSpeed = 8

game.setActionFor(“archer”, “spawn”, onSpawn)

The event handler for “collide” events.

def onCollide(event):
# The event owner who has collided with something.
unit = event.target
# The object the unit collided with.
other = event.other
# Use behavior as a marker for the current frozen state.
# “Scampers” means the archer wasn’t yet tagged.
if unit.behavior == “Scampers”:
# If “other” is the player.
if “other” == player:
# Set unit.behavior to “Defends”:
unit.behavior == “Defends”
# Increase game.tagged by 1:
game.tagged =+ 1
pass
if unit.behavior == “Defends”:
# If other’s type is “archer”:
if other.type == “archer”:
# Set unit.behavior to “Scampers”:
unit.behavior = “Scampers”
# Reduce game.tagged by 1.
game.tagged -= 1

Use setActionFor to assign onCollide to the “collide” event for "archer"s.

game.setActionFor(“archers”, “collide”, onCollide)

while True:
if game.tagged >= 4:
game.setGoalState(goal, True)

1 Like

Hi Vincent_Mainer,

Welcome to the forum!

We’d be happy to help you, but could you start by formatting your code as explained here:

https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521/2

Thanks.

2 Likes

While we do need to see your code properly formatted, just in case there might be indentation problem, in this instance, I’ve seen this one before.

‘other’ is an object, not a string. Yes, the comments referring to this line are a bit misleading, in that they call it “other”, which does imply a string.

If this is not clear enough, feel free to post again, but please be prepared to post properly formatted code…just in case :wink:

2 Likes