/// <summary>
 /// Contructor for the flying animation 
 /// </summary>
 /// <param name="sprite">The sprite to be animated</param>
 /// <param name="delay">The animation delay time in miliseconds. The default value is 0.</param>
 /// <param name="time">The animation time in miliseconds. The default value is 1000.</param>
 /// <param name="direction">The direction for animation. The default value is FlyDirection.FromBottom</param>
 public SpriteAnimation_Fly(Sprite sprite, int delay = 0, int time = 1000, FlyDirection direction = FlyDirection.FromBottom) : base(sprite, delay, time)
 {
     _Direction = direction;
     _OriginalPosition = _Sprite.Position;
     switch (direction)
     {
         case FlyDirection.FromBottom:
         case FlyDirection.ToBottom:
             _TemporaryPosition = new Vector2(_Sprite.Position.X, Global.ScreenHeight);
             break;
         case FlyDirection.FromLeft:
         case FlyDirection.ToLeft:
             _TemporaryPosition = new Vector2(-_Sprite.ViewportWidth, _Sprite.Position.Y);
             break;
         case FlyDirection.FromRight:
         case FlyDirection.ToRight:
             _TemporaryPosition = new Vector2(Global.ScreenWidth, _Sprite.Position.Y);
             break;
         case FlyDirection.FromTop:
         case FlyDirection.ToTop:
             _TemporaryPosition = new Vector2(_Sprite.Position.X, -_Sprite.ViewportHeight);
             break;
         default:
             _TemporaryPosition = Vector2.Zero;
             break;
     }
 }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (visible && Time.time - visibilityChangeTime > visibleTime)
        {
            GetComponent <OTAnimatingSprite>().alpha = 0.015f;
            visible = false;
        }
        else if (!visible && Time.time - visibilityChangeTime > 10.0f)
        {
            SetVisible();
        }

        float xDirection = Mathf.PerlinNoise(perlinXOffset + Time.time / 1.5f, 0.0f) - 0.48f;
        float yDirection = Mathf.PerlinNoise(0.0f, perlinYOffset + Time.time / 1.5f) - 0.47f;

        transform.Translate(speed * xDirection * Time.deltaTime, speed * yDirection * Time.deltaTime, 0.0f);

        if (xDirection > 0 && currentDirection != FlyDirection.RIGHT)
        {
            currentDirection = FlyDirection.RIGHT;
            GetComponent <OTAnimatingSprite>().PlayLoop("right");
        }
        else if (xDirection < 0 && currentDirection != FlyDirection.LEFT)
        {
            currentDirection = FlyDirection.LEFT;
            GetComponent <OTAnimatingSprite>().PlayLoop("left");
        }

        timeLeft -= Time.deltaTime;
    }
Example #3
0
    public void SetText(string text, Color textColor, Color arrowColor, FlyDirection flyDirection, float duration, bool showArrow = true)
    {
        Text.text       = text;
        TextBG.text     = text;
        Text.color      = new Color(textColor.r, textColor.g, textColor.b, 1);
        TextBG.color    = new Color(textColor.r / 1.5f, textColor.g / 1.5f, textColor.b / 1.5f, 1);
        UpArrow.color   = arrowColor;
        DownArrow.color = arrowColor;

        UpArrow.gameObject.SetActive(showArrow);
        DownArrow.gameObject.SetActive(showArrow);

        if (flyDirection == FlyDirection.Up)
        {
            Anim.SetTrigger("BeginFly");
            float duration_ori = ClientUtils.GetClipLength(Anim, "TextJump");
            Anim.speed = Anim.speed * duration_ori / duration;
        }
        else if (flyDirection == FlyDirection.Down)
        {
            Anim.SetTrigger("BeginFlyDown");
            float duration_ori = ClientUtils.GetClipLength(Anim, "TextDownJump");
            Anim.speed = Anim.speed * duration_ori / duration;
        }

        Canvas.overrideSorting = true;
        Canvas.sortingOrder    = 10;

        StartCoroutine(Fly(duration));
    }
Example #4
0
        /// <summary>
        /// Contructor for the flying animation
        /// </summary>
        /// <param name="sprite">The sprite to be animated</param>
        /// <param name="delay">The animation delay time in miliseconds. The default value is 0.</param>
        /// <param name="time">The animation time in miliseconds. The default value is 1000.</param>
        /// <param name="direction">The direction for animation. The default value is FlyDirection.FromBottom</param>
        public SpriteAnimation_Fly(Sprite sprite, int delay = 0, int time = 1000, FlyDirection direction = FlyDirection.FromBottom) : base(sprite, delay, time)
        {
            _Direction        = direction;
            _OriginalPosition = _Sprite.Position;
            switch (direction)
            {
            case FlyDirection.FromBottom:
            case FlyDirection.ToBottom:
                _TemporaryPosition = new Vector2(_Sprite.Position.X, Global.ScreenHeight);
                break;

            case FlyDirection.FromLeft:
            case FlyDirection.ToLeft:
                _TemporaryPosition = new Vector2(-_Sprite.ViewportWidth, _Sprite.Position.Y);
                break;

            case FlyDirection.FromRight:
            case FlyDirection.ToRight:
                _TemporaryPosition = new Vector2(Global.ScreenWidth, _Sprite.Position.Y);
                break;

            case FlyDirection.FromTop:
            case FlyDirection.ToTop:
                _TemporaryPosition = new Vector2(_Sprite.Position.X, -_Sprite.ViewportHeight);
                break;

            default:
                _TemporaryPosition = Vector2.Zero;
                break;
            }
        }
