Ejemplo n.º 1
0
        private void ShootRandomPowerup( SidePiece piece, float midLine )
        {
            BoundaryTubeObject tubeObject = objects.Find( o => o.Object == null );
              if ( tubeObject == null )
              {
            tubeObject = new BoundaryTubeObject();
            objects.Add( tubeObject );
              }
              else
              {
            tubeObject.Path.Clear();
            tubeObject.Time = 0f;
              }

              Vector2 startPos = new Vector2( piece.TubePosition.X, deathLine + Screen.Camera.Position.Y );
              Powerup powerup = Powerup.CreateRandomPowerup( startPos, lastGoldenShake >= goldenShakeSpacing );

              if ( powerup.Type == PowerupType.GoldenShake )
            lastGoldenShake = 0;
              else
            lastGoldenShake++;

              powerup.InTube = true;
              powerup.Update( lastFrame );
              Screen.ObjectTable.Add( powerup );
              tubeObject.Object = powerup;
              tubeObject.Body = powerup.Body;

              Vector2 tubePos = new Vector2( piece.TubePosition.X, piece.TubePosition.Y );
              float finalX = Math.Sign( tubePos.X ) == -1 ? Left + powerup.Size / 2 : Right - powerup.Size / 2;
              Vector2 finalPos = new Vector2( finalX, tubePos.Y );
              tubeObject.Path.Add( startPos );
              tubeObject.Path.Add( tubePos );
              tubeObject.Path.Add( finalPos );

              powerup.Oscillator.SetSource( finalPos.Y );
              powerup.Oscillator.SetDest( midLine );
              powerup.SizeSpring.SetSource( powerup.Size );
              powerup.SizeSpring.SetDest( 1f );
              powerup.SizeSpring.K = 200;
              powerup.SizeSpring.B = .15f * SpringInterpolater.GetCriticalDamping( 200 );
        }
Ejemplo n.º 2
0
        public Boundary( GameplayScreen screen, float left, float right, float rowStart, float rowSpacing )
            : base(screen)
        {
            Left  = left;
              Right = right;

              lastFrame = new GameTime( TimeSpan.FromSeconds( 0 ), TimeSpan.FromSeconds( 0 ),
                                TimeSpan.FromSeconds( 1f / 30f ), TimeSpan.FromSeconds( 1f / 60 ) );

              this.rowSpacing = rowSpacing;
              this.rowStart = rowStart;
              minHoleDist = ( FloorBlock.Height + Size ) / 2f;
              lastHole = rowStart;
              lastGoldenShake = 0;

              DrawOrder = 7;

              // this is for objects, such as powerups and players, so they can travel through the tubes
              objects = new List<BoundaryTubeObject>( 10 );
              for ( int i = 0; i < 10; ++i )
            objects.Add( new BoundaryTubeObject() );

              // left polygon
              polyLeft = new PhysPolygon( polyWidth, 100f, new Vector2( left - halfPolyWidth, 0f ), 1f );
              polyLeft.Elasticity = 1f;
              polyLeft.Friction = 1.5f;
              polyLeft.Flags = BodyFlags.Anchored;
              polyLeft.Parent = this;
              screen.PhysicsSpace.AddBody( polyLeft );

              // right polygon
              polyRight = new PhysPolygon( polyWidth, 100f, new Vector2( right + halfPolyWidth, 0f ), 1f );
              polyRight.Elasticity = 1f;
              polyRight.Friction = 1.5f;
              polyRight.Flags = BodyFlags.Anchored;
              polyRight.Parent = this;
              screen.PhysicsSpace.AddBody( polyRight );

              // model
              cageModel = Screen.Content.Load<InstancedModel>( "Models/cageTile" );
              cageHoleModel = Screen.Content.Load<InstancedModel>( "Models/cageHole" );
              teeModel = Screen.Content.Load<InstancedModel>( "Models/tubeTee" );
              cupModel = Screen.Content.Load<InstancedModel>( "Models/tubeCup" );

              Camera camera = screen.Camera;

              float dist = camera.Position.Z + Size / 2f;
              float tanFovyOverTwo = (float)Math.Tan( camera.Fov / 2f );
              deathLine = dist * tanFovyOverTwo + Size / 2f;

              topLine = camera.Position.Y + deathLine - Size;
              lastTopY = camera.Position.Y + deathLine;

              rows = (int)Math.Ceiling( 2f * deathLine / Size );
              nTransforms = rows * 2;

              rotateL = new Matrix( 0, 0,-1, 0,
                            0, 1, 0, 0,
                            1, 0, 0, 0,
                            0, 0, 0, 1 );
              rotateR = new Matrix( 0, 0, 1, 0,
                            0, 1, 0, 0,
                           -1, 0, 0, 0,
                            0, 0, 0, 1 );
              rotateZ = new Matrix( 0, 1, 0, 0,
                           -1, 0, 0, 0,
                            0, 0, 1, 0,
                            0, 0, 0, 1 );
              flip = new Matrix(-1, 0, 0, 0,
                         0,-1, 0, 0,
                         0, 0, 1, 0,
                         0, 0, 0, 1 );
              scale = Matrix.CreateScale( Size );

              sidePieces = new SidePiece[nTransforms];
              for ( int i = 0; i < nTransforms; ++i )
              {
            sidePieces[i] = new SidePiece();
            SidePiece piece = sidePieces[i];

            int row = i % rows;
            bool onLeftSide = i / rows == 0;
            piece.Hole = false;
            piece.CagePosition = new Vector3( onLeftSide ? Left : Right, topLine - row * Size, 0f );
            Matrix scaleRotate = scale * ( onLeftSide ? rotateL : rotateR );
            piece.CageTransform = scaleRotate * Matrix.CreateTranslation( piece.CagePosition );
            piece.TubePosition = piece.CagePosition + new Vector3( onLeftSide ? -Size / 2 : Size / 2, 0, 0 );
            piece.TubeTransform = scale * Matrix.CreateTranslation( piece.TubePosition );
            piece.Tube = TubePattern.Cup;
              }
        }
Ejemplo n.º 3
0
        private void ConfigurePiece( SidePiece piece, float height, bool leftSide )
        {
            float midLine;
              piece.CagePosition.Y = height;
              piece.CageTransform.M42 = height;
              piece.Hole = IsHoleHere( height, out midLine );
              piece.TubePosition.Y = height;

              if ( piece.Hole )
              {
            lastHole = height;
            piece.Tube = TubePattern.Tee;
            if ( leftSide )
              piece.TubeTransform = scale * Matrix.CreateTranslation( piece.TubePosition );
            else
              piece.TubeTransform = scale * flip * Matrix.CreateTranslation( piece.TubePosition );

            if ( !Screen.GameOver )
              ShootRandomPowerup( piece, midLine );
              }
              else
              {
            if ( rand.Next( 100 ) < 50 )
            {
              piece.Tube = TubePattern.Cup;
              piece.TubeTransform = scale * Matrix.CreateTranslation( piece.TubePosition );
            }
            else
            {
              piece.Tube = TubePattern.Tee;
              if ( leftSide )
            piece.TubeTransform = scale * flip * Matrix.CreateTranslation( piece.TubePosition );
              else
            piece.TubeTransform = scale * Matrix.CreateTranslation( piece.TubePosition );
            }
              }
        }