//Called when the Door Collider has it's CollisionStay2D triggered. //Called whenever any object is touching the door. public void CollisionStay(Collision2D other) { if (door == null) { return; } // Need to check if the player is going towards the door. if (other.gameObject.GetComponent <Player>() && door.state == Door.DoorState.locked) { GameObject player = other.gameObject; bool correctKey = player.GetComponent <PlayerInventory>(). KeyInInventory(door.color); Cardinal4.Direction playerDirection = Cardinal4.Vector2ToDirection(player.GetComponent <Player>().GetPlayerDirectionVector()); bool playerGoingTowardsDoor = (playerDirection == direction); if (currentUnlockDelay <= 0 && playerGoingTowardsDoor && correctKey) { door.ChangeState(Door.DoorState.open); } else if (playerGoingTowardsDoor && correctKey) { currentUnlockDelay -= 1 * Time.deltaTime; } else { currentUnlockDelay = unlockDelay; } } }
IEnumerator DoorAnimation() { // Freezes player movement player.FreezePlayer(); // Instantiates the NextRoom RoomGenerator newRoomGenerator = FindObjectOfType <DungeonDisplay>() .InstantiateRoom(door.GetNextRoom(currentRoom.GetCurrentRoom())); // Disables Door Animations For the new Room newRoomGenerator.EnableDoorAnimations(false); // Changes the player animation to walk in appropreate direction. if (direction == Cardinal4.Direction.NORTH) { playerAnimator.SetFloat("deltaX", 0); playerAnimator.SetFloat("deltaY", 1); } else if (direction == Cardinal4.Direction.SOUTH) { playerAnimator.SetFloat("deltaX", 0); playerAnimator.SetFloat("deltaY", -1); } //Move player into the door Coroutine a = StartCoroutine(player.MovePlayerToPoint( (Vector2)this.transform.position, player.GetSpeed())); yield return(a); //Update the current room Room nextRoom = door.GetNextRoom(currentRoom.GetCurrentRoom()); currentRoom.SetCurrentRoom(nextRoom); //Moves camera to new room Coroutine b = StartCoroutine(mainCamera.MoveCameraToNewRoom( currentRoom.GetCurrentRoom(), cameraMovementTime)); yield return(b); // Move player out of the door into the room Coroutine c = StartCoroutine(player.MovePlayerToPoint( (Vector2)this.transform.position + Cardinal4.DirectionToVector2(direction, distanceFromDoor), player.GetSpeed())); yield return(c); // Enable Door Animations for the Next Room newRoomGenerator.EnableDoorAnimations(true); // Allow for Player Movement player.UnfreezePlayer(); // Destroy current RoomGenerator Destroy(currentRoomGenerator.gameObject); }
private void DisplayDoor(Door door) { Room nextRoom = door.GetNextRoom(room); Vector2 vectorBetweenRooms = nextRoom.roomCoordinate.GetVector2() - room.roomCoordinate.GetVector2(); Cardinal4.Direction direction = Cardinal4.Vector2ToDirection(vectorBetweenRooms); doors[(int)direction].DisplayDoor(); }
public static Vector3 ToVector3XZ(this Cardinal4 cardinal) { switch (cardinal) { case Cardinal4.Up: return(Vector3.forward); case Cardinal4.Down: return(-Vector3.forward); case Cardinal4.Left: return(-Vector3.right); case Cardinal4.Right: return(Vector3.right); } throw new ArgumentException(); }
public static float Angle(this Cardinal4 cardinal) { switch (cardinal) { case Cardinal4.Up: return(0f); case Cardinal4.Down: return(180f); case Cardinal4.Left: return(270f); case Cardinal4.Right: return(90f); } throw new ArgumentException(); }
/// <summary> /// Returns this Cardinal4 as a Cardinal8. /// </summary> /// <returns>This Cardinal4 as a Cardinal8</returns> public static Cardinal8 ToCardinal8(this Cardinal4 cardinal) { switch (cardinal) { case Cardinal4.Up: return(Cardinal8.North); case Cardinal4.Down: return(Cardinal8.South); case Cardinal4.Left: return(Cardinal8.West); case Cardinal4.Right: return(Cardinal8.East); } throw new ArgumentException(); }
private void GenerateDoor(Door door) { Room nextRoom = door.GetNextRoom(room); Vector2 vectorBetweenRooms = nextRoom.roomCoordinate.GetVector2() - room.roomCoordinate.GetVector2(); Cardinal4.Direction direction = Cardinal4.Vector2ToDirection(vectorBetweenRooms); DoorDisplay doorDisplay = Array.Find(doorDisplays, element => element.direction == direction); doorDisplay.door = door; door.doorDisplay = doorDisplay; }
/// <summary> /// Returns this cardinal rotated anti-clockwise by a certain number of 90 degree rotations. /// </summary> /// <param name="rotations">The number of 90 degree rotations to perform</param> /// <returns>The rotated cardinal</returns> public static Cardinal4 RotatedAntiClockwise(this Cardinal4 cardinal, int rotations = 1) { return((Cardinal4)MathUtils.Wrap((int)cardinal - rotations, 0, 3)); }
public static Cardinal4 Reverse(this Cardinal4 cardinal) { int index = (int)cardinal + 2; return((Cardinal4)(index > 3 ? index - 4 : index)); }