private List <(AgarElement eater, List <AgarElement> eateds)> LocateCollisions(List <AgarElement> currentElements) { List <(AgarElement eater, List <AgarElement> eateds)> collision = new List <(AgarElement eater, List <AgarElement> eateds)>(); var cells = currentElements .Select((e, i) => new { e, i }) .Where(x => x.e.ElementType == ElementType.CellPart) .ToList(); foreach (var currentCell in cells) { var p = currentElements .Take(currentCell.i) .Where(otherElement => ElementsHelper.CanOneElementEatsOtherOneByMass(currentCell.e, otherElement) && ElementsHelper.CanOneElementEatsOtherOneByCellGroup(currentCell.e, otherElement) && ElementsHelper.CanOneElementEatsOtherOneByDistance(currentCell.e, otherElement)) .ToList <AgarElement>(); if (p.Any()) { collision.Add((currentCell.e, p)); } } return(collision); }
public override async Task Tic(int fpsTicNum) { // passive loss of mass _Mass = _Mass * 0.999995; if (_Mass > 0 && _Mass < 10) { _Mass = 10; } // go from Vel to VelBase var diffVelVelBase = (Vel - VelBase) * 0.01; //Vel -= diffVelVelBase; // collides with other cellparts in same cell? var collisions = this .Cell .Where(c => c != this) .Where(c => ElementsHelper.Collides(this, c)) .ToList(); foreach (var otherCells in collisions) { this.PushTo(2 * X - otherCells.X, 2 * Y - otherCells.Y, 2); } await base.Tic(fpsTicNum); }
public long YGame2Physics(double y) { var distance_to_cell = (y - CurrentY) * this.Zoom; var center_point = this.VisibleAreaY / 2; var distance_to_center_point = center_point + distance_to_cell; return(ElementsHelper.TryConvert(distance_to_center_point)); }
public override string CssStyle(Player c) => $@" top: {c.YGame2Physics(0)}px ; left: {c.XGame2Physics(0)}px; width: {(ElementsHelper.TryConvert(X * c.Zoom)).ToString()}px ; height: {(ElementsHelper.TryConvert(Y * c.Zoom)).ToString()}px ; ";
public static bool Collides(AgarElement oneElement, AgarElement otherElement) { var r = ElementsHelper.TwoElementsCenterDistance(oneElement, otherElement) <= oneElement.Radius + otherElement.Radius; return(r); }
public static bool CanOneElementEatsOtherOneByDistance(AgarElement oneElement, AgarElement otherElement) { var r = ElementsHelper.TwoElementsCenterDistance(oneElement, otherElement) + otherElement.Radius * 0.4 < oneElement.Radius; return(r); }
public virtual string CssStyle(Player c) => $@" top: {(c.YGame2World(CssY)).ToString()}px ; left: {(c.XGame2World(CssX)).ToString()}px ; width: {(ElementsHelper.TryConvert(Diameter * c.Zoom)).ToString()}px ; height: {(ElementsHelper.TryConvert(Diameter * c.Zoom)).ToString()}px ; ";
public long YGame2World(double y) { return(ElementsHelper.TryConvert(y * this.Zoom)); }
/* --- */ public long XGame2World(double x) { return(ElementsHelper.TryConvert(x * this.Zoom)); }