Exemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        Castle castle = new Castle(CASTLE_WIDTH, CASTLE_HEIGHT, 5);

        Debug.Log("---CastleTileGeneration---");
        for (int y = 0; y < CASTLE_HEIGHT; y++)
        {
            for (int x = 0; x < CASTLE_WIDTH; x++)
            {
                #region exitCreation
                Vector3    exitPosition;
                GameObject roomGameObject  = Instantiate(roomPrefab, new Vector3(x * 6, y * 6), Quaternion.identity);
                string[]   directionsNames = new string[4] {
                    "Up", "Right", "Down", "Left"
                };
                Debug.Log("création de la salle" + "(" + x + ";" + y + ")");
                CastleRoom room = castle.GetRoom(x, y);
                Debug.Log("ouvertures de la salle:" + room.ToString());


                for (int i = 0; i <= 3; i++)
                {
                    if (room.exits[i] != Constants.NO_EXIT)
                    {
                        exitPosition = roomGameObject.transform.Find(directionsNames[i]).transform.position;
                        Destroy(roomGameObject.transform.Find(directionsNames[i]).gameObject);
                        GameObject door = Instantiate(GetPrefab(room.exits[i]), exitPosition, Quaternion.identity, roomGameObject.transform);
                        if (room.exits[i] == Constants.LOCKED_DOOR)
                        {
                            LockedDoorScript doorScript = door.GetComponent <LockedDoorScript>();
                            doorScript.SetId(room.lockedDoorsIDs[i]);
                        }
                    }

                    if (room.isGenerated)//////debuuuuug
                    {
                        exitPosition = roomGameObject.transform.Find("middlePoint").transform.position;
                        Destroy(roomGameObject.transform.Find("middlePoint").gameObject);
                        Instantiate(debugPrefab, exitPosition, Quaternion.identity, roomGameObject.transform);
                    }
                    #endregion
                    #region keysCreation
                    if (room.keys.Count > 0)
                    {
                        Vector3 keyPosition = roomGameObject.transform.Find("keyLocation").transform.position;
                        Destroy(roomGameObject.transform.Find("keyLocation").gameObject);
                        Instantiate(keyPrefab, keyPosition, Quaternion.identity, roomGameObject.transform);
                        Debug.Log("clef posée en " + x + " " + y);
                    }
                    #endregion
                }
            }
        }
    }
Exemplo n.º 2
0
    void PlaceDoor(Vector2 pos, Color color)
    {
        GameObject newDoor = Instantiate(doorPrefab, pos, Quaternion.identity) as GameObject;

        print(pos);
        LockedDoorScript doorScript = newDoor.GetComponent <LockedDoorScript>();

        doorScript.player = player;
        doorScript.SetColor(color);
        doorScript.AdjustSprite(tiles, pos);
    }