private void scanPads() { while (true) { for (int i = 0; i < 4; i++) { AbstractController newGamepad = new GamepadController(i); if (Joystick.GetState(i).IsConnected) { if (!Controllers.Contains(newGamepad)) { Controllers.Add(newGamepad); } } else { if (Controllers.Contains(newGamepad)) { Controllers.Remove(newGamepad); } } } Thread.Sleep(scanTime); } }
public static GamepadController CreateGamepad(bool isPSController = false, int controllerIndex = 1) { JoystickMap map = isPSController ? dualShockMap : xBoneMap; // Use this as long as it works, not ideal though //int controllerIndex = 1; GamepadController gamepad = new GamepadController { //integer i + 1 to match unity's own input system to the player index values moveAxisXName = $"{map.baseMoveAxisXName}{controllerIndex}", moveAxisYName = $"{map.baseMoveAxisYName}{controllerIndex}", lookAxisXName = $"{map.baseLookAxisXName}{controllerIndex}", lookAxisYName = $"{map.baseLookAxisYName}{controllerIndex}", LBKeyName = $"{map.baseLBKeyName}{controllerIndex}", RBKeyName = $"{map.baseRBKeyName}{controllerIndex}", LTAxisName = $"{map.baseLTAxisName}{controllerIndex}", RTAxisName = $"{map.baseRTAxisName}{controllerIndex}", jumpKeyName = $"{map.baseJumpKeyName}{controllerIndex}", interactKeyName = $"{map.baseInteractKeyName}{controllerIndex}", doRagdollKeyName = $"{map.baseDoRagdollKeyName}{controllerIndex}", AxisInversion = isPSController ? -1f : 1f }; return(gamepad); }
public static IInputController[] CreateControllers(int playersCount) { var controllerNames = Input.GetJoystickNames(); int controllerCount = controllerNames.Length; IInputController[] controllers = new IInputController[playersCount]; for (int i = 0; i < playersCount; i++) { //if i exceeds controllerCount then a controller will become a nullcontroller if (i >= controllerCount) { controllers[i] = new NullController(); continue; } // Create gamepad controller bool isPSController = controllerNames[i] == dualShockName; JoystickMap map = isPSController ? dualShockMap : xBoneMap; GamepadController gamepad = CreateGamepad(isPSController, i + 1); // This is fine gamepad.AxisInversion = isPSController ? -1f : 1f; // Now set controller to interface array controllers [i] = gamepad; } return(controllers); }
private void TestAndDiagnostics_Load(object sender, EventArgs e) { MainForm mainForm = Parent.Parent as MainForm; xboxController = mainForm.SharedXBoxController(); gamepadController = mainForm.SharedGamepadController(); }
public Game(Connection serverConnection) { _serverConnection = serverConnection; IPlayerController controller; try { var port = new SerialPort(SerialPort.GetPortNames()[0], 115200, Parity.None); port.Open(); port.Close(); _inputManager = new GamepadInputManager(); _inputManager.sendData(1); controller = new GamepadController(_inputManager, _entityManager); } catch (Exception e) { controller = new KeyboardController(_entityManager); } Player player = new Player(new Vector2f(300.0f, 300.0f), controller, playerTexture, healthBarTexture, _entityManager, camera) { Active = true }; _entityManager.Add(player); _entityManager.ActivePlayer = player; _sceneBuffer = new SceneBuffer(playerTexture, healthBarTexture, _entityManager); _serverConnection.SetCallback((connection, data) => { _sceneBuffer.Process(data); }); }
protected void ConnectGamepad(string gamepadId) { if (string.IsNullOrEmpty(gamepadId)) { return; } if (!gamepads.Any(g => g.Id == gamepadId)) { var gamepad = new GamepadController(gamepadId, this); gamepads.Add(gamepad); ServiceCache.EventBus.Fire(new InputGamepadConnectedEvent(gamepad)); } else { var gamepad = gamepads.Find(g => g.Id == gamepadId) as GamepadController; if (!gamepad.Enabled) { gamepad.Enabled = true; ServiceCache.EventBus.Fire(new InputGamepadConnectedEvent(gamepad)); } } }
// Use this for initialization void Start() { m_canvas = GameObject.FindGameObjectWithTag("Canvas"); m_target = Resources.Load <Sprite>("Sprites/Targets/redSniperTarget"); m_cursor = new GameObject("Cursor"); SpriteRenderer renderer = m_cursor.AddComponent <SpriteRenderer>(); renderer.sprite = m_target; m_cursor.transform.localScale = new Vector3(2, 2, 2); m_cursor.transform.rotation = Camera.main.transform.rotation; m_cursor.transform.SetParent(m_canvas.transform); m_cursor.transform.localPosition = new Vector3(0, 0, 0); if (PlayerSelection_Persistent.keyboardControl) { m_controller = new MouseController(); } else { GamepadController gamepadController = new GamepadController(PlayerSelection_Persistent.shooterGamepadID); m_controller = gamepadController; } }
private void GraphAnalogControl_Load(object sender, EventArgs e) { MainForm mainForm = Parent.Parent as MainForm; xboxController = mainForm.SharedXBoxController(); gamepadController = mainForm.SharedGamepadController(); }
protected override void LoadContent() { ContentManager content = Game.Content; //Loads the gameoptions from last time GameOptions = Serializing.LoadGameOptions(); ControllerViewManager = new ControllerViewManager(Game.GraphicsDevice, content); //Adds the sound controller ControllerViewManager.AddController(soundController); //Loads and add the fonts to the a list so controllers easily can reach this just by the name of the string fonts.Add("Impact", content.Load <SpriteFont>("Fonts/Impact")); fonts.Add("Impact.large", content.Load <SpriteFont>("Fonts/Impact.large")); //Loads the player controllers from file List <Player> players = Serializing.LoadPlayerControllers(); // Init each player by creating a gamepadcontroller foreach player foreach (Player player in players) { GamepadController gamepad = new GamepadController(this, player); gamePads.Add(gamepad); ControllerViewManager.AddController(gamepad); } //Creates the controller for the cursor cursorsController = new CursorController(this); ControllerViewManager.AddController(cursorsController); //Adds the popupmenu to the controllers stack popupMenuController = new OverlayMenuController(this); ControllerViewManager.AddController(popupMenuController); //if startgameplay is true then the game goes straight in to game play if (Constants.StartGameplay) { //Set the right state gameStateManager.CurrentState = GameState.GamePlay; var chars = Serializing.LoadCharacters(); var maps = Serializing.LoadMaps(); gamePads[0].PlayerModel.SelectedCharacter = chars[1]; gamePads[0].PlayerModel.CharacterIndex = 0; gamePads[1].PlayerModel.SelectedCharacter = chars[2]; gamePads[1].PlayerModel.CharacterIndex = 2; GamePlayController game = new GamePlayController(this, maps[1]); ControllerViewManager.AddController(game); } else { gameStateManager.CurrentState = GameState.StartScreen; this.menu = new MenuController(this); ControllerViewManager.AddController(menu); } }
public static void Pause() { //Cursor.visible = true; CameraController.UnlockCamera(); GamepadController.SetRumble(0, 0); Time.timeScale = 0f; pauseMenu.SetActive(true); IsPaused = true; }
private async Task Initialze() { if (LightningProvider.IsLightningEnabled) { LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider(); } else { throw new Exception("Lightning drivers not enabled. Please enable Lightning drivers."); } _camera = new Camera(); await _camera.Initialize(); SpeedSensor.Initialize(); SpeedSensor.Start(); SpeechSynthesis.Initialze(); await AudioPlayerController.Initialize(); _accelerometerSensor = new AccelerometerGyroscopeSensor(); await _accelerometerSensor.Initialize(); _accelerometerSensor.Start(); _automaticSpeakController = new AutomaticSpeakController(_accelerometerSensor); _motorController = new MotorController(); await _motorController.Initialize(_automaticSpeakController); _servoController = new ServoController(); await _servoController.Initialize(); _distanceMeasurementSensor = new DistanceMeasurementSensor(); await _distanceMeasurementSensor.Initialize(I2C_ADDRESS_SERVO); _automaticDrive = new AutomaticDrive(_motorController, _servoController, _distanceMeasurementSensor); _speechRecognation = new SpeechRecognition(); await _speechRecognation.Initialze(_motorController, _servoController, _automaticDrive); _speechRecognation.Start(); _gamepadController = new GamepadController(_motorController, _servoController, _automaticDrive, _accelerometerSensor); _camera.Start(); _httpServerController = new HttpServerController(_motorController, _servoController, _automaticDrive, _camera); SystemController.Initialize(_accelerometerSensor, _automaticSpeakController, _motorController, _servoController, _automaticDrive, _camera, _httpServerController, _speechRecognation, _gamepadController); await SystemController.SetAudioRenderVolume(AUDIO_RENDER_VOLUME, true); await SystemController.SetAudioCaptureVolume(AUDIO_CAPTURE_VOLUME, true); await AudioPlayerController.PlayAndWaitAsync(AudioName.Welcome); _automaticSpeakController.Start(); }
public CharacterModel(GamepadController pad, Vector2 startPos, int countDown, CharacterStats stats) { position = startPos; playerIndex = pad.PlayerIndex; resetTimeLeft = countDown * 1000; maxSpeed = stats.maxSpeed; acceleration = stats.acceleration; weight = stats.weight; JumpStartVelocity = stats.jumpStartVelocity; }
private void InitializeRemoteControl() { _gamepad = new GamepadController(gamepadFile); _log.LogDebug("Configuring ButtonChanged listener..."); _gamepad.ButtonChanged += Gamepad_ButtonChanged; _log.LogDebug("Configuring AxisChanged listener..."); _gamepad.AxisChanged += Gamepad_AxisChanged; }
protected override void Initialize() { keyboardController = new KeyboardController(); gamepadController = new GamepadController(); level = new Level(this); lifeText = new LifeText(this); resetTime = false; InitializeCommands(); base.Initialize(); }
public static void Pause() { CameraController.UnlockCamera(); GamepadController.SetRumble(0, 0); Time.timeScale = 0f; // Update blue lines for this frame (workaround) Player.PlayerIronSteel.SearchForMetals(); instance.gameObject.SetActive(true); Open(); IsPaused = true; }
protected override void Initialize() { level = new Level(this); keyboardController = new KeyboardController(this); gamepadController = new GamepadController(); menuKeyboardController = new MenuKeyboardController(this); collectibleKeyboardController = new CollectiblesKeyboardController(this); playerName = "3Pros1LenUFO"; lifeText = new LifeText(this); resetTime = false; InitializeCommands(); base.Initialize(); }
protected override void Update(GameTime gameTime) { newKeyboardState = Keyboard.GetState(); newGamepadState = GamePad.GetState(PlayerIndex.One); MouseState = Mouse.GetState(); if ((newKeyboardState.IsKeyDown(Keys.P) && oldKeyboardState.IsKeyUp(Keys.P)) || newGamepadState.IsButtonDown(Buttons.Start) && oldGamepadState.IsButtonUp(Buttons.Start)) { if (GameStatus == GameState.Pause) { MediaPlayer.Resume(); GameStatus = GameState.Playing; pauseSoundEffect.Play(); } else if (GameStatus == GameState.Playing) { MediaPlayer.Pause(); GameStatus = GameState.Pause; pauseSoundEffect.Play(); } } if ((newKeyboardState.IsKeyDown(Keys.M) && oldKeyboardState.IsKeyUp(Keys.M))) { MouseControl = !MouseControl; IsMouseVisible = !IsMouseVisible; } Cheat.Update(oldKeyboardState, newKeyboardState); oldKeyboardState = newKeyboardState; oldGamepadState = newGamepadState; if (GameStatus == GameState.Playing) { this.GameTime = gameTime; if (!DisableControl) { KeyboardController.Update(); GamepadController.Update(); MouseController.Update(); CameraPointer.UpdateX(Mario.LocationX); } MarioSprite.Update(gameTime); World.Update(gameTime); Collision_Detection_and_Responses.CollisionHandling.Update(World.Level, this); PlayerStat.Update(gameTime); base.Update(gameTime); } }
public override void StopBurning() { base.StopBurning(); if (HasHighlightedTarget) { HighlightedTarget.RemoveTargetGlow(); HighlightedTarget = null; } steelBurnPercentageLerp = 0; ironBurnPercentageLerp = 0; forceMagnitudeTarget = 0; GamepadController.SetRumble(0, 0); GetComponentInChildren <AllomechanicalGlower>().RemoveAllEmissions(); DisableRenderingBlueLines(); RefreshHUD(); }
/* * Lerps from the current burn percentage to the burn percentage target for both metals. * If the player is not Pulling or Pushing, that burn percentage is instead set to 0. * Set, not lerped - there's more precision there. */ private void LerpToBurnPercentages() { IronBurnPercentageTarget = Mathf.Lerp(IronBurnPercentageTarget, ironBurnPercentageLerp, burnPercentageLerpConstant); SteelBurnPercentageTarget = Mathf.Lerp(SteelBurnPercentageTarget, steelBurnPercentageLerp, burnPercentageLerpConstant); if (SettingsMenu.settingsData.controlScheme == SettingsData.Gamepad) { IronPassiveBurn = 1; SteelPassiveBurn = 1; } else { IronPassiveBurn = IronBurnPercentageTarget; SteelPassiveBurn = SteelBurnPercentageTarget; } // Gamepad rumble if (HasPullTarget || HasPushTarget) { if (IronPulling) { GamepadController.SetRumbleRight(IronBurnPercentageTarget * GamepadController.rumbleFactor); } else { GamepadController.SetRumbleRight(0); } if (SteelPushing) { GamepadController.SetRumbleLeft(SteelBurnPercentageTarget * GamepadController.rumbleFactor); } else { GamepadController.SetRumbleLeft(0); } } else { GamepadController.SetRumble(0, 0); } // If using the Percentage control scheme and the target burn percentage is 0 (and not using a gamepad, which will very often be 0) // Then stop burning metals if (SettingsMenu.settingsData.pushControlStyle == 0 && SettingsMenu.settingsData.controlScheme != SettingsData.Gamepad && (IronBurnPercentageTarget < .001f && SteelBurnPercentageTarget < .001f)) { StopBurning(); } }
private static void AddSelection(Game1 game, KeyboardController keyboard, GamepadController gamepad, IGameState state) { ICommand upSelection = new UpSelection(state); keyboard.Add((int)Keys.Up, upSelection); gamepad.Add((int)Buttons.DPadUp, upSelection); ICommand downSelection = new DownSelection(state); keyboard.Add((int)Keys.Down, downSelection); gamepad.Add((int)Buttons.DPadDown, downSelection); ICommand select = new MadeSelection(game, state); keyboard.Add((int)Keys.Enter, select); gamepad.Add((int)Buttons.A, select); }
//Call this method when player press use button to reset related value void UseDash( ) { if (bAim && !bUsingDash && bCanDash) { Time.timeScale = normalTimeScale; velocity = props.Distance / attr.AnimTime; bUsingDash = true; bCanDash = bInSpaceArea; timer.Reset(attr.AnimTime); AimAnimEnded( ); Player.Anim.SetBool("dash", true); Player.GameController.CameraController.ShakeCamera(attr.DashShakeProps); Player.Rb.velocity = Vector2.zero; Player.FX.PlayVFX(Player.VFXAction[EVFXAction.DASH], Player.IsFacingRight, Math.GetDegree(direction), direction); Player.FX.PlaySFX(ESFXType.DASH); GamepadController.VibrateController(EVibrateDuration.NORMAL, EVibrateStrength.STRONG); Player.Col.size = oriColSize * attr.DashColSizeMultiplier; } }
void Start() { telekenesPoint = GameObject.Find("TelekenesPoint"); moveVectorController = GameObject.Find("MoveVectorController"); player = GameObject.Find("Player"); gamepadControllers = new GamepadController[6]; gamepadControllers[0] = new GamepadController(null, null, 0, keys); gamepadControllers[1] = new GamepadController(null, null, 1, keys); gamepadControllers[2] = new GamepadController(null, null, 2, keys); gamepadControllers[3] = new GamepadController(null, null, 3, keys); gamepadControllers[4] = new GamepadController(() => { if (telekenesObject == null) { UpTelekenesObject(); } else { DownTelekenesObject(); } }, () => { if (telekenesObject == null) { UpTelekenesObject(); } else { CastTeleckenesObject(); } }, 4, keys); gamepadControllers[5] = new GamepadController(() => { if (telekenesObject == null) { InteractiveObject(); } }, null, 5, keys); }
protected override void LoadContent() { SpriteBatch = new SpriteBatch(GraphicsDevice); Texture = Content.Load <Texture2D>("MarioSheet"); BackgroundMusic = Content.Load <Song>("backgroundMusic"); pauseSoundEffect = Content.Load <SoundEffect>("pauseSoundEffect"); blackHole = Content.Load <Texture2D>("blackholeSprite"); MediaPlayer.IsRepeating = true; MediaPlayer.Volume = 0.6f; SpriteFactory.LoadAllTextures(Content); Block = new BlockLogic(this); Mario.LoadContent(Content); World = new WorldManager(this); World.Load(); PlayerStat = new PlayerStatistic(SpriteBatch, Content); KeyboardController = new KeyboardController(); KeyboardController.RegisterCommand(Keys.Left, new MarioLookLeftCommand(this)); KeyboardController.RegisterCommand(Keys.Right, new MarioLookRightCommand(this)); KeyboardController.RegisterCommand(Keys.Down, new MarioLookDownCommand(this)); KeyboardController.RegisterCommand(Keys.A, new MarioLookLeftCommand(this)); KeyboardController.RegisterCommand(Keys.D, new MarioLookRightCommand(this)); KeyboardController.RegisterCommand(Keys.S, new MarioLookDownCommand(this)); KeyboardController.RegisterCommand(Keys.Z, new MarioJumpCommand(this)); KeyboardController.RegisterCommand(Keys.Q, new QuitCommand(this)); KeyboardController.RegisterCommand(Keys.R, new ResetCommand(this)); KeyboardController.RegisterCommand(Keys.X, new MarioRunCommand(this)); GamepadController = new GamepadController(); GamepadController.RegisterCommand(Buttons.LeftThumbstickLeft, new MarioLookLeftCommand(this)); GamepadController.RegisterCommand(Buttons.LeftThumbstickRight, new MarioLookRightCommand(this)); GamepadController.RegisterCommand(Buttons.LeftThumbstickDown, new MarioLookDownCommand(this)); GamepadController.RegisterCommand(Buttons.X, new ResetCommand(this)); GamepadController.RegisterCommand(Buttons.A, new MarioJumpCommand(this)); GamepadController.RegisterCommand(Buttons.B, new MarioRunCommand(this)); MouseController = new MouseController(); MouseController.RegisterCommand("LeftMouseClick", new MarioRunCommand(this)); MouseController.RegisterCommand("RightMouseClick", new MarioJumpCommand(this)); }
public static void PauseControllers(Game1 game, KeyboardController keyboard, GamepadController gamepad, IGameState state) { keyboard.ClearDictionary(); gamepad.ClearDictionary(); ICommand unpause = new UnpauseCommand(); keyboard.Add((int)Keys.P, unpause); gamepad.Add((int)Buttons.X, unpause); //Add the Exit Command to the controllers ICommand exitcommand = new ExitCommand(game); keyboard.Add((int)Keys.Q, exitcommand); gamepad.Add((int)Buttons.Start, exitcommand); ICommand resetcommand = new RestartCommand(); keyboard.Add((int)Keys.R, resetcommand); gamepad.Add((int)Buttons.Back, resetcommand); AddSelection(game, keyboard, gamepad, state); }
public CursorModel(ContentManager content, World world, GamepadController pad, SmashBros.Controllers.GamepadController.NavigationKey navigationMethod, OnCollisionEventHandler col, OnSeparationEventHandler sep, bool enabled = false) { Cursor = new Sprite(content, "Cursors/Player" + pad.PlayerIndex, 70, 70, 280 * pad.PlayerIndex + 100, 680); Cursor.BoundRect(world, 5, 5, BodyType.Dynamic); Cursor.StaticPosition = true; Cursor.Category = Category.Cat4; Cursor.CollidesWith = Category.Cat5; Cursor.Layer = 1002; Cursor.Mass = 1; Cursor.UserData = pad.PlayerIndex; Cursor.BoundBox.IgnoreGravity = true; Cursor.Origin = new Vector2(50, 20); this.Pad = pad; this.Navigation = navigationMethod; this.OnCollision = col; this.OnSeparation = sep; this.Enabled = enabled; }
protected override bool StartBurning(bool startIron) { if (!base.StartBurning(startIron)) { return(false); } GamepadController.Shake(.1f, .1f, .3f); UpdateBurnRateMeter(); HUD.BurnPercentageMeter.SetMetalLineCountText(PullTargets.Size.ToString()); if (SettingsMenu.settingsData.renderblueLines == 1) { EnableRenderingBlueLines(); } ironBurnPercentageLerp = 1; steelBurnPercentageLerp = 1; forceMagnitudeTarget = 600; SearchForMetals(); // first frame of blue lines return(true); }
private void HandleGamepadConnection(CancellationToken token) { try { while (true) { token.ThrowIfCancellationRequested(); if (RemoteControlConnected() && !_remoteControlInitialized) { _log.LogDebug($"Gamepad detected, connecting to it..."); InitializeRemoteControl(); _remoteControlInitialized = true; _log.LogWarning($"Gamepad connected."); } else if (!RemoteControlConnected() && _remoteControlInitialized) { _log.LogWarning($"Gamepad disconected."); // If the gamepad file doens't exist any more, clear the initialized flag, // So when gamepad becomes available again we reconnect to it _remoteControlInitialized = false; _gamepad = null; } Thread.Sleep(1000); } } catch (TaskCanceledException) { _log.LogDebug("Gamepad connection task correctly cancelled"); } catch (Exception ex) { _log.LogError($"Unexpected error in GamepadConnection task", ex); } }
public static void Initialize(AccelerometerGyroscopeSensor accelerometerSensor, AutomaticSpeakController automaticSpeakController, MotorController motorController, ServoController servoController, AutomaticDrive automaticDrive, Camera camera, HttpServerController httpServerController, SpeechRecognition speechRecognation, GamepadController gamepadController) { _accelerometerSensor = accelerometerSensor; _automaticSpeakController = automaticSpeakController; _motorController = motorController; _servoController = servoController; _automaticDrive = automaticDrive; _camera = camera; _httpServerController = httpServerController; _speechRecognation = speechRecognation; _gamepadController = gamepadController; _initialized = true; }
static void Main(string[] args) { // You should provide the gamepad file you want to connect to. /dev/input/js0 is the default using (var gamepad = new GamepadController("/dev/input/js0")) { Console.WriteLine("Start pushing the buttons/axis of your gamepad/joystick to see the output"); // Configure this if you want to get events when the state of a button changes gamepad.ButtonChanged += (object sender, ButtonEventArgs e) => { Console.WriteLine($"Button {e.Button} Changed: {e.Pressed}"); }; // Configure this if you want to get events when the state of an axis changes gamepad.AxisChanged += (object sender, AxisEventArgs e) => { Console.WriteLine($"Axis {e.Axis} Changed: {e.Value}"); }; Console.ReadLine(); } // Remember to Dispose the GamepadController, so it can finish the Task that listens for changes in the gamepad }
private void Awake() { instance = this; }
// Set a static reference void Awake() { if (controller == null) { DontDestroyOnLoad(gameObject); controller = this; } else if (controller != this) { Destroy(gameObject); } p1rumbleEvents = new List<xRumble>(); p2rumbleEvents = new List<xRumble>(); }