Exemple #1
0
        Vector2D direction = new Vector2D(); //运动方向

        public MissPoint(TextureManager texturemanager, double X, double Y, Vector2D dir, int score = 100)
        {
            //确定类型
            this.Type = Item.Miss_Point;
            working   = true;

            //确定弹射范围
            Position.X = X; Position.Y = Y;
            if (dir.Y < 0)
            {
                dir.Y = -dir.Y;
            }
            if (dir.X >= 0)
            {
                double rad = dir.GetAngle();
                if (rad > 60)
                {
                    rad = 60;
                }
                direction = new Vector2D(0, 1);
                direction.rotate((float)(Datas.LooselyRandom.NextDouble() * (rad - 2 * randDomain) + randDomain));
            }
            else
            {
                double rad = dir.GetAngle();
                rad = 360 - rad;
                if (rad > 60)
                {
                    rad = 60;
                }
                direction = new Vector2D(0, 1);
                direction.rotate(-((float)(Datas.LooselyRandom.NextDouble() * (rad - 2 * randDomain) + randDomain)));
            }

            speed_right = speed_totle * direction.X;
            speed_up    = speed_totle * direction.Y;

            double offset_x = Center_Distance * direction.X;
            double offset_y = Center_Distance * direction.Y;

            Position.X += offset_x;
            Position.Y += offset_y;

            offset_x    = Datas.LooselyRandom.NextDouble() * 2 * randFireDomain - randFireDomain;
            Position.X += offset_x;

            Texture texture = texturemanager.Get("Ef_etama2");

            sprite         = new Sprite();
            sprite.Texture = texture;
            sprite.SetHeight(16);
            sprite.SetWidth(16);
            sprite.SetUVs(14 * per_256, 8 * per_256, 16 * per_256, 10 * per_256);

            //保存了MissPoint的一些必要信息
            ItemData = new itemdata.MissPoint(score, 3);
        }
Exemple #2
0
        public override void Update(double elapsedTime)
        {
            if (!working)
            {
                if (disposing)
                {
                    if (disposingTime > 0)
                    {
                        angle += (float)elapsedTime * 360 * 3;
                        _alpha = disposingTime / 12.0f;
                        disposingTime--;          //注销计时-1
                    }
                    else
                    {
                        disposing = false;
                        disabled = true;          //在最后的旋转特效以后,同意注销此子弹
                    }
                }
                return;
            }

            speed += 2;         //每帧速度+1
            if (Datas.CurrentEnemys.Count > 0)
            {
                double distance = 100000000;                            //取一个极端数值,使每一个求得值都会小于这个值
                double lastdistance = distance;
                foreach (Enemy e in Datas.CurrentEnemys)              //将离Player距离最短的作为跟踪对象
                {
                    if (e.Position.X < -200 || e.Position.X > 200 || e.Position.Y < -40 || e.Position.Y > 500)
                        continue;
                    distance = (Datas.CurrentPlayer.Position.X - e.Position.X) * (Datas.CurrentPlayer.Position.X - e.Position.X) +
                        (Datas.CurrentPlayer.Position.Y - e.Position.Y) * (Datas.CurrentPlayer.Position.Y - e.Position.Y);
                    if (distance < lastdistance)
                    {
                        FollowEnemy = e;
                    }
                    lastdistance = distance;
                }
            }
            if (Position.X < -190 || Position.X > 190 || Position.Y < -20 || Position.Y > 450)
            {
                speed = 0;
                working = false;
                disabled = true;
            }

            move(elapsedTime);
            //跟踪旋转
            if (FollowEnemy != null && !FollowEnemy.disabled && FollowEnemy.living)
            {
                Vector2D vct = new Vector2D(FollowEnemy.Position.X - Position.X,
                    FollowEnemy.Position.Y - Position.Y);
                if (!(vct.X == 0 && vct.Y == 0))
                {
                    double distance = vct.X * vct.X + vct.Y * vct.Y;
                    double percent = distance / 40000;
                    if (percent > 1)
                        percent = 1;
                    percent = 1 - percent;
                    float addangle = (float)percent * 1080;

                    vct.Normalize();
                    double vct_angle = vct.GetAngle();                 //目标的角度值
                    double dir_angle = Direction.GetAngle();           //当前方向的角度值
                    if (vct_angle < dir_angle)
                    {
                        if (dir_angle - vct_angle < 180)
                        {
                            Direction.rotate( (addangle + rotateSpeed) * (float)elapsedTime);
                            double d_2 = Direction.GetAngle();
                            if (d_2 > dir_angle)        //如果左旋转后反而比原本角度更大,则证明旋转过度
                            {
                                Direction.X = vct.X;
                                Direction.Y = vct.Y;
                            }
                            else if (d_2 < vct_angle)   //如果旋转后跑到方向角左边,则证明旋转过度
                            {
                                Direction.X = vct.X;
                                Direction.Y = vct.Y;
                            }
                        }
                        else
                        {
                            Direction.rotate((- addangle -rotateSpeed) * (float)elapsedTime);
                            double d_2 = Direction.GetAngle();
                            if (d_2 < dir_angle)         //如果旋转后反而比原本角度更小,则证明旋转过了一周
                            {
                                if (d_2 > vct_angle)
                                {
                                    Direction.X = vct.X;
                                    Direction.Y = vct.Y;
                                }
                            }
                        }
                    }
                    else if (vct_angle > dir_angle)
                    {
                        if (vct_angle - dir_angle < 180)
                        {
                            Direction.rotate((-addangle -rotateSpeed) * (float)elapsedTime);
                            double d_2 = Direction.GetAngle();
                            if (d_2 < dir_angle)
                            {
                                Direction.X = vct.X;
                                Direction.Y = vct.Y;
                            }
                            else if (d_2 > vct_angle)
                            {
                                Direction.X = vct.X;
                                Direction.Y = vct.Y;
                            }
                        }
                        else
                        {
                            Direction.rotate((addangle + rotateSpeed) * (float)elapsedTime);
                            double d_2 = Direction.GetAngle();
                            if (d_2 > dir_angle)
                            {
                                if (d_2 < vct_angle)
                                {
                                    Direction.X = vct.X;
                                    Direction.Y = vct.Y;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        public MissPoint(TextureManager texturemanager, double X, double Y,Vector2D dir,int score = 100)
        {
            //确定类型
            this.Type = Item.Miss_Point;
            working = true;

            //确定弹射范围
            Position.X = X; Position.Y = Y;
            if (dir.Y < 0)
                dir.Y = -dir.Y;
            if (dir.X >= 0)
            {
                double rad = dir.GetAngle();
                if (rad > 60)
                    rad = 60;
                direction = new Vector2D(0, 1);
                direction.rotate((float)(Datas.LooselyRandom.NextDouble() * (rad - 2*randDomain) + randDomain));
            }
            else
            {
                double rad = dir.GetAngle();
                rad = 360 - rad;
                if (rad > 60)
                    rad = 60;
                direction = new Vector2D(0, 1);
                direction.rotate(-((float)(Datas.LooselyRandom.NextDouble() * (rad - 2 * randDomain) + randDomain)));
            }

            speed_right = speed_totle * direction.X;
            speed_up = speed_totle * direction.Y;

            double offset_x = Center_Distance * direction.X;
            double offset_y = Center_Distance * direction.Y;
            Position.X += offset_x;
            Position.Y += offset_y;

            offset_x = Datas.LooselyRandom.NextDouble() * 2 *randFireDomain - randFireDomain;
            Position.X += offset_x;

            Texture texture = texturemanager.Get("Ef_etama2");
            sprite = new Sprite();
            sprite.Texture = texture;
            sprite.SetHeight(16);
            sprite.SetWidth(16);
            sprite.SetUVs(14 * per_256, 8 * per_256, 16 * per_256, 10 * per_256);

            //保存了MissPoint的一些必要信息
            ItemData = new itemdata.MissPoint(score,3);
        }
Exemple #4
0
        public override void Update(double elapsedTime)
        {
            if (!working)
            {
                if (disposing)
                {
                    if (disposingTime > 0)
                    {
                        angle += (float)elapsedTime * 360 * 3;
                        _alpha = disposingTime / 12.0f;
                        disposingTime--;          //注销计时-1
                    }
                    else
                    {
                        disposing = false;
                        disabled  = true;         //在最后的旋转特效以后,同意注销此子弹
                    }
                }
                return;
            }

            speed += 2;         //每帧速度+1
            if (Datas.CurrentEnemys.Count > 0)
            {
                double distance     = 100000000;                      //取一个极端数值,使每一个求得值都会小于这个值
                double lastdistance = distance;
                foreach (Enemy e in Datas.CurrentEnemys)              //将离Player距离最短的作为跟踪对象
                {
                    if (e.Position.X < -200 || e.Position.X > 200 || e.Position.Y < -40 || e.Position.Y > 500)
                    {
                        continue;
                    }
                    distance = (Datas.CurrentPlayer.Position.X - e.Position.X) * (Datas.CurrentPlayer.Position.X - e.Position.X) +
                               (Datas.CurrentPlayer.Position.Y - e.Position.Y) * (Datas.CurrentPlayer.Position.Y - e.Position.Y);
                    if (distance < lastdistance)
                    {
                        FollowEnemy = e;
                    }
                    lastdistance = distance;
                }
            }
            if (Position.X < -190 || Position.X > 190 || Position.Y < -20 || Position.Y > 450)
            {
                speed    = 0;
                working  = false;
                disabled = true;
            }

            move(elapsedTime);
            //跟踪旋转
            if (FollowEnemy != null && !FollowEnemy.disabled && FollowEnemy.living)
            {
                Vector2D vct = new Vector2D(FollowEnemy.Position.X - Position.X,
                                            FollowEnemy.Position.Y - Position.Y);
                if (!(vct.X == 0 && vct.Y == 0))
                {
                    double distance = vct.X * vct.X + vct.Y * vct.Y;
                    double percent  = distance / 40000;
                    if (percent > 1)
                    {
                        percent = 1;
                    }
                    percent = 1 - percent;
                    float addangle = (float)percent * 1080;

                    vct.Normalize();
                    double vct_angle = vct.GetAngle();                 //目标的角度值
                    double dir_angle = Direction.GetAngle();           //当前方向的角度值
                    if (vct_angle < dir_angle)
                    {
                        if (dir_angle - vct_angle < 180)
                        {
                            Direction.rotate((addangle + rotateSpeed) * (float)elapsedTime);
                            double d_2 = Direction.GetAngle();
                            if (d_2 > dir_angle)        //如果左旋转后反而比原本角度更大,则证明旋转过度
                            {
                                Direction.X = vct.X;
                                Direction.Y = vct.Y;
                            }
                            else if (d_2 < vct_angle)   //如果旋转后跑到方向角左边,则证明旋转过度
                            {
                                Direction.X = vct.X;
                                Direction.Y = vct.Y;
                            }
                        }
                        else
                        {
                            Direction.rotate((-addangle - rotateSpeed) * (float)elapsedTime);
                            double d_2 = Direction.GetAngle();
                            if (d_2 < dir_angle)         //如果旋转后反而比原本角度更小,则证明旋转过了一周
                            {
                                if (d_2 > vct_angle)
                                {
                                    Direction.X = vct.X;
                                    Direction.Y = vct.Y;
                                }
                            }
                        }
                    }
                    else if (vct_angle > dir_angle)
                    {
                        if (vct_angle - dir_angle < 180)
                        {
                            Direction.rotate((-addangle - rotateSpeed) * (float)elapsedTime);
                            double d_2 = Direction.GetAngle();
                            if (d_2 < dir_angle)
                            {
                                Direction.X = vct.X;
                                Direction.Y = vct.Y;
                            }
                            else if (d_2 > vct_angle)
                            {
                                Direction.X = vct.X;
                                Direction.Y = vct.Y;
                            }
                        }
                        else
                        {
                            Direction.rotate((addangle + rotateSpeed) * (float)elapsedTime);
                            double d_2 = Direction.GetAngle();
                            if (d_2 > dir_angle)
                            {
                                if (d_2 < vct_angle)
                                {
                                    Direction.X = vct.X;
                                    Direction.Y = vct.Y;
                                }
                            }
                        }
                    }
                }
            }
        }