Exemplo n.º 1
0
 public void Shake(float duration, float shakeTime, float power, ShakeDirection shakeDirection = ShakeDirection.AllDirections)
 {
     foreach (var _s in _sprites)
     {
         _s.Shake(duration, shakeTime, power, shakeDirection);
     }
 }
Exemplo n.º 2
0
    private void Update()
    {
        if (shakeCamera)
        {
            //Get current rotation values
            //float XRot = mainCamera.transform.rotation.x;
            //float YRot = mainCamera.transform.rotation.y;
            float ZRot = mainCamera.transform.rotation.z;
            //float WRot = mainCamera.transform.rotation.w;

            //Shake main camera
            //Order of Camera "Shake" operations (aka applying Z Rotation left and right)
            //1. Move Camera Z Rot to shakeZRotMin
            //2. Move Camera Z Rot to shakeZRotMax
            //3. At zero, increment currectShakeBounces
            //4. Repeat until currectShakeBounces == shakeBounces

            float RotStep;
            if (currentShakeDirection == ShakeDirection.RIGHT)
            {
                RotStep = rotationStep * -1;
            }
            else
            {
                RotStep = rotationStep;
            }

            mainCamera.transform.Rotate(new Vector3(0f, 0f, RotStep));
            //mainCamera.transform.rotation.SetFromToRotation(mainCamera.transform.rotation,);

            ZRot = mainCamera.transform.rotation.z;
            if (ZRot <= -5)
            {
                currentShakeDirection = ShakeDirection.LEFT;
            }

            if (ZRot >= 5)
            {
                currentShakeDirection = ShakeDirection.RIGHT;
            }

            if (ZRot == 0.0f)
            {
                currectShakeBounces++;
            }

            if (currectShakeBounces == shakeBounces)
            {
                shakeCamera = false;
            }
        }
    }
