Ejemplo n.º 1
0
 public void AttachTo(Paddle paddle)
 {
     _attachedToPaddle = paddle;
         Location.X = _attachedToPaddle.Location.X + _attachedToPaddle.Width + 1f;
         Location.Y = _attachedToPaddle.Location.Y + ((_attachedToPaddle.Height / 2) - (Height / 2));
         Velocity = Vector2.Zero;
 }
Ejemplo n.º 2
0
            public override void Update(GameTime gameTime, GameObjects gameObjects)
            {

                if (_attachedToPaddle != null)
                {
                    Location.X = _attachedToPaddle.Location.X + _attachedToPaddle.Width + 1f;
                    Location.Y = _attachedToPaddle.Location.Y + ((_attachedToPaddle.Height/2) - (Height/2));
                    hitCount = 0; 
                    if (Keyboard.GetState().IsKeyDown(Keys.Space))
                    {
                        var newVelocity = new Vector2(10f, _attachedToPaddle.Velocity.Y * .75f);
                        Velocity = newVelocity;
                        _attachedToPaddle = null;
                    }
                }
                else if (boundingBox.Intersects(gameObjects.PlayerPaddle.boundingBox))
                    {

                        Velocity = new Vector2(-Velocity.X, ((gameObjects.PlayerPaddle.Velocity.Y *.75f) + Velocity.Y * .5f));
                    }

                else if( boundingBox.Intersects(gameObjects.ComputerPaddle.boundingBox))
                       {

                           Velocity = new Vector2(-Velocity.X - hitCount, ((gameObjects.ComputerPaddle.Velocity.Y * .75f) + Velocity.Y * .5f));
                           hitCount = hitCount + 0.1f; 
                    }
                base.Update(gameTime, gameObjects);
            }
Ejemplo n.º 3
0
 public void launchBall()
 {
     if (_attachedToPaddle != null)
         {
             showTutorial = false;
             var newVelocity = new Vector2(10f, _attachedToPaddle.Velocity.Y * .75f);
             Velocity = newVelocity;
             _attachedToPaddle = null;
         }
 }
Ejemplo n.º 4
0
        protected override void LoadContent() //Load all Game Contenet
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);
            gameBoundaries = new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height); 

            //Paddle creation
            var paddleTexture = Content.Load<Texture2D>("paddle");
            var personPaddleLocation = new Vector2(10f, gameBoundaries.Height / 2);
            var computerPaddleLocation = new Vector2(gameBoundaries.Width - paddleTexture.Width - 10, gameBoundaries.Height/2);
            playerPaddle = new Paddle(paddleTexture, personPaddleLocation, gameBoundaries, PlayerTypes.Human );
            computerPaddle = new Paddle(paddleTexture, computerPaddleLocation, gameBoundaries, PlayerTypes.Computer);
            //Ball creation
            _ball = new Ball(Content.Load<Texture2D>("Ball"), Vector2.Zero, gameBoundaries);
            _ball.AttachTo(playerPaddle);

           // Score Creation
           SpriteFont sF = Content.Load<SpriteFont>("font"); 
           _score = new Score(sF, gameBoundaries );

           //Aggregate reference to all game objects
            gameObjects = new GameObjects { PlayerPaddle = playerPaddle, ComputerPaddle = computerPaddle, Ball = _ball ,Score = _score}; 
            
        }
Ejemplo n.º 5
0
 public void AttachTo(Paddle paddle)
 {
     _attachedToPaddle = paddle;
     Velocity = Vector2.Zero; 
 }