Beispiel #1
0
 /// <summary>
 /// Allows the game to perform any initialization it needs to before starting to run.
 /// This is where it can query for any required services and load any non-graphic
 /// related content.  Calling base.Initialize will enumerate through any components
 /// and initialize them as well.
 /// </summary>
 protected override void Initialize()
 {
     playerPaddle = new Paddle(Content, "paddle1", new Vector2(0,0),true);
     computerPaddle = new Paddle(Content, "paddle1", new Vector2((GraphicsDevice.Viewport.Width - TEXTUREWIDTH), 0),false);
     ball = new Ball(Content, "ball", new Vector2((GraphicsDevice.Viewport.Width / 2),(GraphicsDevice.Viewport.Height / 2)));
     base.Initialize();
 }
Beispiel #2
0
        public void Update(GameTime gametime, Ball ball)
        {
            keyState = Keyboard.GetState();

            if (isPlayer)
            {
                if (keyState.IsKeyDown(Keys.Down) && (position.Y <= 600 - texture.Height))
                {
                    position.Y += speed;
                }
                if (keyState.IsKeyDown(Keys.Up) && position.Y > 0)
                {
                    position.Y -= speed;
                }
            }
            else
            {
                if (ball.Position.Y >= position.Y)
                {
                    position.Y += speed;
                }
                if (ball.Position.Y <= position.Y)
                {
                    position.Y -= speed;
                }
            }

            rect = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);
        }
Beispiel #3
0
 private bool Collision(Paddle paddle, Ball ball)
 {
     if (paddle.Rect.Intersects(ball.Rect))
         return true;
     return false;
 }