View Full Version : Random Amount of Monsters
wayzey
06-15-2008, 12:33 PM
I have a movieclip called zombie, now I want to make it so across a 3 minute time period(I have the timer already) they randomly spawn in a certain area.
Can someone supply me with code to do this.
Thanks.
jeangj
06-15-2008, 04:34 PM
Hey
I just created a shooting game and needed the same random targets on the stage. I did this:
var ufo_timer:Timer = new Timer(4000);
ufo_timer.addEventListener(TimerEvent.TIMER, addUfo);
var ufo01_mc:Ufo01;
var lastPos:Number = 0;
var position:Number;
//set the stage limit
var maxLimit:uint = 50;
var minLimit:uint = 750;
var range = maxLimit - minLimit;
function addUfo(e:TimerEvent){
ufo01_mc = new Ufo01();
addChild(ufo01_mc);
position = Math.ceil(Math.random() * range) + minLimit;
trace(Math.random() * range);
// if oldPosition and position is within 50 of each other, increase position by 50
if(Math.abs(position - lastPos) < 50)
{
position += 200;
}
// capture the value of position so that we have it available for testing next time
lastPos = position;
//trace(position);
//if(old, new)
ufo01_mc.x = position;
ufo01_mc.y = 10;
//remove the ufo
ufo01_mc.addEventListener(Event.ENTER_FRAME, moveUfo);
}
wayzey
06-15-2008, 11:03 PM
Do you have the rest of the code you put in to make that work aswell. Like the functions and the code you had to put on ufo1_mc to make it work?
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.