Exemple #1
0
 public void Spawn(GeneratedRoom generatedRoom)
 {
     this.transform.position = new Vector3(
         generatedRoom.position.x * 25,
         0,
         generatedRoom.position.y * 25
         );
 }
 private RectInt GenerateRoom(Vector2Int position, GeneratedRoom from)
 {
     return(new RectInt
            (
                position.x + from.xDisplacement - from.width / 2,
                position.y + from.yDisplacement - from.height / 2,
                from.width,
                from.height
            ));
 }
Exemple #3
0
    /// <summary>
    /// Spawns the provided object and parents it to the currently loaded level
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="original"></param>
    /// <param name="position"></param>
    /// <param name="rotation"></param>
    /// <returns></returns>
    public static T InstantiateInCurrentLevel <T>(T original, Vector3 position, Quaternion?rotation = null) where T : Object
    {
        GeneratedRoom parent    = Object.FindObjectOfType <GeneratedRoom>();
        Transform     transform = null;

        if (parent != null)
        {
            transform = parent.transform;
        }

        return(Object.Instantiate(original, position, rotation ?? Quaternion.identity, transform));
    }
Exemple #4
0
 private void GenerateRoomObjects()
 {
     generatedRooms = new GameObject[columns, rows];
     for (int row = 0; row < rows; row++)
     {
         for (int column = 0; column < columns; column++)
         {
             GameObject generatedRoomGameObject = Instantiate(roomPrefab, new Vector3Int(column * roomWidth, row * roomHeight, 0), Quaternion.identity) as GameObject;
             generatedRoomGameObject.transform.SetParent(transform);
             GeneratedRoom room = generatedRoomGameObject.GetComponent <GeneratedRoom>();
             room.roomRow                = row;
             room.roomColumn             = column;
             room.roomHeight             = roomHeight;
             room.roomWidth              = roomWidth;
             room.levelGenerator         = this;
             generatedRooms[column, row] = generatedRoomGameObject;
         }
     }
 }
    /// <summary>
    /// Generates the next room
    /// </summary>
    public void GenerateNext()
    {
        /*
         * Destroy current room and background
         */
        DestroyImmediate(CurrentRoomObject);
        Destroy(CurrentBackgroundObject);


        /*
         * Create the room configuration
         */
        RoomParameters parameters;
        var            builder = RoomParameterBuilder;

        //Use parameter builder overrides if present
        while (RoomParameterBuilderOverrides.Any())
        {
            if (RoomParameterBuilderOverrides.Peek().HasNext())
            {
                builder = RoomParameterBuilderOverrides.Peek();
                break;
            }

            RoomParameterBuilderOverrides.Pop();
        }

        //Generate parameters with builder
        if (CurrentRoomConfig == null)
        {
            parameters = builder.GetInitialParameters(RoomRng);
        }
        else
        {
            parameters = builder.GetNextParameters(History, RoomRng);
        }

        /*
         * Spawn room
         */
        CurrentRoomObject = Instantiate(parameters.Layout).gameObject;

        //Create generation entry
        GeneratedRoom generatedRoom = CurrentRoomObject.AddComponent <GeneratedRoom>();

        generatedRoom.Parameters = parameters;

        //Add to history
        History.RegisterHistory(parameters);

        /*
         * Spawn background
         */
        if (!parameters.Effect.HasFlag(RoomEffects.Darkness))
        {
            var background = Backgrounds.SingleOrDefault(i => i.Theme == parameters.Theme);

            if (background != null)
            {
                CurrentBackgroundObject = Instantiate(background.Background);
            }
        }

        /*
         * Post-generation setup
         */

        //Reload tilesets
        foreach (Tilemap i in FindObjectsOfType <Tilemap>())
        {
            i.RefreshAllTiles();
        }

        //Clear puzzle keys
        Commons.Inventory.PuzzleKeys = 0;

        //Set optional objects
        foreach (var i in CurrentRoomObject.GetComponentsInChildren <OptionalObjectGroup>())
        {
            i.Select(RoomRng);
        }

        //Spawn enemies
        foreach (var i in CurrentRoomObject.GetComponentsInChildren <EnemySpawnPoint>())
        {
            i.SpawnEnemy(RoomRng, parameters.GroundEnemies, parameters.AirEnemies);
        }

        //Set up room effects
        Commons.RoomEffectController.OnRoomStart(parameters);

        //Flip camera
        FlipCamera.IsFlipped = CurrentRoomConfig.FlipHorizontal;

        if (!parameters.Class.IsSafeRoom())
        {
            //Level up enemies
            if ((CurrentRoomNumber + 1) % EnemyHealthUpFrequency == 0)
            {
                Commons.EnemyProgression.LevelUpHealth();
            }

            if ((CurrentRoomNumber + 1) % EnemyDamageUpFrequency == 0)
            {
                Commons.EnemyProgression.LevelUpDamage();
            }
        }

        //Spawn the player
        FindObjectOfType <Entrance>().SpawnPlayer();

        //Set light level
        if (parameters.Theme == RoomTheme.Cave || parameters.Theme == RoomTheme.Volcano || parameters.Theme == RoomTheme.Snow)
        {
            FindObjectsOfType <Light>().Single(i => i.type == LightType.Directional).intensity = 0.25f;
        }
        else
        {
            FindObjectsOfType <Light>().Single(i => i.type == LightType.Directional).intensity = 1f;
        }

        /*
         *  Add to seconds to speedrun timer
         */

        if (Commons.SpeedRunMode && History.Any())
        {
            var add = parameters.Layout.TimerEffectSeconds;

            if (Commons.CountdownTimer.CurrentSeconds > Mathf.Max(10, 20 - CurrentRoomNumber))
            {
                add *= 0.5f;
            }

            Commons.CountdownTimer.AddTime(add);
        }
    }
 private int NextRoomDistance(GeneratedRoom generatedRoom)
 {
     return(Math.Max(generatedRoom.width, generatedRoom.height) * 2);
 }