public TargetList GetEnemiesInBeamDirection(Vector3D startPoint, Vector3D direction, float length, float thickness = 0f) { Vector3D beamEnd = PowerMath.TranslateDirection2D(startPoint, direction, startPoint, length); float fixedActorRadius = 1.5f; // TODO: calculate based on actor.ActorData.Cylinder.Ax2 ? return(_GetTargetsInRadiusHelper(startPoint, length + thickness, -1, actor => PowerMath.CircleInBeam(new Circle(actor.Position.X, actor.Position.Y, fixedActorRadius), startPoint, beamEnd, thickness), _EnemyActorFilter)); }
public TargetList GetEnemiesInArcDirection(Vector3D center, Vector3D direction, float radius, float lengthDegrees) { Vector2F arcCenter2D = PowerMath.VectorWithoutZ(center); Vector2F arcDirection2D = PowerMath.VectorWithoutZ(direction); float arcLength = lengthDegrees * PowerMath.DegreesToRadians; float fixedActorRadius = 1.5f; // TODO: calculate based on actor.ActorData.Cylinder.Ax2 ? return(_GetTargetsInRadiusHelper(center, radius, -1, actor => PowerMath.ArcCircleCollides(arcCenter2D, arcDirection2D, radius, arcLength, new Circle(actor.Position.X, actor.Position.Y, fixedActorRadius)), _EnemyActorFilter)); }
private void _SetupMove(Vector3D destination, float speed) { Vector3D dir_normal = PowerMath.Normalize(new Vector3D(destination.X - this.Target.Position.X, destination.Y - this.Target.Position.Y, destination.Z - this.Target.Position.Z)); this.Velocity = new Vector3D(dir_normal.X * speed, dir_normal.Y * speed, dir_normal.Z * speed); this.ArrivalTime = new RelativeTickTimer(this.Target.World.Game, (int)(PowerMath.Distance2D(this.Target.Position, destination) / speed)); _startPosition = this.Target.Position; _endPosition = destination; _startTick = this.Target.World.Game.TickCounter; }
public Actor GetClosestTo(Vector3D position) { Actor closest = null; float closestDistance = float.MaxValue; foreach (Actor actor in this.Actors) { float distance = PowerMath.Distance2D(actor.Position, position); if (distance < closestDistance) { closest = actor; closestDistance = distance; } } return(closest); }
private void _SetupArcMove(Vector3D destination, float crestHeight, float gravity) { // TODO: handle when target and destination heights differ float absGravity = Math.Abs(gravity); float arcLength = (float)Math.Sqrt(2f * crestHeight / absGravity); int arrivalTicks = (int)(arcLength * 2f); float distance = PowerMath.Distance2D(this.Target.Position, destination); Vector3D normal = PowerMath.Normalize(new Vector3D(destination.X - this.Target.Position.X, destination.Y - this.Target.Position.Y, 0f)); this.Velocity = new Vector3D(normal.X * (distance / arrivalTicks), normal.Y * (distance / arrivalTicks), absGravity * arcLength); this.ArrivalTime = new RelativeTickTimer(this.Target.World.Game, arrivalTicks); _startPosition = this.Target.Position; _endPosition = destination; _startTick = this.Target.World.Game.TickCounter; _arcGravity = gravity; }
private void _CheckCollisions() { if (OnCollision == null) { return; } // check if we collided with anything since last update float radius = this.ActorData.Cylinder.Ax2; Circle startCircle = new Circle(_prevUpdatePosition.X, _prevUpdatePosition.Y, radius); // make a velocity representing the change to the current position Vector2F velocity = PowerMath.VectorWithoutZ(this.Position - _prevUpdatePosition); Actor hit = null; TargetList targets = this.Context.GetEnemiesInRadius(this.Position, radius + 25f); if (CollisionFilter != null) { targets.Actors.RemoveAll(actor => !CollisionFilter(actor)); } targets.SortByDistanceFrom(_prevUpdatePosition); foreach (Actor target in targets.Actors) { float targetRadius = 1.5f; // TODO: use target.ActorData.Cylinder.Ax2 ? if (PowerMath.MovingCircleCollides(startCircle, velocity, new Circle(target.Position.X, target.Position.Y, targetRadius))) { hit = target; break; } } if (hit != null) { OnCollision(hit); } }
public void SortByDistanceFrom(Vector3D position) { this.Actors = this.Actors.OrderBy(actor => PowerMath.Distance2D(actor.Position, position)).ToList(); }