public static void Move() { PointConsole tempPoint = BodyPoints.First(); if (Direct == Direction.Up) { tempPoint = new PointConsole(tempPoint.X, tempPoint.Y - 1); } if (Direct == Direction.Down) { tempPoint = new PointConsole(tempPoint.X, tempPoint.Y + 1); } if (Direct == Direction.Left) { tempPoint = new PointConsole(tempPoint.X - 1, tempPoint.Y); } if (Direct == Direction.Right) { tempPoint = new PointConsole(tempPoint.X + 1, tempPoint.Y); } BodyPoints.Insert(0, tempPoint); new PointConsole(BodyPoints.Last().X, BodyPoints.Last().Y).DrawPoint(' '); BodyPoints.Remove(BodyPoints.Last()); DrawSnake(); }
void Calc() { //==================== Filter disabled bodies List<CelestialBody> targets = new List<CelestialBody>(); for ( int i = 0; i < SimControl._bodies.Count; i++ ) { if ( SimControl._bodies[i].isActiveAndEnabled ) { targets.Add( SimControl._bodies[i] ); } } //===================== //===================== Create working data array from bodies. bodies = new BodyPoints[targets.Count]; for ( int i = 0; i < bodies.Length; i++ ) { var targetComponent = targets[i].GetComponent<PredictionSystemTarget>(); bool isVisibleOrb = targetComponent == null || targetComponent.AllowDisplayPredictionOrbit; Material mat = targetComponent == null ? LinesMaterial : targetComponent.OrbitMaterial; bodies[i] = new BodyPoints() { pos = targets[i]._transform.position, v = targets[i].Velocity, m = targets[i].Mass, isFixed = targets[i].IsFixedPosition, isVisible = isVisibleOrb, material = mat, width = targetComponent == null ? LinesWidth : targetComponent.OrbitWidth, points = new Vector2[PointsCount] }; } //===================== //===================== Calculate scene motion progress and record points into arrays. for ( int i = 0; i < PointsCount; i++ ) { //======================== calculate next step velocities for each body for ( int j = 0; j < bodies.Length; j++ ) { if ( bodies[j].isFixed ) { continue; } Vector2 acceleration = Vector2.zero; for ( int n = 0; n < bodies.Length; n++ ) { if ( n != j ) { acceleration += Acceleration( bodies[j].pos, bodies[n].pos, bodies[n].m * SimControl.GravitationalConstant, 0.5f, SimControl.MaxAttractionRange ); } } bodies[j].v += acceleration * CalcStep; } //======================== move bodies and store current step positions for ( int j = 0; j < bodies.Length; j++ ) { if ( bodies[j].isFixed ) { continue; } bodies[j].points[i] = bodies[j].pos; bodies[j].pos += bodies[j].v * CalcStep; } } //===================== }
static void DrawSnake() { Console.ForegroundColor = ColorSnake; foreach (var p in BodyPoints) { Console.SetCursorPosition(p.X, p.Y); if (BodyPoints.First() == p) { Console.Write(HeadSymb); } else { Console.Write(BodySymb); } } }
void Calc() { //==================== Filter disabled bodies List <CelestialBody> targets = new List <CelestialBody>(); for (int i = 0; i < SimControl._bodies.Count; i++) { if (SimControl._bodies[i].isActiveAndEnabled) { targets.Add(SimControl._bodies[i]); } } //===================== //===================== Create working data array from bodies. bodies = new BodyPoints[targets.Count]; for (int i = 0; i < bodies.Length; i++) { var targetComponent = targets[i].GetComponent <PredictionSystemTarget>(); bool isVisibleOrb = targetComponent == null || targetComponent.AllowDisplayPredictionOrbit; Material mat = targetComponent == null ? LinesMaterial : targetComponent.OrbitMaterial; bodies[i] = new BodyPoints() { pos = targets[i]._transform.position, v = targets[i].Velocity, m = targets[i].Mass, isFixed = targets[i].IsFixedPosition, isVisible = isVisibleOrb, material = mat, width = targetComponent == null ? LinesWidth : targetComponent.OrbitWidth, points = new Vector2[PointsCount] }; } //===================== //===================== Calculate scene motion progress and record points into arrays. for (int i = 0; i < PointsCount; i++) { //======================== calculate next step velocities for each body for (int j = 0; j < bodies.Length; j++) { if (bodies[j].isFixed) { continue; } Vector2 acceleration = Vector2.zero; for (int n = 0; n < bodies.Length; n++) { if (n != j) { acceleration += Acceleration(bodies[j].pos, bodies[n].pos, bodies[n].m * SimControl.GravitationalConstant, 0.5f, SimControl.MaxAttractionRange); } } bodies[j].v += acceleration * CalcStep; } //======================== move bodies and store current step positions for (int j = 0; j < bodies.Length; j++) { if (bodies[j].isFixed) { continue; } bodies[j].points[i] = bodies[j].pos; bodies[j].pos += bodies[j].v * CalcStep; } } //===================== }
private void Calc() { // Filter disabled bodies: List <CelestialBody> targets = new List <CelestialBody>(); for (int i = 0; i < SimControl.Bodies.Count; i++) { if (SimControl.Bodies[i].isActiveAndEnabled) { targets.Add(SimControl.Bodies[i]); } } // Check is any body visible: if (!targets.Any(t => { var targetComponent = t.GetComponent <PredictionSystemTarget>(); return(targetComponent == null || targetComponent.enabled); })) { for (int i = 0; i < lineRends.Count; i++) { lineRends[i].enabled = false; } bodies = new BodyPoints[0]; HideAllOrbits(); // Don't calculate: return; } // Create working data array from bodies: bodies = new BodyPoints[targets.Count]; for (int i = 0; i < bodies.Length; i++) { var targetComponent = targets[i].GetComponent <PredictionSystemTarget>(); bool isVisibleOrb = targetComponent == null || targetComponent.enabled; Material mat = targetComponent == null ? LinesMaterial : targetComponent.OrbitMaterial; bodies[i] = new BodyPoints() { pos = targets[i].transform.position, v = (Vector3)targets[i].Velocity, m = (float)targets[i].Mass, isFixed = targets[i].IsFixedPosition, isVisible = isVisibleOrb, material = mat, width = targetComponent == null ? LinesWidth : targetComponent.OrbitWidth, points = new Vector3[PointsCount] }; } // Calculate scene motion progress and record points into arrays: for (int i = 0; i < PointsCount; i++) { // Calculate next step velocities for each body: for (int j = 0; j < bodies.Length; j++) { if (bodies[j].isFixed) { continue; } Vector3 acceleration = Vector3.zero; for (int n = 0; n < bodies.Length; n++) { if (n != j) { acceleration += SpaceGravity2D.CelestialBodyUtils.AccelerationByAttractionForce(bodies[j].pos, bodies[n].pos, bodies[n].m * (float)SimControl.GravitationalConstant, 0.5f, (float)SimControl.MaxAttractionRange); } } bodies[j].v += acceleration * CalcStep; } // Move bodies and store current step positions: for (int j = 0; j < bodies.Length; j++) { if (bodies[j].isFixed) { continue; } bodies[j].points[i] = bodies[j].pos; bodies[j].pos += bodies[j].v * CalcStep; } } }
public static void Rise() { BodyPoints.Add(BodyPoints.Last()); }
public float getDamage(float distance, BodyPoints point) { return(getDamageOverDistance(distance) * damageMultipliers[(int)point]); }
void Calc() { //>===== Filter disabled bodies List <CelestialBody> targets = new List <CelestialBody>(); for (int i = 0; i < SimControl.bodies.Count; i++) { if (SimControl.bodies[i].isActiveAndEnabled) { targets.Add(SimControl.bodies[i]); } else { if (ShowTraceForDisabledBodies && SimControl.bodies[i].gameObject.activeSelf) { targets.Add(SimControl.bodies[i]); } } } //<===== //>=====Check is any body visible if (!targets.Any(t => { var targetComponent = t.GetComponent <PredictionSystemTarget>(); return(targetComponent == null || targetComponent.enabled); })) { for (int i = 0; i < lineRends.Count; i++) { lineRends[i].enabled = false; } bodies = new BodyPoints[0]; HideAllOrbits(); return; //Don't calculate } //<===== //>===== Create working data array from bodies. bodies = new BodyPoints[targets.Count]; for (int i = 0; i < bodies.Length; i++) { var targetComponent = targets[i].GetComponent <PredictionSystemTarget>(); bool isVisibleOrb = targetComponent == null || targetComponent.enabled; Material mat = targetComponent == null ? LinesMaterial : targetComponent.OrbitMaterial; bodies[i] = new BodyPoints() { pos = targets[i].transformRef.position, v = (Vector3)targets[i].velocity, m = (float)targets[i].mass, isFixed = targets[i].isFixedPosition, isVisible = isVisibleOrb, material = mat, width = targetComponent == null ? LinesWidth : targetComponent.OrbitWidth, points = new Vector3[PointsCount] }; } //<===== //>===== Calculate scene motion progress and record points into arrays. for (int i = 0; i < PointsCount; i++) { //>===== calculate next step velocities for each body for (int j = 0; j < bodies.Length; j++) { if (bodies[j].isFixed) { continue; } Vector3 acceleration = Vector3.zero; for (int n = 0; n < bodies.Length; n++) { if (n != j) { acceleration += Acceleration(bodies[j].pos, bodies[n].pos, bodies[n].m * (float)SimControl.gravitationalConstant, 0.5f, (float)SimControl.maxAttractionRange); } } bodies[j].v += acceleration * CalcStep; } //<===== //>===== move bodies and store current step positions for (int j = 0; j < bodies.Length; j++) { if (bodies[j].isFixed) { continue; } bodies[j].points[i] = bodies[j].pos; bodies[j].pos += bodies[j].v * CalcStep; } //<===== } //<====== }