PDA

View Full Version : Random Motion within a Controlled Area



Joe123
12-21-2007, 08:08 PM
Well, it's the flies from LA: DX, but I'm sure a more creative use could be interpreted =P
Quite pointless on it's own really, purely aesthetic, but you could use it as a movement pattern for a custom boss or something?

Requires the 'Run Script on Screen Init.' Flag checked

ffc script fly{
void run(){
int t = 0; int x; int y;
this->X = (Rand(240)+8);
this->Y = (Rand(160)+8);
while(true){
if(this->X < 8){
x = (Rand(26)/80);
y = (Rand(26)/80);
if(Rand(2) == 1){y = y*-1;}
this->Vx = x;
this->Vy = y;
t = 1;
}
if(this->X > 248){
x = (Rand(26)/80);
y = (Rand(26)/80);
if(Rand(2) == 1){y = y*-1;}
this->Vx = -x;
this->Vy = y;
t = 1;
}
if(this->Y < 8){
x = (Rand(26)/80);
y = (Rand(26)/80);
if(Rand(2) == 1){x = x*-1;}
this->Vx = x;
this->Vy = y;
t = 1;
}
if(this->Y > 168){
x = (Rand(26)/80);
y = (Rand(26)/80);
if(Rand(2) == 1){x = x*-1;}
this->Vx = x;
this->Vy = -y;
t = 1;
}
if(t==45){t = 0;}
if(t == 0){
x = (Rand(26)/80);
y = (Rand(26)/80);
if(Rand(2) == 1){x = x*-1;}
if(Rand(2) == 1){y = y*-1;}
this->Vx = x;
this->Vy = y;
}
t++;
Waitframe();
}
}
}

It's also a bit hard-coded as is, but you could change the time limit it takes before changing direction or the speed limits on it's movement or whatever if you wanted.