Пример #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);

            // Ask graphics device about screen bounds we are using. 
            var screenBounds = GraphicsDevice.Viewport.Bounds;
            // Load paddle texture using Content.Load static method 
            Texture2D paddleTexture = Content.Load<Texture2D>("paddle");  // loading texutres for paddle
            PaddleBottom = new Paddle(paddleTexture);  //applying
            PaddleTop = new Paddle(paddleTexture);      //applying
            PaddleBottom.Position.Y = 848;   //Y value 900 - paddle height = 52
            PaddleBottom.Position.X = 250;        // middle of x range
            PaddleTop.Position = new Vector2(250, 40);
            Texture2D ballTexture = Content.Load<Texture2D>("ball");
            Balla = new Ball(ballTexture);
            Balla.Position = screenBounds.Center.ToVector2();
            Texture2D backgroundTexture = Content.Load<Texture2D>("background");
            Backgrounda = new Background(backgroundTexture, screenBounds.Width, screenBounds.Height);
            HitSound = Content.Load<SoundEffect>("hit");
            Music = Content.Load<Song>("music");
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(Music);
            SpritesForDrawList.Add(Backgrounda);

            SpritesForDrawList.Add(PaddleTop);
            SpritesForDrawList.Add(PaddleBottom);
            SpritesForDrawList.Add(Balla);

        }
Пример #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()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            var gameboundaries = new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height);
            var paddleTexture = Content.Load<Texture2D>("Paddle");

            _spriteBatch = new SpriteBatch(GraphicsDevice);
            _playerPaddle = new Paddle(Content.Load<Texture2D>("Paddle"), Vector2.Zero, gameboundaries, PlayerTypes.Human);

            var computerPaddleLocation = new Vector2(Window.ClientBounds.Width - paddleTexture.Width, 0);
            _computerPaddle = new Paddle(Content.Load<Texture2D>("Paddle"), computerPaddleLocation , gameboundaries, PlayerTypes.Computer);
            _ball = new Ball(Content.Load<Texture2D>("Ball"), Vector2.Zero, gameboundaries);
            _ball.AttachTo(_playerPaddle);
            Score = new Score(Content.Load<SpriteFont>("NewSpriteFont"),gameboundaries);

            GameObjects = new GamesObjects { PlayerPaddle = _playerPaddle, Computeraddle = _computerPaddle, Ball = _ball, Score = Score};
            // TODO: use this.Content to load your game content here
        }
Пример #3
0
            public static bool Overlaps(Ball balll, Paddle pad)
            {
                if (balll.Position.X < pad.Position.X + pad.Size.Width &&
                    balll.Position.X + balll.Size.Width > pad.Position.X &&
                    balll.Position.Y < pad.Position.Y + pad.Size.Height &&
                    balll.Size.Height + balll.Position.Y > pad.Position.Y)
                    return true;



                return false;
            }