Hey
I’m pretty new to action script and have been asked to create flocking behaviar with a seeker that the flock moves away from.
I managed to find some code for flocking and seeking in separate classes and am having trouble putting them in the same class so the seeker seeks the flock.
I have attached all relavant movement files.
Any help will be much appreciated.
package
{
import com.foed.SteeredVehicle;
import com.foed.Vector2D;
import com.foed.Vehicle;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
public class FlockTest extends Sprite
{
private var _vehicles:Array;
private var _numVehicles:int = 30;
private var _seeker:SteeredVehicle;
private var _fleer:SteeredVehicle;
public function FlockTest()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
_vehicles = new Array();
for(var i:int = 0; i < _numVehicles; i++)
{
var vehicle:SteeredVehicle = new SteeredVehicle();
vehicle.position = new Vector2D(Math.random() * stage.stageWidth, Math.random() * stage.stageHeight);
vehicle.velocity = new Vector2D(Math.random() * 20 - 10, Math.random() * 20 - 10);
vehicle.edgeBehavior = Vehicle.BOUNCE;
_vehicles.push(vehicle);
addChild(vehicle);
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function SeekFleeTest1()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
_seeker = new SteeredVehicle();
_seeker.position = new Vector2D(200, 200);
_seeker.edgeBehavior = Vehicle.BOUNCE;
addChild(_seeker);
_fleer = new SteeredVehicle();
_fleer.position = new Vector2D(400, 300);
_fleer.edgeBehavior = Vehicle.BOUNCE;
addChild(_fleer);
}
private function onEnterFrame(event:Event):void
{
for(var i:int = 0; i < _numVehicles; i++)
{
_vehicles*.flock(_vehicles);*
_vehicles.update();*
}
_seeker.seek(_fleer.position);
_fleer.flee(_seeker.position);
_seeker.update();
_fleer.update();
}
}
}
As Mentioned above.
I want to create a flocking behavour FlockTest.as that has a predator pursueing it SeekFleeTest.as. I am having trouble combining the code together.
Thank you*