flash on 2014-10-3

by mutantleg
♥0 | Line 113 | Modified 2014-10-04 06:10:14 | 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/h6Bj
 */

package {
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            
            vecChar = new Vector.<xChar>;
            vecRoom = new Vector.<xRoom>;
            
            var a:xRoom;
             a = new xRoom();
                vecRoom.push(a);
           
             a = new xRoom();
                 vecRoom.push(a);
 
            var c:xChar;
            c = new xChar();
            c.cx= 160;
            c.cy = 120;
            vecChar.push(c);
            
            c = new xChar();
            c.id = 1;
            c.cx = 200;
            c.cy= 120;
            c.room = 1;
            vecChar.push(c);
            
            var t:xThing;
            t = new xThing();
            t.cx = 20;            t.cy = 60;
            t.cw = 20;            t.ch = 60;
            t.spec = 1;
            t.arg = 1;
            vecRoom[0].vecThing.push(t);
            
            t = new xThing();
            t.cx = 300;            t.cy = 60;
            t.cw = 20;            t.ch = 60;
            t.spec = 1;
            t.arg = 0;
            vecRoom[1].vecThing.push(t);
            
           

            stage.addEventListener(MouseEvent.MOUSE_DOWN, mdown);
            stage.addEventListener(MouseEvent.MOUSE_UP, mup);
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor
        
        public function mdown(e:MouseEvent):void {  bMdown = true; }
        public function mup(e:MouseEvent):void { bMdown = false;}
        
        public var bMdown:Boolean = false;
        
        public var vecChar:Vector.<xChar>;
        public var vecRoom:Vector.<xRoom>;
        
        public var curRoom:int = 0;
        
        public var gt:int = 0;
        
        public function onEnter(e:Event):void
        {
            graphics.clear();
            graphics.lineStyle(2,0);
            
            var mx:Number; var my:Number;
            var i:int; var num:int; var a:xChar; 
            var room:xRoom;
            room = vecRoom[curRoom];
            
            mx = stage.mouseX;
            my = stage.mouseY;
            
            num = vecChar.length;
            for (i =0; i < num; i++)
            {
              a = vecChar[i];
               if (a.room != curRoom) { continue; }
               if (a.id == 1) { a.cx += 3; if (a.cx >=320){a.cx=0;} }
               graphics.drawCircle(a.cx,a.cy,8);    
            }//nexti
            
            var t:xThing;
            var vec:Vector.<xThing>;
            vec = room.vecThing;
            num = vec.length;
            for (i = 0; i < num; i++)
            {
              t = vec[i];
              graphics.drawRect(t.cx,t.cy,t.cw,t.ch);  
              if (mx < t.cx) { continue; }
              if (my < t.cy) { continue; }
              if (mx > t.cx+t.cw) { continue; }
              if (my > t.cy+t.ch) { continue; }
              graphics.beginFill(0,0.5);
               graphics.drawRect(t.cx,t.cy,t.cw,t.ch);                
              graphics.endFill();
              if (bMdown == false) { continue; }
              if (t.spec == 1) { curRoom = t.arg; continue; }                
            }//nexti
            
            
            graphics.drawRect(16,16,320,240);
            gt+=1;
        }//onenter
        
    }//classend
}

internal class xChar
{
 public var id:int = 0;
 public var room:int = 0;
 public var cx:Number = 0;
 public var cy:Number = 0;
 public var vecThing:Vector.<xThing> = new Vector.<xThing>(0,false);
    
}//xchar

internal  class xThing
{
 public var id:int = 0;
 public var cx:Number = 0;
 public var cy:Number = 0;
 public var cw:Number = 32;
 public var ch:Number = 32;
 public var spec:int = 0;
 public var arg:int = 0;
 
}//xport

internal  class xRoom
{
  public var id:int = 0;
  public var back:int = 0;
  public var vecThing:Vector.<xThing> = new Vector.<xThing>(0,false);  
}//xroom