Beispiel #1
0
        Defs.Direction ChangeDirectionRight(Defs.Direction currentDirection)
        {
            int dirInt = System.Convert.ToInt32(currentDirection);

            dirInt = (dirInt + 1) % Defs.Facings.Count;
            return((Defs.Direction)dirInt);
        }
Beispiel #2
0
        void OnBeat(object sender, EventArgs e)
        {
            ++m_currentCellIndex;
            if (m_currentCellIndex >= m_dungeon.GetCellCount() - 1)
            {
                m_currentCellIndex = 0;
            }

            Cell currentCell = m_dungeon.GetCellAtIndex(m_currentCellIndex);

            StartCoroutine(MoveTo(transform, new Vector3(currentCell.x, 0.25f, currentCell.y), 0.125f));

            if (m_currentCellIndex < m_dungeon.GetCellCount() - 1)
            {
                Cell             nextCell  = m_dungeon.GetCellAtIndex(m_currentCellIndex + 1);
                CoordinateOffset offset    = CoordinateOffset.Create(nextCell.x - currentCell.x, nextCell.y - currentCell.y);
                Defs.Direction   direction = Defs.Direction.Forwards;
                foreach (var entry in Defs.Facings)
                {
                    if (entry.Value == offset)
                    {
                        direction = entry.Key;
                        break;
                    }
                }

                float targetAngle = 0.0f;
                switch (direction)
                {
                case Defs.Direction.Forwards:
                    targetAngle = 0.0f;
                    break;

                case Defs.Direction.Right:
                    targetAngle = 90.0f;
                    break;

                case Defs.Direction.Backwards:
                    targetAngle = 180.0f;
                    break;

                case Defs.Direction.Left:
                    targetAngle = 270.0f;
                    break;
                }

                StartCoroutine(RotateTo(transform, targetAngle, 0.125f));
            }
            else if (m_currentCellIndex == m_dungeon.GetCellCount() - 1)
            {
            }
        }
Beispiel #3
0
        void BuildDungeon()
        {
            // First generate path for the floor and block out all surrounding walls
            Defs.Direction currentDirection = Defs.Direction.Forwards;
            Cell           currentPosition;

            currentPosition.x = 0;
            currentPosition.y = 0;
            AddCellAtPosition(currentPosition.x, currentPosition.y);

            for (int i = 0; i < m_settings.segmentCount; ++i)
            {
                CoordinateOffset offset;
                Defs.Facings.TryGetValue(currentDirection, out offset);

                int length = m_rng.Next(m_settings.minSegmentLength, m_settings.maxSegmentLength);
                for (int j = 0; j < length; ++j)
                {
                    offset.Apply(ref currentPosition);
                    AddCellAtPosition(currentPosition.x, currentPosition.y);
                }

                if (i < m_settings.segmentCount - 1)
                {
                    int directionChange = m_rng.Next(2);
                    if (directionChange == 0)
                    {
                        currentDirection = ChangeDirectionLeft(currentDirection);
                    }
                    else if (directionChange == 1)
                    {
                        currentDirection = ChangeDirectionRight(currentDirection);
                    }
                }
            }

            // Generate floors, tunnelling through the walls with all overlapping cells
            foreach (var entry in m_floorCells)
            {
                CreateFloor(entry);
                m_wallCells.Remove(entry);
            }

            // Generate walls
            foreach (var entry in m_wallCells)
            {
                CreateWall(entry);
            }

            // Find valid locations to spawn enemies
            float       range                = m_settings.maxEnemyPopulation - m_settings.minEnemyPopulation;
            float       enemyPopulation      = m_settings.minEnemyPopulation + System.Convert.ToSingle(m_rng.NextDouble()) * range;
            int         enemiesToSpawn       = System.Convert.ToInt32(m_floorCells.Count * enemyPopulation);
            List <Cell> enemyLocationChoices = new List <Cell>();

            foreach (var cell in m_floorCells)
            {
                enemyLocationChoices.Add(cell);
            }

            // Remove starting tiles from list of location choices
            for (int i = 0; i < 5; ++i)
            {
                var cell = m_dungeon.GetCellAtIndex(i);
                enemyLocationChoices.Remove(cell);
            }

            // Spawn Enemies
            for (int i = 0; i < enemiesToSpawn; ++i)
            {
                int index = m_rng.Next(enemyLocationChoices.Count);
                var type  = (m_rng.Next(2) == 0) ? Enemy.EnemyType.Magic : Enemy.EnemyType.Melee;
                var enemy = m_enemyFactory.CreateEnemy(enemyLocationChoices[index], type);
                enemy.transform.SetParent(transform, false);
                m_dungeon.AddEnemyAtCell(enemyLocationChoices[index], enemy);
                enemyLocationChoices.RemoveAt(index);
            }
        }