Jump to content


Photo

Tower Defense AOE Damage *SOLVED*


  • Please log in to reply
8 replies to this topic

#1 thecrazygamemaster

thecrazygamemaster

    Devcodier

  • GMC Member
  • 670 posts
  • Version:GM:Studio

Posted 17 April 2012 - 05:02 AM

SOLVED! See code below this:

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.

  • 0

#2 Max:Tyson

Max:Tyson

    GMC Member

  • GMC Member
  • 102 posts
  • Version:GM:HTML5

Posted 17 April 2012 - 05:32 AM

Is this AOE damage supposed to come from a missle tower or grenade tower? as in would it throw a projectile that then has the AOE, or would the AOE come straight from the tower itself?
  • 0

#3 thecrazygamemaster

thecrazygamemaster

    Devcodier

  • GMC Member
  • 670 posts
  • Version:GM:Studio

Posted 17 April 2012 - 07:08 AM

Is this AOE damage supposed to come from a missle tower or grenade tower? as in would it throw a projectile that then has the AOE, or would the AOE come straight from the tower itself?

Straight from the tower. I've got the projectile > explosion system done already using the burning object w/ circular sprite system.
  • 0

#4 decroded

decroded

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM8

Posted 17 April 2012 - 08:35 AM

Just to point out that "hitscan" code is a little flawed. Need a tmp dmg var to subtract the dmg taken by the shield before applying dmg to hp.
Otherwise when shield = 10, hp = 50, a bullet of 50dmg will kill target instead of needing 60dmg.
  • 0

#5 thecrazygamemaster

thecrazygamemaster

    Devcodier

  • GMC Member
  • 670 posts
  • Version:GM:Studio

Posted 17 April 2012 - 12:57 PM

Just to point out that "hitscan" code is a little flawed. Need a tmp dmg var to subtract the dmg taken by the shield before applying dmg to hp.
Otherwise when shield = 10, hp = 50, a bullet of 50dmg will kill target instead of needing 60dmg.

That's true, but only if this was run more than once per impact. It's not. It's run once. But back on topic, AOE?
  • 0

#6 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5379 posts
  • Version:GM:Studio

Posted 18 April 2012 - 12:34 AM

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();
  }

}
and decroded is right, even tho the shield and hp is 50 and he is hit for 50 dmg, then both the shield and hp will be set to 0 .. and it doens't need to run more then once before that happens, an alternative one:
var temp;
temp  = max(0,other.dmg - shield);
shield = max(0,shield-other.dmg);
hp -= temp;
if hp<=0 instance_destroy()

  • 0

#7 decroded

decroded

    GMC Member

  • GMC Member
  • 524 posts
  • Version:GM8

Posted 18 April 2012 - 03:58 AM

Yeah it makes sense to just code it in the enemy parent and let the enemies inherit this behaviour.
coding from tower could be done but I think is messy and the wrong way to do it.
Edit: what is aoe anyway? Age of empires? Lol

Edited by decroded, 18 April 2012 - 04:04 AM.

  • 0

#8 thecrazygamemaster

thecrazygamemaster

    Devcodier

  • GMC Member
  • 670 posts
  • Version:GM:Studio

Posted 18 April 2012 - 05:39 PM

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();
  }

}
and decroded is right, even tho the shield and hp is 50 and he is hit for 50 dmg, then both the shield and hp will be set to 0 .. and it doens't need to run more then once before that happens, an alternative one:
var temp;
temp  = max(0,other.dmg - shield);
shield = max(0,shield-other.dmg);
hp -= temp;
if hp<=0 instance_destroy()

Thanks, that AOE code works perfectly. I've tested out your system and mine, but there doesnt seem to be a difference. Oh well, yours IS less code. Thanks for that, too! :D. You've been extremely helpful.
  • 0

#9 Subject0001

Subject0001

    GMC Member

  • New Member
  • 127 posts

Posted 18 April 2012 - 06:30 PM

lol when you wrote AOE i thought it was Age Of Empires :biggrin:

oops... not reading description. sorry :)

Edited by Subject0001, 18 April 2012 - 06:46 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users