Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.         public function smoothRotateClockwise():void {
  3.             setRotate( 1);
  4.         }
  5.        
  6.         public function smoothRotateCounterclockwise():void {
  7.             setRotate( -1);
  8.         }
  9.        
  10.         private function setRotate(direction:Number):void {
  11.             rotationDirection = forcedRotationDirection = direction;
  12.             forcedRotate = true;
  13.             Scenario.substate = Scenario.SUBSTATE_ROTPAUSE;
  14.             for each (var mino:Mino in members)
  15.                 mino.visible = false;
  16.         }
  17.        
  18.         override public function update():void {
  19.             if (rotationDirection)
  20.                 rotateSmoothly();
  21.             super.update();
  22.         }
  23.        
  24.         public function rotateSmoothly():void {
  25.             justRotated = false;
  26.            
  27.             var curRot:Number = rotation;
  28.             rotationDirection = forcedRotate ? forcedRotationDirection : -forcedRotationDirection;
  29.             var dR:Number = rotationDirection * FlxG.elapsed * 2 * Math.PI / rotationPeriod;
  30.             rotation += dR;
  31.            
  32.             var section:Number = rotation * 2 / Math.PI;
  33.             var curSection:Number = curRot * 2 / Math.PI;
  34.            
  35.             if (Math.floor(section) != Math.floor(curSection)) {
  36.                 var hit:Mino;
  37.                 if (rotationDirection == 1)
  38.                     hit = rotateCounterclockwise()
  39.                 else
  40.                     hit = rotateClockwise();
  41.                
  42.                 if (hit) {
  43.                     rotation = curRot; //bump! revert to last rotation
  44.                 } else {
  45.                     //rotation = section * Math.PI / 2;
  46.                     rotation = 0; //redundant with piecewise rotation otherwise
  47.                     if (!forcedRotate) {
  48.                         rotationDirection = NaN;  //lock in
  49.                         justRotated = true;
  50.                         Scenario.substate = Scenario.SUBSTATE_NORMAL;
  51.                         for each (var mino:Mino in members)
  52.                             mino.visible = true;
  53.                     }
  54.                 }
  55.             }
  56.            
  57.             forcedRotate = false; //require continuous presses to keep rotating!
  58.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement