コード例 #1
0
        public BTracker(SpriteX sprite, ref float moveSpeed, float RotSpeed,
                        float RotSpeedInc)
        {
            currentTarget = sprite.GetPosition();
            newTarget     = sprite.GetPosition();

            Speed            = moveSpeed;
            this.sprite      = sprite;
            IsTracking       = false;
            IsReached        = false;
            this.MaxRotSpeed = RotSpeed;
            this.RotSpeed    = RotSpeed;
            this.RotSpeedInc = RotSpeedInc;
        }
コード例 #2
0
ファイル: BTracker.cs プロジェクト: PssProgram/Lost-In-Trek
        public BTracker(SpriteX  sprite,ref float moveSpeed,float RotSpeed,
            float RotSpeedInc)
        {
            currentTarget = sprite.GetPosition();
            newTarget = sprite.GetPosition();

            Speed = moveSpeed ;
            this.sprite =sprite;
            IsTracking = false;
            IsReached  = false;
            this.MaxRotSpeed = RotSpeed;
            this.RotSpeed = RotSpeed;
            this.RotSpeedInc = RotSpeedInc;
        }
コード例 #3
0
        void TrackNow(Vector2 newPos)
        {
            Vector2 nowPos = sprite.GetPosition();

            if (Maths.VectorsEquals(nowPos, currentTarget, 10f))
            {            //到目标位置 就停止
                IsTracking = false;
                IsReached  = true;
            }

            Vector2 targetDir = currentTarget - nowPos;

            Maths.Normalize(ref targetDir);

            //用叉乘来确定两个向量的位置关系
            float cross = -sprite.NowDirection.X * targetDir.Y -
                          -sprite.NowDirection.Y * targetDir.X;

            //选择旋转方向
            if (Maths.VectorsEquals(targetDir, sprite.NowDirection, 0.16f))
            {
                cross    = 0;
                RotSpeed = MaxRotSpeed;
            }
            else
            {
                #region 旋转……
                if (cross >= 0)
                {
                    RotSpeed  = Maths.Abs(RotSpeed);
                    RotSpeed += RotSpeedInc;
                }
                if (cross < 0)
                {
                    RotSpeed  = -Maths.Abs(RotSpeed);
                    RotSpeed -= RotSpeedInc;
                }
                #endregion
                sprite.Rotate(RotSpeed);
            }

            sprite.SetPosition(sprite.GetPosition() +
                               sprite.NowDirection * Speed);
        }