Ejemplo n.º 1
0
    public void UpdateTrajectory(Vector2 baseMousePosition, Vector2 startVelocity, float angle, float time, float cancelSize, Vector2 maxVelocity)
    {
        if (startVelocity.x == 0 && startVelocity.y == 0)
        {
            return;
        }

        float velocity = startVelocity.magnitude;

        float velocityX = Mathf.Cos(angle);
        float velocityY = Mathf.Sin(angle);

        Vector2 distance;

        distance.x = Mathf.Abs(velocity * time * velocityX);
        distance.y = Mathf.Abs(velocity * time * velocityY);

        float lengthZ = Mathf.Sqrt(Mathf.Pow(distance.x, 2) + Mathf.Pow(distance.y, 2));

        float maximumVelocity = maxVelocity.magnitude;

        float maxVelocityX = Mathf.Cos(angle);
        float maxVelocityY = Mathf.Sin(angle);

        Vector2 maxDistance;

        maxDistance.x = Mathf.Abs(maximumVelocity * time * maxVelocityX);
        maxDistance.y = Mathf.Abs(maximumVelocity * time * maxVelocityY);

        float maxLengthZ = Mathf.Sqrt(Mathf.Pow(maxDistance.x, 2) + Mathf.Pow(maxDistance.y, 2));


        if (startVelocity.x < 0)
        {
            distance.x *= -1;
        }

        if (startVelocity.y < 0)
        {
            distance.y *= -1;
        }

        if (!activeIndicator)
        {
            activeIndicators     = Instantiate(indicatorsPrefab, transform.position, Quaternion.identity);
            activeIndicator      = activeIndicators.GetComponentInChildren <Indicator>();
            activeMouseIndicator = Instantiate(mouseIndicatorPrefab, baseMousePosition, Quaternion.identity);
            activeMouseIndicator.SetCancelDistance(cancelSize);
        }

        activeIndicators.transform.position    = transform.position;
        activeIndicators.transform.eulerAngles = new Vector3(0, 0, angle);
        activeIndicator.SetDistance(maxLengthZ / 2);
        activeIndicator.SetWidth(lengthZ / 4);
    }
Ejemplo n.º 2
0
    void Start()
    {
        cam            = Camera.main;
        mouseIndicator = GetComponent <MouseIndicator>();

        //Vector3 point = new Vector3();
        //Event currentEvent = Event.current;
        //Vector2 mousePos = new Vector2();
        //mousePos.x = currentEvent.mousePosition.x;
        //mousePos.y = cam.pixelHeight - currentEvent.mousePosition.y;
        //point = cam.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, cam.nearClipPlane));
    }
Ejemplo n.º 3
0
 // Start is called before the first frame update
 void Start()
 {
     energy              = GameObject.FindObjectOfType <Energy>();
     SecondJumpReady     = true;
     idle                = false;
     blocking            = false;
     blockBox.enabled    = false;
     dashAtkBox.enabled  = false;
     upAtkBox.enabled    = false;
     rightAtkBox.enabled = false;
     downAtkBox.enabled  = false;
     shield.SetActive(false);
     mouse = GetComponentInChildren <MouseIndicator>();
     anim  = gameObject.GetComponent <Animator>();
     rb2d  = gameObject.GetComponent <Rigidbody2D>();
     setPlayerState(CharacterState.Moveable);
 }
Ejemplo n.º 4
0
    public void RemoveIndicators()
    {
        if (activeIndicators)
        {
            if (activeIndicator)
            {
                activeIndicator = null;
            }
            Destroy(activeIndicators.gameObject);
        }


        if (activeMouseIndicator)
        {
            Destroy(activeMouseIndicator.gameObject);
            activeMouseIndicator = null;
        }
    }
Ejemplo n.º 5
0
 private void Start()
 {
     closeUpCam = this.gameObject.GetComponent <Camera>();
     mouse      = gameObject.GetComponent <MouseIndicator>();
 }
