Exemple #1
0
        public static Vector2 NextVec2CircularEven(this UnifiedRandom rand, float halfWidth, float halfHeight)
        {
            double x = rand.NextDouble();
            double y = rand.NextDouble();

            if (x + y > 1)
            {
                x = 1 - x;
                y = 1 - y;
            }

            double s = 1 / (x + y);

            if (double.IsNaN(s))
            {
                return(Vector2.Zero);
            }

            s *= s;
            s  = Math.Sqrt(x * x * s + y * y * s);
            s  = 1 / s;

            x *= s;
            y *= s;

            double angle = rand.NextDouble() * (2 * Math.PI);
            double cos   = Math.Cos(angle);
            double sin   = Math.Sin(angle);

            return(new Vector2((float)(x * cos - y * sin) * halfWidth, (float)(x * sin + y * cos) * halfHeight));
        }
Exemple #2
0
        //private Node _build2(Node node, Vector2 pos, Vector2 vel, bool isMain, Vector2 target) {
        //    cnt++;
        //    keyPoints.Add(pos);
        //    // 终止条件:树枝太细了,或者太短了
        //    if (node.size < 0.1f || node.length < 1) return node;
        //    var r2 = (target - pos).ToRotation() - vel.ToRotation();
        //    var r = r2 + rand(MathHelper.Pi / 4f);
        //    Vector2 unit = (vel.ToRotation() + r).ToRotationVector2();
        //    Node main = new Node(rand(r), node.size * 0.95f, node.length);
        //    node.children.Add(_build(main, pos + unit * node.length, unit, isMain, target));
        //    // 只有较小的几率出分支
        //    if (rand() > 0.9f) {
        //        // 生成分支的时候长度变化不大,但是大小变化很大
        //        r = rand(MathHelper.Pi / 3f);
        //        unit = (vel.ToRotation() + r).ToRotationVector2();
        //        Node child = new Node(r, node.size * 0.6f, node.length);
        //        node.children.Add(_build(child, pos + unit * node.length, unit, false, target));
        //    }
        //    return node;
        //}


        //private Node _build(Node node, Vector2 pos, Vector2 vel, bool root) {
        //    keyPoints.Add(pos);
        //    cnt++;
        //    if (node.size < 0.1f || node.length < 1) return node;
        //    var r2 = (target - pos).ToRotation() - vel.ToRotation();
        //    var r = r2 + rand(MathHelper.Pi / 4f);
        //    var unit = (vel.ToRotation() + r).ToRotationVector2();
        //    Node rchild = new Node(r, node.size * 0.9f, node.length);
        //    // 闪电树主节点(树干)
        //    node.children.Add(_build(rchild, pos + unit * node.length, unit, root));
        //    if (root) {
        //        if (rand() > 0.8f) {
        //            for (int i = 0; i < 1; i++) {
        //                r = rand(MathHelper.Pi / 3f);
        //                unit = (vel.ToRotation() + r).ToRotationVector2();
        //                Node child = new Node(r, rand() * node.size * 0.6f, node.length * 0.6f);
        //                node.children.Add(_build(child, pos + unit * node.length, unit, false));
        //            }
        //        }
        //    }
        //    return node;
        //}



        private float rand()
        {
            double u = -2 * Math.Log(random.NextDouble());
            double v = 2 * Math.PI * random.NextDouble();

            return((float)Math.Max(0, Math.Sqrt(u) * Math.Cos(v) * 0.3 + 0.5));
        }
Exemple #3
0
 public void ResetLantern(int i)
 {
     _lanterns[i].Depth             = (1f - (float)i / (float)_lanterns.Length) * 4.4f + 1.6f;
     _lanterns[i].Speed             = -1.5f - 2.5f * (float)_random.NextDouble();
     _lanterns[i].Texture           = _texture.get_Value();
     _lanterns[i].Variant           = _random.Next(3);
     _lanterns[i].TimeUntilFloat    = (int)((float)(2000 + _random.Next(1200)) * 2f);
     _lanterns[i].TimeUntilFloatMax = _lanterns[i].TimeUntilFloat;
 }
 public void ResetBalloon(int i)
 {
     _balloons[i].Depth   = (float)i / (float)_balloons.Length * 1.75f + 1.6f;
     _balloons[i].Speed   = -1.5f - 2.5f * (float)_random.NextDouble();
     _balloons[i].Texture = _textures[_random.Next(2)].Value;
     _balloons[i].Variant = _random.Next(3);
     if (_random.Next(30) == 0)
     {
         _balloons[i].Texture = _textures[2].Value;
     }
 }
