/// <summary> /// The default behaviour when moving is that the player sprite will either /// be facing left or right (where "left" and "right" depend on whether the /// movement controls are "normal" or "reversed"). /// </summary> /// <param name="playerController">Player controller.</param> public override void UpdateAnimation(PlayerController playerController) { PlayerControlBehavior playerControlBehavior = playerController.PlayerControlBehavior; int animationState = 0; switch (playerControlBehavior) { case PlayerControlBehavior.NORMAL: if (playerController.CurrentDirection == GameConstants.RIGHT) { animationState = GameConstants.ANIMATION_WALK_RIGHT; } else if (playerController.CurrentDirection == GameConstants.LEFT) { animationState = GameConstants.ANIMATION_WALK_LEFT; } break; case PlayerControlBehavior.REVERSED: if (playerController.CurrentDirection == GameConstants.RIGHT) { animationState = GameConstants.ANIMATION_WALK_LEFT; } else if (playerController.CurrentDirection == GameConstants.LEFT) { animationState = GameConstants.ANIMATION_WALK_RIGHT; } break; } changeAnimationState(playerController, animationState); }
private void SetDirection() { // in a similar manner to the playercontroller, the direction of the weapon // is controlled by rotating the transform. if (playerController != null) { PlayerControlBehavior playerControlBehavior = playerController.PlayerControlBehavior; float lookRight = 0f; float lookLeft = 180f; switch (playerControlBehavior) { case PlayerControlBehavior.NORMAL: lookRight = 0f; lookLeft = 180f; break; case PlayerControlBehavior.REVERSED: lookRight = 180f; lookLeft = 0f; break; } // if player direction has changed if (playerController.CurrentDirection != prevDirection) { // rotate the weapon transform accordingly if (playerController.CurrentDirection == GameConstants.RIGHT) { if (transform.rotation.y != lookRight) { transform.Rotate(0, 180, 0); prevDirection = playerController.CurrentDirection; } } else if (playerController.CurrentDirection == GameConstants.LEFT) { if (transform.rotation.y != lookLeft) { transform.Rotate(0, 180, 0); prevDirection = playerController.CurrentDirection; } } } } }
protected void moveLeft(PlayerController playerController) { Transform transform = playerController.Transform; PlayerControlBehavior playerControlBehavior = playerController.PlayerControlBehavior; Vector3 left = Vector3.left; switch (playerControlBehavior) { case PlayerControlBehavior.REVERSED: left = Vector3.right; break; } transform.Translate(left * getWalkRate(playerController) * Time.fixedDeltaTime); }
private void setupRoomPhysics(string[] bits) { float creatureSpeedMultipler = float.Parse(bits[1]); float playerSpeedMultiplier = float.Parse(bits[2]); float gravityXMultiplier = float.Parse(bits[3]); float gravityYMultiplier = float.Parse(bits[4]); PlayerControlBehavior playerControlBehaviour = ParseEnum <PlayerControlBehavior>(bits[5]); Vector2 gravity = Physics2D.gravity; Physics2D.gravity = new Vector2(gravity.x * gravityXMultiplier, gravity.y * gravityYMultiplier); this.currentRoom.CreatureSpeedMultiplier = creatureSpeedMultipler; this.currentRoom.PlayerSpeedMultiplier = playerSpeedMultiplier; this.currentRoom.GravityXMultiplier = gravityXMultiplier; this.currentRoom.GravityYMultiplier = gravityYMultiplier; this.currentRoom.PlayerControlBehavior = playerControlBehaviour; }
protected void jumpLeft(PlayerController playerController) { Rigidbody2D rigidbody2D = playerController.Rigidbody2D; PlayerControlBehavior playerControlBehavior = playerController.PlayerControlBehavior; Vector2 up = -1 * Mathf.Sign(Physics2D.gravity.y) * Vector2.up; Vector2 left = Vector2.left; switch (playerControlBehavior) { case PlayerControlBehavior.REVERSED: left = Vector2.right; break; } rigidbody2D.velocity = left * getJumpRateX(playerController) + up * getJumpRateY(playerController); }
// Use this for initialization void Start() { this.animator = this.GetComponent <Animator>(); this.rb = this.GetComponent <Rigidbody2D>(); this.playerDiedEvent = new PlayerDiedEvent(); EventManager.AddPlayerDiedInvoker(this); EventManager.AddNextRoomListener(leftRoom); // Player starts the room standing at the start position this.startPosition = transform.position; this.currentPlayerState = PlayerState.STANDING; IRoom currentRoom = Camera.main.GetComponent <RoomBuilder>().CurrentRoom; this.playerSpeedMultiplier = currentRoom.PlayerSpeedMultiplier; this.playerControlBehavior = currentRoom.PlayerControlBehavior; Vector2 playerSize = this.GetComponent <SpriteRenderer>().size; this.distToGround = playerSize.y / 2; this.halfWidth = playerSize.x / 2; // set sprite orientation based on gravity direction float gravityDirection = Mathf.Sign(Physics2D.gravity.y); if (gravityDirection > 0f) { this.transform.Rotate(180, 0, 0); } this.trailRenderer = GetComponent <TrailRenderer>(); this.gameState = Camera.main.GetComponent <GameState>(); if (this.gameState.PlayerHasTheWeapon) { this.gameState.AddWeaponToPlayer(false); } this.commandHandler = this.gameState.GetCommandHandler(); }