コード例 #1
0
ファイル: Ball.cs プロジェクト: AdrianMH/PongMono
        public override void Update(GameTime gameTime,GameObjects gameObjects)
        {
            if((Keyboard.GetState().IsKeyDown(Keys.Space) || gameObjects.TouchInput.Tapped) && attachedToPaddle!=null)
            {
                var newVelocity = new Vector2(BALL_SPEED, 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);
        }
コード例 #2
0
ファイル: Ball.cs プロジェクト: AdrianMH/PongMono
 public void AttachTo(Paddle paddle)
 {
     attachedToPaddle = paddle;
 }
コード例 #3
0
ファイル: Game1.cs プロジェクト: AdrianMH/PongMono
        /// <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");

            playerPaddle = new Paddle(paddleTexture, Vector2.Zero, gameBoundaries,PlayerTypes.Human);
            computerPaddle = new Paddle(paddleTexture,Vector2.Zero ,gameBoundaries,PlayerTypes.Computer);

            var computerPaddleLocation = new Vector2(gameBoundaries.Width - paddleTexture.Width, 0);
            computerPaddle = new Paddle(paddleTexture, computerPaddleLocation, gameBoundaries,PlayerTypes.Computer);

            ball=new Ball(Content.Load<Texture2D>("Ball"), Vector2.Zero, gameBoundaries);
            ball.AttachTo(playerPaddle);

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

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