Esempio n. 1
0
 public ScreenShake_Random(Vector2 amplitude, float duration, float dampingPow = 0)
 {
     m_horizontalDistribution = new UniformFloatDistribution(-amplitude.x, amplitude.x);
     m_verticalDistribution   = new UniformFloatDistribution(-amplitude.y, amplitude.y);
     m_duration   = duration;
     m_dampingPow = dampingPow;
 }
Esempio n. 2
0
    public void kill()
    {
        m_animator.SetTrigger(dieTrigger);

        Event <BossDieEvent> .Broadcast(new BossDieEvent());

        var rand = new StaticRandomGenerator <DefaultRandomGenerator>();
        var d    = new UniformFloatDistribution(-m_explosionRadius, m_explosionRadius);

        for (float i = 0; i <= m_explosionTime; i += m_explosionDelta)
        {
            DOVirtual.DelayedCall(i, () =>
            {
                var pos = transform.position + new Vector3(d.Next(rand), d.Next(rand), -0.5f);
                Instantiate(m_explosionPrefab, pos, Quaternion.identity);
            });
        }

        DOVirtual.DelayedCall(m_explosionTime, () =>
        {
            DOVirtual.DelayedCall(0.2f, () => gameObject.SetActive(false));

            Event <PlaySoundEvent> .Broadcast(new PlaySoundEvent(m_bossExplosionClip));

            for (int i = 0; i < m_explosionFinalCount; i++)
            {
                var pos = transform.position + new Vector3(d.Next(rand), d.Next(rand), -0.5f);
                Instantiate(m_explosionPrefab, pos, Quaternion.identity);
            }
        });
    }
Esempio n. 3
0
    public Perlin(int size, float amplitude, int frequency, Int32 seed)
    {
        m_size      = size;
        m_amplitude = amplitude;
        m_frequency = frequency;

        m_generator    = new RandomHash(seed);
        m_distribution = new UniformFloatDistribution(-amplitude, amplitude);
    }
Esempio n. 4
0
    private void Awake()
    {
        var rand = new StaticRandomGenerator <DefaultRandomGenerator>();
        var d    = new UniformFloatDistribution(m_minModifierLevel, m_maxModifierLevel);

        modifier.life     *= (int)((float)modifier.life * m_baseModifierValue + d.Next(rand) * GameInfos.level);
        modifier.speed    *= (int)((float)modifier.speed * m_baseModifierValue + d.Next(rand) * GameInfos.level);
        modifier.fireRate *= (int)((float)modifier.fireRate * m_baseModifierValue + d.Next(rand) * GameInfos.level);
        modifier.power    *= (int)((float)modifier.power * m_baseModifierValue + d.Next(rand) * GameInfos.level);
    }
Esempio n. 5
0
    public override void update(ShipLogic ship)
    {
        m_delayToNextProjectile -= Time.deltaTime;

        if (ship.fire && m_delayToNextProjectile <= 0)
        {
            m_delayToNextProjectile = m_fireRate;

            var rot = new UniformFloatDistribution(-m_rotation, m_rotation).Next(new StaticRandomGenerator <DefaultRandomGenerator>());

            SoundSystem.instance.play(new BernoulliDistribution().Next(new StaticRandomGenerator <DefaultRandomGenerator>()) ? m_shootClip : m_shootClip2, 0.1f);
            fire(m_projectile, ship.gameObject, new Vector3(0, 0, 1), rot, (int)m_power, m_baseSpeed + m_rateSpeed * ship.fireRate, m_life, m_color);
        }
    }
