Example #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            var gameBoundaries         = new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height);
            var paddleTexture          = Content.Load <Texture2D>("Paddle");
            var computerPaddleLocation = new Vector2(Window.ClientBounds.Width + 148 - (paddleTexture.Width / 2), 0);

            playerPaddle   = new Paddle(paddleTexture, Vector2.Zero, gameBoundaries, PlayerTypes.Human);
            computerPaddle = new Paddle(paddleTexture, computerPaddleLocation, gameBoundaries, PlayerTypes.Computer);
            ball           = new Ball(Content.Load <Texture2D>("Ball"), Vector2.Zero, gameBoundaries);
            ball.AttachTo(playerPaddle);

            score = new PongClone.Score(Content.Load <SpriteFont>("GameFont"), gameBoundaries);

            gameObjects = new GameObjects {
                PlayerPaddle = playerPaddle, ComputerPaddle = computerPaddle, Ball = ball, Score = score
            };

            // TODO: use this.Content to load your game content here
        }
Example #2
0
        public override void Update(GameTime gameTime, GameObjects gameObjects)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Space) && attachedToPaddle != null)
            {
                var newVelocity = new Vector2(4.0f, attachedToPaddle.Velocity.Y * .65f);
                Velocity         = newVelocity;
                attachedToPaddle = null;
            }
            if (attachedToPaddle != null)
            {
                Location.X = attachedToPaddle.Location.X + attachedToPaddle.Width;
                Location.Y = attachedToPaddle.Location.Y;
            }
            else
            {
                if (BoundingBox.Intersects(gameObjects.PlayerPaddle.BoundingBox) || BoundingBox.Intersects(gameObjects.ComputerPaddle.BoundingBox))
                {
                    Velocity = new Vector2(-Velocity.X, Velocity.Y);
                }
            }

            base.Update(gameTime, gameObjects);
        }
Example #3
0
        public virtual void Update(GameTime gameTime, GameObjects gameObjects)
        {
            Location += Velocity;

            CheckBounds();
        }