# Enemy walking / take away health & lives

**URL:** https://forum.kirupa.com/t/enemy-walking-take-away-health-lives/260146
**Category:** programming
**Created:** [May 12, 2008, 11:07pm UTC](https://forum.kirupa.com/t/enemy-walking-take-away-health-lives/260146 "2008-05-12T23:07:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Amymation](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@Amymation](https://forum.kirupa.com/u/Amymation)
#### Post date: [May 12, 2008, 11:07pm UTC](https://forum.kirupa.com/t/enemy-walking-take-away-health-lives/260146/1 "2008-05-12T23:07:32Z")

</div>

Ok so I have a platform game and I have two types of enemies.  
Type 1 = Takes away 1 life if collides with character  
Type 2 = Takes away 5hp (health points) if collides with character.

I know this sounds nooby but I was wondering if anyone can help me with code for the two types of enemies THEY BOTH NEED TO WALK LEFT TO RIGHT ASWELL.

Instance names:

Enemy type 1 = enim1  
Enemy type 2 = enim2  
Character = char

Please help me.

---

<div class="post-metadata">

### Author: ![leonthelion](https://avatars.discourse-cdn.com/v4/letter/l/58956e/32.png) [@leonthelion](https://forum.kirupa.com/u/leonthelion)
#### Post date: [May 13, 2008, 12:04am UTC](https://forum.kirupa.com/t/enemy-walking-take-away-health-lives/260146/2 "2008-05-13T00:04:49Z")

</div>

Okay for hit testing and losing lives:

\_global.life=3  
\_global. can be accesed on any timeline (meaning you can change the variables inside mcs)  
or  
\_root.life=3  
\_root.can only be acessed on the the timeline it was created on (I think)

if you picked \_global.life:

onClipEvent(enterFrame){  
if(this.hitTest(\_root.enim1)){  
\_global.life–}}

if you picked \_root.life:

onClipEvent(enterFrame){  
if(this.hitTest(\_root.enim1)){  
\_root.life–}}

if you want a delay in between losing lives then do something like this:  
onClipEvent(enterFrame){  
\_root.hitdelay–  
if(\_root.hitdelay\<=**(insert number)**){  
if(this.hitTest(\_root.enim1)){  
\_global.life–}}}

So first \_root.hitdelay is subtracted by 1 every frame. Second if the delay is less than a number then it will run the code after. Third if you hi enim1 it subtracts a life. I hope this helps =D

---

<div class="post-metadata">

### Author: ![cooldude88](https://avatars.discourse-cdn.com/v4/letter/c/e0b2c6/32.png) [@cooldude88](https://forum.kirupa.com/u/cooldude88)
#### Post date: [May 13, 2008, 12:31am UTC](https://forum.kirupa.com/t/enemy-walking-take-away-health-lives/260146/3 "2008-05-13T00:31:48Z")

</div>

ok so for the walking left and right just go into the enemy mc and create two blank keyframes make one where they are facing left and the other naturally facing right put stop(); in both frames and name the frames then simply go into the main code and put something like  
if(Key.isDown(Key.RIGHT)){  
\_root.badguy.gotoAndStop(‘right’);  
}  
and repeat for facing left.  
i believe the rest was already explained so any more questions just post em up.  
:party:
