# Slow Tower for a Tower Defense Game

I am making a tower defense game in Flash and I have a slow tower that is built directly on the path. I have it setup to use a hitTestObject function.

The tower is in its own class and the enemies are in their own class.

In the update function for the tower, it has

if (this.hitTestObject(enemy))
{
enemy.slow = true;
}


In the enemy class update function, I have:

if (slow == true)
{
finalSpeed = speed/2;
}
else
{
finalSpeed = speed;
}


This seems to work fine until I build a second slow tower. Whenever I build the second one, it works, but the first one stops working (it no longer slows enemies). However, it is still detecting the collisions with the enemies. I don't understand why it doesn't slow them down though.

• Half your post is missing. – The Communist Duck May 23 '11 at 14:47
• Can you describe exactly what doesn't work with the first tower when the second is built? Should they cumulate the speed reduction (and it doesn't) or should it behave another way ? – Valkea May 23 '11 at 14:51
• @Valkea as i can understand from his question i think he means after building the second tower the first tower doesn't slow enemies anymore. – Ali1S232 May 23 '11 at 15:57
• Yes, my problem is, once the second tower is built, the first one stops working (it no longer slows enemies). However, it is still detecting the collisions with the enemies. I don't understand why it doesn't slow them down though. – Sean May 23 '11 at 16:03
• Is the enemy's slow variable being set but the speed is not changing? or is the slow variable not being set? – lathomas64 May 23 '11 at 16:47

i guess for some reason the first if statement which should be working for every tower is only working for the latest tower build, (maybe it's just an instancing problem, eg. you just create an instance for tower shape but not from the whole tower class)