/// <summary> /// Aligns this item at the center or to the left of a view. /// </summary> /// <param name="helper">The helper to be used.</param> private void Align(GeometricHelper helper) { switch (AlignmentProperty) { case (Alignment.LEFT): { helper.separatorX = helper.titleX = helper.x1; if (Data != null) { helper.dataX = helper.separatorX + Title.Length + 1; } break; } case (Alignment.CENTER): { helper.separatorX = helper.x1 + (helper.length / 2) - (Separator.Width / 2); helper.titleX = helper.x1 + (helper.center - Title.Length / 2); if (Data != null) { int dataLength = Data.ToString().Length; if (Separator.Width > Title.Length) { helper.titleX = helper.separatorX; helper.dataX = helper.separatorX + Separator.Width - dataLength; } else { helper.titleX = helper.x1 + (helper.center - (Title.Length + dataLength) / 2); helper.dataX = helper.titleX + Title.Length + 1; } } break; } } }
private void timer_Tick(object sender, EventArgs e) { var CurrentValue = DateTime.Now - this.Ticktimer; //Console.WriteLine("TickTimer : " + CurrentValue.Milliseconds); foreach (Bee bee in this.Bees) { SensorManager.Detection(bee, this.Honeys); this._neuralNetworkManager.ManageOutputsOfNetwork(bee); GeometricHelper.StayOnPanelRange(bee); foreach (Honey honey in Honeys) { if (GeometricHelper.Contain(honey, bee)) { honey.Rectangle.SetValue(Canvas.LeftProperty, this.RandomCoord.NextDouble() * ApplicationConfig.MAX_WIDTH_PANEL); honey.Rectangle.SetValue(Canvas.TopProperty, this.RandomCoord.NextDouble() * ApplicationConfig.MAX_HEIGHT_PANEL); bee.Fitness = bee.Fitness + 1; } } } if (this.New_MyTimerTick != null) { New_MyTimerTick(this, new NewMyTimerTickEventArgs((double)CurrentValue.Seconds + ((double)CurrentValue.Milliseconds / 1000))); } }
private void HandleOrientation(InputState inputState) { if (_orientation.X != 0 || _orientation.Y != 0) { _orientation.Normalize(); rotation = GeometricHelper.GetAngleFromVectorDirection(_orientation); } InputState.StickPosition currentPosition = InputState.ConvertVectorDirectionToStickPosition(_orientation); string newAnimation = ""; if (animationMap.ContainsKey(currentPosition)) { newAnimation = animationMap[currentPosition]; } if (!newAnimation.Equals(_currentAnimationState)) { _currentAnimationState = newAnimation; SetCurrentAnimationState(_currentAnimationState); } if (_movementVector.X == 0 && _movementVector.Y == 0) { PauseAnimation(); } else { ResumeAnimation(); } }
public static void Detection(Bee _bee, List <Honey> _honeys) { IntersectionManager intersectionManager = new IntersectionManager(); foreach (Sensor sensor in _bee.Sensors) { sensor.State = 0; foreach (Honey honey in _honeys) { if (intersectionManager.LineIntersectsRect(sensor.Display, honey.Rectangle)) { GeometricHelper.GetClosestDistance(sensor, CalculateDistance(new Point(sensor.Display.X1, sensor.Display.Y1), new Point(intersectionManager.IntersectionX, intersectionManager.IntersectionY))); sensor.State = 1; // ==> Avec un événement ça aurait été plus propre //Console.WriteLine("Distance sensor object = " + sensor.DistanceToObject + // " intersection (X;Y) = (" + intersectionManager.IntersectionX + ";" + intersectionManager.IntersectionY + ")" + // " sensorcoor (X;Y) = (" + sensor.Display.X1 + ";" + sensor.Display.Y1 + ")"); } } if (sensor.State == 1) { sensor.Display.Stroke = Brushes.Red; } else { sensor.Display.Stroke = Brushes.Black; if (sensor.DistanceToObject != SensorConfig.SENSOR_LENGHT) { sensor.DistanceToObject = SensorConfig.SENSOR_LENGHT; } } } }
/// <summary> /// Draws the data in form of a toString in this item. /// </summary> /// <param name="helper">The helper to be used.</param> /// <param name="startY">Start position on the y-axis in a view.(Column index).</param> private void DrawData(GeometricHelper helper, int startY) { if (Data != null) { Console.SetCursorPosition(helper.dataX, startY); Console.WriteLine(Data.ToString()); } }
/// <summary> /// Draws the separator for this item. /// </summary> /// <param name="helper">The helper to be used.</param> /// <param name="startY">Start position on the y-axis in a view.(Column index).</param> private void DrawSeparator(GeometricHelper helper, int startY) { for (int i = 0; i <= Separator.Width; i++) { int x = helper.separatorX + i; Console.SetCursorPosition(x, startY + 1); Console.Write(Unicode.ItemCodes.SEPARATOR); } }
public void Activate(Vector2 fromPosition, Vector2 direction, float speed, float size, int team) { Show(); _speed = 10; _team = team; position = fromPosition + (direction * 10); SetTextureRectangle(new Rectangle(112 + (32 * team), 80, 10, 8)); rotation = GeometricHelper.GetAngleFromVectorDirection(direction); directionVector = direction; SetScale(size * 2); damage = (int)size; _lifeTimer = cTimeToLive; }
/// <summary> /// Draw or clears all the items in this view. /// This function simply projects all the items text on to this view or removes it if the boolean blank is set to true, which /// would be usefull if the properties of a item is changed. /// </summary> /// <param name="blank">Condition to draw the items with the themes background color.</param> public void DrawItems(bool blank = false) { _accumulation = 0; GeometricHelper helper = new GeometricHelper(Rectangle, Margin); foreach (Item item in _items.Values) { int itemHeight = item.DrawItem(helper, blank?new Theme(Theme.Background, Theme.Background, Theme.Background, Theme.Background): Theme, _accumulation); _accumulation += itemHeight + VerticalSpacing; } }
/// <summary> /// Draws a title for this item. /// </summary> /// <param name="helper">The helper to be used.</param> /// <param name="theme">The theme to be used.</param> /// <param name="startY">Start position on the y-axis in a view.(Column index)</param> private void DrawTitle(GeometricHelper helper, Theme theme, int startY) { char binder = Binder.ToString()[0]; for (int i = 0; i < Title.Length; i++) { int x = helper.titleX + i; Console.SetCursorPosition(x, startY); char c = Title[i]; Console.ForegroundColor = binder == c ? theme.HotKey : theme.Foreground; Console.Write(c); } Console.ForegroundColor = theme.Foreground; }
public void Explode(Vector2 position, Vector2 direction, float spreadInRadians, float maxLifeTime) { foreach (Fragment fragment in fragments) { Vector2 randomPosition = direction * 16 + position; float directionRadians = GeometricHelper.GetAngleFromVectorDirection(direction); int randomAngleThousands = PlayScreen.random.Next((int)(1000f * (directionRadians - spreadInRadians)), (int)(1000f * (directionRadians + spreadInRadians))); Vector2 randomDirection = GeometricHelper.GetVectorDirectionFromAngle((float)randomAngleThousands / 1000f); float randomVelocity = (float)PlayScreen.random.NextDouble() * 20 + 10; float randomRotation = (float)PlayScreen.random.NextDouble() * 0.1f; float randomTime = PlayScreen.random.Next((int)(maxLifeTime / 2)) + maxLifeTime / 2; fragment.Activate(randomPosition, randomDirection, randomVelocity, randomRotation, 1000); } fragmentsRemaining = fragments.Count; _isUsable = false; }
private void DrawLine(double x1, double y1, double x2, double y2, ChartPlotInfo info, Brush brush, bool isDashed = false) { var line = new Line(); line.X1 = GeometricHelper.XCoordToChart(x1, info); line.X2 = GeometricHelper.XCoordToChart(x2, info); line.Y1 = GeometricHelper.YCoordToChart(y1, info); line.Y2 = GeometricHelper.YCoordToChart(y2, info); line.Stroke = brush; line.StrokeThickness = 2; if (isDashed) { line.StrokeThickness = 1; line.StrokeDashOffset = 5; } RenderElement(line); }
/// <summary> /// Draws this item, requires a Geometric Helper to aid with the boundries rules. Also a integer that keeps track of the height for this specific item is necessery. /// </summary> /// <param name="helper">Helper to be used.</param> /// <param name="theme">Theme to be used.</param> /// <param name="accumulation">The height that this item should be drawn at.</param> /// <returns>Returns the height of the item when rendered.</returns> public int DrawItem(GeometricHelper helper, Theme theme, int accumulation) { if (Title.Length > helper.length || Separator.Width > helper.length) { throw new Exception("Not enough space to draw."); } Align(helper); int startY = accumulation + helper.y1; DrawTitle(helper, theme, startY); DrawSeparator(helper, startY); DrawData(helper, startY); int rows = DrawDescription(helper, startY); return(Description.Length == 0?2:2 + rows + 1); }
private void DrawCircle(DateTime dateTime, double p, ChartPlotInfo info, Brush brush) { var circle = new Ellipse(); circle.ToolTip = string.Format("Дата: {0:yyyy MMM dd}, значення: {1}", dateTime, p); circle.Stroke = brush; circle.Fill = Brushes.White; circle.Width = 10; circle.Height = 10; circle.StrokeThickness = 2; var x = GeometricHelper.DateToChart(dateTime, info) - circle.Width / 2; var y = GeometricHelper.YCoordToChart(p, info) - circle.Height / 2; Canvas.SetTop(circle, y); Canvas.SetLeft(circle, x); RenderElement(circle); }
private void DrawLine(DateTime x1, double y1, DateTime x2, double y2, ChartPlotInfo info, Brush brush, bool isDashed = false) { var line = new Line(); line.X1 = GeometricHelper.DateToChart(x1, info); line.X2 = GeometricHelper.DateToChart(x2, info); line.Y1 = GeometricHelper.YCoordToChart(y1, info); line.Y2 = GeometricHelper.YCoordToChart(y2, info); line.Stroke = brush; line.StrokeThickness = 2; if (isDashed) { DoubleCollection dashes = new DoubleCollection(2); dashes.Add(5); dashes.Add(5); line.StrokeThickness = 1; line.StrokeDashArray = dashes; } RenderElement(line); }
/// <summary> /// Draws the description of this item. /// </summary> /// <param name="helper">The helper to be used.</param> /// <param name="startY">Start position on the y-axis in a view.(Column index).</param> private int DrawDescription(GeometricHelper helper, int startY) { if (Description.Length == 0) { return(1); } int availableLength = Separator.Width > Title.Length?Separator.Width:helper.length; int sx = Separator.Width > Title.Length?helper.separatorX:helper.titleX; string[] words = Description.Split(' '); int written = 0; int rows = startY + 2; string w; foreach (string word in words) { w = word; int toWrite = word.Length; if (toWrite + written > availableLength || w.Contains("*")) { rows++; written = 0; } else if (w.Contains("~")) { w = w.Replace("~", ""); rows++; written = 0; toWrite--; } Console.SetCursorPosition(sx + written, rows); Console.Write(w); written += toWrite + 1; } return(rows - startY - 1); }