Example #1
0
        public override void Update(GameTime gameTime, GameObjects gameObjects)
        {
            if (playerTypes == PlayerTypes.COMPUTER)
            {
                //// super AI
                //// this all makes sense if you take everything from the zero zero top left corner
                //if (gameObjects.Ball.location.Y + gameObjects.Ball.Height < location.Y)
                //{
                //    Velocity = new Vector2(0, -speedCom);
                //}

                //if (gameObjects.Ball.location.Y > location.Y + Height)
                //{
                //    Velocity = new Vector2(0, speedCom);
                //}

                // NOT SO super AI
                // this all makes sense if you take everything from the zero zero top left corner
                Random rt = new Random();
                double rtime = rt.Next(30, 140);

                if (gameObjects.Ball.location.Y + gameObjects.Ball.Height < location.Y + rtime)

                {
                    Velocity = new Vector2(0, -speedCom);
                }

                if (gameObjects.Ball.location.Y > location.Y + Height  + rtime)
                {
                    Velocity = new Vector2(0, speedCom);
                }
            }

            if (playerTypes == PlayerTypes.Human)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Left))
                {
                    Velocity = new Vector2(0, -speedHu);

                }// from the input lib of Xna

                if (Keyboard.GetState().IsKeyDown(Keys.Right))
                {
                    Velocity = new Vector2(0, speedHu);

                }// from the input lib of Xna
            }

            base.Update(gameTime, gameObjects);
        }
Example #2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // have to save png files to 24bit and have copy if fewer enabled
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            // need to make better images for the textures

            var gameBoundaries = new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height);
            var textureOfPaddles = Content.Load<Texture2D>("paddle");
            paddle = new Paddle(textureOfPaddles, Vector2.Zero, gameBoundaries, PlayerTypes.Human);
            ball = new Ball(Content.Load<Texture2D>("Ball"), Vector2.Zero, gameBoundaries);
            ball.AttachTo(paddle);
            var p2Local = new Vector2(gameBoundaries.Width - textureOfPaddles.Width, 0);
            paddle2 = new Paddle(textureOfPaddles, p2Local, gameBoundaries, PlayerTypes.COMPUTER);
            // TODO: use this.Content to load your game content here

            gameObjects = new GameObjects { PlayerPaddle = paddle, ComputerPaddle = paddle2, Ball = ball };
        }
Example #3
0
        public virtual void Update(GameTime gameTime, GameObjects gameObjects)
        {
            location += Velocity;

            CheckBounds();
        }