//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- /// /// Controller code for the game, includes GameController and MenuController /// namespace DWControllerDemo { #region Using Statements using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; using DarkWynter.Engine.Controllers; using DW.Globals; #endregion /// /// Game Controller for getting player inputs in-game /// public class GameController : Controller { #region CTORs /// /// Constructor for PC and mouse controls /// /// Player index for this controller public GameController(int playerNumber): base(playerNumber) { Init(); } /// /// Constructor for Xbox only controls /// public GameController(PlayerIndex playerIndex) : base(playerIndex) { Init(); } /// /// Constructor for Xbox and keyboard controls /// /// Player index in ObjectLibrary /// Player index for this controller public GameController(int player, PlayerIndex playerIndex) : base(player, playerIndex) { Init(); } #endregion // NOTES: // We need different controller constructors for differentiating xbox vs. pc vs. xboxpc controller types // We only want two key setups most of the time tho, so we defer to Init which switches pc and xbox configs concisely based on type. private void Init() { if (playerControllerType == ControllerType.PC_ONLY || playerControllerType == ControllerType.PC_AND_XBOX) { Add(new KeyboardControl(Keys.Back, SwitchGameMode, 200)); Add(new KeyboardControl(Keys.Escape, Escape, 0)); Add(new KeyboardControl(Keys.M, SwitchGameMode, 100)); Add(new KeyboardControl(Keys.W, MoveForward, 10)); Add(new KeyboardControl(Keys.A, MoveLeft, 10)); Add(new KeyboardControl(Keys.D, ChangeColorNeg, 10)); Add(new KeyboardControl(Keys.S, MoveBackward, 10)); Add(new KeyboardControl(Keys.Down, ChangeColorNeg, 100)); Add(new KeyboardControl(Keys.Up, ChangeColorPos, 100)); Add(new MouseControl(ControlType.LeftButton, ChangeColorPos, 100)); Add(new MouseControl(ControlType.LeftButton, ChangeColorNeg, 100, 0)); Add(new MouseControl(ControlType.Motion, Motion, 0)); } if (playerControllerType == ControllerType.XBOX_ONLY || playerControllerType == ControllerType.PC_AND_XBOX) { // Add xbox control bindings here !!! Add(new XboxDigitalControl(Buttons.Back, Escape, 100)); } } // NOTES: // the args list coming into each Input Delegate contain a "value" and a List "args". // "value" is always the EventArg type (booleventarg=true/false; floateventarg=0-1) // "args" can be used to pass data from PhoenixGame to the Input Delegates. // // EG- PhoenixGame could pass player into controller.Update(new object[]{player}) // Then our Input Delegate can access sumthing like: (args.args[0] as Player).paddle.MoveUp(args.value); // BTB: Apologies for the double "args" thing.. makes it easy to trace though.. Better ideas??? contact me.. flatline.darkwynter.com #region Input Delegates private void Escape(ControllerBoolEventArgs args) { Statics._self.Exit(); } private void SwitchGameMode(ControllerBoolEventArgs args) { } private void MoveForward(ControllerBoolEventArgs args) { Console.Write("test"); } private void Motion(ControllerVec2EventArgs args) { } private void MoveBackward(ControllerBoolEventArgs args) { } private void MoveLeft(ControllerBoolEventArgs args) { } private void MoveRight(ControllerBoolEventArgs args) { } private void ChangeColorPos(ControllerBoolEventArgs args) { } private void ChangeColorNeg(ControllerBoolEventArgs args) { } #endregion } }