Esempio n. 1
0
 public Floor(Room room)
 {
     gameObject = chooseFloor();
     gameObject.transform.parent        = room.gameObject.transform;
     gameObject.name                    = "Floor";
     gameObject.transform.localPosition = Vector3.zero;
     gameObject.transform.localScale    = Vector3.one;
     gameObject.isStatic                = true;
     gameObject.AddComponent <RoomDetection>();
     roomDetection = gameObject.GetComponent <RoomDetection>();
     roomDetection.setRoom(room);
 }
Esempio n. 2
0
    // Start is called before the first frame update
    void Start()
    {
        //Asignando a cada variable su componente
        RoomDetection = transform.GetComponent <RoomDetection>();
        gameObject.AddComponent <Grid>();
        algorithm = FindObjectOfType <FloorAlgorithm>();

        paco                    = new GameObject();
        paco.name               = "paco";
        paco.transform.parent   = transform;
        paco.transform.position = Vector3.zero;

        tilemap      = paco.AddComponent <Tilemap>();
        Tilerenderer = paco.AddComponent <TilemapRenderer>();
        paco.AddComponent <TilemapCollider2D>();

        ID = RoomDetection.RoomNumber;
        tilemap.tileAnchor = Vector3.zero;

        int Dimensiones = algorithm.Dimensiones;

        Ygen = algorithm.Ygen;

        Tile DaTile = algorithm.Muro_Blank;

        GameObject[] HArray = algorithm.Habitaciones.ToArray();

        for (int y = 0; y < Ygen; y++)
        {
            Vector3Int border = new Vector3Int(Mathf.FloorToInt(HArray[ID].transform.position.x + Dimensiones), Mathf.FloorToInt(HArray[ID].transform.position.y + y), 0);
            tilemap.SetTile(border, DaTile);

            border = new Vector3Int(Mathf.FloorToInt(HArray[ID].transform.position.x + Dimensiones), Mathf.FloorToInt(HArray[ID].transform.position.y - y), 0);
            tilemap.SetTile(border, DaTile);

            border = new Vector3Int(Mathf.FloorToInt(HArray[ID].transform.position.x - Dimensiones), Mathf.FloorToInt(HArray[ID].transform.position.y + y), 0);
            tilemap.SetTile(border, DaTile);

            border = new Vector3Int(Mathf.FloorToInt(HArray[ID].transform.position.x - Dimensiones), Mathf.FloorToInt(HArray[ID].transform.position.y - y), 0);
            tilemap.SetTile(border, DaTile);
        }
        for (int x = 0; x < (Dimensiones); x++)
        {
            Vector3Int border = new Vector3Int(Mathf.FloorToInt(HArray[ID].transform.position.x + x), Mathf.FloorToInt(HArray[ID].transform.position.y + Ygen), 0);
            tilemap.SetTile(border, DaTile);

            border = new Vector3Int(Mathf.FloorToInt(HArray[ID].transform.position.x + x), Mathf.FloorToInt(HArray[ID].transform.position.y - Ygen), 0);
            tilemap.SetTile(border, DaTile);

            border = new Vector3Int(Mathf.FloorToInt(HArray[ID].transform.position.x - x), Mathf.FloorToInt(HArray[ID].transform.position.y + Ygen), 0);
            tilemap.SetTile(border, DaTile);

            border = new Vector3Int(Mathf.FloorToInt(HArray[ID].transform.position.x - x), Mathf.FloorToInt(HArray[ID].transform.position.y - Ygen), 0);
            tilemap.SetTile(border, DaTile);
        }

        for (int e = 0; e < 4; e++)
        {
            Vector3Int border = new Vector3Int(Mathf.FloorToInt(HArray[ID].transform.position.x - Dimensiones), Mathf.FloorToInt(HArray[ID].transform.position.y + Ygen), 0);
            if (e == 0)
            {
                tilemap.SetTile(border, DaTile);
            }
            if (e == 1)
            {
                border = new Vector3Int(Mathf.FloorToInt(HArray[ID].transform.position.x + Dimensiones), Mathf.FloorToInt(HArray[ID].transform.position.y + Ygen), 0);
                tilemap.SetTile(border, DaTile);
            }
            if (e == 2)
            {
                border = new Vector3Int(Mathf.FloorToInt(HArray[ID].transform.position.x - Dimensiones), Mathf.FloorToInt(HArray[ID].transform.position.y - Ygen), 0);
                tilemap.SetTile(border, DaTile);
            }
            if (e == 3)
            {
                border = new Vector3Int(Mathf.FloorToInt(HArray[ID].transform.position.x + Dimensiones), Mathf.FloorToInt(HArray[ID].transform.position.y - Ygen), 0);
                tilemap.SetTile(border, DaTile);
            }
        }

        start = false;

        StartCoroutine(LateStart());
    }
    public static void Init()
    {
        //jobsList is just jobs on tiles atm
        jobList = new List <Action <Tile, Villager> > ();


        jobList.Add(New);
        jobList [(int)Jobs.Idle] +=
            (Tile tile, Villager v) =>
        {
            //Idle or wandering code, but not for the end of the job
        };


        jobList.Add(New);
        jobList [(int)Jobs.PickUp] +=
            (Tile tile, Villager vil) =>
        {
            vil.Inventory.Carrying = tile.Loose;
            tile.Loose             = null;

            Tile closestAvailableToPlace = InventoryManager.Instance.ClosestAvailableTile(vil.CurrentTile);

            if (closestAvailableToPlace != null)
            {
                JobController.Instance.AddJob(1f /* FIXME */, new Job(closestAvailableToPlace,
                                                                      (Tile t, Villager v) => {
                    PlaceLoose(closestAvailableToPlace, v);
                }),
                                              vil);
            }
        };

        jobList.Add(New);
        jobList [(int)Jobs.PlaceLoose] += PlaceLoose;

        jobList.Add(New);
        jobList [(int)Jobs.StandardInstallBegin] += MoveVillagersOutOfWay;

        jobList.Add(New);
        jobList [(int)Jobs.StandardInstallEnd] += MakeNewGraphicalObject;
        jobList [(int)Jobs.StandardInstallEnd] += (Tile t, Villager v) => {
            foreach (Tile u in t.GetNeighbours())
            {
                RoomDetection.RoomDetect(u, MapController.Instance.Map);
            }
        };

        jobList.Add(New);
        jobList [(int)Jobs.Lock] += MoveVillagersOutOfWay;        //FIXME
        jobList [(int)Jobs.Lock] += ToggleMoveThrough;
        jobList [(int)Jobs.Lock] += (Tile tile, Villager v) => {
            AddGraphic(tile, v, ExtraGraphicalElementHolder.Elements [0]);
        };
        jobList [(int)Jobs.Lock] += (Tile tile, Villager v) => {
            SetActivePossibleJob(tile, v, (int)Jobs.Lock, false);
        };
        jobList [(int)Jobs.Lock] += (Tile tile, Villager v) => {
            SetActivePossibleJob(tile, v, (int)Jobs.Unlock, true);
        };

        jobList.Add(New);
        jobList [(int)Jobs.Unlock] += ToggleMoveThrough;
        jobList [(int)Jobs.Unlock] += RemoveGraphic;
        jobList [(int)Jobs.Unlock] += (Tile tile, Villager v) => {
            SetActivePossibleJob(tile, v, (int)Jobs.Unlock, false);
        };
        jobList [(int)Jobs.Unlock] += (Tile tile, Villager v) => {
            SetActivePossibleJob(
                tile, v, (int)Jobs.Lock, true);
        };

        jobList.Add(New);
        jobList [(int)Jobs.RemoveInstalled] += RemoveGraphic;
        jobList [(int)Jobs.RemoveInstalled] += (Tile t, Villager v) => {
            InstalledObject obj = t.Installed;
            Debug.Log(obj.Name);
            MapController.Instance.DestroyObjectGraphic(t.Installed);
        };

        //End of init
        for (int a = 0; a < jobList.Count; a++)
        {
            jobList[a] += (tile, villager) => {
                JobController.Instance.RemoveJob(tile);
            };
        }
    }