home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / midnightstrike1.swf / scripts / __Packages / com / neodelight / v2D / RectSprite.as < prev    next >
Encoding:
Text File  |  2007-04-02  |  14.4 KB  |  351 lines

  1. class com.neodelight.v2D.RectSprite extends com.neodelight.v2D.Sprite
  2. {
  3.    var collisionStyle;
  4.    var wall;
  5.    var ground;
  6.    var cargo;
  7.    var tv;
  8.    var id;
  9.    var v;
  10.    var colPos;
  11.    var carryable;
  12.    var boundingRect;
  13.    var ghost;
  14.    var pos;
  15.    var size;
  16.    var colGhosts;
  17.    var tpos;
  18.    var strong;
  19.    var crusher;
  20.    var fixed;
  21.    var colType;
  22.    var colPartner;
  23.    var flex;
  24.    var colNewVy;
  25.    var colNewVx;
  26.    var colNewPartnerVx;
  27.    var colNewPartnerVy;
  28.    var carrier;
  29.    var collisionCheck70 = com.neodelight.v2D.RectObject.prototype.collisionCheck70;
  30.    var collisionCheck71 = com.neodelight.v2D.RectObject.prototype.collisionCheck71;
  31.    function RectSprite(mc, f, weight, flags, collisionPartners)
  32.    {
  33.       super(mc,f,undefined,flags,collisionPartners,undefined);
  34.       this.collisionStyle = 2;
  35.       this.updateTotalBoundingRect();
  36.    }
  37.    function move()
  38.    {
  39.       this.wall = undefined;
  40.       var _loc5_ = this.ground;
  41.       this.ground = undefined;
  42.       super.move();
  43.       for(var _loc4_ in this.cargo)
  44.       {
  45.          this.cargo[_loc4_].tryPush(new com.neodelight.std.Vector3D(this.tv.x,Math.max(0,this.tv.y),0));
  46.       }
  47.       if(this.ground != _loc5_)
  48.       {
  49.          delete _loc5_.cargo[this.id];
  50.       }
  51.       if(this.ground)
  52.       {
  53.          var _loc6_ = this.tryPush(new com.neodelight.std.Vector3D(this.v.x * _global.dt * (1 - this.colPos),0));
  54.          if(this.ground.carrier && this.carryable)
  55.          {
  56.             this.ground.cargo[this.id] = this;
  57.          }
  58.       }
  59.       if(this.wall)
  60.       {
  61.          _loc6_ = this.tryPush(new com.neodelight.std.Vector3D(0,this.v.y * _global.dt * (1 - this.colPos)));
  62.          if(_loc6_ < 1 && this.v.y < 0)
  63.          {
  64.             this.v.y = 0;
  65.          }
  66.       }
  67.    }
  68.    function tryPush(v)
  69.    {
  70.       var _loc5_ = this.ground;
  71.       var _loc6_ = super.tryPush(v);
  72.       for(var _loc4_ in this.cargo)
  73.       {
  74.          this.cargo[_loc4_].tryPush(new com.neodelight.std.Vector3D(v.x,Math.max(0,v.y),0));
  75.       }
  76.       if(this.ground != _loc5_)
  77.       {
  78.          delete _loc5_.cargo[this.id];
  79.       }
  80.       return _loc6_;
  81.    }
  82.    function collisionCheck2(partner)
  83.    {
  84.       if(this.boundingRect.p0.x <= partner.pos.x + partner.size.x && this.boundingRect.p1.x >= partner.pos.x && this.boundingRect.p0.y <= partner.pos.y + partner.size.y && this.boundingRect.p1.y >= partner.pos.y)
  85.       {
  86.          if(this.ghost || partner.ghost)
  87.          {
  88.             if(this.pos.x <= partner.pos.x + partner.size.x && this.pos.x + this.size.x >= partner.pos.x && this.pos.y <= partner.pos.y + partner.size.y && this.pos.y + this.size.y >= partner.pos.y)
  89.             {
  90.                this.colGhosts.push({pos:scale,obj:partner});
  91.             }
  92.             return undefined;
  93.          }
  94.          if(this.v.x > 0)
  95.          {
  96.             if(Math.round((this.pos.x + this.size.x) * 1000) / 1000 <= Math.round(partner.pos.x * 1000) / 1000 && Math.round((this.tpos.x + this.size.x) * 1000) / 1000 >= Math.round(partner.pos.x * 1000) / 1000)
  97.             {
  98.                var scale = (partner.pos.x - (this.pos.x + this.size.x)) / (this.tpos.x - this.pos.x);
  99.                if(scale <= this.colPos)
  100.                {
  101.                   var _loc3_ = Math.round((this.pos.y + scale * (this.tpos.y - this.pos.y) - partner.pos.y) * 1000) / 1000;
  102.                   if(_loc3_ < Math.round(partner.size.y * 1000) / 1000 && _loc3_ > Math.round(-1 * this.size.y * 1000) / 1000)
  103.                   {
  104.                      var _loc5_ = false;
  105.                      if(this.strong && !partner.fixed && !partner.ghost)
  106.                      {
  107.                         var _loc6_ = this.tpos.x + this.size.x - partner.pos.x;
  108.                         if(partner.tryPush(new com.neodelight.std.Vector3D(_loc6_,0,0)) < 1)
  109.                         {
  110.                            if(this.crusher)
  111.                            {
  112.                               partner.damage(1);
  113.                            }
  114.                            scale = (partner.pos.x - (this.pos.x + this.size.x)) / (this.tpos.x - this.pos.x);
  115.                            _loc5_ = true;
  116.                         }
  117.                      }
  118.                      if(!partner.ghost && !this.ghost && (!this.fixed || _loc5_))
  119.                      {
  120.                         this.colType = 40;
  121.                         this.colPartner = partner;
  122.                         this.colPos = scale;
  123.                         if(this.flex > 0)
  124.                         {
  125.                            this.colNewVy = this.v.y * this.flex;
  126.                            this.colNewVx = Math.abs(this.v.x) * -1 * this.flex;
  127.                         }
  128.                         else
  129.                         {
  130.                            this.colNewVx = 0;
  131.                            this.colNewVy = undefined;
  132.                         }
  133.                         this.colNewPartnerVx = undefined;
  134.                         this.colNewPartnerVy = undefined;
  135.                         this.wall = partner;
  136.                      }
  137.                      else
  138.                      {
  139.                         this.colGhosts.push({pos:scale,obj:partner});
  140.                      }
  141.                   }
  142.                }
  143.             }
  144.          }
  145.          else if(this.v.x < 0)
  146.          {
  147.             if(Math.round(this.pos.x * 1000) / 1000 >= Math.round((partner.pos.x + partner.size.x) * 1000) / 1000 && Math.round(this.tpos.x * 1000) / 1000 < Math.round((partner.pos.x + partner.size.x) * 1000) / 1000)
  148.             {
  149.                var scale = (partner.pos.x + partner.size.x - this.pos.x) / (this.tpos.x - this.pos.x);
  150.                if(scale < this.colPos)
  151.                {
  152.                   _loc3_ = Math.round((this.pos.y + scale * (this.tpos.y - this.pos.y) - partner.pos.y) * 1000) / 1000;
  153.                   if(_loc3_ < Math.round(partner.size.y * 1000) / 1000 && _loc3_ > Math.round(-1 * this.size.y * 1000) / 1000)
  154.                   {
  155.                      _loc5_ = false;
  156.                      if(this.strong && !partner.fixed && !partner.ghost)
  157.                      {
  158.                         _loc6_ = this.tpos.x - (partner.pos.x + partner.size.x);
  159.                         if(partner.tryPush(new com.neodelight.std.Vector3D(_loc6_,0,0)) < 1)
  160.                         {
  161.                            if(this.crusher)
  162.                            {
  163.                               partner.damage(1);
  164.                            }
  165.                            scale = (partner.pos.x + partner.size.x - this.pos.x) / (this.tpos.x - this.pos.x);
  166.                            _loc5_ = true;
  167.                         }
  168.                      }
  169.                      if(!partner.ghost && !this.ghost && (!this.fixed || _loc5_))
  170.                      {
  171.                         this.colType = 41;
  172.                         this.colPartner = partner;
  173.                         this.colPos = scale;
  174.                         if(this.flex > 0)
  175.                         {
  176.                            this.colNewVy = this.v.y * this.flex;
  177.                            this.colNewVx = Math.abs(this.v.x) * this.flex;
  178.                         }
  179.                         else
  180.                         {
  181.                            this.colNewVx = 0;
  182.                            this.colNewVy = undefined;
  183.                         }
  184.                         this.colNewPartnerVx = undefined;
  185.                         this.colNewPartnerVy = undefined;
  186.                         this.wall = partner;
  187.                      }
  188.                      else
  189.                      {
  190.                         this.colGhosts.push({pos:scale,obj:partner});
  191.                      }
  192.                   }
  193.                }
  194.             }
  195.          }
  196.          if(this.v.y > 0)
  197.          {
  198.             if(Math.round((this.pos.y + this.size.y) * 1000) / 1000 <= Math.round(partner.pos.y * 1000) / 1000 && Math.round((this.tpos.y + this.size.y) * 1000) / 1000 >= Math.round(partner.pos.y * 1000) / 1000)
  199.             {
  200.                var scale = (partner.pos.y - (this.pos.y + this.size.y)) / (this.tpos.y - this.pos.y);
  201.                if(scale <= this.colPos)
  202.                {
  203.                   var _loc4_ = Math.round((this.pos.x + scale * (this.tpos.x - this.pos.x) - partner.pos.x) * 1000) / 1000;
  204.                   if(_loc4_ < Math.round(partner.size.x * 1000) / 1000 && _loc4_ > Math.round(-1 * this.size.x * 1000) / 1000)
  205.                   {
  206.                      _loc5_ = false;
  207.                      if(this.strong && !partner.fixed && !partner.ghost)
  208.                      {
  209.                         _loc6_ = this.tpos.y + this.size.y - partner.pos.y;
  210.                         if(partner.tryPush(new com.neodelight.std.Vector3D(0,_loc6_,0)) < 1)
  211.                         {
  212.                            if(this.crusher)
  213.                            {
  214.                               partner.damage(1);
  215.                            }
  216.                            scale = (partner.pos.y - (this.pos.y + this.size.y)) / (this.tpos.y - this.pos.y);
  217.                            _loc5_ = true;
  218.                         }
  219.                      }
  220.                      if(!partner.ghost && !this.ghost && (!this.fixed || _loc5_))
  221.                      {
  222.                         this.colType = 30;
  223.                         this.colPartner = partner;
  224.                         this.colPos = scale;
  225.                         if(this.flex > 0)
  226.                         {
  227.                            this.colNewVy = Math.abs(this.v.y) * -1 * this.flex;
  228.                            this.colNewVx = this.v.x * this.flex;
  229.                         }
  230.                         else
  231.                         {
  232.                            this.colNewVx = undefined;
  233.                            this.colNewVy = 0;
  234.                         }
  235.                         this.colNewPartnerVx = undefined;
  236.                         this.colNewPartnerVy = undefined;
  237.                         this.ground = partner;
  238.                      }
  239.                      else
  240.                      {
  241.                         this.colGhosts.push({pos:scale,obj:partner});
  242.                      }
  243.                   }
  244.                }
  245.             }
  246.          }
  247.          else if(this.v.y < 0)
  248.          {
  249.             if(Math.round(this.pos.y * 1000) / 1000 >= Math.round((partner.pos.y + partner.size.y) * 1000) / 1000 && Math.round(this.tpos.y * 1000) / 1000 < Math.round((partner.pos.y + partner.size.y) * 1000) / 1000)
  250.             {
  251.                var scale = (partner.pos.y + partner.size.y - this.pos.y) / (this.tpos.y - this.pos.y);
  252.                if(scale < this.colPos)
  253.                {
  254.                   _loc4_ = Math.round((this.pos.x + scale * (this.tpos.x - this.pos.x) - partner.pos.x) * 1000) / 1000;
  255.                   if(_loc4_ < Math.round(partner.size.x * 1000) / 1000 && _loc4_ > Math.round(-1 * this.size.x * 1000) / 1000)
  256.                   {
  257.                      _loc5_ = false;
  258.                      if(this.strong && !partner.fixed && !partner.ghost)
  259.                      {
  260.                         if(this.carrier && partner.carryable)
  261.                         {
  262.                            delete partner.ground.cargo[partner.id];
  263.                            partner.ground = this;
  264.                            this.cargo[partner.id] = partner;
  265.                         }
  266.                         _loc6_ = this.tpos.y - partner.size.y - partner.pos.y;
  267.                         if(partner.tryPush(new com.neodelight.std.Vector3D(0,_loc6_,0)) < 1)
  268.                         {
  269.                            if(this.crusher)
  270.                            {
  271.                               partner.damage(1);
  272.                            }
  273.                            scale = (partner.pos.y + partner.size.y - this.pos.y) / (this.tpos.y - this.pos.y);
  274.                            _loc5_ = true;
  275.                         }
  276.                      }
  277.                      if(!partner.ghost && !this.ghost && (!this.fixed || _loc5_))
  278.                      {
  279.                         this.colType = 2;
  280.                         this.colPartner = partner;
  281.                         this.colPos = scale;
  282.                         if(this.flex > 0)
  283.                         {
  284.                            this.colNewVy = Math.abs(this.v.y) * this.flex;
  285.                            this.colNewVx = this.v.x * this.flex;
  286.                         }
  287.                         else
  288.                         {
  289.                            this.colNewVx = undefined;
  290.                            this.colNewVy = 0;
  291.                         }
  292.                         this.colNewPartnerVx = undefined;
  293.                         this.colNewPartnerVy = undefined;
  294.                      }
  295.                      else
  296.                      {
  297.                         this.colGhosts.push({pos:scale,obj:partner});
  298.                      }
  299.                   }
  300.                }
  301.             }
  302.          }
  303.       }
  304.    }
  305.    function collisionCheck30(partner)
  306.    {
  307.       if(this.v.y <= 0)
  308.       {
  309.          return undefined;
  310.       }
  311.       if(Math.round((this.pos.y + this.size.y) * 1000) / 1000 <= Math.round(partner.pos.y * 1000) / 1000 && Math.round((this.tpos.y + this.size.y) * 1000) / 1000 > Math.round(partner.pos.y * 1000) / 1000)
  312.       {
  313.          var _loc3_ = (partner.pos.y - (this.pos.y + this.size.y)) / (this.tpos.y - this.pos.y);
  314.          if(_loc3_ <= this.colPos)
  315.          {
  316.             var _loc4_ = this.pos.x + _loc3_ * (this.tpos.x - this.pos.x) - partner.pos.x;
  317.             if(_loc4_ <= partner.size.x && _loc4_ >= -1 * this.size.x)
  318.             {
  319.                this.colPos = _loc3_;
  320.                this.colType = partner.collisionStyle;
  321.                this.colPartner = partner;
  322.                if(this.flex > 0)
  323.                {
  324.                   this.colNewVy = Math.abs(this.v.y) * -1 * this.flex;
  325.                   this.colNewVx = this.v.x * this.flex;
  326.                }
  327.                else
  328.                {
  329.                   this.colNewVx = undefined;
  330.                   this.colNewVy = 0;
  331.                }
  332.                this.colNewPartnerVx = undefined;
  333.                this.colNewPartnerVy = undefined;
  334.                this.ground = partner;
  335.             }
  336.          }
  337.       }
  338.    }
  339.    function collisionCheck5(partner)
  340.    {
  341.    }
  342.    function getBoundingRect()
  343.    {
  344.       this.boundingRect.p0.x = Math.min(this.pos.x,this.tpos.x);
  345.       this.boundingRect.p0.y = Math.min(this.pos.y,this.tpos.y);
  346.       this.boundingRect.p1.x = Math.max(this.pos.x,this.tpos.x) + this.size.x;
  347.       this.boundingRect.p1.y = Math.max(this.pos.y,this.tpos.y) + this.size.y;
  348.       return this.boundingRect;
  349.    }
  350. }
  351.