class Person extends MovieClip { private var normalMoveFactor:Number = 50; private var oldForceDecayFactor:Number = 0.999; private var normalRotFactor:Number = 45; //waS 4 private var normalNoFrames:Number = 90; private var oldForceX:Number = 0; private var oldForceY:Number = 0; private var oldRotation:Number = this._rotation; private var newForceX:Number; private var newForceY:Number; private var direction:Number; private var rotation:Number; private var alreadyThinking:Boolean = false; private var boy:Boolean; private var date:Object; private var noDates:Number = 0; private var kissing:Boolean; private var distCount:Boolean; private var walkOut:Boolean; private static var dateThreshold:Number = 1; private static var walkOutRotation:Number; public function Person() { // rotation var rotation:Number = 90; this._rotation = rotation; // position var xPos:Number = random(_root.screenWidth); var yPos:Number = random(_root.screenHeight); this._x = 10; this._y = yPos; kissing = false; distCount = false; walkOut = false; if(this._name.indexOf('boy') != -1) { boy = true; } else { boy = false; } } public function startThinking() { this.alreadyThinking = true; this.attachMovie("thinking", "thinking", this.getNextHighestDepth()); this['thinking']._x += 40; this['thinking']._width *= 0.5; this['thinking']._height *= 0.5; this['thinking']._y -= 35; this['thinking'].onUnload = function() { _parent.alreadyThinking= false; }; } public function kissDate() { kissing = true; this.attachMovie("heart", "heart", this.getNextHighestDepth()); this['heart']._x = -24.5; this['heart']._y = -82.5; this['heart'].onUnload = function() { _parent.distCount = true; _parent.kissing = false; _parent.walkOut = true; _parent._rotation = Person.walkOutRotation; }; } public function checkHit(targetObj:MovieClip) { var sx:Number = this._x; var sy:Number = this._y; var trw:Number = targetObj._width/2; var trh:Number = targetObj._height/2; var tx:Number = targetObj._x; var ty:Number = targetObj._y; var dist:Number = Math.sqrt( (Math.pow(tx-sx,2)) + Math.pow(ty-sy,2) ); if(dist dateThreshold) { // is this the person's first date? if(typeof(date) != 'movieclip') { date = targ; } // did person run into previous date? if(date._name == targ._name) { // check to end kissing if(distCount) { var dist:Number = Math.sqrt( (Math.pow(date._x-this._x,2)) + Math.pow(date._y-this._y,2) ); if(dist>150) { distCount = false; } } noDates++; if(noDates <= dateThreshold) { startThinking(); } else if(!kissing && !distCount) { //START KISSING Person.walkOutRotation = this._rotation; this.kissDate(); date.kissDate(); } } else//TESTING { //trace(date._name +" "+ targ._name); }//END TESTING } } public function move() { //om de kysser varandra ska de stå stilla! if(kissing) { return; } //Get some Gauss-adjusted random numbers: //X _root.normal.gotoAndStop(random(normalNoFrames)+1); var xMove:Number = _root.normal.normalpos._y/normalMoveFactor; //Y _root.normal.gotoAndStop(random(normalNoFrames)+1); var yMove:Number = _root.normal.normalpos._y/normalMoveFactor; //Rotation _root.normal.gotoAndStop(random(normalNoFrames)+1); var newRot; newRot = _root.normal.normalpos._y/normalRotFactor; // Random Thinking if(typeof(date) == 'movieclip') { var rand:Number = random(300); if(rand == 50 && !alreadyThinking && !walkOut) { startThinking(); } } //BOUNDARIES (not move off stage) if(!walkOut) { if(this._x>_root.screenWidth) //högerkanten { this._rotation *= -1; this._x = _root.screenWidth - 5; } if(this._x<0) //vänsterkanten { this._rotation += 180; this._x = 5; } if(this._y>_root.screenHeight) //Nederkanten { var diff:Number = 90-(Math.abs(this._rotation)); if(this._rotation < 0) //går åt vänster { this._rotation = 90+diff; } else //går åt höger { this._rotation = -90-diff; } this._y = _root.screenHeight - 5; } if(this._y<0) //Övre kanten { var diff:Number = 90-(Math.abs(this._rotation)); if(this._rotation < 0) //går åt vänster { this._rotation = -90-diff; } else //går åt höger { this._rotation = 90+diff; } this._y = 5; } } else // person is going off stage { if( ((this._x < 0) || (this._x > _root.screenWidth)) || ((this._y < 0) || (this._y > _root.screenHeight)) ) this.unloadMovie(); } //--ROTATION-- if(!this.walkOut) { direction = 0; while(direction==0) { var direction:Number = 1 - random(3); } this._rotation += newRot * direction; } else { var smallChange = 2 - random(4); this._rotation += smallChange; } oldRotation = newRot; //Get bearings if(this._rotation>0) { rotation = this._rotation; } else if(this._rotation < 0) { rotation = 360 + this._rotation; } //Convert to radians: var rotDeg:Number = rotation;//TEST rotation = rotation * (Math.PI/180); //Apply the random numbers to move the chicks: //--X-- //newForceX = (oldForceX*0.75 + xMove*Math.sin(rotation)); //newForceX = xMove*Math.sin(rotation); newForceX = (oldForceX / 3) + xMove*Math.sin(rotation); this._x += newForceX; oldForceX = newForceX; oldForceX *= oldForceDecayFactor; //--Y-- //newForceY = (oldForceY*0.75 + xMove*Math.cos(rotation)); //newForceY = -1*yMove*(Math.cos(rotation)); newForceY = (oldForceY / 3) + -1*yMove*(Math.cos(rotation)); this._y += newForceY; oldForceY = newForceY; oldForceY *= oldForceDecayFactor; } }