Exemple #1
0
 private void Form1_Load(object sender, EventArgs e)
 {
     ball        = new Ball(this.Width / 2, this.Height / 2, 32, 32);
     paddle1     = new Paddle(this.Height / 4, 10, OFFSET_FROM_WALL, this.Height / 2);
     paddle2     = new Paddle(this.Height / 4, 10, this.Width - 40, this.Height / 2);
     topSide     = new Rectangle(0, 0, this.Width, WALL_THICKNESS);
     bottomSide  = new Rectangle(0, this.Height - BOTTOM_SIDE_OFFSET, this.Width, WALL_THICKNESS);
     leftSide    = new Rectangle(0, 0, WALL_THICKNESS, this.Height);
     rightSide   = new Rectangle(this.Width - 20, 0, WALL_THICKNESS, this.Height);
     scoreKeeper = new ScoreKeeper();
 }
Exemple #2
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()
        {
            _scoreKeeper = new ScoreKeeper(this);

            _arena = new Arena(this);

            _paddles    = new Paddle[2];
            _paddles[0] = new Paddle(this, new Vector2(20, Window.ClientBounds.Height / 2), Player.One);
            _paddles[1] = new Paddle(this, new Vector2(Window.ClientBounds.Width - 40, Window.ClientBounds.Height / 2), Player.Two);

            _ball = new Ball(this);

            base.Initialize();
        }
Exemple #3
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);
            stopwatch    = new Stopwatch();
            stopwatch.Start();

            var PaddleTexture = Content.Load <Texture2D>("Paddle");
            var BallTexture   = Content.Load <Texture2D>("Ball");
            var defaultFont   = Content.Load <SpriteFont>("Fonts/Default");
            // TODO: use this.Content to load your game content here
            int fontWidth = defaultFont.Texture.Width;

            ScoreKeeper = new ScoreKeeper(new Vector2((ScreenSize.Width / 2) - (fontWidth / 4), 10), defaultFont, Color.Black);
            int offsetX = 5;

            player1 = new Paddle
                      (
                new Vector2(GraphicsDevice.Viewport.X + offsetX, GraphicsDevice.Viewport.Y),
                PaddleTexture,
                Color.White,
                2
                      );
            player2 = new Paddle
                      (
                new Vector2(GraphicsDevice.Viewport.Width - PaddleTexture.Width - offsetX, GraphicsDevice.Viewport.Height - PaddleTexture.Height),
                PaddleTexture,
                Color.White,
                2
                      );

            ball = new Ball(
                new Vector2(ScreenSize.Width / 2, ScreenSize.Height / 2),
                BallTexture,
                Color.White,
                new Vector2(2, 2));
        }