Ejemplo n.º 6
0
    public override void Generate(bool reallocate)
    {
        base.Generate(reallocate);
        BaseTerrain t = gameObject.GetComponentInParent <BaseTerrain>();

        if (!reallocate)
        {
            for (int i = 0; i < t.resolution; i++)
            {
                for (int j = 0; j < t.resolution; j++)
                {
                    elevationValues[i, j] = 0;
                    colorValues[i, j]     = Color.clear;
                }
            }
        }

        Random.InitState(seed);

        List <Vector2> craterPositions;

        if (poissonSampling)
        {
            craterPositions = FastPoissonDiskSampling.Sampling(Vector2.zero, Vector2.one * t.size, t.size / Mathf.Sqrt(craters));
        }
        else
        {
            craterPositions = new List <Vector2>((int)craters);
            for (int i = 0; i < craters; i++)
            {
                craterPositions.Add(new Vector2(Random.value, Random.value) * t.size);
            }
        }

        FastNoiseSIMD shapeNoise = new FastNoiseSIMD(seed);

        shapeNoise.SetNoiseType(FastNoiseSIMD.NoiseType.Perlin);
        float[] shapeNoiseSet = shapeNoise.GetNoiseSet(0, 0, 0, t.resolution, 1, t.resolution, t.size / t.resolution / shapeNoiseScale);

        float[] rcNoiseSet = ridgeColorNoise.fastNoiseSIMD.GetNoiseSet(0, 0, 0, t.resolution, 1, t.resolution, t.size / t.resolution);
        float[] hcNoiseSet = holeColorNoise.fastNoiseSIMD.GetNoiseSet(0, 0, 0, t.resolution, 1, t.resolution, t.size / t.resolution);

        foreach (Vector2 craterPos in craterPositions)
        {
            float variation = 0;
            if (enableVariation)
            {
                variation = Mathf.Pow(Random.Range(0f, 1f), Mathf.Exp(-variationShapeFactor / 5)) * 2 - 1;
            }

            float r  = Tools.Variate(radius, variation);
            float hd = Tools.Variate(holeDepth, variation);
            float hs = Tools.Variate(holeSteepness, variation);
            float rh = Tools.Variate(rimHeight, variation);
            float rs = Tools.Variate(rimSteepness, variation);
            float sf = Tools.Variate(smoothFactor, variation);

            float rcv    = Tools.Variate(ridgeColorValue, variation);
            float rca    = Tools.Variate(ridgeColorAlpha, variation);
            float rcspr  = Tools.Variate(ridgeColorSpread, variation);
            float rcdc   = Tools.Variate(ridgeColorDecay, variation);
            float rcnstr = Tools.Variate(ridgeColorNoiseStrength, variation);

            float hcv    = Tools.Variate(holeColorValue, variation);
            float hca    = Tools.Variate(holeColorAlpha, variation);
            float hcds   = Tools.Variate(holeColorDropSteepness, variation);
            float hcnstr = Tools.Variate(holeColorNoiseStrength, variation);

            float elevationRadius = r + Mathf.Sqrt(rh / rs);
            float colorRadius     = r + rcspr;
            float affectedRadius  = Mathf.Max(elevationRadius, colorRadius);
            int   minx            = Math.Max(0, Mathf.FloorToInt((craterPos.x - affectedRadius) / t.size * t.resolution));
            int   miny            = Math.Max(0, Mathf.FloorToInt((craterPos.y - affectedRadius) / t.size * t.resolution));
            int   maxx            = Math.Min(t.resolution, Mathf.CeilToInt((craterPos.x + affectedRadius) / t.size * t.resolution));
            int   maxy            = Math.Min(t.resolution, Mathf.CeilToInt((craterPos.y + affectedRadius) / t.size * t.resolution));

            MouseIndicator mi = gameObject.GetComponentInParent <BaseTerrain>().GetComponentInChildren <MouseIndicator>();

            for (int x = minx; x < maxx; x++)
            {
                for (int y = miny; y < maxy; y++)
                {
                    float dist = (new Vector2(x, y) / t.resolution * t.size - craterPos).magnitude + shapeNoiseSet[x + t.resolution * y] * shapeNoiseStrength;

                    // Adapted from S. Lague - https://github.com/SebLague/Solar-System
                    float hole = (Tools.Square(dist / r) - 1) * (hd + rh) * hs + rh;
                    float rimX = Mathf.Min(dist - elevationRadius, 0);
                    float rim  = rs * Tools.Square(rimX);

                    float craterShape = Tools.SmoothMax(hole, -hd, sf);
                    craterShape            = Tools.SmoothMin(craterShape, rim, sf);
                    elevationValues[x, y] += craterShape;

                    float distToRidge = Mathf.Abs(dist - r);
                    Color ridgeColor  = new Color(rcv, rcv, rcv, rca);
                    ridgeColor.a += rcNoiseSet[x + t.resolution * y] * rcnstr;
                    ridgeColor.a *= Mathf.Pow(Mathf.Max(0, 1 - distToRidge / rcspr), rcdc);

                    Color holeColor = new Color(hcv, hcv, hcv, hca);
                    holeColor.a += hcNoiseSet[x + t.resolution * y] * hcnstr;
                    holeColor.a *= Mathf.Max(0, Tools.SmoothMin(hcds * (1 - dist / r), 1, .5f));

                    colorValues[x, y] = Tools.OverlayColors(colorValues[x, y], holeColor);
                    colorValues[x, y] = Tools.OverlayColors(colorValues[x, y], ridgeColor);
                }
            }
        }
    }