home *** CD-ROM | disk | FTP | other *** search
/ Champak 108 / jogo-disk-108.iso / Games / Rabbit_Rivalry.swf / scripts / __Packages / disney / rabbitRivalry / GameCamera.as < prev    next >
Encoding:
Text File  |  2010-05-15  |  4.6 KB  |  171 lines

  1. class disney.rabbitRivalry.GameCamera extends smashing.keithm.BaseCamera
  2. {
  3.    var __groundY;
  4.    var __state;
  5.    var __moveRate;
  6.    var __delay;
  7.    var isZooming;
  8.    var __zoomHeadedOut;
  9.    var x;
  10.    var y;
  11.    var z;
  12.    var __zoomTimer;
  13.    var xdiff;
  14.    var ydiff;
  15.    var updateChangeX;
  16.    var updateChangeY;
  17.    var __ZOOM_RATE = 0.03;
  18.    var __ZOOMOUT_POINT = {x:1340,y:850,z:-3500};
  19.    var __MOVE_RATE = 400;
  20.    var __MOVE_DECAY = 100;
  21.    var __Y_OFFSET = 100;
  22.    function GameCamera(t_data)
  23.    {
  24.       super(t_data);
  25.       this.__groundY = t_data.ground;
  26.       this.__state = disney.rabbitRivalry.GameState.getInstance();
  27.       this.__moveRate = this.__MOVE_RATE;
  28.       this.setBounds(0,3550,0,this.__groundY + 60);
  29.       this.__delay = 0;
  30.       this.isZooming = false;
  31.       this.__zoomHeadedOut = true;
  32.    }
  33.    function setDelay(num)
  34.    {
  35.       this.__delay = num;
  36.    }
  37.    function zoomOut()
  38.    {
  39.       this.isZooming = this.__zoomHeadedOut = true;
  40.       this.x -= (this.x - this.__ZOOMOUT_POINT.x) / 2;
  41.       this.y -= (this.y - this.__ZOOMOUT_POINT.y) / 2;
  42.       this.z = this.__ZOOMOUT_POINT.z / 2;
  43.       this.enforceBounds();
  44.       this.__zoomTimer = this.__ZOOM_RATE;
  45.    }
  46.    function zoomIn(player)
  47.    {
  48.       this.x -= (this.x - player.x) / 2;
  49.       this.y -= (this.y - player.y) / 2;
  50.       this.z = this.__ZOOMOUT_POINT.z / 2;
  51.       this.enforceBounds();
  52.       this.__zoomTimer = this.__ZOOM_RATE;
  53.       this.__zoomHeadedOut = false;
  54.    }
  55.    function endZoomOut()
  56.    {
  57.       this.x = this.__ZOOMOUT_POINT.x;
  58.       this.y = this.__ZOOMOUT_POINT.y;
  59.       this.z = this.__ZOOMOUT_POINT.z;
  60.       this.enforceBounds();
  61.    }
  62.    function endZoomIn(player)
  63.    {
  64.       this.x = player.nextX;
  65.       this.y = player.y;
  66.       this.z = 0;
  67.       this.enforceBounds();
  68.       this.isZooming = false;
  69.    }
  70.    function update(dt, player)
  71.    {
  72.       if(this.isZooming)
  73.       {
  74.          if(this.__zoomHeadedOut)
  75.          {
  76.             if(this.__zoomTimer > 0)
  77.             {
  78.                this.__zoomTimer -= dt;
  79.                if(this.__zoomTimer <= 0)
  80.                {
  81.                   this.endZoomOut();
  82.                }
  83.             }
  84.          }
  85.          else
  86.          {
  87.             this.__zoomTimer -= dt;
  88.             if(this.__zoomTimer <= 0)
  89.             {
  90.                this.endZoomIn(player);
  91.             }
  92.          }
  93.       }
  94.       else
  95.       {
  96.          if(this.__delay > 0)
  97.          {
  98.             this.__delay -= dt;
  99.             if(this.__delay > 0)
  100.             {
  101.                return undefined;
  102.             }
  103.             this.__moveRate = this.__MOVE_RATE * 3;
  104.          }
  105.          if(this.__moveRate > this.__MOVE_RATE)
  106.          {
  107.             this.__moveRate -= this.__MOVE_DECAY * dt;
  108.             if(this.__moveRate < this.__MOVE_RATE)
  109.             {
  110.                this.__moveRate = this.__MOVE_RATE;
  111.             }
  112.          }
  113.          if(player.isAttacking || player.isCharging)
  114.          {
  115.             this.xdiff = player.nextX + 150 - this.x;
  116.             this.ydiff = player.nextY - this.y - this.__Y_OFFSET;
  117.          }
  118.          else if(this.__state.actionState <= 3)
  119.          {
  120.             this.xdiff = player.nextX - this.x + 60;
  121.             this.ydiff = player.nextY - this.y - this.__Y_OFFSET + 25;
  122.          }
  123.          else
  124.          {
  125.             this.xdiff = player.nextX - this.x;
  126.             this.ydiff = player.nextY - this.y - this.__Y_OFFSET;
  127.          }
  128.          dt *= 2;
  129.          this.updateChangeX = this.updateChangeY = this.__moveRate * dt;
  130.          if(this.xdiff < - this.updateChangeX)
  131.          {
  132.             this.x -= this.updateChangeX;
  133.          }
  134.          else if(this.xdiff > this.updateChangeX)
  135.          {
  136.             this.x += this.updateChangeX;
  137.          }
  138.          else if(player.isAttacking || player.isCharging)
  139.          {
  140.             this.x = player.nextX + 150;
  141.          }
  142.          else if(this.__state.actionState <= 3)
  143.          {
  144.             this.x = player.nextX + 60;
  145.          }
  146.          else
  147.          {
  148.             this.x = player.nextX;
  149.          }
  150.          if(this.ydiff < - this.updateChangeY)
  151.          {
  152.             this.y -= this.updateChangeY;
  153.          }
  154.          else if(this.ydiff > this.updateChangeY)
  155.          {
  156.             this.y += this.updateChangeY;
  157.          }
  158.          else if(this.__state.actionState <= 3)
  159.          {
  160.             this.y = player.nextY - this.__Y_OFFSET + 25;
  161.          }
  162.          else
  163.          {
  164.             this.y = player.nextY - this.__Y_OFFSET;
  165.          }
  166.       }
  167.       this.enforceBounds();
  168.       this.refreshEdges();
  169.    }
  170. }
  171.