Example #1
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            this.sphere = (Sphere)this.Game.Services.GetService(typeof(Sphere));
            this.State = PaddleState.PLAYING;
        }
Example #2
0
        public void SetUp()
        {
            this.isTakingInput = false;

            if (this.paddleManager != null)
            {
                this.Remove(paddleManager);
                this.paddleManager.Dispose();
            }

            if (this.submitPanel != null)
            {
                this.Remove(this.submitPanel);
                this.submitPanel.Dispose();
            }

            if (this.score != null)
            {
                this.Remove(this.score);
                this.score.Dispose();
            }

            if (this.sphere != null)
            {
                this.Remove(this.sphere);
                this.sphere.Dispose();
            }

            this.paddleManager = null;

            this.sphere = new Sphere(this.Game
                , sphereModel
                , sphereScale
                , hitSound
                , width
                , height
                , depth
            );

            this.sphere.Initialize();

            if(this.sideManager != null)
                this.sphere.CalculateCollisionNormal += this.sideManager.CollisionNormal;

            this.Game.Services.RemoveService(typeof(Sphere));
            this.Game.Services.AddService(typeof(Sphere), this.sphere);

            this.Add(sphere);

            if (this.GetGameType() == Paddle.Type.KINECT)
            {
                KinectPaddleManager kinectManager = new KinectPaddleManager(
                    this.Game
                    , paddleTexture
                    , paddleActiveTexture
                    , new Vector3(
                        this.width/2 - this.paddleWidth/2
                        , this.height/2 - this.paddleWidth/2
                        , 0f
                    )
                    , Vector3.Backward
                    , Vector3.Up
                    , paddleWidth
                    , paddleWidth
                    , paddleWidth
                    , paddleSound
                    , 2.5f
                    , width
                    , height
                );

                kinectManager.OnActive += this.PushSphere;
                this.sphere.OnBallPassesDepth += kinectManager.PutOnStandBy;
                this.sphere.OnBallPassesZero += kinectManager.PutOnStandBy;

                this.paddleManager = kinectManager;
            }
            else
            {
                this.paddleManager = new PaddleManager(this.Game);
                Paddle paddle = PaddleManager.CreatePaddle(
                    this.Game
                    , this.GetGameType()
                    , paddleTexture
                    , paddleActiveTexture
                    , paddleSound
                    , width
                    , height
                );

                paddle.OnActive += this.PushSphere;
                this.sphere.OnBallPassesDepth += paddle.PutOnStandBy;
                this.sphere.OnBallPassesZero += paddle.PutOnStandBy;

                this.paddleManager.AddPaddle(paddle);
            }

            ComputerPaddle computerPaddle = new ComputerPaddle(this.Game
                , paddleTexture
                , paddleActiveTexture
                , new Vector3(
                    this.width / 2 - this.paddleWidth / 2
                    , this.height / 2 - this.paddleWidth / 2
                    , -this.depth
                )
                , Vector3.Backward
                , Vector3.Up
                , paddleWidth
                , paddleWidth
                , paddleWidth
                , paddleSound
                , 3
                , width
                , height
            );

            this.sphere.OnBallPassesDepth += computerPaddle.IncreaseSpeed;

            this.paddleManager.AddPaddle(computerPaddle);

            this.Add(paddleManager);
            this.paddleManager.Initialize();

            this.score = new Score(this.Game, this.font);
            this.Add(this.score);
            this.score.Initialize();

            this.sphere.OnOneNonIdleTick += this.score.IncreaseScoreForStayingAlive;
            this.sphere.OnBallPassesZero += this.score.DecreaseLife;
            this.sphere.OnBallPassesDepth += this.score.LevelUp;

            this.score.OnNoMoreLives += this.LockGameAndShowSubmittingPanel;
        }
Example #3
0
        /// <summary>
        /// Handles the effect on the sphere
        /// </summary>
        /// <param name="elapsedTime">The elapsedTime that has to be used to calculate the effect.</param>
        /// <param name="sphere">The sphere on which collisions should be detected.</param>
        private void SetSphereImpactEffects(float elapsedTime, Sphere sphere)
        {
            float deltaX = this.oldPosition.X - this.Position.X;
            float deltaY = this.oldPosition.Y - this.Position.Y;
            deltaX = -deltaX;

            sphere.Curving = Vector3.Left * deltaX + Vector3.Up * deltaY;
            sphere.Curving *= 750 * elapsedTime;
            sphere.RotationYdelta = MathHelper.Pi / 20 * Math.Sign(deltaX);
            sphere.RotationXdelta = MathHelper.Pi / 20 * Math.Sign(deltaY);
        }
Example #4
0
 private bool IsMovingAway(Sphere sphere)
 {
     return sphere.Direction.Z < 0 && this.GetType() == typeof(ComputerPaddle)
         || sphere.Direction.Z > 0 && this.GetType() != typeof(ComputerPaddle);
 }
Example #5
0
        /// <summary>
        /// Handles the collision between the paddle and the sphere.
        /// </summary>
        public void HandleCollision(float elapsedTime, Sphere sphere)
        {
            if (this.paddlestate == PaddleState.PLAYING)
            {
                if (this.Bounds.Intersects(sphere.Bounds))
                {
                    // Removes sticky ball phenomenon
                    // by only allowing to bounce in the opposite direction
                    if (this.IsMovingAway(sphere))
                    {
                        sound.Play();

                        sphere.Direction = Vector3.Reflect(sphere.Direction, this.Normal);

                        this.SetSphereImpactEffects(
                            elapsedTime
                            , sphere
                        );
                    }
                }
            }

            this.oldPosition = this.Position;
        }
Example #6
0
 /// <summary>
 /// Checks for collision with it's paddles
 /// </summary>
 /// <param name="bounds">The bounds that should be checked for collision.</param>
 /// <returns>The normal of the colliding plane.</returns>
 public void HandleCollisions(float elapsedTime, Sphere sphere)
 {
     foreach (Paddle paddle in this.paddles)
         paddle.HandleCollision(elapsedTime, sphere);
 }