home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Classicos / smashout.swf / scripts / __Packages / Game / Players / HumanPlayer.as < prev   
Encoding:
Text File  |  2005-11-09  |  1.9 KB  |  70 lines

  1. class Game.Players.HumanPlayer extends Engine.PongPlayer
  2. {
  3.    var mouseListener;
  4.    var world;
  5.    var __paddle;
  6.    var __ball;
  7.    var lastMouseY;
  8.    var curMouseY;
  9.    static var RELEASE_KEY = 32;
  10.    static var DOWN_KEY = 40;
  11.    static var UP_KEY = 38;
  12.    var className = "HumanPlayer";
  13.    var keyboardFactor = 0.75;
  14.    var __keyboardUsed = false;
  15.    function HumanPlayer(myWorld, myPaddle, myBall, myGoal, mySide)
  16.    {
  17.       super(myWorld,myPaddle,myBall,myGoal,mySide);
  18.       var controller = this;
  19.       this.mouseListener = {onMouseUp:function()
  20.       {
  21.          controller.releaseBall();
  22.       }};
  23.       Mouse.addListener(this.mouseListener);
  24.    }
  25.    function releaseBall()
  26.    {
  27.       if(this.world.engine.paused || !this.world.active)
  28.       {
  29.          return undefined;
  30.       }
  31.       this.__paddle.releaseBall();
  32.    }
  33.    function onUpdate(elapsed)
  34.    {
  35.       if(this.__paddle.sticky && Key.isDown(Game.Players.HumanPlayer.RELEASE_KEY))
  36.       {
  37.          this.releaseBall();
  38.       }
  39.       var _loc3_ = (Key.isDown(Game.Players.HumanPlayer.DOWN_KEY) - Key.isDown(Game.Players.HumanPlayer.UP_KEY)) * elapsed * this.__speed * this.keyboardFactor;
  40.       if(_loc3_ != 0)
  41.       {
  42.          this.__paddle.moveByPlayer(_loc3_,this.__ball);
  43.          this.__keyboardUsed = true;
  44.          return undefined;
  45.       }
  46.       var _loc4_ = this.world.target._ymouse;
  47.       this.lastMouseY = this.curMouseY;
  48.       this.curMouseY = _loc4_;
  49.       if(this.__keyboardUsed && this.lastMouseY == this.curMouseY)
  50.       {
  51.          return undefined;
  52.       }
  53.       this.__keyboardUsed = false;
  54.       var _loc2_ = _loc4_ - this.__paddle.y;
  55.       var _loc5_ = elapsed * this.__speed;
  56.       if(_loc2_ < 0)
  57.       {
  58.          _loc2_ = Math.max(_loc2_,- _loc5_);
  59.       }
  60.       else if(_loc2_ > 0)
  61.       {
  62.          _loc2_ = Math.min(_loc2_,_loc5_);
  63.       }
  64.       if(_loc2_ != 0)
  65.       {
  66.          this.__paddle.moveByPlayer(_loc2_,this.__ball);
  67.       }
  68.    }
  69. }
  70.