/// <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() { PlayerInputControlBindings player1Bindings = new PlayerInputControlBindings(); player1Bindings.ActionKeyBindings[InputAction.AltitudeDecrease] = Keys.Right; player1Bindings.ActionKeyBindings[InputAction.AltitudeIncrease] = Keys.Left; player1Bindings.ActionKeyBindings[InputAction.SpeedDecrease] = Keys.Down; player1Bindings.ActionKeyBindings[InputAction.SpeedIncrease] = Keys.Up; player1Bindings.ActionKeyBindings[InputAction.Fire] = Keys.Space; PlayerInputControlBindings player2Bindings = new PlayerInputControlBindings(); player2Bindings.ActionKeyBindings[InputAction.AltitudeDecrease] = Keys.D; player2Bindings.ActionKeyBindings[InputAction.AltitudeIncrease] = Keys.A; player2Bindings.ActionKeyBindings[InputAction.SpeedDecrease] = Keys.S; player2Bindings.ActionKeyBindings[InputAction.SpeedIncrease] = Keys.W; player2Bindings.ActionKeyBindings[InputAction.Fire] = Keys.LeftShift; player1 = new PlayerComponent(this, player1Bindings, @"Sprites\p1"); player1.Killed += new KilledEventHandler((sender) => { player1.Initialize(); Components.Add(player1); }); player2 = new PlayerComponent(this, player2Bindings, @"Sprites\p2"); player2.Killed += new KilledEventHandler((sender) => { player2.Initialize(); Components.Add(player2); }); Components.Add(player1); Components.Add(player2); center = new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2); base.Initialize(); }
public PlayerComponent(Game game, PlayerInputControlBindings bindings, string imagePath) : base(game) { controlBindings = bindings; this.imagePath = imagePath; }