Esempio n. 6
0
    static void makeStructures(PlanetData planet, IRandomGenerator gen)
    {
        planet.structuresPrefabs = new List <GameObject>();
        planet.structures        = new List <StructureInfo>();

        int[] structStartIndex = new int[planet.biomes.Length];
        for (int i = 0; i < planet.biomes.Length; i++)
        {
            structStartIndex[i] = planet.structuresPrefabs.Count;

            foreach (var s in planet.biomes[i].structures)
            {
                planet.structuresPrefabs.Add(s.prefab);
            }
        }

        var dAngle = new UniformFloatDistribution(0, 360.0f);

        for (int i = 0; i < planet.triangles.Length; i++)
        {
            int biomeId = PlanetEx.biomeIndexOfTriangle(planet, i);
            if (biomeId < 0)
            {
                continue;
            }

            if (planet.biomes[biomeId].structureDensity <= 0 || planet.biomes[biomeId].structures.Count == 0)
            {
                continue;
            }

            var t = planet.triangles[i];

            float area = MathEx.triangleArea(planet.points[t.v1].point, planet.points[t.v2].point, planet.points[t.v3].point) * planet.biomes[biomeId].structureDensity;

            float v = area - (int)area;
            if (new BernoulliDistribution(v).Next(gen))
            {
                area = (int)area + 1;
            }
            else
            {
                area = (int)area;
            }

            var p1 = planet.points[t.v1].point * (planet.points[t.v1].height + 1) * planet.scale;
            var p2 = planet.points[t.v2].point * (planet.points[t.v2].height + 1) * planet.scale;
            var p3 = planet.points[t.v3].point * (planet.points[t.v3].height + 1) * planet.scale;

            var d = new Uniform3DTriangleDistribution(p1, p2, p3);

            List <float> weights = new List <float>();
            for (int j = 0; j < planet.biomes[biomeId].structures.Count; j++)
            {
                weights.Add(planet.biomes[biomeId].structures[j].weight);
            }
            var dStructs = new DiscreteDistribution(weights);

            for (int j = 0; j < area; j++)
            {
                var pos = d.Next(gen);
                planet.structures.Add(new StructureInfo(dStructs.Next(gen) + structStartIndex[biomeId], i, pos, dAngle.Next(gen)));
            }
        }
    }
Esempio n. 7
0
    static void makeFinalElevation(PlanetData planet, float minHeight, float maxHeight, float forcedOffsetElevation, float oceanLevel, float lakeSize, AnimationCurve elevationCurve, IRandomGenerator gen, float randomizeElevation)
    {
        var distrib = new UniformFloatDistribution(0, randomizeElevation);

        int oceanBiomeIndex = -1;
        int lakeBiomeIndex  = -1;

        Stopwatch sw = new Stopwatch();

        sw.Start();

        for (int i = 0; i < planet.biomes.Length; i++)
        {
            if (planet.biomes[i].isLakeBiome)
            {
                lakeBiomeIndex = i;
            }
            if (planet.biomes[i].isOceanBiome)
            {
                oceanBiomeIndex = i;
            }
        }

        setWaterBiomes(planet, oceanLevel, oceanBiomeIndex, lakeBiomeIndex, lakeSize);

        UnityEngine.Debug.Log("\tElapsed water biomes " + sw.Elapsed); sw.Reset(); sw.Start();

        bool[] setPoints            = new bool[planet.points.Length];
        bool[] nextPoints           = new bool[planet.points.Length];
        LinkedList <NextValue> next = new LinkedList <NextValue>();

        float[] newHeight = new float[planet.points.Length];

        int loop = 0;

        for (int i = 0; i < planet.points.Length; i++)
        {
            if (planet.points[i].biomeID == oceanBiomeIndex)
            {
                continue;
            }

            bool isBorder = false;
            foreach (var p in planet.points[i].connectedPoints)
            {
                if (planet.points[p].height >= oceanLevel || (planet.points[p].biomeID == lakeBiomeIndex && lakeBiomeIndex >= 0))
                {
                    continue;
                }
                isBorder = true;
                break;
            }
            if (!isBorder)
            {
                continue;
            }

            setPoints[i] = true;
            loop++;
        }

        if (next.Count == 0)
        {
            setPoints[new UniformIntDistribution(0, setPoints.Length).Next(gen)] = true;
        }

        for (int i = 0; i < planet.points.Length; i++)
        {
            if (setPoints[i])
            {
                foreach (var p in planet.points[i].connectedPoints)
                {
                    if (!setPoints[p] && !nextPoints[p])
                    {
                        next.AddLast(new NextValue(p, 0));
                        nextPoints[p] = true;
                    }
                }
            }
        }

        while (next.Count > 0)
        {
            var current = next.First.Value.index;
            next.RemoveFirst();
            nextPoints[current] = false;
            setPoints[current]  = true;

            int  bestIndex = -1;
            bool haveCheckedNotsetPoint = false;
            foreach (var p in planet.points[current].connectedPoints)
            {
                if (setPoints[p])
                {
                    if (bestIndex < 0 || newHeight[p] < newHeight[bestIndex])
                    {
                        bestIndex = p;
                    }
                }
                else if (!nextPoints[p])
                {
                    haveCheckedNotsetPoint = true;
                }
            }

            float d       = (planet.points[bestIndex].point - planet.points[current].point).magnitude;
            float dHeight = Mathf.Abs(planet.points[bestIndex].height - planet.points[current].height);
            if (planet.points[current].biomeID == lakeBiomeIndex && lakeBiomeIndex >= 0)
            {
                newHeight[current] = newHeight[bestIndex];
            }
            else
            {
                newHeight[current] = newHeight[bestIndex] + d * (forcedOffsetElevation + distrib.Next(gen)) + dHeight;
            }

            if (!haveCheckedNotsetPoint)
            {
                continue;
            }

            if (next.First == null || newHeight[current] <= next.First.Value.weight)
            {
                foreach (var p in planet.points[current].connectedPoints)
                {
                    if (!setPoints[p] && !nextPoints[p])
                    {
                        next.AddFirst(new NextValue(p, newHeight[current]));
                        nextPoints[p] = true;
                    }
                }
            }
            else
            {
                var item = next.Last;
                while (item.Previous != null)
                {
                    if (item.Value.weight <= newHeight[current])
                    {
                        break;
                    }
                    item = item.Previous;
                }

                foreach (var p in planet.points[current].connectedPoints)
                {
                    if (!setPoints[p] && !nextPoints[p])
                    {
                        next.AddAfter(item, new NextValue(p, newHeight[current]));
                        nextPoints[p] = true;
                    }
                }
            }
        }

        if (oceanBiomeIndex >= 0)
        {
            for (int i = 0; i < newHeight.Length; i++)
            {
                if (planet.points[i].biomeID == oceanBiomeIndex)
                {
                    newHeight[i] *= -1;
                }
            }
        }

        UnityEngine.Debug.Log("\tElapsed heights " + sw.Elapsed); sw.Reset(); sw.Start();

        for (int i = 0; i < planet.points.Length; i++)
        {
            if (newHeight[i] == 0 || (planet.points[i].biomeID == lakeBiomeIndex && lakeBiomeIndex >= 0))
            {
                planet.points[i].height = newHeight[i];
                continue;
            }

            float sum = 0;

            foreach (var p in planet.points[i].connectedPoints)
            {
                sum += newHeight[p];
            }
            planet.points[i].height = sum / planet.points[i].connectedPoints.Count;
        }

        UnityEngine.Debug.Log("\tElapsed smooth " + sw.Elapsed); sw.Reset(); sw.Start();

        float min = Mathf.Min(newHeight);
        float max = Mathf.Max(newHeight);

        for (int i = 0; i < planet.points.Length; i++)
        {
            float h = planet.points[i].height;
            if (h < 0)
            {
                h /= -min;
                h  = elevationCurve.Evaluate(h);
                h *= -minHeight;
            }
            else
            {
                h /= max;
                h  = elevationCurve.Evaluate(h);
                h *= maxHeight;
            }
            planet.points[i].height = h;
        }

        UnityEngine.Debug.Log("\tElapsed height curve " + sw.Elapsed); sw.Reset(); sw.Start();
    }
