Advertisement
Uhfgood

process command queue

Nov 8th, 2015
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 2.20 KB | None | 0 0
  1. public function IsCommandSetFinished() : Bool
  2. {
  3.     var allDone : Bool = true; // assuming all commands are done
  4.    
  5.     for ( command in this.commandSet )
  6.     {
  7.         for ( enemy in this.enemyGroup )
  8.         {
  9.             if ( command.eid == enemy.ID )
  10.             {
  11.                 if ( enemy.commandDone )
  12.                     enemy.commandDone = false;
  13.                 else
  14.                 {
  15.                     allDone = false;
  16.                     break;
  17.                 }
  18.             }
  19.         }
  20.         if ( !allDone )
  21.             break;
  22.     }
  23.    
  24.     return( allDone );
  25. }
  26.  
  27. public function ExecuteDropCommand( enemy : Enemy, command : GameGrid.Command )
  28. {
  29.     // the drop command will only drop one space
  30.     var targetX =
  31.         ( command.x * this.charWidth ) +
  32.             this.dropbox.x + enemy.offset.x;
  33.     var targetY =
  34.         ( ( command.y + 1 ) * this.charHeight ) +
  35.             this.dropbox.y;
  36.    
  37.     enemy.boxTween = FlxTween.tween
  38.     (
  39.         enemy,
  40.         {
  41.             x : targetX,
  42.             y : targetY
  43.         },
  44.         .20,
  45.         {
  46.             complete :
  47.                 function tweenDone( tween : FlxTween )
  48.                 {
  49.                     enemy.boxTween = null;
  50.                     enemy.commandDone = true;
  51.                 },
  52.                
  53.             ease : FlxEase.elasticInOut
  54.         }
  55.     );
  56.    
  57. }
  58.  
  59. public function ProcessCommands()
  60. {
  61.     // make sure the command set is empty first
  62.     // otherwise it will just pull off nothing and
  63.     // only the first command is executed
  64.     if( this.commandSet.length <= 0 )
  65.         this.commandSet = this.gameGrid.PullCommandSet();
  66.  
  67.     // we want to exit early so check it again
  68.     if ( this.commandSet.length <= 0 )
  69.         return;
  70.        
  71.     for ( enemy in this.enemyGroup )
  72.     {
  73.         // boxTween should only be the dropping animations
  74.         if ( enemy.boxTween == null )
  75.         {
  76.             var i : Int = 0;
  77.             while( i < this.commandSet.length )
  78.             {
  79.                 // Do we have a command and the correct enemy id?
  80.                 var command = this.commandSet[ i ];
  81.                 if ( command != null && enemy.ID == command.eid )
  82.                 {
  83.                     if ( command.name == "drop" )
  84.                         ExecuteDropCommand( enemy, command );
  85.                     else
  86.                     if ( command.name == "kill" )
  87.                     {
  88.                         enemy.hypnoMode = DYING;
  89.                         enemy.commandDone = true;
  90.                     }
  91.                    
  92.                 }  // end if command
  93.                
  94.                 i++;
  95.                
  96.             }  // end while commands
  97.            
  98.             if( IsCommandSetFinished() )
  99.                 this.commandSet.splice( 0, this.commandSet.length );  // empty it
  100.            
  101.         }  // end if not tweening
  102.        
  103.     }  // end enemy loop
  104.    
  105. }  // end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement