Esempio n. 1
0
    public static Vector2Int AddRoom(this Dictionary <Vector2Int, OpenDoors> grid, Vector2Int position, Room.PlayerExit direction)
    {
        if (!grid.ContainsKey(position))
        {
            OpenDoors doors = new OpenDoors();
            doors.OpenDoor(direction);
            grid.Add(position, doors);
        }
        else
        {
            var doors = grid[position];
            doors.OpenDoor(direction);
            grid[position] = doors;
        }

        var newPosition       = position + GetAddition(direction);
        var oppositeDirection = direction.GetOppositeExit();

        if (!grid.ContainsKey(newPosition))
        {
            OpenDoors newDoors = new OpenDoors(oppositeDirection);
            grid.Add(newPosition, newDoors);
        }
        else
        {
            var doors = grid[newPosition];
            doors.OpenDoor(oppositeDirection);
            grid[newPosition] = doors;
        }

        //Debug.Log("" + position + ": " + direction + ": " + newPosition);
        return(newPosition);
    }
Esempio n. 2
0
    private void OnTriggerEnter2D(Collider2D collider)
    {
        Key key = collider.GetComponent <Key>();

        if (key != null)
        {
            AddKey(key.GetKeyType());
            Destroy(key.gameObject);
        }

        OpenDoors keyDoor = collider.GetComponent <OpenDoors>();

        if (keyDoor != null)
        {
            if (ContainsKey(keyDoor.GetKeyType()))
            {
                RemoveKey(keyDoor.GetKeyType());
                keyDoor.OpenDoor();
            }
        }
    }