Beispiel #1
0
        void AddHakoRandom()
        {
            Vector2Int[] _candi    = new Vector2Int[Data.Size.x * Data.Size.y];
            int          _maxCount = 0;

            int[] _typeCount = new int[] { 0, 0, 0, 0, 0, 0 };
            // 出現位置は:まず、外周以外にランダム。
            for (int x = 1; x < Data.Size.x - 1; x++)
            {
                for (int y = 1; y < Data.Size.y - 1; y++)
                {
                    if (HakoManaer.Instance.Map[x, y] < 0)
                    {
                        _candi[_maxCount] = new Vector2Int(x, y);
                        _maxCount++;
                    }
                    else
                    {
                        _typeCount[(int)HakoManaer.Instance.Hakos[HakoManaer.Instance.Map[x, y]].Type]++;
                    }
                }
            }
            // 出現位置は:つぎに、外周にランダム。
            if (_maxCount <= 0)
            {
                Vector2Int _start = Vector2Int.zero;
                for (int i = 0; i < 4; i++)
                {
                    Vector2Int _dir = HakoManaer.Instance.DirVector(InputManager.GetIntToDir(i));
                    int        _max = i % 2 == 0?Data.Size.y - 1:Data.Size.x - 1;
                    for (int j = 0; j < _max; j++)
                    {
                        Vector2Int _target = _start + _dir * j;
                        if (HakoManaer.Instance.Map[_target.x, _target.y] < 0)
                        {
                            _candi[_maxCount] = _target;
                            _maxCount++;
                        }
                        else
                        {
                            _typeCount[(int)HakoManaer.Instance.Hakos[HakoManaer.Instance.Map[_target.x, _target.y]].Type]++;
                        }
                    }
                    _start += _dir * _max;
                }
            }
            if (_maxCount > 0)
            {
                HakoType _type       = 0;
                int      _typeRandom = 0;
                for (int i = 1; i < 5; i++)
                {
                    _typeRandom += (Data.MaxHakos - _typeCount[i]);
                }
                _typeRandom = Random.Range(0, _typeRandom - 1);
                for (int i = 1; i < 5; i++)
                {
                    _typeRandom -= (Data.MaxHakos - _typeCount[i]);
                    if (_typeRandom < 0)
                    {
                        _type = HakoManaer.Instance.GetIntToType(i);
                        break;
                    }
                }
                Vector2Int _pos = _candi[Random.Range(0, _maxCount)];
                HakoManaer.Instance.AddHako(_type, _pos, 1.0f / Data.AppearTimes[Level]);
            }
        }