tower create event
range=n;
dmg=n;
tower alarm event:with(parent_enemy) if distance_to_object(other)<other.range { if shield > 0 { shield-=other.dmg; } if shield <=0 { hp-=other.dmg; } if hp <=0 { instance_destroy(); } }
Game Maker Version: 8.1 Pro
Drag and Drop?: I certainly hope you're kidding. No.
I recently started a tower defense game. I'm having trouble figuring out the code for one of the towers. This tower is supposed to do AOE damage to any enemy in it's range. I've already figured out multiple targets, and yes, I could use the sprite system (round sprite and an object that burns any enemy it contacts). I could also add a checking event in the enemy parent object. I'd rather do it with code from the tower, though.
Currently, the tower will burn up to 5 separate targets via the targeting system I coded, and that's fine and dandy. For a different tower. I need this one to burn ALL enemies within the range of it.
Important stuff you might want to know:
parent_enemy is the parent object for all enemies.
parent_tower is the parent object for all towers you can build. It has code that is inherited to the various towers in different locations according to the tower.
obj_tower_laser is the tower I'm speaking of.
target is the target variable I use in my targeting system.
My game treats uninitialized variables as 0.
dmg is a variable set at tower creation which determines, well, shockingly enough, damage.
maxrange: same thing as above, for max range.
My game uses hitscans (at least I think that's what this system is called). Bullets hitscan the enemys they hit, and towers can do the same hitscan thing. Nice global system. Here's the code for the hitscan:
if other.shield > 0
{
other.shield-=dmg;
}
if other.shield <=0
{
other.hp-=dmg;
}
if other.hp <=0
{
with other
{
instance_destroy();
}
}Any help would be appreciated.
Edited by thecrazygamemaster, 18 April 2012 - 05:41 PM.











