Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shark class
- package
- {
- import flash.display.*;
- import flash.events.*;
- public class Shark extends MovieClip
- {
- var CharacterX:Number = 0;
- var CharacterY:Number = 0;
- static var targetX:int;
- static var targetY:int
- public function Shark()
- {
- this.x = 300;
- this.y = 200;
- addEventListener(Event.ENTER_FRAME,playGame);
- }
- public function set CX(characterx:Number){
- this.CharacterX = characterx - this.x;
- }
- public function set CY(charactery:Number){
- this.CharacterY = charactery - this.y;
- }
- function playGame(event:Event):void
- {
- var ease:int = 20;
- var speed:int = 10;
- targetX = root.CharacterX - this.x;
- targetY = root.CharacterY - this.y;
- var rotation = Math.atan2(targetY,targetX) * 180 / Math.PI;
- if (Math.abs((rotation - this.rotation)) > 180)
- {
- if (((rotation > 0) && this.rotation < 0))
- {
- this.rotation -= (((360 - rotation) + this.rotation) / ease);
- }
- else if (this.rotation > 0 && rotation < 0)
- {
- this.rotation += (((360 - rotation) + this.rotation) / ease);
- }
- }
- else if ((rotation < this.rotation))
- {
- this.rotation -= Math.abs(this.rotation - rotation) / ease;
- }
- else
- {
- this.rotation += Math.abs((rotation - this.rotation)) / ease;
- }
- var vx:Number = speed * (90 - Math.abs(this.rotation)) / 90;
- var vy:Number;//Velocity in y is the difference of speed and vx.
- if (this.rotation < 0)
- {
- vy = - speed + Math.abs(vx);//Going upwards.
- }
- else
- {
- vy = speed - Math.abs(vx);//Going downwards.
- }
- this.x += vx;
- this.y += vy;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement