real fish behavior using as3
screen shot
click here to download
screen shot
fish class
-----------------
package utils{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.*;
import flash.utils.getTimer;
public class fish1 extends MovieClip {
public var myDivision:Number =0;
private var XSpeed:Number;
private var YSpeed:Number;
private var DirectionChangeTime:Number;
private var gotoX:Number;
private var gotoY:Number;
public function fish1() {
//
init();
}
//string
public function init() {
DirectionChangeTime = (getTimer()+Math.random()*1000+2000);
gotoX =Math.random()*900;
gotoY = Math.random()*600;
this.addEventListener(Event.ENTER_FRAME,mover);
}
public function mover(e:Event) {
this.XSpeed = (this.gotoX-e.currentTarget.x)/myDivision;
this.YSpeed = (this.gotoY-e.currentTarget.y)/myDivision;
e.currentTarget.x += this.XSpeed;
e.currentTarget.y += this.YSpeed;
if (getTimer()>this.DirectionChangeTime) {
this.DirectionChangeTime = (getTimer()+Math.random()*(1000)+2000);
this.gotoX = Math.random()*900;
this.gotoY = Math.random()*600;
}
if (this.gotoX<e.currentTarget.x) {
this.scaleX = 1;
} else {
this.scaleX = -1;
}
}
}
}
download source codeclick here to download

Comments
Post a Comment