Example #5
0
        public async Task <bool> Fly(FlyDirection flyDirection, int distance)
        {
            if (distance < 20 || distance > 500)
            {
                throw new ArgumentOutOfRangeException(nameof(distance), "Distance should be between 20 and 500");
            }

            return(await _telloUpdClient.SendActionAsync($"{GetCommand(flyDirection)} {distance}"));
        }
    void Update()
    {
        PlayerController player = Player.GetComponent <PlayerController>();
        KinectController kinect = Kinect.GetComponent <KinectController>();
        FlyDetector      fly    = Fly.GetComponent <FlyDetector>();

        if (kinect.PlayerSkeleton == null)
        {
            return;
        }

        if (fly.IsActivated)
        {
            float elapsedTime = Time.deltaTime;

            if (takeOffTimer < takeOffTime)
            {
                transform.position += Vector3.up * speed * elapsedTime;
                takeOffTimer       += elapsedTime;
            }
            else
            {
                WindowsKinect.Body playerSkeleton = kinect.PlayerSkeleton;

                fly.Set(
                    playerSkeleton.GetPosition(WindowsKinect.JointType.ShoulderLeft),
                    playerSkeleton.GetPosition(WindowsKinect.JointType.ShoulderRight),
                    playerSkeleton.GetPosition(WindowsKinect.JointType.ElbowLeft),
                    playerSkeleton.GetPosition(WindowsKinect.JointType.ElbowRight));

                //Debug.Log(string.Format("{0} | {1}", transform.rotation.z, fly.Angle));
                if (Mathf.Abs(transform.rotation.z - fly.Angle) > 0.02f)
                {
                    FlyDirection rotation = fly.FlyDirection;

                    float degree = 0f;

                    if (rotation == FlyDirection.Right)
                    {
                        degree = fly.Angle > transform.rotation.z ? 1f : -1f;
                    }
                    else if (rotation == FlyDirection.Left)
                    {
                        degree = fly.Angle < transform.rotation.z ? -1f : 1f;
                    }

                    transform.Rotate(new Vector3(0f, 0f, 1f), 2f * degree * Mathf.PI / 2f * elapsedTime);
                }

                //transform.position += new Vector3(0f, 0f, -1f) * speed * elapsedTime;
            }
        }
        else if (!player.renderer.enabled)
        {
            fly.Activate();
        }
    }
Example #7
0
 public Bat(Game game, ref Texture2D textureForBat, int speed) : base(game)
 {
     textureBat          = textureForBat;
     randNum             = new Random(speed);
     rectangleSizeSprite = new Rectangle(0, 0, 32, 32);
     screenBounds        = new Rectangle(0, 0, game.Window.ClientBounds.Width, game.Window.ClientBounds.Height);
     positionBat.X       = (float)randNum.NextDouble() * (screenBounds.Width - rectangleSizeSprite.Width);
     positionBat.Y       = (float)randNum.NextDouble() * (screenBounds.Height - rectangleSizeSprite.Height);
     color = new Color((byte)randNum.Next(0, 256), (byte)randNum.Next(0, 256), (byte)randNum.Next(0, 256));
     InitializeRectangle();
     stepNumber   = 0;
     this.speed   = new Vector2();
     flyDirection = FlyDirection.Down;
 }
Example #8
0
        /// <summary>
        /// In case the positioningstate is lost, the drone will try to fly back in the opposite direction from
        /// where it came. If it's not lost and theres a successor, the successor will handle the positioning.
        /// </summary>
        /// <param name="newState"></param>
        /// <param name="oldState"></param>
        /// <param name="isForward"></param>
        /// <returns></returns>
        public override bool HandlePositioningChange(PositioningState newState, PositioningState oldState, bool isForward)
        {
            bool result = true;

            if (newState == PositioningState.Lost)
            {
                FlyDirection direction = getDirection(oldState);
                result = LineNavigator.Instance.FindLine(controller, 2, direction); //Try to find back the line
            }
            else if (successor != null)
            {
                result = successor.HandlePositioningChange(newState, oldState, isForward);
            }
            return(result);
        }
