Beispiel #1
0
        private void RandomizeVelocityX()
        {
            var velocityX = RandomUtil.Float(BounceXVarianceMin, BounceXVarianceMax);

            velocityX = RandomUtil.RandomlyNegative(velocityX);
            Velocity  = new Vector2(velocityX, Velocity.y);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        private void BuildCube(int pIndex)
        {
            var hold = new GameObject("Hold" + pIndex);

            hold.transform.SetParent(vCubesObj.transform, false);

            GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

            cube.name = "Cube" + pIndex;
            cube.transform.SetParent(hold.transform, false);
            cube.GetComponent <Renderer>().sharedMaterial = vCubeMat;

            ////

            hold.transform.localRotation = UnityEngine.Random.rotationUniform;
            cube.transform.localRotation = UnityEngine.Random.rotationUniform;

            float radius = RandomUtil.Float(4, 10);

            float bobPos = RandomUtil.Float(-1, 1);

            bobPos = (float)Math.Sin(bobPos * Math.PI) / 2f + 0.5f;
            bobPos = Mathf.Lerp(radius, radius + 3, bobPos);
            cube.transform.localPosition = new Vector3(0, 0, bobPos);

            float growPos = RandomUtil.Float(-1, 1);

            growPos = (float)Math.Sin(growPos * Math.PI) / 2f + 0.5f;
            cube.transform.localScale = Vector3.Lerp(
                RandomUtil.UnitVector(0.4f) * 0.6f, RandomUtil.UnitVector(0.4f) * 1.2f, growPos);
        }
        private Vector3 AddVelocityNoise(Vector3 velocity)
        {
            float       scaleMin = 1f - VelocityNoiseScale;
            const float ScaleMax = 1f;
            //float scaleMax = 1f + VelocityNoiseScale;

            Vector2 normalVelocity = RandomUtil.Bool()
                ? new Vector2(-velocity.y, velocity.x)
                : new Vector2(velocity.y, -velocity.x);

            //Debug.DrawRay(Player.Position, velocity, Color.red, 1.0f);
            //Debug.DrawRay(Player.Position, normalVelocity, Color.cyan, 1.0f);

            float normalScale = RandomUtil.Float(0f, VelocityScaleMax);

            velocity.x += (normalScale * normalVelocity.x);
            velocity.y += (normalScale * normalVelocity.y);

            velocity *= RandomUtil.Float(scaleMin, ScaleMax);

            return(velocity);

            //float averageOfValues = (velocity.x + velocity.y) * 0.5f;

            //velocity.x += RandomUtil.Float(-VelocityNoiseOffset, VelocityNoiseOffset);
            //velocity.x *= RandomUtil.Float(scaleMin, ScaleMax);

            //velocity.y += RandomUtil.Float(-VelocityNoiseOffset, VelocityNoiseOffset);
            //velocity.y *= RandomUtil.Float(scaleMin, ScaleMax);

            //return velocity;
        }
Beispiel #4
0
        public override EnemyBullet[] GetBullets(Vector3 enemyFirePos)
        {
            var bullet = PoolManager.Instance.EnemyBulletPool.Get <TankEnemyBullet>(enemyFirePos);

            int   varianceIndex = FireCounter + NumBulletsPerBurst;
            float variance      = varianceIndex * SpeedVariancePerBullet;

            float velocityX = FireXFlip * RandomUtil.Float(0, variance);

            FireXFlip      *= -1f;
            bullet.Velocity = new Vector2(velocityX, bullet.Speed);

            bullet.OnSpawn();

            FireCounter++;

            if (FireCounter != 0)
            {
                FireTimer.ActivationInterval = FireSpeed;
            }
            else
            {
                FireTimer.ActivationInterval = ReloadSpeed;
                FireCounter = -NumBulletsPerBurst;
            }

            var ret = new EnemyBullet[] { bullet };

            return(ret);
        }
        protected override void OnBulletSpawn()
        {
            float speed = RandomUtil.Float(SpeedMin, SpeedMax, out float speedRatio);

            Vector2 initialVelocityUnit = RandomUtil.RandomDirectionVectorTopQuarter();
            Velocity = initialVelocityUnit * speed;

            Vector2 positionOffset = (speedRatio * PositionOffsetMax) * initialVelocityUnit;
            transform.position += (Vector3)positionOffset;
        }
        private Vector3 AddPositionNoise(Vector3 position)
        {
            float noiseMin = -PositionNoiseOffset;
            float noiseMax = PositionNoiseOffset;

            position.x += RandomUtil.Float(noiseMin, noiseMax);
            position.y += RandomUtil.Float(noiseMin, noiseMax);

            return(position);
        }
        private void ResetTravelSequence()
        {
            TravelSequence.ResetSelf();

            float   newX        = RandomUtil.Float(SpawnMin.x, SpawnMax.x);
            float   newY        = RandomUtil.Float(SpawnMin.y, SpawnMax.y);
            Vector3 newPosition = new Vector3(newX, newY, PositionZ);

            float distance = Vector2.Distance(transform.position, newPosition) + float.Epsilon;
            float duration = distance / TravelSpeed;

            TravelMoveEase.Duration = duration;
            TravelMove.ReinitializeMove(transform.position, newPosition);
            TravelSequence.RecalculateDuration();
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        private void BuildCube(int pIndex)
        {
            float radius        = RandomUtil.Float(4, 10);
            float radiusPercent = (radius - 4) / 6f;
            float orbitSpeed    = (float)Math.Pow(1 - radiusPercent, 2) * 0.2f + 0.8f;

            var hold = new GameObject("Hold" + pIndex);

            hold.transform.parent = vCubesObj.transform;
            vHolds[pIndex]        = hold;

            DemoCubeHold holdData = hold.AddComponent <DemoCubeHold>();

            holdData.OrbitAxis    = RandomUtil.UnitVector();
            holdData.OrbitSpeed   = RandomUtil.Float(0.7f, 1, 2) * orbitSpeed;
            holdData.OrbitInitRot = UnityEngine.Random.rotationUniform;

            ////

            GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

            cube.transform.parent = hold.transform;
            cube.name             = "Cube" + pIndex;
            cube.GetComponent <Renderer>().material = new Material(Shader.Find("Diffuse"));
            vCubes[pIndex] = cube;

            DemoCube cubeData = cube.AddComponent <DemoCube>();

            cubeData.ColorRandom  = RandomUtil.UnitColor(0.1f, 1);
            cubeData.SpinAxis     = RandomUtil.UnitVector();
            cubeData.SpinSpeed    = RandomUtil.Float(0.5f, 1, 2);
            cubeData.SpinInitRot  = UnityEngine.Random.rotationUniform;
            cubeData.BobSpeed     = RandomUtil.Float(0.5f, 1, 2);
            cubeData.BobInitPos   = RandomUtil.Float(-1, 1);
            cubeData.BobRadiusMin = radius;
            cubeData.BobRadiusMax = cubeData.BobRadiusMin + 3;
            cubeData.GrowSpeed    = RandomUtil.Float(0.5f, 1, 2);
            cubeData.GrowInitPos  = RandomUtil.Float(-1, 1);
            cubeData.GrowScaleMin = RandomUtil.UnitVector(0.4f) * 0.6f;
            cubeData.GrowScaleMax = RandomUtil.UnitVector(0.4f) * 1.2f;
        }
Beispiel #9
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public void Awake()
        {
            RandomUtil.Init(RandomSeed);

            vPixels      = new DemoTextPixels(PixelText);
            vLetters     = new List <DemoLetter>();
            vLetterCache = new List <DemoLetter>();

            ////

            for (int i = 0; i < 6; ++i)
            {
                var lettHoldObj = new GameObject("LetterHold" + i);
                lettHoldObj.transform.SetParent(gameObject.transform, false);

                var lettObj = new GameObject("Letter");
                lettObj.transform.SetParent(lettHoldObj.transform, false);
                lettObj.transform.localScale = Vector3.one * 0.3f;

                var lett = lettObj.AddComponent <DemoLetter>();
                lett.RandomAxis = Random.onUnitSphere;
                vLetterCache.Add(lett);

                lettObj.SetActive(false);
            }

            ////

            for (int i = 0; i < 40; ++i)
            {
                var ringObj = new GameObject("Ring" + i);
                ringObj.transform.SetParent(gameObject.transform, false);
                ringObj.transform.localPosition = Random.onUnitSphere * 2;
                ringObj.transform.localRotation = Random.rotation;

                DemoRing ring = ringObj.AddComponent <DemoRing>();
                ring.Radius = RandomUtil.Float(6) + 3;
            }
        }
Beispiel #10
0
        protected override void OnEnemySpawn()
        {
            Ring = PoolManager.Instance.EnemyPool.Get <RingEnemyRing>();
            Ring.transform.position = transform.position;
            Ring.OnSpawn();
            Ring.Host = this;

            PointValue += Ring.CurrentHealth;

            float maxY = SpaceUtil.WorldMap.Top.y - Ring.HeightHalf;
            float minY = SpaceUtil.WorldMap.Center.y + Ring.HeightHalf;

            float   targetY     = RandomUtil.Float(minY, maxY);
            Vector3 destination = new Vector3(transform.position.x, targetY);

            float distance = transform.position.y - targetY;
            float duration = MinimumTravelTime + distance;

            var moveTo = new MoveTo(this, destination, duration);

            Ease = new EaseIn(moveTo);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public void Awake()
        {
            RandomUtil.Init(RandomSeed);

            ////

            var lightObj = new GameObject("Light");

            lightObj.transform.SetParent(gameObject.transform, false);
            lightObj.transform.localPosition = new Vector3(0, 1.5f, 0);

            vLight           = lightObj.AddComponent <Light>();
            vLight.type      = LightType.Point;
            vLight.range     = LightRange;
            vLight.intensity = 1;

            ////

            var pixObj = new GameObject("PixelLabel");

            pixObj.transform.SetParent(gameObject.transform, false);

            UiLabel pix = pixObj.AddComponent <UiLabel>();

            pixObj.SetActive(false);

            vPixels = new DemoTextPixels(pix);

            ////

            /*var boxesObj = new GameObject("Boxes");
             * boxesObj.transform.SetParent(gameObject.transform, false);
             * boxesObj.transform.localPosition = new Vector3(0, 0, 3.5f);
             * boxesObj.transform.localRotation =
             *      Quaternion.FromToRotation(Vector3.up, new Vector3(0, 1, -1.5f).normalized);
             * boxesObj.transform.localScale = Vector3.one*0.2f;
             *
             * vBoxes = boxesObj.AddComponent<DemoBoxes>();*/

            for (int i = 0; i < 6; ++i)
            {
                var lettHoldObj = new GameObject("LetterHold" + i);
                lettHoldObj.transform.SetParent(gameObject.transform, false);

                var lettObj = new GameObject("Letter");
                lettObj.transform.SetParent(lettHoldObj.transform, false);
                lettObj.transform.localScale = Vector3.one * 0.3f;

                var lett = lettObj.AddComponent <DemoLetter>();
                lett.RandomAxis = Random.onUnitSphere;
                vLetterCache.Add(lett);

                lettObj.SetActive(false);
            }

            ////

            for (int i = 0; i < 40; ++i)
            {
                var ringObj = new GameObject("Ring" + i);
                ringObj.transform.SetParent(gameObject.transform, false);
                ringObj.transform.localPosition = Random.onUnitSphere * 2;
                ringObj.transform.localRotation = Random.rotation;

                DemoRing ring = ringObj.AddComponent <DemoRing>();
                ring.Radius = RandomUtil.Float(LightRange * 0.4f) + 3;
            }

            ////

            GameObject ovrObj = GameObject.Find("LeapOVRPlayerController");

            if (ovrObj != null)
            {
                OVRPlayerController ovrPlayer = ovrObj.GetComponent <OVRPlayerController>();
                ovrPlayer.SetSkipMouseRotation(true);
            }
        }