private void InitStage()
        {
            // add tube maze first
              tubeMaze = new TubeMaze( this, -5f, 2.3f );
              ObjectTable.Add( tubeMaze );

              // side boundaries
              float leftBoundX = -.5f * stageWidth;
              FirstRow = lastRowY;
              Boundary boundary = new Boundary( this, leftBoundX, -leftBoundX, FirstRow, rowSpacing );
              ObjectTable.Add( boundary );

              // starting shelves
              Shelves shelves = new Shelves( this );
              ObjectTable.Add( shelves );

              // players
              AddPlayers( shelves );
        }
Example #2
0
        public Shelves( GameplayScreen screen )
            : base(screen)
        {
            int nCages = nMaxPlayers * nCagesPerBox;
              cagePieces = new CagePiece[nCages];

              DrawOrder = 4;

              for ( int i = 0; i < nCages; ++i )
            cagePieces[i] = new CagePiece();

              hingeTransforms = new Matrix[4];

              angleSpring = new SpringInterpolater( 1, 50, SpringInterpolater.GetCriticalDamping( 50 ) );

              cageModel = screen.Content.Load<InstancedModel>( "Models/cage" );
              hingeModel = screen.Content.Load<InstancedModel>( "Models/cageHinge" );

              // determine transforms for each piece
              boundary = screen.ObjectTable.GetObjects<Boundary>()[0];
              if ( boundary == null )
            throw new InvalidOperationException( "boundary must be initialized before shelf" );
              float totalLength = boundary.Right - boundary.Left - size - 2f * offsetFromWall;
              spacing = totalLength / 3f;

              Camera camera = Screen.Camera;

              float tanFovOver2 = (float)Math.Tan( camera.Fov / 2f );
              float depth = camera.Position.Z + size / 2f;
              float height = depth * tanFovOver2;
              topLine = height - size / 2f;

              depth = camera.Position.Z - size / 2f;
              height = depth * tanFovOver2;
              deathLine = Screen.Camera.Position.Y - height;

              // cage bottoms stored in first four indices
              for ( int i = 0; i < nMaxPlayers; ++i )
              {
            Vector3 pos = new Vector3( boundary.Left + offsetFromWall + i * spacing, topLine - size / 2f, 0f );
            cagePieces[i].Translation = Matrix.CreateTranslation( pos );
            cagePieces[i].Rotation = bottomStart;
            cagePieces[i].Transform = scale * bottomStart * cagePieces[i].Translation;
            cagePieces[i].Body = new PhysPolygon( size, .014f * size, new Vector2( pos.X + size / 2f, pos.Y ), 1f );
            cagePieces[i].Body.Friction = 1.75f;
            cagePieces[i].Body.SetPivotPoint( new Vector2( -size / 2, 0f ) );
            cagePieces[i].Body.Flags = BodyFlags.Anchored;
            cagePieces[i].Body.Parent = this;
            Screen.PhysicsSpace.AddBody( cagePieces[i].Body );

            hingeTransforms[i] = Matrix.CreateScale( size ) *
                             Matrix.CreateTranslation( new Vector3( cagePieces[i].Body.Position, 0 ) );
              }

              // all other cage pieces won't change
              for ( int i = nMaxPlayers; i < nCages; ++i )
              {
            int box = ( i - nMaxPlayers ) / 2;
            int side = i % 2;

            float x = boundary.Left + offsetFromWall + box * spacing + side * size;
            Vector3 pos = new Vector3( x, topLine, 0f );
            Matrix translation = Matrix.CreateTranslation( pos );
            Matrix rotation = side == 0 ? rotateL : rotateR;
            cagePieces[i].Translation = translation;
            cagePieces[i].Rotation = rotation;
            cagePieces[i].Transform = scale * rotation * translation;
            cagePieces[i].Body = new PhysPolygon( .014f, size, new Vector2( pos.X, pos.Y ), 1f );
            cagePieces[i].Body.Flags = BodyFlags.Anchored;
            cagePieces[i].Body.Parent = this;
            Screen.PhysicsSpace.AddBody( cagePieces[i].Body );
              }
        }