Beispiel #1
0
    /// <summary>
    /// A 1/3 chance de générer une pièce annexe au chemin principale dans une direction aléatoire.
    /// Si la pièce est déjà générée, on crée une porte à sens unique pour la rejoindre.
    /// </summary>
    /// <returns>
    /// true si une piece annexe ou une porte a sens unique a été crée, sinon false.
    /// </returns>

    private bool GenerateAnnexPath(int castleWidth, int castleHeight)
    {
        if (Constants.RANDOM.Next(3) == 0)
        {
            Vector2Int[] possibleDirections = new Vector2Int[] { Vector2Int.left, Vector2Int.up, Vector2Int.right, Vector2Int.down };
            Vector2Int   choosenDirection   = HomeMadeFunctions.GetRandom(possibleDirections);
            Vector2Int   annexPathPosition  = choosenDirection + actualMainRoomPosition;
            Debug.Log("position de la piece annexe: " + annexPathPosition + " " + actualMainRoomPosition);
            if (!IsInBounds(annexPathPosition, castleWidth, castleHeight) || annexPathPosition == oldRoomPosition)
            //si la piece annexe est en dehors des limites du chateau ou qu'elle retourne sur les pas de la génération du chemin principale
            {
                return(false);
            }
            CastleRoom AnnexRoom = rooms[annexPathPosition.x, annexPathPosition.y];

            if (AnnexRoom.isGenerated)
            {
                Debug.Log("porte sens unique créé en position:" + actualMainRoomPosition);
                rooms[actualMainRoomPosition.x, actualMainRoomPosition.y].CreateOneWayDoor(true, choosenDirection);
                //Castle[annexPathPosition.x, annexPathPosition.y].CreateOneWayDoor(false, choosenDirection);
            }
            else
            {
                GenerateAnnexRoom(annexPathPosition);
                AnnexRoom.Generate(keysToInstall);
                Debug.Log("piece annexe crée: " + annexPathPosition);
            }
            return(true);
        }
        return(false);
    }
Beispiel #2
0
 private SpriteRenderer spriteRenderer;/*
                                        * void Start()
                                        * {
                                        * spriteRenderer = GetComponent<SpriteRenderer>();
                                        * }*/
 public void SetId(int ID)
 {
     Debug.LogWarning(ID);
     spriteRenderer.color = new Color(0, HomeMadeFunctions.Map(0f, 1f, -1, 5, ID), 0);
 }
Beispiel #3
0
    /// <summary>
    /// Génère la prochaine piece du chemin principale
    /// </summary>
    /// <returns>retourne true par défaut et false si la génération du chemin est terminée</returns>
    private bool GenerateMainPath(int castleWidth, int castleHeight)
    {
        Debug.Log("room en cours de création:" + actualMainRoomPosition);
        bool isRoomGenerated = false;

        while (!isRoomGenerated)//tant qu'aucune nouvelle pièce n'a été crée:
        {
            Debug.Log("nbr de directions possibles:");
            Debug.Log(allowedGenerationDirection.Count);
            //choisis une direction au hasard
            Vector2Int generationDirection = HomeMadeFunctions.GetRandom(allowedGenerationDirection);
            Vector2Int nextRoomPosition    = generationDirection + actualMainRoomPosition;
            if (IsInBounds(nextRoomPosition, castleWidth, castleHeight) && !(rooms[nextRoomPosition.x, nextRoomPosition.y].isGenerated))
            //si la future pièce ne dépasse pas les limites du chateau et si la piece n'a pas déjà été générée:
            {
                //a de chances de bloquer le chemin principale si nécessaire
                if (blockMainPath != 0 && Constants.RANDOM.NextDouble() > 1f / (blockMainPath) / 1.10f)
                {
                    //bloque le chemin principale
                    rooms[actualMainRoomPosition.x, actualMainRoomPosition.y].CreateLockedDoor(-1, generationDirection);
                    Debug.Log("chemin principale bloqué");
                    blockMainPath--;
                }
                else
                {
                    rooms[actualMainRoomPosition.x, actualMainRoomPosition.y].CreateHoleExit(generationDirection);
                }

                //créé la prochaine pièce et la relie avec l'actuelle
                rooms[nextRoomPosition.x, nextRoomPosition.y].CreateHoleExit(generationDirection * (-1));
                rooms[nextRoomPosition.x, nextRoomPosition.y].Generate(keysToInstall);

                Debug.Log("sortie de " + actualMainRoomPosition + ":" + rooms[actualMainRoomPosition.x, actualMainRoomPosition.y].ToString());

                oldRoomPosition        = actualMainRoomPosition;
                actualMainRoomPosition = nextRoomPosition;
                //re-remplis la liste des directions possible
                allowedGenerationDirection = new List <Vector2Int>();
                allowedGenerationDirection.Add(Vector2Int.left);
                allowedGenerationDirection.Add(Vector2Int.up);
                allowedGenerationDirection.Add(Vector2Int.right);
                allowedGenerationDirection.Add(Vector2Int.down);

                //empeche la génération de revenir en arrière en interdisant cette direction
                allowedGenerationDirection.Remove(generationDirection * (-1));

                Debug.Log("direction impossible:" + (generationDirection * -1));

                isRoomGenerated = true;
            }
            else
            //sinon on interdit d'aller dans cette direction et on repart pour un tour de boucle
            {
                allowedGenerationDirection.Remove(generationDirection);
                Debug.Log("direction impossible:" + (generationDirection));
                isRoomGenerated = false;
            }
            if (allowedGenerationDirection.Count == 0)
            //si aucune direction n'est possible
            {
                Debug.Log("generation du chemin principale finie!");
                Debug.Log("sortie de " + actualMainRoomPosition + ":" + rooms[actualMainRoomPosition.x, actualMainRoomPosition.y].ToString());
                return(false);
            }
        }
        return(true);
    }