Example #9
0
        /// <summary>
        /// Makes the drone fly in a direction for a maximum amount of meters until the line is found.
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="maxMeters"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        public bool FindLine(DroneController controller, float maxMeters, FlyDirection direction)
        {
            if (direction == FlyDirection.None)
            {
                controller.Land();
                return(false);
            }
            bool lineDetected = findLine(controller, maxMeters, direction);

            if (lineDetected)
            {
                controller.Hover();
            }
            else
            {
                controller.Land();
            }
            return(lineDetected);
        }
Example #10
0
 //Moves the drone in a direction.
 private void move(DroneController controller, FlyDirection direction)
 {
     if (direction == FlyDirection.Forward)
     {
         controller.Forward();
     }
     else if (direction == FlyDirection.Backward)
     {
         controller.Backward();
     }
     else if (direction == FlyDirection.Left)
     {
         controller.Left();
     }
     else if (direction == FlyDirection.Right)
     {
         controller.Right();
     }
 }
    void Update()
    {
        if (IsActivated)
        {
            float angleLeft  = GetAngle(elbowLeft, shoulderLeft);
            float angleRight = GetAngle(elbowRight, shoulderRight);

            if (angleRight < 0f && angleLeft > 0f)
            {
                Rotation = FlyDirection.Right;
            }
            else if (angleLeft < 0f && angleRight > 0f)
            {
                Rotation = FlyDirection.Left;
            }
            else
            {
                Rotation = FlyDirection.None;
            }
        }
    }
Example #12
0
        /// <summary>
        /// Checks if the drone can detect the line when flying in the given direction for the given amount of maximum meters.
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="maxMeters"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        private bool findLine(DroneController controller, float maxMeters, FlyDirection direction)
        {
            float speed    = .1F / 3;
            float time     = maxMeters / speed * 200;
            float oldSpeed = controller.Speed;

            controller.Speed = speed;
            move(controller, direction);
            Stopwatch s = new Stopwatch();

            s.Start();
            bool lineDetected = false;

            while (!lineDetected && s.Elapsed < TimeSpan.FromMilliseconds(time))
            {
                Bitmap bmp = controller.GetBitmapFromBottomCam();
                lineDetected = LineProcessor.Instance.IsLineVisible(bmp);
            }
            controller.Speed = oldSpeed;
            s.Stop();
            return(lineDetected);
        }
 public override void Deactivate()
 {
     Rotation = FlyDirection.None;
     base.Deactivate();
 }
 public override void Start()
 {
     Rotation = FlyDirection.None;
     base.Start();
 }
Example #15
0
        protected virtual void Move(GameTime gameTime)
        {
            if (stepNumber > 0)
            {
                stepNumber--;
                if (positionBat.X < newPosition.X)
                {
                    positionBat.X += speed.X;
                    flyDirection   = FlyDirection.Right;

                    if (iterRightFrame < rightFrameOfTextureBat.Length - 1)
                    {
                        iterRightFrame++;
                    }
                    else
                    {
                        iterRightFrame = 0;
                    }
                }
                if (positionBat.X > newPosition.X)
                {
                    positionBat.X -= speed.X;
                    flyDirection   = FlyDirection.Left;
                    if (iterLeftFrame < leftFrameOfTextureBat.Length - 1)
                    {
                        iterLeftFrame++;
                    }
                    else
                    {
                        iterLeftFrame = 0;
                    }
                }
                if (positionBat.Y < newPosition.Y)
                {
                    positionBat.Y += speed.Y;
                    flyDirection   = FlyDirection.Down;
                    if (iterDownFrame < downFrameOfTextureBat.Length - 1)
                    {
                        iterDownFrame++;
                    }
                    else
                    {
                        iterDownFrame = 0;
                    }
                }
                if (positionBat.Y > newPosition.Y)
                {
                    positionBat.Y -= speed.Y;
                    flyDirection   = FlyDirection.Up;
                    if (iterUpFrame < upFrameOfTextureBat.Length - 1)
                    {
                        iterUpFrame++;
                    }
                    else
                    {
                        iterUpFrame = 0;
                    }
                }
            }
            if (stepNumber == 0)
            {
                flyDirection  = FlyDirection.Down;
                stepNumber    = randNum.Next(50, 200);
                newPosition.X = (float)randNum.NextDouble() * (screenBounds.Width - downFrameOfTextureBat[0].Width);
                newPosition.Y = (float)randNum.NextDouble() * (screenBounds.Height - downFrameOfTextureBat[0].Height);
                speed.X       = randNum.Next(0, 8);
                speed.Y       = randNum.Next(0, 8);
                color         = new Color((byte)randNum.Next(0, 256), (byte)randNum.Next(0, 256), (byte)randNum.Next(0, 256));
            }
            Check();
        }