topical media & game development

talk show tell print

lib-flex-animation-code-03-com-friendsofed-isometric-IsoWorld.ax

lib-flex-animation-code-03-com-friendsofed-isometric-IsoWorld.ax (swf ) [ flash ] flex


  package com.friendsofed.isometric
  {
          import flash.display.DisplayObject;
          import flash.display.Sprite;
          import flash.geom.Rectangle;
  
          public class @ax-lib-flex-animation-code-03-com-friendsofed-isometric-IsoWorld extends Sprite
          {
                  private var _floor:Sprite;
                  private var _objects:Array;
                  private var _world:Sprite;
                  
                  public function @ax-lib-flex-animation-code-03-com-friendsofed-isometric-IsoWorld()
                  {
                          _floor = new Sprite();
                          addChild(_floor);
                          
                          _world = new Sprite();
                          addChild(_world);
                          
                          _objects = new Array();
                  }
                  
                  public function addChildToWorld(child:IsoObject):void
                  {
                          _world.addChild(child);
                          _objects.push(child);
                          sort();
                  }
                  
                  public function addChildToFloor(child:IsoObject):void
                  {
                          _floor.addChild(child);
                  }
                  
                  public function sort():void
                  {
                          _objects.sortOn("depth", Array.NUMERIC);
                          for(var i:int = 0; i < _objects.length; i++)
                          {
                                  _world.setChildIndex(_objects[i], i);
                          }
                  }
                  
                  public function canMove(obj:IsoObject):Boolean
                  {
                          var rect:Rectangle = obj.rect;
                          rect.offset(obj.vx, obj.vz);
                          for(var i:int = 0; i < _objects.length; i++)
                          {
                                  var objB:IsoObject = _objects[i] as IsoObject;
                                  if(obj != objB && !objB.walkable && rect.intersects(objB.rect))
                                  {
                                          return false;
                                  }
                          }
                          return true;
                  }
          }
  }


(C) Æliens 18/6/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.