Esempio n. 8
0
    void RealyStartSpawning()
    {
        m_time     = m_spawningTime;
        m_velocity = new Vector2(0, 0);

        var   rand            = new StaticRandomGenerator <MT19937>();
        float spawnMultiplier = m_isPowered ? m_poweredSpawnMultiplier : 1;
        int   spawnNb         = Mathf.RoundToInt(new UniformIntDistribution(m_minSpawnNb, m_maxSpawnNb + 1).Next(rand) * spawnMultiplier);

        if (spawnNb > 0)
        {
            var pos = transform.position;

            float angle    = new UniformFloatDistribution(0, Mathf.PI * 2).Next(rand);
            float minAngle = Mathf.PI / spawnNb / 2;
            float maxAngle = minAngle * 4;

            int tryCount = 0;
            for (int i = 0; i < spawnNb; i++)
            {
                var dir = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * new UniformFloatDistribution(m_minSpawnDistance, m_maxSpawnDistance).Next(rand);

                var ray = Physics2D.Raycast(transform.position, dir, dir.magnitude, LayerMask.GetMask("Default"));
                if (ray.collider != null)
                {
                    tryCount++;
                    if (tryCount < 10)
                    {
                        i--;
                    }
                    else
                    {
                        tryCount = 0;
                    }
                }
                else
                {
                    tryCount = 0;

                    DOVirtual.DelayedCall(new UniformFloatDistribution(m_minSpawnDelay, m_maxSpawnDelay).Next(rand), () =>
                    {
                        if (this == null)
                        {
                            return;
                        }

                        DOVirtual.DelayedCall(0.3f, () =>
                        {
                            if (this == null)
                            {
                                return;
                            }
                            var index = new UniformIntDistribution(0, m_entities.Count).Next(rand);
                            var obj   = Instantiate(m_entities[index]);
                            obj.transform.position = pos + new Vector3(dir.x, dir.y);
                        });

                        if (m_spawnFx != null)
                        {
                            var fx = Instantiate(m_spawnFx);
                            fx.transform.position = pos + new Vector3(dir.x, dir.y, -0.1f);
                            Destroy(fx, 2);
                        }
                        SoundSystem.Instance().play(m_spawnSound, 0.5f, true);
                    });
                }

                angle += new UniformFloatDistribution(minAngle, maxAngle).Next(rand);
            }
        }

        m_animator.SetTrigger("Invoke");

        m_state = State.Spawning;
    }
Esempio n. 9
0
 public ScreenShake_RandomRotation(float amplitude, float duration, float dampingPow = 0)
 {
     m_distribution = new UniformFloatDistribution(-amplitude, amplitude);
     m_duration     = duration;
     m_dampingPow   = dampingPow;
 }
Esempio n. 10
0
    void Update()
    {
        if (PlayerControler.Instance() == null)
        {
            return;
        }

        m_jumpTimer -= Time.deltaTime;

        if (m_jumpTimer < 0 && PlayerControler.Instance() != null && !m_jumping)
        {
            m_animator.SetTrigger("StartJump");
            SoundSystem.Instance().play(m_jumpSound, 0.5f, true);

            m_jumping = true;

            Vector2 target = PlayerControler.Instance().transform.position;
            Vector2 pos    = transform.position;

            var dist = new UniformFloatDistribution(m_minJumpDistance, m_maxJumpDistance).Next(new StaticRandomGenerator <MT19937>());

            var dir = (target - pos).normalized * dist;

            float jumpTime = dist / m_moveSpeed;

            DOVirtual.DelayedCall(m_startJumpDelay, () =>
            {
                if (this == null)
                {
                    return;
                }

                m_velocity = dir / jumpTime;

                DOVirtual.DelayedCall(jumpTime, () =>
                {
                    if (this == null)
                    {
                        return;
                    }

                    m_velocity  = new Vector2(0, 0);
                    m_jumpTimer = new UniformFloatDistribution(m_minIdleTime, m_maxIdleTime).Next(new StaticRandomGenerator <MT19937>());
                    m_jumping   = false;

                    m_animator.SetTrigger("EndJump");
                    SoundSystem.Instance().play(m_landSound);
                });
            });
        }

        m_rigidbody.velocity = m_velocity;

        {
            Vector2 target = PlayerControler.Instance().transform.position;
            Vector2 pos    = transform.position;

            float angle = Mathf.Atan2(target.y - pos.y, target.x - pos.x);

            m_animator.SetBool("Left", angle <-Mathf.PI / 2 || angle> Mathf.PI / 2);
        }
    }