Exemple #5
0
 private void GenerateSlimes()
 {
     _slimes = new Slime[Main.maxTilesY / 6];
     for (int i = 0; i < _slimes.Length; i++)
     {
         int num      = (int)((double)Main.screenPosition.Y * 0.7 - (double)Main.screenHeight);
         int minValue = (int)((double)num - Main.worldSurface * 16.0);
         _slimes[i].Position = new Vector2(_random.Next(0, Main.maxTilesX) * 16, _random.Next(minValue, num));
         _slimes[i].Speed    = 5f + 3f * (float)_random.NextDouble();
         _slimes[i].Depth    = (float)i / (float)_slimes.Length * 1.75f + 1.6f;
         _slimes[i].Texture  = _textures[_random.Next(2)].get_Value();
         if (_random.Next(60) == 0)
         {
             _slimes[i].Texture = _textures[3].get_Value();
             _slimes[i].Speed   = 6f + 3f * (float)_random.NextDouble();
             _slimes[i].Depth  += 0.5f;
         }
         else if (_random.Next(30) == 0)
         {
             _slimes[i].Texture = _textures[2].get_Value();
             _slimes[i].Speed   = 6f + 2f * (float)_random.NextDouble();
         }
         _slimes[i].Active = true;
     }
     _slimesRemaining = _slimes.Length;
 }
Exemple #6
0
        public override void Update(float elapsedTime)
        {
            UpdateEyelid(elapsedTime);
            bool num = _timeUntilPupilMove <= 0f;

            _pupilOffset         = (_targetOffset + _pupilOffset) * 0.5f;
            _timeUntilPupilMove -= elapsedTime;
            if (num)
            {
                float num2 = (float)_random.NextDouble() * ((float)Math.PI * 2f);
                float scaleFactor;
                if (_isSpawning)
                {
                    _timeUntilPupilMove = (float)_random.NextDouble() * 0.4f + 0.3f;
                    scaleFactor         = (float)_random.NextDouble() * 0.7f;
                }
                else
                {
                    _timeUntilPupilMove = (float)_random.NextDouble() * 0.4f + 0.6f;
                    scaleFactor         = (float)_random.NextDouble() * 0.3f;
                }
                _targetOffset = new Vector2((float)Math.Cos(num2), (float)Math.Sin(num2)) * scaleFactor;
            }
        }
        /*
         * Returns a random position near the position given.
         *
         * rand : a Random to use to get the position.
         * minDistance : the minimum amount of distance from the position.
         * maxDistance : the maximum amount of distance from the position.
         * circular : If true, gets a random point around a circle instead of a square.
         */
        public static Vector2 GetRandomPosNear(Vector2 pos, UnifiedRandom rand, int minDistance, int maxDistance, bool circular = false)
        {
            int distance = maxDistance - minDistance;

            if (!circular)
            {
                float newPosX = pos.X + (Main.rand.Next(2) == 0 ? -(minDistance + rand.Next(distance)) : (minDistance + rand.Next(distance)));
                float newPosY = pos.Y + (Main.rand.Next(2) == 0 ? -(minDistance + rand.Next(distance)) : (minDistance + rand.Next(distance)));
                return(new Vector2(newPosX, newPosY));
            }
            else
            {
                return(RotateVector(pos, pos + new Vector2(minDistance + rand.Next(distance)), MathHelper.Lerp(0, (float)(Math.PI * 2f), (float)rand.NextDouble())));
            }
        }
Exemple #8
0
 public static bool NextBool(this UnifiedRandom r)
 => r.NextDouble() < .5;
Exemple #9
0
 public static float NextFloat(this UnifiedRandom r, float minValue, float maxValue)
 => (float)r.NextDouble() * (maxValue - minValue) + minValue;
Exemple #10
0
 /// <summary>
 /// Equal chance to return true or false.
 /// </summary>
 /// <param name="rand"></param>
 /// <returns>Equal chance for true or false</returns>
 public static bool NextBool(this UnifiedRandom rand) => rand.NextDouble() < 0.5;