In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

flash on 2013-6-10

Get Adobe Flash player
by mutantleg 13 Jun 2013
    Embed
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/trvE
 */

package {
    import flash.text.TextField;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
       
       //edit: corrected mouse from iso to world coordinate conversion
       
        public function FlashTest() {
            
            mwidth = 8;
            mheight = 8;
            vecGrid = Vector.<int>([
            3,3,1,1, 1,1,1,1, 
            3,2,2,1, 1,1,1,1, 
            1,2,1,1, 1,3,1,1, 
            1,1,1,1, 3,1,2,1, 
            
            1,2,2,1, 3,1,2,1, 
            1,2,1,1, 3,1,1,1, 
            1,2,1,1, 2,1,1,1, 
            1,1,1,1, 1,1,1,1
            ]);
            
            
            deb = new TextField();
            deb.width = 320;
            deb.height = 240;
            deb.mouseEnabled = false;
            addChild(deb);
            
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor
        
        public var vecGrid:Vector.<int>;
        public var mwidth:int = 0;
        public var mheight:int = 0;
        public var cw:Number = 32;
        public var ch:Number = 32;
       
        public var deb:TextField;
       
        public var ang:Number = 0;
       
        public function onEnter(e:Event):void
        {
            graphics.clear();
            graphics.lineStyle(2, 0);
          
              var i:int;
              var k:int;
              var yt:int;
              var t:int;
              var rx:Number;
              var ry:Number;
              var rz:Number;
              var sx:Number;
              var sy:Number;
              
              var kw:Number;
              var kh:Number;
              
              var c:uint;
              
              var mx:Number;
              var my:Number;
              
              ang += 0.1;
              
              kw = cw*0.5;
              kh = ch*0.5;
              
              for (i = 0; i < mheight; i++)
              {
                  yt = i * mwidth;
                for (k = 0; k < mwidth; k++)
                {
                   t = vecGrid[yt+k];
                   if (t <= 0) { continue; } 
                    
                    rx = k * cw;
                    rz = 0;
                    ry = i * ch;
                    
                    sx = rx - ry;
                    sy = (rx*0.5)+(ry*0.5) - rz;
                    
                    sx += 200;
                    sy += 100;
                   // graphics.drawCircle(sx, sy, 4);
                  
                      if (t == 1) { c= 0xFF0000;}
                      else if (t == 2) { c = 0x00FF00;}
                      else if (t == 3) { c = 0x0000ff;}
                  
                   graphics.beginFill(c, 0.5);
                    graphics.moveTo(sx, sy);
                    graphics.lineTo(sx+cw,sy+kh);  
                    graphics.lineTo(sx+cw-cw,sy+kh+kh);
                    graphics.lineTo(sx-cw, sy+kh);
                    graphics.lineTo(sx,sy);
                   graphics.endFill();   
                   
                   /*
                   //testing if order is correct
                   graphics.beginFill(c, 1);
                       graphics.drawCircle(sx,sy-8,32);
                   graphics.endFill();
                    */
                    
              
                }//nextk  
                  
              }//nexti
          
                mx = mouseX-200;
                my = mouseY-100;
                
                var tx:int = 0;
                var ty:int  =0;

                var tempx:Number;
                var tempy:Number
                    
                tempy = (2*my - mx)*0.5;
                tempx = mx + tempy;
          
                  tx = tempx / cw;
                  ty = tempy / ch;
          
              //old
                //tx = (mx + 2 *my)/(cw*2);
               // ty = (2*my-mx)/(ch*2);
                
                
                
                deb.text ="tx " +tx + "  ty  " + ty; 
                
                if (tx < 0) { return;}
                if (ty < 0) { return;}
                if (tx >= mwidth) { return; }
                if (ty >= mheight) { return;}
            
                t = vecGrid[ty*mwidth+tx];
                if (t == 3) { return; }
                t = 3-t;
                vecGrid[ty*mwidth+tx]=t;
            
            
        }//onenter 
        
    }//classend
}