Regenerating Enemies

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:

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!

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

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? :slight_smile:

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

Have a good time:cool: