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; }
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); }
public void launchBall() { if (_attachedToPaddle != null) { showTutorial = false; var newVelocity = new Vector2(10f, _attachedToPaddle.Velocity.Y * .75f); Velocity = newVelocity; _attachedToPaddle = null; } }
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}; }
public void AttachTo(Paddle paddle) { _attachedToPaddle = paddle; Velocity = Vector2.Zero; }