void Jump() { if (isGrounded) { rigidbody.velocity = Vector2.up * jumpForce; } else { if (Input.GetButtonDown("Jump")) { if (canDoubleJump) { rigidbody.velocity = Vector2.up * (jumpForce + 2); Instantiate(jumpEffectPrefab, new Vector3(transform.position.x, transform.position.y, -9), Quaternion.identity); canDoubleJump = false; } } } //Test for small jump (NOT WORKING) if (Input.GetButtonUp("Jump") && rigidbody.velocity.y > 0) { rigidbody.velocity = new Vector2(rigidbody.velocity.x, rigidbody.velocity.y * .5f); } playerState = PlayerStateEnum.Jumping; }
void Respawn() { AudioManager.Instance.PlayAudioClip(onRevive); transform.position = spawnPosition; if (playerRigidbody != null) { playerRigidbody.constraints = RigidbodyConstraints2D.FreezeRotation; playerRigidbody.velocity = Vector2.zero; } Collider2D collider = GetComponent <Collider2D>(); if (collider != null) { collider.enabled = true; } transform.up = Vector2.up; stateEnum = PlayerStateEnum.Idle; animator.SetBool("OnKilled", false); Instantiate(playerRespawnEffect, transform.position, Quaternion.identity); canBeKilled = false; Invoke("RemortalizePlayer", inmortalTimeAfterRespawn); }
private void PlayerStateChanged(PlayerStateEnum playerState) { if (OnPlayerStateChanged == null) { return; } OnPlayerStateChanged(this, new PlayerStateChangedEventArgs(PlayerState, playerState)); }
void OnCollisionExit2D(Collision2D collision2D) { if (collision2D.gameObject.CompareTag("Grounds")) { isGrounded = false; canDoubleJump = true; playerState = PlayerStateEnum.Jumping; } }
void Idle() { animator.SetBool("OnAiming", false); if (Input.GetKeyDown(KeyCode.Mouse0)) { stateEnum = PlayerStateEnum.Aiming; OnAimingEnter(); } }
/// <summary> /// /// </summary> public PlayerInfo() { Name = "Anonymous Player"; NoSeat = -1; MoneySafeAmnt = 0; MoneyBetAmnt = 0; State = PlayerStateEnum.Zombie; FaceUpCards = new string[0]; FaceDownCards = new string[0]; }
void OnAimingExit() { stateEnum = PlayerStateEnum.Idle; TimeScaleManager.Instance.DisableSlowMoTimeScale(); analogStick.SetActive(false); aimingArrow.SetActive(false); Shoot(); }
void Update() { if (curState != null) { PlayerStateEnum nextState = curState.Update(); if (nextState != curState.state) { curState.Exit(); curState = GetState(nextState); curState.Enter(); } } }
private void player_StateChanged(Player player) { if (!isPlayerOwner) { return; } playerState = player.State; updateInfoTextBox(player); //normally, the PlayButton is in the correct state, but once the player becomes idle (or error), it should switch from // displaying the stop symbol to displaying the play symbol updatePauseButton(); }
public override void OnUpdate(StatedMono <PlayerStateEnum> statedMono) { string message = null; if (Input.GetMouseButton(0)) //A click, you can replace this by a more sophisticated input module in real project. { //This is algorithm for testing if player did 1% of the distance of the diagonal of it screen. //if (startDragPoint == null) // startDragPoint = Input.mousePosition; //if (Vector2.Distance((Vector2)startDragPoint, Input.mousePosition) /(Mathf.Sqrt(Screen.height* Screen.height + Screen.width* Screen.width)) >= 0.01) // if (startDragPoint == null) { startDragPoint = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -Camera.main.transform.position.z)); } //But I prefere to check if player did 10% of the current grid cellul as a swipe if (Vector2.Distance((Vector2)startDragPoint, Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -Camera.main.transform.position.z))) >= 0.1) { foundPiece = currentGrid.AskForAPiece((Vector2)startDragPoint); message = "PieceTaken"; nextState = PlayerStateEnum.DRAGGING_PIECE; } } else if (Input.GetMouseButtonUp(0)) { Vector2 position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -Camera.main.transform.position.z)); foundPiece = currentGrid.AskForAPiece(position); message = "PieceSelected"; nextState = PlayerStateEnum.SELECTING_PIECE; } else { startDragPoint = null; } if (foundPiece) { currentGrid.Take(foundPiece); //Just in case, double check we really can get this Player player = statedMono as Player; player.frameDataBuffer.AddData(new MessageData <Piece>(message, foundPiece)); //Pass the data to the next state foundPiece.Select(); } }
/// <summary> /// Sets the message for what state the player is in /// </summary> /// <param name="playerStateEnum">The state the player is in</param> /// <param name="statusPanel">Whether to show the status panel</param> internal void UpdateState(PlayerStateEnum playerStateEnum, bool statusPanel) { var msg = ""; switch (playerStateEnum) { case PlayerStateEnum.CharacterSelection: msg = "Selecting character"; break; case PlayerStateEnum.NameEntry: msg = "Entering name"; break; case PlayerStateEnum.Ready: msg = "Ready"; break; } TxtCurrentAction.text = msg; PnlStatus.gameObject.SetActive(statusPanel); }
public override void Command(RoleCommand _cmd, params object[] _args) { if (curState == null) { return; } PlayerStateEnum nextState = curState.Command(_cmd, _args); if (nextState != curState.state) { curState.Exit(); curState = GetState(nextState, _args); curState.Enter(); } }
void Start() { rigidbody = GetComponent <Rigidbody2D>(); spriteRenderer = GetComponent <SpriteRenderer>(); //Gets the Score Text from player 1 scoreText = GameObject.Find("Player1 Name & Score").GetComponent <TextMeshProUGUI>(); scoreText.text = "P1 - " + PlayerPrefs.GetString("p1Selection") + ": " + score.ToString(); // Gets the jump effect at runtime jumpEffectPrefab = Resources.Load <GameObject>("Prefabs/pfDoubleJumpEffect"); // Default State playerState = PlayerStateEnum.Idle; }
private void SetState(PlayerStateEnum _state) { switch (_state) { case PlayerStateEnum.Battle: btPVP.SetActive(true); btPVE.SetActive(true); btCancel.SetActive(false); btQuit.SetActive(true); SuperFunction.Instance.AddOnceEventListener(BattleView.battleManagerEventGo, BattleManager.BATTLE_QUIT, BattleOver); SuperFunction.Instance.AddEventListener <MemoryStream, Action <BinaryReader> >(BattleView.battleManagerEventGo, BattleManager.BATTLE_SEND_DATA, SendBattleAction); UIManager.Instance.ShowInParent <BattleView>(new Tuple <bool, int, IEnumerator>(false, 0, null), uid); break; case PlayerStateEnum.Free: btPVP.SetActive(true); btPVE.SetActive(true); btCancel.SetActive(false); btQuit.SetActive(true); break; case PlayerStateEnum.Searching: btPVP.SetActive(false); btPVE.SetActive(false); btCancel.SetActive(true); btQuit.SetActive(false); break; } }
public static BoxCollider2D Get(GameObject go, PlayerStateEnum state) { BoxCollider2D bc = go.AddComponent <BoxCollider2D>(); switch (state) { case PlayerStateEnum.TestIdle: bc.size = new Vector2(2, 2); break; case PlayerStateEnum.TestMove: bc.size = new Vector2(2, 2); break; case PlayerStateEnum.TestRoll: bc.size = new Vector2(1, 1); break; case PlayerStateEnum.TestHighAttack: break; case PlayerStateEnum.TestMidAttack: break; case PlayerStateEnum.TestLowAttack: break; case PlayerStateEnum.TestMidAttackCombo: break; case PlayerStateEnum.TestJump: break; case PlayerStateEnum.TestAirborneMove: bc.size = new Vector2(2, 2); break; default: Debug.Log("Warning: " + state + " does not have a BoxCollider set"); break; } return(bc); }
void Jump() { if (isGrounded) { rigidbody.velocity = Vector2.up * jumpForce; } else { if (Input.GetButtonDown("Jump2")) { if (canDoubleJump) { rigidbody.velocity = Vector2.up * (jumpForce + 2); Instantiate(jumpEffectPrefab, new Vector3(transform.position.x, transform.position.y, -9), Quaternion.identity); canDoubleJump = false; } } } playerState = PlayerStateEnum.Jumping; }
void HandleMovement() { float movimento = Input.GetAxisRaw("Horizontal"); if (movimento < 0) { spriteRenderer.flipX = true; // Just play the walking animation when the player is grounded if (isGrounded) { playerState = PlayerStateEnum.Walking; } } else if (movimento > 0) { spriteRenderer.flipX = false; // Just play the walking animation when the player is grounded if (isGrounded) { playerState = PlayerStateEnum.Walking; } } else if (movimento == 0 && isGrounded) { playerState = PlayerStateEnum.Idle; } rigidbody.velocity = new Vector2(movimento * maxSpeed, rigidbody.velocity.y); if (Input.GetButtonDown("Jump")) { Jump(); } if (isSliding && isGrounded == false) { Slide(); } }
private void ReplyClient(int _uid, bool _isPush, PlayerStateEnum _playerState) { using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { if (_isPush) { bw.Write((int)ScPackageTag.PlayerState); } PlayerStateMessage message = new PlayerStateMessage(); message.PlayerState = _playerState; bw.Write(message.ToByteArray()); SendData(_uid, _isPush, ms); } } }
public void Kill() { if (canBeKilled == false) { return; } AudioManager.Instance.PlayAudioClip(deathSound); analogStick.SetActive(false); aimingArrow.SetActive(false); animator.SetBool("OnKilled", true); cameraShake.StartShake(); transform.up = -Vector2.up; if (playerRigidbody != null) { playerRigidbody.constraints = RigidbodyConstraints2D.None; playerRigidbody.velocity = Vector2.zero; playerRigidbody.AddForce(Vector2.up * forceToApplyOnKilled); } Collider2D collider = GetComponent <Collider2D>(); if (collider != null) { collider.enabled = false; } stateEnum = PlayerStateEnum.OnKilled; Time.timeScale = 1; OnLiveLost_Event(); }
private PlayerState GetState(PlayerStateEnum _pse, params object[] _args) { PlayerState _ret = null; switch (_pse) { case PlayerStateEnum.Stand: _ret = new PlayerStandState(gameObject); _ret.Reset(); break; case PlayerStateEnum.Walk: Vector2 _walkDir = (Vector2)_args[0]; PlayerWalkState _pws = new PlayerWalkState(gameObject); _pws.Dir = _walkDir; _ret = _pws; break; case PlayerStateEnum.Run: Vector2 _runDir = (Vector2)_args[0]; PlayerRunState _prs = new PlayerRunState(gameObject); _prs.Dir = _runDir; _ret = _prs; break; default: break; } if (_ret == null) { MyLogger.Error("RoleControl", "{0} state don't have a creator!", _pse); return(_ret); } else { return(_ret); } }
void Start() { Renderer particleRenderer = trailParticleSystem.GetComponent <Renderer>(); string currentPlayerTrail = PersistentGameData.Instance.gameData.currentPlayerTrail; particleRenderer.material = Resources.Load <Material>(currentPlayerTrail); playerRigidbody = GetComponent <Rigidbody2D>(); playerRigidbody.interpolation = RigidbodyInterpolation2D.Interpolate; animator = GetComponent <Animator>(); stateEnum = PlayerStateEnum.Idle; slingshotCounter = 0; spawnPosition = transform.position; cameraShake = Camera.main.GetComponent <CameraShake>(); canBeKilled = true; gameOver = false; }
private void Player_OnPlayerStateChanged(object sender, PlayerStateChangedEventArgs e) { //Handle any logic entering the new state switch (e.NewPlayerState) { case PlayerStateEnum.Dead: _CanMove = false; _CanJump = false; break; case PlayerStateEnum.Idle: _CanMove = true; _CanJump = true; _PlayerState = PlayerStateEnum.Idle; break; case PlayerStateEnum.Jumping: break; case PlayerStateEnum.PantsDown: _CurentMaxMoveSpeed = MaxMoveSpeedWithPantsDown; _CanMove = true; _CanJump = false; break; case PlayerStateEnum.PartialReload: if (AllowMovementDuringPartialReload) { _CanMove = true; _CanJump = true; } else { _CanMove = false; _CanJump = false; } break; case PlayerStateEnum.FullReload: if (AllowMovementDuringFullReload) { _CanMove = true; _CanJump = true; } else { _CanMove = false; _CanJump = false; } break; case PlayerStateEnum.FailedReload: _CanMove = false; _CanJump = false; break; case PlayerStateEnum.Respawning: _CanMove = false; _CanJump = false; break; case PlayerStateEnum.Running: _CanMove = true; _CanJump = true; break; case PlayerStateEnum.SlodeSlide: break; case PlayerStateEnum.WallSlide: break; } }
public static void ChangeState(this PlayerInfo p, PlayerStateEnum state) { p.State = state; }
// Use this for initialization void Start() { meshrenderer = GetComponent <MeshFilter>(); boxCollider = GetComponent <BoxCollider2D>(); playerstateenum = GetComponent <PlayerStateEnum>(); }
void Start() { rigidbody = GetComponent <Rigidbody2D>(); playerstateenum = GetComponent <PlayerStateEnum>(); }
public PlayerState(PlayerStateEnum pse) { state = pse; }
/// <summary> /// Constructor /// </summary> public LobbyState() { _state = PlayerStateEnum.ProfileSelection; }
// Update is called once per frame void Update() { if (areaHome.playerInHome == true) { playerlocation = "Home"; } else if (areaChase.playerInChase == true) { playerlocation = "Chase"; } else if (areaA.playerInA == true) { playerlocation = "A"; } else if (areaB.playerInB == true) { playerlocation = "B"; } else if (areaC.playerInC == true) { playerlocation = "C"; } switch (playerState) { case PlayerStateEnum.AtHome: if (playerlocation == "Chase") { playerState = PlayerStateEnum.Esacaping; } break; case PlayerStateEnum.Esacaping: if (playerlocation == "Home") { playerState = PlayerStateEnum.AtHome; } if (playerlocation == "A") { Time.timeScale = 0; ui.panelFreedom.SetActive(true); playerState = PlayerStateEnum.LookingForFun; //cannotGetBackCollider2D.SetActive(true); } break; case PlayerStateEnum.LookingForFun: if (playerlocation == "B") { //Time.timeScale = 0; playerState = PlayerStateEnum.HomeSick; //cannotGetBackCollider2D.SetActive(false); } break; case PlayerStateEnum.HomeSick: if (playerlocation == "Home") { playerState = PlayerStateEnum.HomeSick; } break; case PlayerStateEnum.Backhome: break; } }
public void DataReset() { playerState = PlayerStateEnum.AtHome; }
/// <summary> /// Sets the stored state to the specified state /// </summary> /// <param name="value">The current state to set</param> public void SetState(PlayerStateEnum value) { _state = value; }
protected void ChangeState(PlayerStateEnum newState) { _playerInput = null; _selfTransition = ((int)newState == AnimatorCommon.GetState(_animator)); AnimatorCommon.SetState(_animator, (int)newState); }