Mymath

myAngle

package com.myMath{
    import flash.display.MovieClip;
    import com.globals;
    import com.globalFunctions;
    public class myAngle {
        public function myAngle():void {
        }
        public static function getAngle(xVar1:Number, xVar2:Number,yVar1:Number, yVar2:Number):Number {
            return Math.atan2(dist.getDiff(yVar1,yVar2),dist.getDiff(xVar1,xVar2))/(Math.PI/180);
        }
        public static function getObjAngle(obj1:MovieClip, obj2:MovieClip):Number {
            return getAngle(globalFunctions.getX(obj1), globalFunctions.getX(obj2), globalFunctions.getY(obj1), globalFunctions.getY(obj2));
        }
    }
}

dist

package com.myMath{
        import flash.display.MovieClip;
        import com.globalFunctions;
    public class dist {
        public function dist():void {
        }
        static function getDiff(xVar:Number, yVar:Number):Number{
            return yVar-xVar;
        }
        static function getObjDist(obj1:MovieClip, obj2:MovieClip):Number{
            return getDist(globalFunctions.getX(obj1), globalFunctions.getX(obj2), globalFunctions.getY(obj1), globalFunctions.getY(obj2));
        }
        static function getDist(x1:Number, x2:Number, y1:Number, y2:Number):Number{
            var xDist=getDiff(x1, x2)
            var yDist=getDiff(y1, y2)
            return Math.sqrt(xDist*xDist+yDist*yDist);
        }
    }
}

hitTestLine

package com.myMath{
    import flash.display.MovieClip;
    public class hitTestLine {
        public function hitTestLine():void {
        }
        public static function getAngledLine(startX:int, startY:int, myAngle:int,testObj:MovieClip,dist:int, testPoints:int):int {
            var lineVar:int=0;
            for(var i:int=testPoints;i<dist;i+=dist/testPoints){
                var xComp:Number = Math.cos(myAngle*(Math.PI/180))*i+startX; 
                var yComp:Number = Math.sin(myAngle*(Math.PI/180))*i+startY; 
                if(testObj.hitTestPoint(xComp, yComp, true)){
                    lineVar++;
                }
            }
            return lineVar;
        }
        public static function getLine(startX:int, startY:int, testObj:MovieClip,dist:int, testPoints:int,invert:Boolean=false,xDir:int=0, yDir:int=1):int{
            //if invert is true, then I am looking for the number of points NOT touching, as opposed to the points that ARE touching. 
            var lineVar:int=0;
            var interval:int=dist/testPoints;
            for(var i:int=interval;i<dist;i+=interval){
                var xComp:Number = i*xDir+startX;
                var yComp:Number = i*yDir+startY;
                if(testObj.hitTestPoint(xComp, yComp, true)){
                    lineVar+=interval;
                }
            }
            if(invert){
                return dist-lineVar;
            }
            return lineVar;
        }
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License