# Regenerating Enemies

**URL:** <https://forum.kirupa.com/t/regenerating-enemies/7584>\
**Category:** flash\
**Created:** [November 3, 2002, 5:22pm UTC](https://forum.kirupa.com/t/regenerating-enemies/7584 "2002-11-03T17:22:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeonGold](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@NeonGold](https://forum.kirupa.com/u/NeonGold)\
**Post date:** [November 3, 2002, 5:22pm UTC](https://forum.kirupa.com/t/regenerating-enemies/7584/1 "2002-11-03T17:22:41Z")

</div>

Hi there. I’m working on a simple shoot to kill game… but how do I…

1. Say, there’s one enemy and I kill it. After it dies, I want another one of it to appear randomly in the screen.

Oh… and I’m planning on making games that involve collission detection (Like a mario game of some sort) any fine tutorials on the matter? Or even a sample game with source with tutorial? Thanks!:cool:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 3, 2002, 5:28pm UTC](https://forum.kirupa.com/t/regenerating-enemies/7584/2 "2002-11-03T17:28:03Z")

</div>

You can have the enemy in an mc and then use duplicate mc with a random position when you hit the target.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 3, 2002, 6:24pm UTC](https://forum.kirupa.com/t/regenerating-enemies/7584/3 "2002-11-03T18:24:02Z")

</div>

thanks for the idea but… I’m having a bit of trouble with the coding part hehehe…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 3, 2002, 6:54pm UTC](https://forum.kirupa.com/t/regenerating-enemies/7584/4 "2002-11-03T18:54:00Z")

</div>

the duplicating action:

duplicateMovieClip(mctoduplicate, “newname”, depth);

mctoduplicate would be the enemy you want to duplicate.  
newname would be the name for the duplicated movieclip  
depth would be the depth for the duplicated movieclip.  
exmpl: let’s say we want to duplicate “\_root.enemy”

duplicateMovieClip(\_root.enemy, “enemy”+i,i);  
i++

This code should be triggered if the nemey is killed  
and the random position: this code should be put on the movieclip(enemy)

onClipEvent(load) {  
\_x = random(moviewidth)  
\_y = random(movieheight)  
}

## moviewidth should be the width of the movie. movieheight the height of the movie.

now let’s say theres a screen (like a rectangle) where you want those enemies to appear.  
Like X position would be from 10-90  
and Y position would be from 10-90 too  
(80 would be the width and height of the screen(rectangle) then)  
then use this:

onClipEvent(load) {  
\_x = Math.random()\*80+10  
\_y = Math.random()\*80+10  
}  
Math.random creates a new random number from 0-1 and by multiplying it by 80 we get a random number from 0-80 and by adding 10 we get a random number from 10-90.  
for example if the number would be 0 and we add 10 it’s 10 and if the nuber is 80 we add 10 it’s 90… =)  
Anything else? 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 4, 2002, 4:34am UTC](https://forum.kirupa.com/t/regenerating-enemies/7584/5 "2002-11-04T04:34:18Z")

</div>

Thanks a lot!!! I’ll be playing around then hehehe…

Have a good time:cool:
