Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function smoothRotateClockwise():void {
- setRotate( 1);
- }
- public function smoothRotateCounterclockwise():void {
- setRotate( -1);
- }
- private function setRotate(direction:Number):void {
- rotationDirection = forcedRotationDirection = direction;
- forcedRotate = true;
- Scenario.substate = Scenario.SUBSTATE_ROTPAUSE;
- for each (var mino:Mino in members)
- mino.visible = false;
- }
- override public function update():void {
- if (rotationDirection)
- rotateSmoothly();
- super.update();
- }
- public function rotateSmoothly():void {
- justRotated = false;
- var curRot:Number = rotation;
- rotationDirection = forcedRotate ? forcedRotationDirection : -forcedRotationDirection;
- var dR:Number = rotationDirection * FlxG.elapsed * 2 * Math.PI / rotationPeriod;
- rotation += dR;
- var section:Number = rotation * 2 / Math.PI;
- var curSection:Number = curRot * 2 / Math.PI;
- if (Math.floor(section) != Math.floor(curSection)) {
- var hit:Mino;
- if (rotationDirection == 1)
- hit = rotateCounterclockwise()
- else
- hit = rotateClockwise();
- if (hit) {
- rotation = curRot; //bump! revert to last rotation
- } else {
- //rotation = section * Math.PI / 2;
- rotation = 0; //redundant with piecewise rotation otherwise
- if (!forcedRotate) {
- rotationDirection = NaN; //lock in
- justRotated = true;
- Scenario.substate = Scenario.SUBSTATE_NORMAL;
- for each (var mino:Mino in members)
- mino.visible = true;
- }
- }
- }
- forcedRotate = false; //require continuous presses to keep rotating!
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement