Forums

ForumsProgramming Forum

Need help whit Enemies!

Posted Mar 19, '08 at 11:33pm

SeoMX

SeoMX

91 posts

Does anyone knows how to make enemies appear randomly??? (like in "Storm the House&quot

 

Posted Mar 20, '08 at 7:05pm

nonkodesign

nonkodesign

1 post

Are you working with Actionscript? If yes, you can set the _x and _y properties of any object on creation, or after being created with a number of different commands based on the way you have chosen to program the game. I won't go into syntax but to generate a random x coordinate, set your x value of the object (enemy) to a random value. Most lay areas' will have bounds within the actual viewing area and you need to take this into account. For instance if your play area starts at an x coordinate of 25 pixels and it ends at 600 pixels from 0, then your play area is 575 pixels wide and starts at 25. so your random x coordinate would be _x = 25 + random(575). This will likely cause unwanted clipping at the minimum and maximum coordinates so you may need to add and subtract the width of the object as well to make it look good. These exact same details apply to the y coordinate as well. Hope that helps a bit.

 

Posted Mar 20, '08 at 8:17pm

minibeast198

minibeast198

41 posts

Make your enemy a movie clip, and set the actions for the movie clip as the following:

onClipEvent(enterFrame) {
randomX = Math.random() * (highX - lowX)) + lowX;
randomY = Math.random() * (highY - lowY)) + lowY;
this._x = randomX
this._y = randomY
}


Replace "highX" with the x-value of the farthest right you'd want an enemy appear. Likewise, replace "lowX" with the x-value of the farthest to the left you'd want an enemy appear. Do the same with "highY" (lowest on the stage you'd want enemy to appear) and "lowY" (highest on the stage you'd want enemy to appear.) Hope this works, I'm not 100% sure this is correct.

 
Reply to Need help whit Enemies!

You must be logged in to post a reply!