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; } } } } } } }
/// <summary> /// 对敌人的技能判定 /// </summary> /// <param name="e">判定的敌人对象</param> /// <param name="msg">返回的判定信息</param> /// <returns>是否进入判定域</returns> public virtual bool AttackCollision(Enemy e, ref MessageManager msg) { return false; }