public void setFacing(PlayerFacing newPlayerFacing) { if (newPlayerFacing != currentPlayerFacing) { currentPlayerFacing = newPlayerFacing; } }
void PlayerDirection(float x, float y) { if (x != 0) { if (x < 0) { facing = PlayerFacing.LEFT; } else { facing = PlayerFacing.RIGHT; } } else if (y != 0) { if (y < 0) { facing = PlayerFacing.DOWN; } else { facing = PlayerFacing.UP; } } }
void GetOrientation() { float angle = GetAngle(); if (angle <= 45 && angle > -45) { facing = PlayerFacing.Right; } else if (angle <= 135 && angle >= 45) { facing = PlayerFacing.Top; } else if (angle <= -135 && angle > 180 || angle >= -180 && angle < -135) { facing = PlayerFacing.Left; } else if (angle <= -45 && angle > -135) { facing = PlayerFacing.Bottom; } //print angle; }
public void MoveRight() { action = PlayerAction.Walking; playerFacing = PlayerFacing.Right; playerTile.SetFacing(playerFacing); playerTile.SetAction(action); Translate(new Vector2(Constants.playerMoveAmount, 0)); }
public void MoveDown() { action = PlayerAction.Walking; playerFacing = PlayerFacing.Front; playerTile.SetFacing(playerFacing); playerTile.SetAction(action); Translate(new Vector2(0, -Constants.playerMoveAmount)); }
public void SneakRight() { action = PlayerAction.Sneaking; playerFacing = PlayerFacing.Right; playerTile.SetFacing(playerFacing); playerTile.SetAction(action); Translate(new Vector2(Constants.playerSneakAmount, 0)); }
// Start is called before the first frame update void Start() { facing = PlayerFacing.DOWN; playerMoveTrue = false; PLAYER_SPEED = speed; WOLF_SPEED = speed * 1.35f; multiplier = 3; }
public void SneakUp() { action = PlayerAction.Sneaking; playerFacing = PlayerFacing.Back; playerTile.SetFacing(playerFacing); playerTile.SetAction(action); Translate(new Vector2(0, Constants.playerSneakAmount)); }
void Start() { playerFacing = GetComponent <PlayerFacing>(); playerControls = GetComponent <PlayerControls>(); playerMovement = GetComponent <PlayerMovement>(); anim = GetComponent <Animator> (); hitboxLength = hitboxManager.Length; stance_timeStamp = Time.time; }
void Start() { playerGraphic = GetComponent <SpriteRenderer>(); SetSprite("player_standMid"); playerFacing = PlayerFacing.MID; playerJumping = false; playerCatchFood = false; jumpWalkingPower = 0; }
// Use this for initialization void Start() { playerControls = GetComponent <PlayerControls>(); playerFacing = GetComponent <PlayerFacing>(); playerBody = GetComponent <Rigidbody2D>(); dodgeCoolTimeStamp = Time.time; dodgeLenTimeStamp = Time.time; attackCoolTimeStamp = Time.time; attack1LenTimeStamp = Time.time; attack2LenTimeStamp = Time.time; attack3LenTimeStamp = Time.time; }
public void SetPlayerFacing(PlayerFacing playerFacing) { currentPlayerFacing = playerFacing; if (playerFacing == PlayerFacing.UP) { m_transform.eulerAngles = new Vector3(0, 0, 0); } else if (playerFacing == PlayerFacing.RIGHT) { m_transform.eulerAngles = new Vector3(0, 90, 0); } else if (playerFacing == PlayerFacing.DOWN) { m_transform.eulerAngles = new Vector3(0, 180, 0); } else if (playerFacing == PlayerFacing.LEFT) { m_transform.eulerAngles = new Vector3(0, 270, 0); } }
//[System.Obsolete] void OnCollisionStay2D(Collision2D collision) { if ("Ground".Equals(collision.gameObject.name)) { playerJumping = false; } if ("Food(Clone)".Equals(collision.gameObject.name) && !playerCatchFood) { ScoreManager.Instance.AddToScore(10); addScorelLabel.text = "+ 10"; playerCatchFood = true; rb.isKinematic = true; rb.constraints = RigidbodyConstraints2D.FreezePosition | RigidbodyConstraints2D.FreezeRotation; SetSprite("player_jumpMid"); collision.gameObject.transform.SetParent(gameObject.transform); Destroy(collision.gameObject.GetComponent <Rigidbody2D>()); playerFacing = PlayerFacing.MID; collision.gameObject.transform.position = gameObject.transform.Find("CatchPosition").transform.position; CountDownTimer.GetInstance().CountDown("addScorelLabel_timer", 1f, () => { addScorelLabel.text = ""; }); CountDownTimer.GetInstance().CountDown("playerFall_timer", 0.3f, () => { rb.isKinematic = false; rb.constraints = RigidbodyConstraints2D.None | RigidbodyConstraints2D.FreezeRotation; SetSprite("player_StandMid"); collision.gameObject.transform.position = gameObject.transform.Find("FoodPosition").transform.position; eatAudio.PlayDelayed(0.8f); }); CountDownTimer.GetInstance().CountDown("eatingFood_Timer", 3.2f, () => { playerCatchFood = false; Destroy(gameObject.transform.Find("Food(Clone)").gameObject); }); } }
// Use this for initialization void Start() { playerFacing = GameObject.Find("Player").GetComponent <PlayerFacing>(); }
private void handleWalkAndJump(bool jump, bool left, bool right) { if (jump && !playerJumping && !playerCatchFood) { playerJumping = true; if (left) { rb.velocity = Vector2.up * (jumpVelocity + jumpWalkingPower); SetSprite("player_jumpL01"); playerFacing = PlayerFacing.LEFT; } else if (right) { rb.velocity = Vector2.up * (jumpVelocity + jumpWalkingPower); SetSprite("player_jumpR01"); playerFacing = PlayerFacing.RIGHT; } else { rb.velocity = Vector2.up * (jumpVelocity + jumpWalkingPower); SetSprite("player_jumpMid"); playerFacing = PlayerFacing.MID; } jumpAudio.Play(); } else { if (left && !playerCatchFood) { rb.velocity = new Vector2(-1 * speed, rb.velocity.y); if (!playerJumping) { SetSprite("player_walkL01"); jumpWalkingPower += 0.02f; } playerFacing = PlayerFacing.LEFT; } else if (right && !playerCatchFood) { rb.velocity = new Vector2(1 * speed, rb.velocity.y); if (!playerJumping) { SetSprite("player_walkR01"); jumpWalkingPower += 0.02f; } playerFacing = PlayerFacing.RIGHT; } else { jumpWalkingPower = 0; switch (playerFacing) { case PlayerFacing.LEFT: if (!playerJumping) { SetSprite("player_standL"); } break; case PlayerFacing.RIGHT: if (!playerJumping) { SetSprite("player_standR"); } break; case PlayerFacing.MID: if (!playerJumping) { SetSprite("player_standMid"); } break; } } } }
//Movement //For the time being there will be keyboard controls, ultimately aiming for 4 Controllers void Move() { if (m_playerState != PlayerState.ATTACK) { m_playerState = PlayerState.IDLE; } //Up if (Input.GetKey(KeyCode.W)) { position.y += 0.1f; } //Down if (Input.GetKey(KeyCode.S)) { position.y -= 0.1f; } //Left if (Input.GetKey(KeyCode.A)) { position.x -= 0.1f; } //Right if (Input.GetKey(KeyCode.D)) { position.x += 0.1f; } //Gamepad Input float horizontalInput = Input.GetAxis(controller + "Horizontal"); float verticalInput = Input.GetAxis(controller + "Vertical"); if (horizontalInput >= 0.1 || horizontalInput <= -0.1) { m_playerState = PlayerState.WALK; position.x += horizontalInput / 10; if (!isSword) { input.x = horizontalInput / 10; } if (horizontalInput <= -0.15) { m_facing = PlayerFacing.LEFT; } if (horizontalInput >= 0.15) { m_facing = PlayerFacing.RIGHT; } forward = new Vector3(Mathf.Cos(forward.x), Mathf.Sin(forward.x), 0.0f); } if (verticalInput >= 0.1 || verticalInput <= -0.1) { m_playerState = PlayerState.WALK; position.y += -verticalInput / 10; if (!isSword) { input.y = -verticalInput / 10; } if (-verticalInput <= -0.15) { m_facing = PlayerFacing.DOWN; } if (-verticalInput >= 0.15) { m_facing = PlayerFacing.UP; } } input.Normalize(); StayOnScreen(); this.transform.position = position; Sword.transform.position = new Vector3(transform.position.x + (input.x * swordDistance), transform.position.y + (input.y * swordDistance), 0.0f); Sword.transform.rotation = transform.rotation * Quaternion.Euler(new Vector3(0, 0, 90.0f)); }
public void SetFacing(PlayerFacing facing) { playerFacing = facing; }
void Start() { playerControls = GetComponent <PlayerControls>(); playerFacing = GetComponent <PlayerFacing>(); playerBody = GetComponent <Rigidbody2D>(); }
// Update is called once per frame void Update() { if (frozen) { return; } if (Input.GetKey(KeyCode.W)) { direction = PlayerFacing.Up; if (!isMoving) { direction = PlayerFacing.Up; StartCoroutine(MoveToTile((Vector2)transform.position + new Vector2(0, 1))); } } if (Input.GetKey(KeyCode.A)) { if (!isMoving) { direction = PlayerFacing.Left; StartCoroutine(MoveToTile((Vector2)transform.position + new Vector2(-1, 0))); } } if (Input.GetKey(KeyCode.S)) { if (!isMoving) { direction = PlayerFacing.Down; StartCoroutine(MoveToTile((Vector2)transform.position + new Vector2(0, -1))); } } if (Input.GetKey(KeyCode.D)) { if (!isMoving) { direction = PlayerFacing.Right; StartCoroutine(MoveToTile((Vector2)transform.position + new Vector2(1, 0))); } } if (isMoving) { ChangeAnimationState("walk_" + direction.ToString().ToLower()); } else { ChangeAnimationState("stand_" + direction.ToString().ToLower()); } //check for interactions if (Input.GetKeyDown(KeyCode.Z) && !isMoving) { Debug.Log("Checking"); Vector2 location = transform.position; switch (direction) { case PlayerFacing.Up: location += Vector2.up; break; case PlayerFacing.Down: location += Vector2.down; break; case PlayerFacing.Left: location += Vector2.left; break; case PlayerFacing.Right: location += Vector2.right; break; } OverworldObject[] overworldObjects = GameObject.FindObjectsOfType <OverworldObject>(); foreach (OverworldObject oObject in overworldObjects) { if (location == (Vector2)oObject.transform.position) { oObject.OnInteract(); } } } }