home *** CD-ROM | disk | FTP | other *** search
- class Game.Players.HumanPlayer extends Engine.PongPlayer
- {
- var mouseListener;
- var world;
- var __paddle;
- var __ball;
- var lastMouseY;
- var curMouseY;
- static var RELEASE_KEY = 32;
- static var DOWN_KEY = 40;
- static var UP_KEY = 38;
- var className = "HumanPlayer";
- var keyboardFactor = 0.75;
- var __keyboardUsed = false;
- function HumanPlayer(myWorld, myPaddle, myBall, myGoal, mySide)
- {
- super(myWorld,myPaddle,myBall,myGoal,mySide);
- var controller = this;
- this.mouseListener = {onMouseUp:function()
- {
- controller.releaseBall();
- }};
- Mouse.addListener(this.mouseListener);
- }
- function releaseBall()
- {
- if(this.world.engine.paused || !this.world.active)
- {
- return undefined;
- }
- this.__paddle.releaseBall();
- }
- function onUpdate(elapsed)
- {
- if(this.__paddle.sticky && Key.isDown(Game.Players.HumanPlayer.RELEASE_KEY))
- {
- this.releaseBall();
- }
- var _loc3_ = (Key.isDown(Game.Players.HumanPlayer.DOWN_KEY) - Key.isDown(Game.Players.HumanPlayer.UP_KEY)) * elapsed * this.__speed * this.keyboardFactor;
- if(_loc3_ != 0)
- {
- this.__paddle.moveByPlayer(_loc3_,this.__ball);
- this.__keyboardUsed = true;
- return undefined;
- }
- var _loc4_ = this.world.target._ymouse;
- this.lastMouseY = this.curMouseY;
- this.curMouseY = _loc4_;
- if(this.__keyboardUsed && this.lastMouseY == this.curMouseY)
- {
- return undefined;
- }
- this.__keyboardUsed = false;
- var _loc2_ = _loc4_ - this.__paddle.y;
- var _loc5_ = elapsed * this.__speed;
- if(_loc2_ < 0)
- {
- _loc2_ = Math.max(_loc2_,- _loc5_);
- }
- else if(_loc2_ > 0)
- {
- _loc2_ = Math.min(_loc2_,_loc5_);
- }
- if(_loc2_ != 0)
- {
- this.__paddle.moveByPlayer(_loc2_,this.__ball);
- }
- }
- }
-