Пример #1
0
 public newGameMulti(Game game, Paddle _computer_paddle, Paddle _player_paddle, Song _bgm, SoundEffect _p1, SoundEffect _p2, SoundEffect _ballhit, Ball _ball, GraphicsDeviceManager _graphics, SpriteBatch _spriteBatch, Texture2D _bgi)
     : base(game)
 {
     computer_paddle = _computer_paddle;
     player_paddle = _player_paddle;
     //sourceRectpleft = _sourceRectpleft;
     //sourceRectpright = _sourceRectpright;
     bgm = _bgm;
     p1 = _p1;
     p2 = _p2;
     ballhit = _ballhit;
     ball = _ball;
     graphics = _graphics;
     spriteBatch = _spriteBatch;
     bgi = _bgi;
 }
Пример #2
0
        public void Move(Ball ball)
        {
            //  Paddles can only move in the Y direction, and cannot leave the screen
            //  If paddle moves to screen edge, invert velocity

            //  check top and bottom boundaries
            if ((position.Y + size.Y + velocity.Y > screenSize.Y) || (position.Y + velocity.Y < 0))
            {
                velocity *= -1;
            }

            // now see if need to change direction to keep paddle Y near ball Y
            // This simple test accomplishes our computer player "AI"
            else if ((position.Y > ball.position.Y) && (velocity.Y > 0) ||
                    (position.Y < ball.position.Y) && (velocity.Y < 0))
            {
                velocity *= -1;
            }
        }
Пример #3
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);
            Services.AddService(typeof(SpriteBatch), spriteBatch);

            //Load the SoundEffect resources
            // Load the SoundEffect resource
            p1 = Content.Load<SoundEffect>("p1m");
            p2 = Content.Load<SoundEffect>("p2m");
            bgm = Content.Load<Song>("bgm");
            ballhit = Content.Load<SoundEffect>("ball");
            win1Scr=Content.Load<Texture2D>("p1win");
            bgi = Content.Load<Texture2D>("bg-Recovered");
            MediaPlayer.IsRepeating = true;

            menuBack = Content.Load<Texture2D>("title");

            menuTxt = Content.Load<Texture2D>("menu1");
            menu = new MenuScreen(this, menuBack, menuTxt);

            Components.Add(menu);
            menu.Show();

            winScrPl = new Win1Screen(this, win1Scr, spriteBatch);
            Font1 = Content.Load<SpriteFont>("Courier New");
            sourceRectpleft = new Rectangle(0, 0, 48, 124);
            sourceRectpright = new Rectangle(0, 0, 48, 124);
            sourceRectBall = new Rectangle(0, 0, 40, 40);
            computer_paddle = new Paddle(Content.Load<Texture2D>("p1"), new Vector2(20,384), new Vector2(42, 124),
                graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            player_paddle = new Paddle(Content.Load<Texture2D>("p2"), new Vector2(950,384), new Vector2(42, 124),
                graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            ball = new Ball(Content.Load<Texture2D>("ballsprite"), new Vector2(384, 284), new Vector2(40, 40),
                graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            newGameSingle1 = new newGameSingle(this, computer_paddle, player_paddle, bgm, p1, p2, ballhit, ball, graphics, spriteBatch, bgi);
            newGameMulti1 = new newGameMulti(this, computer_paddle, player_paddle, bgm, p1, p2, ballhit, ball, graphics, spriteBatch, bgi);
            //  set the speed the objects will move

            // the ball always starts in the middle and moves toward the player
            ball.Reset();
            computer_paddle.velocity = new Vector2(0, 2);
        }
Пример #4
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);

            //Load the SoundEffect resources
            // Load the SoundEffect resource
            ballhit = Content.Load<SoundEffect>("ballhit");
            killshothit = Content.Load<SoundEffect>("killshot");
            paddlemiss = Content.Load<SoundEffect>("miss");

            Font1 = Content.Load<SpriteFont>("Courier New");

            computer_paddle = new Paddle(Content.Load<Texture2D>("left_paddle"), new Vector2(20f, 268f), new Vector2(24f, 64f),
                graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            player_paddle = new Paddle(Content.Load<Texture2D>("right_paddle"), new Vector2(756f, 268f), new Vector2(24f, 64f),
                graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            ball = new Ball(Content.Load<Texture2D>("small_ball"), new Vector2(384f, 284f), new Vector2(32f, 32f),
                graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);

            //  set the speed the objects will move
            // the ball always starts in the middle and moves toward the player
            ball.Reset();
            computer_paddle.velocity = new Vector2(0, 2);
        }