flash on 2013-3-5

by mutantleg
♥0 | Line 80 | Modified 2013-03-05 01:16:16 | MIT License
play

ActionScript3 source code

/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/liUv
 */

package {
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        
        public var col:Sprite;
        
        public function FlashTest() {
            
            col = new Sprite();
            col.graphics.clear();
            col.graphics.beginFill(0, 1);
            col.graphics.drawRect(32,32,64,64);
            col.graphics.endFill();
            addChild(col);
            
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor
        
        
        public var px:Number = 48;
        public var py:Number = 27;
        public var pdir:int = 0;
        public var pang:Number = 0;
        
        //my 189312837whateverth attemp at 
        //commander keen 2 red walkers movement
        //(or those not familiar with dos games:
        //movement those metroid wallhuggers got)
        
        //so far its promising i guess
        
        public function onEnter(e:Event):void
        {
            
            
            graphics.clear();
            graphics.lineStyle(2,0);
            graphics.drawCircle(px, py, 8);
      
      
      if (pdir == 7)
      {
            if (col.hitTestPoint(px, py+8,true) == false)
            {  px += 2; } else { pdir = 0;}
          
          }
           
           if (pdir == 0)
           {
            
            if (col.hitTestPoint(px, py+8,true) == true)
            {  px += 2; 
            
              if (col.hitTestPoint(px, py+6,true)) { py -=1;}
            }
            else
            {
             pdir = 1;   
            }
           }
           
           if (pdir == 1)
           {
            if (col.hitTestPoint(px-8,py,true) == false)
            { py +=2;} else {pdir = 2;}   
           }
           
           if (pdir == 2)
           {
             if (col.hitTestPoint(px-8,py, true) == true)
             { py += 2;
               if (col.hitTestPoint(px-6, py,true)) { px +=1;}

             }  
             else
             {  pdir = 3;} 
           }
           
           if (pdir == 3)
           {
             if (col.hitTestPoint(px, py-8,true) == false)
             { px -=2; }else { pdir =4; }   
           }
          
           if (pdir == 4)
           {
             if (col.hitTestPoint(px, py-8,true) == true)
             { px -=2; 
              if (col.hitTestPoint(px, py-6,true)) { py +=1;}

             }else { pdir =5; }   
           }
           
           if (pdir == 5)
           {
            if (col.hitTestPoint(px+8,py, true) == false)
            { py -= 2; } else { pdir = 6;}   
               
           }
           
           if (pdir == 6)
           {
            if (col.hitTestPoint(px+8,py, true) == true)
            { py -= 2; 
             if (col.hitTestPoint(px+6, py,true)) { px -=1;}

            } else { pdir = 7;}   
               
           }
           
           
          
           
             
        }//onenter
        
    }//classend
}