Forums → Programming Forum → Need help whit Enemies!
- 2 Replies
Does anyone knows how to make enemies appear randomly??? (like in "Storm the House"
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.
Make your enemy a movie clip, and set the actions for the movie clip as the following:
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.
You must be logged in to post a reply!
We strive to deliver the best gaming experiences on the internet and on your mobile phone. Play thousands of free online games, get access to free mmorpg games, online rpg games, fun online flash games, and more.
We offer free flash games in many different genres: online shooting games, online puzzle games, online war games, free online car games, free online hidden object games and dozens more.
This is the best place on the web to play online games for free! No matter what game style you prefer, we've got it here.
Want to advertise on Armor Games? Send us a note!
Gaming websites, passionate bloggers, and quirky streamers are welcome to share or review our games. If you need game keys, art, trailers, screenshots or more check out our press kit website.
Game developer? Visit developers.armorgames.com to request AG developer status, find documentation on our APIs, and get access to our development environment. Let's make sweet, sweet games together.
Looking for a publishing partner that can help your app rocket to success? Contact the mobile team to learn more about how we can help!