dynamic class Rubynoid.Ball extends MovieClip { var _state:Function = null; var _game:Rubynoid.Game = null; var _paddle:MovieClip = null; var _deltaX:Number = 0; // Pixels per frame var _deltaY:Number = 0; var _halfwidth:Number = 0; function Ball( ) { _state = this.none; _halfwidth = _width / 2; } function setState( statename ) { if ( typeof(this[statename]) == "function" ) { _state = this[statename]; } _paddle = _game.getPaddle(); } function runFrame( clicked ) { return _state( clicked ); } function bounce( horiz, vert ) { if ( horiz ) { _deltaX = -_deltaX; }; if ( vert ) { _deltaY = -_deltaY; }; } function bounceonpaddle() { switch( _state ) { case none: case onPaddle: return null; default: _deltaY = (_deltaY < 0) ? _deltaY : (- _deltaY); _deltaY = (_deltaY > -2) ? -2 : _deltaY; if (_game._xdelta < 0) { _deltaX = (_game._xdelta < -15) ? -15 : _game._xdelta; } else { _deltaX = (_game._xdelta > 15) ? 15 : _game._xdelta; } _deltaY -= Math.abs(_deltaX)/4; _deltaX = (_deltaX + this._x - _paddle._x - (_paddle._width / 2)) / 4; return "otherbounce"; } } function onPaddle( clicked ) { _x = _paddle._x + (_paddle._width/2); _y = _paddle._y - (_width/2); _deltaX = 0; _deltaY = -2; if (clicked) { this._state = this["normal"]; } } function none( clicked ) { } function normal( clicked ) { sound = null; _x += _deltaX; _y += _deltaY; if ((_x > (_game._rightedge - _halfwidth)) && (_deltaX > 0)) { _deltaX = -_deltaX; _x = (_game._rightedge - _halfwidth); sound="otherbounce";}; if ((_x < (_game._leftedge + _halfwidth)) && (_deltaX < 0)) { _deltaX = -_deltaX; _x = (_game._leftedge + _halfwidth); sound="otherbounce";}; if ((_y < (_game._topedge + _halfwidth)) && (_deltaY < 0)) { _deltaY = -_deltaY; _y = (_game._topedge + _halfwidth); sound="otherbounce";}; return sound; } }