private void InitializeAsKeyboard(ScreenAccess ParentForm, InputDeviceAccess.TypeOfDevices NewTypeOfDevice) { try { this.device = new DirectInput.Device(DirectInput.SystemGuid.Keyboard); this.device.SetCooperativeLevel ( ParentForm, DirectInput.CooperativeLevelFlags.Background | DirectInput.CooperativeLevelFlags.NonExclusive ); device.Acquire(); this._TypeOfDevice = NewTypeOfDevice; //Determine how many users are suited for this device this._DeviceUserMax = 2; // Get space in the keytable for the number of device users this.KeyTable = new System.Collections.Hashtable[this._DeviceUserMax]; //record guid as used InputDeviceAccess.AssignedGuids.Add(this.device.DeviceInformation.InstanceGuid); } catch (Exception err) { throw err; } }
public WriterAccess(ScreenAccess NewParentScreen) { this.ParentScreen = NewParentScreen; //Create fonts type and font buffer this.ScoreFont = new System.Drawing.Font("Verdana", 14.0f, FontStyle.Italic | FontStyle.Bold); this.ScoreTextBuffer = new Direct3D.Font(this.ParentScreen.device, this.ScoreFont); }
public GameAccess() { this.Screen = new ScreenAccess(); this.sound = new SoundAccess(this.Screen); this.InputDeviceManager = new InputDeviceManagerAccess(this.Screen); this.Writer = new WriterAccess(this.Screen); //Check the App.config to see if it is correct GameConfig.ValidateConfigFile(); }
private void InitializeAsGamePad(ScreenAccess ParentForm, InputDeviceAccess.TypeOfDevices NewTypeOfDevice) { //Check to see if this type of device is available and try to get it for this user try { //Grab first attached gamepad that isnt already assigned foreach (DirectInput.DeviceInstance CurrDeviceInstance in DirectInput.Manager.GetDevices(DirectInput.DeviceClass.GameControl, DirectInput.EnumDevicesFlags.AttachedOnly)) { if (InputDeviceAccess.IsFreeDeviceGuid(CurrDeviceInstance.InstanceGuid) == true) { this.device = new DirectInput.Device(CurrDeviceInstance.InstanceGuid); //If this device is dead throw an exception if (this.device == null) { throw new Exception("found a gamepad GUID, but when we tried to make a device from it it was null"); } else { break; } } } //throw an exception if there is no device if (this.device == null) { throw new Exception("A gamepad was assigned as an input device, but none were found."); } //Setup device this._TypeOfDevice = NewTypeOfDevice; this.device.SetDataFormat(DirectInput.DeviceDataFormat.Joystick); this.device.SetCooperativeLevel(ParentForm, DirectInput.CooperativeLevelFlags.Background | DirectInput.CooperativeLevelFlags.NonExclusive); this.device.Properties.AxisModeAbsolute = true; this.device.Acquire(); //Determine how many users are suited for this device this._DeviceUserMax = 1; // Get space in the keytable for the number of device users this.KeyTable = new System.Collections.Hashtable[this._DeviceUserMax]; //record guid as used InputDeviceAccess.AssignedGuids.Add(this.device.DeviceInformation.InstanceGuid); //Get the keys just so PressedKeys wont be null this.PollInput(); } catch (Exception err) { throw err; } }
public SoundAccess(ScreenAccess ParentForm) { try { device = new DirectSound.Device(); device.SetCooperativeLevel(ParentForm, DirectSound.CooperativeLevel.Normal); // BackgroundMusic = new DirectSound.SecondaryBuffer(GameFiles.BgMusic, device); // // BackgroundMusic.Play(0, DirectSound.BufferPlayFlags.Looping); } catch (Exception err) { throw err; } }
public InputDeviceAccess(ScreenAccess ParentForm, InputDeviceAccess.TypeOfDevices TypeOfDevice) { if (TypeOfDevice == InputDeviceAccess.TypeOfDevices.Keyboard) { this.InitializeAsKeyboard(ParentForm, TypeOfDevice); } else if (TypeOfDevice == InputDeviceAccess.TypeOfDevices.Gamepad) { this.InitializeAsGamePad(ParentForm, TypeOfDevice); } else if (TypeOfDevice == InputDeviceAccess.TypeOfDevices.Mouse) { throw new System.Exception("mouse not yet added to InputDeviceAccess"); } }
public InputDeviceManagerAccess(ScreenAccess NewParentForm) { this.ParentForm = NewParentForm; this.Devices = new ArrayList(); this.ControllerIds = new ArrayList(); }