Example #1
0
 private void InitializeGrid()
 {
     // fill tube grid
       tubes[0, 0] = TubePiece.GetRandomPiece( rand );
       for ( int c = 1; c < cols; ++c )
       {
     bool rightOpen = tubes[0, c - 1].RightOpen();
     if ( c % 2 == 0 )
       tubes[0, c] = TubePiece.GetRandomPieceLeft( rand, rightOpen );
     else if ( rightOpen )
       tubes[0, c] = new TubePiece( TubePattern.Cup, 1 );
       }
       for ( int r = 1; r < rows; ++r )
       {
     bool bottomOpen = tubes[r - 1, 0].BottomOpen();
     if ( r % 2 == 0 )
       tubes[r, 0] = TubePiece.GetRandomPieceTop( rand, bottomOpen );
     else if ( bottomOpen )
       tubes[r, 0] = new TubePiece( TubePattern.Cup, 0 );
       }
       for ( int r = 1; r < rows; ++r )
       {
     if ( r % 2 == 0 )
     {
       for ( int c = 1; c < cols; ++c )
       {
     bool rightOpen = tubes[r, c - 1].RightOpen();
     bool bottomOpen = tubes[r - 1, c].BottomOpen();
     if ( c % 2 == 0 )
       tubes[r, c] = TubePiece.GetRandomPieceLeftTop( rand, rightOpen, bottomOpen );
     else if ( rightOpen )
       tubes[r, c] = new TubePiece( TubePattern.Cup, 1 );
       }
     }
     else
     {
       for ( int c = 1; c < cols; ++c )
       {
     if ( ( c % 2 == 0 ) && tubes[r - 1, c].BottomOpen() )
       tubes[r, c] = new TubePiece( TubePattern.Cup, 0 );
       }
     }
       }
 }
Example #2
0
        public override void Update( GameTime gameTime )
        {
            int nColors = colors.Length;
              float timePerColor = 4f;
              float time = Screen.AccumulatedTime;
              float fakeTime = time / timePerColor;

              int a = (int)( fakeTime ) % nColors;
              int b = ( a + 1 ) % nColors;
              float t = .5f + -(float)Math.Cos( (float)Math.PI * fakeTime ) / 2f;
              if ( (int)fakeTime % 2 == 1 )
            t = 1f - t;

              // set color for tubes
              Vector4 color = colors[a] + t * ( colors[b] - colors[a] );
              foreach ( InstancedModel model in tubeModels )
              {
            ReadOnlyCollection<InstancedModelPart> parts = model.ModelParts;
            int nParts = parts.Count;
            for ( int i = 0; i < nParts; ++i )
            {
              InstancedModelPart part = parts[i];
              part.EffectParameterColor.SetValue( color );
              part.EffectParameterSpecularPower.SetValue( 200 );
            }
              }

              while ( topLeft.Y > Screen.Camera.Position.Y + DeathLine )
              {
            int lowestRow = highestRow;
            int secondLowestRow = ( highestRow + rows - 1 ) % rows;
            highestRow = ( highestRow + 1 ) % rows;
            topLeft.Y -= TubeSize;

            // recreate row to fit with its new predecessor
            if ( !cupRow )
            {
              tubes[lowestRow, 0] = TubePiece.GetRandomPieceTop( rand, tubes[secondLowestRow, 0].BottomOpen() );
              for ( int c = 1; c < cols; ++c )
              {
            bool rightOpen = tubes[lowestRow, c - 1].RightOpen();
            bool bottomOpen = tubes[secondLowestRow, c].BottomOpen();
            if ( c % 2 == 0 )
              tubes[lowestRow, c] = TubePiece.GetRandomPieceLeftTop( rand, rightOpen, bottomOpen );
            else if ( tubes[lowestRow, c - 1].RightOpen() )
              tubes[lowestRow, c] = new TubePiece( TubePattern.Cup, 1 );
            else
              tubes[lowestRow, c].Alive = false;
              }
            }
            else
            {
              for ( int c = 0; c < cols; ++c )
              {
            if ( c % 2 == 0 )
            {
              if ( tubes[secondLowestRow, c].BottomOpen() )
                tubes[lowestRow, c] = new TubePiece( TubePattern.Cup, 0 );
              else
                tubes[lowestRow, c].Alive = false;
            }
            else
            {
              tubes[lowestRow, c].Alive = false;
            }
              }
            }

            cupRow = !cupRow;
              }
        }