PDA

View Full Version : Randomizing help


RETraX
03-19-2005, 12:03 PM
Ok, here's my problem. I want to make a simple shoot 'em up, and it would be boring if every enemy would pop up at exactly the same moment over and over, so I want to randomize it. How can I do that? (with a randomizing between 1-10 seconds, with 12 fps)

sycross
03-19-2005, 09:07 PM
You could create an MC and use:

_root.timerandom=Math.random()*10
if (_root.timerandom=1) {
getTimer......

something of that sort. You do know how to use those functions right?

G3M3NI
03-20-2005, 01:26 AM
Hehe... I used this code for one of my games... You may have to modify it because our games are not the same...

onClipEvent(load) {
function koki() {
this._x = random(550)+1;
this._y = random(0)+-10;
speedy = random(5)+3;
}
koki();
}
onClipEvent(enterFrame) {
this._y+= speedy;
if (this.hitTest(_root.Laser)) {
koki();
}
if (this.hitTest(_root.Player)) {
koki();
}
if (this.hitTest(_root.bottomofscreen)) {
koki;
}
}




Thats like for a space game... Just mod those numbers and instance names (and obviously the objective) and away u go... :)

RETraX
03-20-2005, 11:09 AM
My game's gonna be simple..... Not so much AS or sumthing. I'm really just a beginner though I learn fast. The plan is to make a shooter game based on MC's with buttons in them and if the button is pressed the value of a var goes up till a certain limit. Ofcourse the mouse'll become a crosshair...

G3M3NI
03-21-2005, 10:04 AM
Ok try something more like this...

onClipEvent(load) {
//sets the function and randomizes the lot
function koki() {
this._x = random(550)+1;
this._y = random(0)+-10;
speedy = random(5)+3;
}
koki();
}
//Makes the object move down the screen and
//Test when it hits the bottom of the screen
//With a hitTest from a MC placed there and
// Makes the number of escaped ships increase
onClipEvent(enterFrame) {
this._y+= speedy;
if (this.hitTest(_root.bottomofscreen)) {
koki;
_root.Shipsescaped = _root.Shipsescaped + 1;
}
}
//When the object is clicked it resets and randomizes and
//Puts score up by one
on (release) {
koki;
_root.score = _root.score + 1;
}


:) Hope that might help you... :)