public void detectController() { if (Input.GetJoystickNames().Length > 2) { this.input = new IController (); profile = controllerProfile.Controller; controller_conected = true; setControllerDefalts(); setControllers(); } else { this.input = new IKeyboard(); profile = controllerProfile.Keys; controller_conected = false; setKeyDefaults(); } }
public InputManager() { _observers = new List <IInputObserver>(); _generalObserver = new List <IGeneralInputObserver>(); _mouseInput = new MouseInput(); _rawEntities = new List <IEntity>(); }
/// <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 controller = new NonInvertedKeyboardBehaviour(); positionRepository = ObjectPositionRepository.InitializeRepository(); base.Initialize(); }
public PlayerRollState(GameObject t, PlayerSM playerSM, IControllerInput c) : base(t, playerSM, c) { this.target = t; this.sm = playerSM; rb = t.GetComponent <Rigidbody2D>(); endtime = ((PlayerSM)sm).pparams.rolltime; speed = ((PlayerSM)sm).pparams.rollspeed; curve = ((PlayerSM)sm).pparams.rollcurve; }
public InputManager() { #if UNITY_EDITOR ControllerInput = new InputSettingsWindows(); #endif #if UNITY_ANDROID ControllerInput = new InputSettingsAndroid(); #endif }
//constructor takes target game object, state machine running it, controller configuration, and arm gameobject for aiming public PlayerAimState(GameObject t, PlayerSM playerSM, IControllerInput c, GameObject a, GameObject g) : base(t, playerSM, c) { this.target = t; //Debug.Log("In stand state: " + target); this.sm = playerSM; rb = target.GetComponent <Rigidbody2D>(); arm = a; gun = g; enemyList = new List <GameObject>(); lockOnResetLimit = playerSM.pparams.lockOnResetTime; lockResetTimer = lockOnResetLimit + 1; }
// Start is called before the first frame update private void Awake() { if (!pilot) { pilot = gameObject; } if (pilot) { playerInput = pilot.GetComponent <IControllerInput>(); playerInput.ForwardEvent += ForwardThrust; playerInput.YawEvent += YawMovement; playerInput.PitchEvent += PitchMovement; playerInput.RollEvent += RollMovement; playerInput.VerticalStrafeEvent += VerticalStrafeMovement; playerInput.SideStrafeEvent += SideStrafeMovement; playerInput.SlideEvent += EnableSlide; } else { Debug.LogError("No pilot on", gameObject); } }
private static void UpdatePlayerPositions(ObjectPositionRepository objectPositionRepository, IControllerInput controllerInput) { foreach (var player in objectPositionRepository.GetPlayerPositions()) { if (controllerInput.MoveLeft()) { player.Effects = SpriteEffects.FlipHorizontally; Rectangle newPosition = player.DestinationRectangle; newPosition.X -= MOVEMENTINTERVAL; if (!CollidedWithSolidObject(objectPositionRepository, newPosition)) { player.DestinationRectangle = newPosition; } } if (controllerInput.MoveRight()) { player.Effects = SpriteEffects.None; Rectangle newPosition = player.DestinationRectangle; newPosition.X += MOVEMENTINTERVAL; if (!CollidedWithSolidObject(objectPositionRepository, newPosition)) { player.DestinationRectangle = newPosition; } } } }
public static void UpdateObjectPositions(ObjectPositionRepository objectPositionRepository, IControllerInput controllerInput) { UpdatePlayerPositions(objectPositionRepository, controllerInput); }
public abstract void UpdateInput(IControllerInput controller);
public void Update(IGameObject obj, IControllerInput controller) { }
public PlayerState(GameObject t, GameStateMachine s, IControllerInput c) : base(t, s, c) { }
public void Update(IControllerInput controllerInput) { DataFrameState lastRemote; lock (_framesRemote) { lastRemote = _framesRemote[_indexCurrent]; } var paddleLocalMovement = controllerInput.IsMovingLeft ? -1f : 0f; paddleLocalMovement += controllerInput.IsMovingRight ? 1f : 0f; var leftBound = -.5f * Composition.DataMeta.CourtRatio; var rightBound = .5f * Composition.DataMeta.CourtRatio; var lastLocalDelta = _frame.Time; Composition.NetState.SetTimeStamp(ref _frame); var bufferedDeltaTime = (float)(DateTime.FromBinary(_frame.Time) - DateTime.FromBinary(lastRemote.Time)).TotalSeconds; var simDeltaTime = (float)(DateTime.FromBinary(_frame.Time) - DateTime.FromBinary(lastLocalDelta)).TotalSeconds; // update paddle local _frame.PaddleLocalSpeed = Composition.DataMeta.PaddleSpeed * paddleLocalMovement; _frame.PaddleLocalPosition += Frame.PaddleLocalSpeed * simDeltaTime; var leftPaddleLocalBound = _frame.PaddleLocalPosition - _frame.PaddleLocalReflectorHalfSize; var rightPaddleLocalBound = _frame.PaddleLocalPosition + _frame.PaddleLocalReflectorHalfSize; // limit _frame.PaddleLocalPosition = leftBound > leftPaddleLocalBound ? leftBound + _frame.PaddleLocalReflectorHalfSize : Frame.PaddleLocalPosition; _frame.PaddleLocalPosition = rightBound < rightPaddleLocalBound ? rightBound - _frame.PaddleLocalReflectorHalfSize : Frame.PaddleLocalPosition; // update paddle remote _frame.PaddleRemoteSpeed = lastRemote.PaddleRemoteSpeed; _frame.PaddleRemotePosition = lastRemote.PaddleRemotePosition; _frame.PaddleRemotePosition += lastRemote.PaddleRemoteSpeed * bufferedDeltaTime; var leftPaddleRemoteBound = _frame.PaddleRemotePosition - _frame.PaddleRemoteReflectorHalfSize; var rightPaddleRemoteBound = _frame.PaddleRemotePosition + _frame.PaddleRemoteReflectorHalfSize; // limit _frame.PaddleRemotePosition = leftBound > leftPaddleRemoteBound ? leftBound + _frame.PaddleRemoteReflectorHalfSize : Frame.PaddleRemotePosition; _frame.PaddleRemotePosition = rightBound < rightPaddleRemoteBound ? rightBound - _frame.PaddleRemoteReflectorHalfSize : Frame.PaddleRemotePosition; // update ball var ballSpeed = new Vector2(Frame.BallSpeedX, Frame.BallSpeedY); var ballPosition = new Vector2(Frame.BallPositionX, Frame.BallPositionY); // debug if (simDeltaTime < bufferedDeltaTime) { ((Vector3)ballPosition * Composition.ModelScaleFactor).DebugDrawPoint(Color.yellow, .01f, 20f); } // - init bounce calc buffers _bouncedTotal = 0; _bounced = _bounced ?? new IObstacle[_bouncers.Length]; _frameBallTrail = _frameBallTrail ?? new DataBallState[_bouncers.Length + 1]; _frameBallTrail[_bouncedTotal] = new DataBallState { Position = ballPosition, Speed = ballSpeed, DeltaTime = simDeltaTime, }; // - calc bounce for (var index = 0; index < _bouncers.Length; index++) { // exclude obstacle been bounced var indexBounced = 0; for (; indexBounced < _bouncedTotal; indexBounced++) { if (ReferenceEquals(_bouncers[index], _bounced[indexBounced])) { break; } } if (indexBounced != _bouncedTotal) { continue; } // check bounce (default should the last one) if (_bouncers[index].Bounce(_frameBallTrail[_bouncedTotal], ref _frameBallTrail[_bouncedTotal + 1])) { _bounced[_bouncedTotal] = _bouncers[index]; index = 0; _bouncedTotal++; } } // - calc out, with default move //for(var index = 0; index < _finishers.Length; index++) //{ // if(_finishers[index].Bounce(_frameBallTrail[indexTrail], ref _frameBallTrail[indexTrail + 1])) // { // indexTrail++; // } //} _frame.BallPositionX = _frameBallTrail[_bouncedTotal].Position.x; _frame.BallPositionY = _frameBallTrail[_bouncedTotal].Position.y; _frame.BallSpeedX = _frameBallTrail[_bouncedTotal].Speed.x; _frame.BallSpeedY = _frameBallTrail[_bouncedTotal].Speed.y; //_phase = // _phase ?? // new ControllerSimPhase( // _frame, // _frameBallTrail[_bouncedTotal], // _bouncers); //if(!_phase.ApplyCorrection(ref _frame)) //{ // _phase = new ControllerSimPhase( // _frame, // _frameBallTrail[_bouncedTotal], // _bouncers); //} }
public override void UpdateInput(IControllerInput controller) { base.Input.Update(this, controller); }
public PlayerStandState(GameObject t, PlayerSM playerSM, IControllerInput c, GameObject a, GameObject g) : base(t, playerSM, c, a, g) { }
float speed; //hardcoded movement speed placeholder public PlayerWalkState(GameObject t, PlayerSM playerSM, IControllerInput c, GameObject a, GameObject g) : base(t, playerSM, c, a, g) { speed = ((PlayerSM)sm).pparams.walkspeed; //fetch walk speed from player parameters asset }
public InputState(GameObject t, GameStateMachine s, IControllerInput c) : base(t, s) { cont = c; }
public void SetController(IControllerInput c) { cont = c; }