Exemplo n.º 3
0
 // This is a either or question, calling it once with x and then with y will only do y scaling
 public void Scale(float factor, ShakeDirection dir = ShakeDirection.AllDirections)
 {
     if (dir == ShakeDirection.AllDirections)
     {
         _sprite.Scale = new Vector2f(factor * _scaleVector.X, factor * _scaleVector.X);
     }
     else if (dir == ShakeDirection.UpDown)
     {
         _sprite.Scale = new Vector2f(_scaleVector.X, factor * _scaleVector.X);
     }
     else if (dir == ShakeDirection.LeftRight)
     {
         _sprite.Scale = new Vector2f(factor * _scaleVector.X, _scaleVector.X);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        ///  currently buggy
        /// </summary>
        /// <param name="duration"></param>
        /// <param name="shakeTime"></param>
        /// <param name="power"></param>
        /// <param name="shakeDirection"></param>
        public void Shake(float duration, float shakeTime, float power, ShakeDirection shakeDirection = ShakeDirection.AllDirections)
        {
            if (duration < 0.0f)
            {
                throw new ArgumentOutOfRangeException("duration", duration, "Duration for a shake must be non-negative");
            }
            if (shakeTime < 0.0f)
            {
                throw new ArgumentOutOfRangeException("shakeTime", shakeTime, "Time for a shake must be non-negative");
            }
            _shakePower    = power;
            _shakeTimer    = 0.0f;
            _shakeTimerMax = shakeTime;

            _shakeDirection = shakeDirection;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a shake to the camera. If the previous shaking is not complete, the remaining strength
        /// will combine with the new one.
        /// </summary>
        /// <param name="direction">The direction of the shake.</param>
        /// <param name="strength">
        /// The strength of the shake, or how many pixels it will move at most in one direction (assuming
        /// the shake function stays in its default range of [-1, 1]). Defaults to 10.
        /// </param>
        /// <param name="time">How long, in seconds, the shake should last. Defaults to .5.</param>
        /// <param name="speed">The speed of the shake. The lower, the less the camera will shake. Defaults to 100.</param>
        public void Shake(ShakeDirection direction = ShakeDirection.Horizontal, uint strength = 10, float time = .5f, uint speed = 100)
        {
            switch (direction)
            {
            case ShakeDirection.Horizontal:
                Shake(t => new Vector2(MathF.Cos(t), 0), strength, time, speed);
                break;

            case ShakeDirection.Vertical:
                Shake(t => new Vector2(0, MathF.Cos(t)), strength, time, speed);
                break;

            case ShakeDirection.Circular:
                Shake(t => new Vector2(MathF.Sin(t), MathF.Cos(t)), strength, time, speed);
                break;

            default:
                throw new ArgumentOutOfRangeException("Unexpected case");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///  Start the Effect and Call DoStartEffect
        /// </summary>
        /// <param name="duration"></param>
        /// <param name="inverseFrequency"></param>
        /// <param name="col"></param>
        /// <param name="power"></param>
        /// <param name="shakeDirection"></param>
        public void StartEffect(float duration, float inverseFrequency, Color col, float power, ShakeDirection direction = ShakeDirection.AllDirections)
        {
            if ((duration < 0.0f) && (duration != -1.0f))
            {
                throw new ArgumentOutOfRangeException("duration", duration, "Duration for a screen effect must be non-negative or -1.0f ");
            }
            if (inverseFrequency < 0.0f)
            {
                throw new ArgumentOutOfRangeException("shakeTime", inverseFrequency, "Time for a shake must be non-negative");
            }

            EffectTotalTime   = EffectRemainingTime = duration;
            _inverseFrequency = _inverseFrequencyTotal = inverseFrequency;
            _color            = col;
            _initialAlpha     = _color.A;
            _power            = power;
            _direction        = direction;
            IsEffectActive    = true;

            DoStartEffect();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Give the camera a shaking effect.
        /// </summary>
        /// <param name="intensity">The amount of camera shake.</param>
        /// <param name="duration">The duration of the camera shake, in seconds.</param>
        /// <param name="decreasing">Whether the shake intensity will decrease over time or not.</param>
        /// <param name="forceReset">A flag used to determine if the shake will reset any current camera shake.</param>
        /// <param name="callback">The method that will be invoked after the camera shake has finished.</param>
        /// <param name="direction">The direction of the camera shake.</param>
        public void Shake(float intensity = 5f, float duration = 1f, bool decreasing = false, bool forceReset = false, Action callback = null, ShakeDirection direction = ShakeDirection.Both)
        {
            // Apply the shake if the camera is not already shaking, unless force reset is true.
            if (!_shakeTimer.IsRunning || forceReset)
            {
                _shakeIntensity = intensity;
                _shakeDecreasing = decreasing;
                _shakeDirection = direction;

                _shakeTimer.Duration = duration;
                _shakeTimer.Callback = callback;
                _shakeTimer.Start(true);
            }
        }
        public static void CreateLinearGlowInOut(out Texture targetTexture, uint sizeX, uint sizeY, Color col, float opacity = 0.2f, PennerDoubleAnimation.EquationType type = PennerDoubleAnimation.EquationType.Linear, ShakeDirection direction = ShakeDirection.UpDown)
        {
            Image targetImage = new Image(sizeX, sizeY);

            float centerPosition = 0.0f;

            if (direction == ShakeDirection.UpDown)
            {
                centerPosition = sizeY / 2.0f;
            }
            else if (direction == ShakeDirection.LeftRight)
            {
                centerPosition = sizeX / 2.0f;
            }

            for (uint i = 0; i != sizeX; i++)
            {
                for (uint j = 0; j != sizeY; j++)
                {
                    Color pixelCol = col;

                    float distanceToCenter = 0.0f;
                    if (direction == ShakeDirection.UpDown)
                    {
                        distanceToCenter = (float)Math.Abs(centerPosition - j);
                    }
                    else if (direction == ShakeDirection.LeftRight)
                    {
                        distanceToCenter = (float)Math.Abs(centerPosition - i);
                    }
                    float newAlpha = 255.0f * opacity * (1.0f - (float)PennerDoubleAnimation.GetValue(type, distanceToCenter, 0, 1, centerPosition));
                    if (newAlpha < 0.0f)
                    {
                        newAlpha = 0.0f;
                    }
                    //Console.WriteLine(newAlpha);
                    pixelCol.A = (byte)newAlpha;
                    targetImage.SetPixel(i, j, pixelCol);
                }
            }

            targetTexture = new Texture(targetImage);
        }