/// <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() { // TODO: Add your initialization logic here KeySet p1keyset = new KeySet(Keys.Z, Keys.S); p1 = new Player(graphics, new Vector2(10, 10), p1keyset); KeySet p2keyset = new KeySet(Keys.Up, Keys.Down); p2 = new Player(graphics, new Vector2(0, 0), null); p2.Position = new Vector2(graphics.PreferredBackBufferWidth - p2.Size.X - 10, 10); ball = new Ball(graphics); base.Initialize(); }
public Player(GraphicsDeviceManager graphics, Vector2 position, KeySet keySet) { this.Position = position; this.Score = 0; this.Speed = 200f; this.keySet = keySet; this._isCPU = (keySet == null); this._size = new Vector2(20, 80); this.texture = new Texture2D(graphics.GraphicsDevice, (int)_size.X, (int)_size.Y); Color[] data = new Color[(int)_size.X * (int)_size.Y]; for (int i = 0; i < data.Length; ++i) { data[i] = Color.White; } texture.SetData(data); }