private void Timer_Tick(object sender, EventArgs e) { foreach (Autobug bug in Bugs) { bug.act(Foods); foreach (Food food in Foods) { if (Measure2.Distance(bug.ActualPosition, food.Position) < 0.001) { food.shrink(bug.BiteSize); } else { food.grow(); } } Labels[Bugs.IndexOf(bug)].ShowLabel = bug._showLabel; Labels[Bugs.IndexOf(bug)].ShowLabelPersistent = bug._showLabelPersistent; Labels[Bugs.IndexOf(bug)].BugName = (bug._amDying) ? "MORTO" : bug.Name; Labels[Bugs.IndexOf(bug)].BugType = bug.Type; Labels[Bugs.IndexOf(bug)].AgeNow = bug.Age; Labels[Bugs.IndexOf(bug)].AgeMax = bug.LifeSpan; Labels[Bugs.IndexOf(bug)].RelativeAge = chkRelativeAge.IsChecked.Value; Labels[Bugs.IndexOf(bug)].IsOn = chkLabels.IsChecked.Value; Labels[Bugs.IndexOf(bug)].RenderTransform = new TranslateTransform(bug.pos.X + 50 + bug.Size / 2, bug.pos.Y + 25 + bug.Size / 2); Labels[Bugs.IndexOf(bug)].populate(); } }
public void think() { double distanceFromFood, distanceFromTarget; target = AquireTarget(); FoodPosition = Convert2.toVector(target); distanceFromFood = Measure2.Distance(WhereAmI, FoodPosition); TargetPosition = FoodPosition; distanceFromTarget = distanceFromFood; LastReassurance++; switch (WhatAmIDoing) { case "WALK": if (distanceFromTarget <= 0.001) { _whatToDo = "STOP"; } else if (distanceFromTarget > WalkingSpeed) { _whatToDo = "WALK"; } break; case "STOP": if (distanceFromTarget > WalkingSpeed) { _whatToDo = "EVOLVE"; } else { _timeStopped++; } break; case "EVOLVE": if (_timeToEvolve < _timeStopped * 10) { MySize += 1 / _timeStopped / 10; BiteSize += 1 / _timeStopped / 10000; WalkingSpeed += 1 / _timeStopped / 100000; _timeToEvolve++; _whatToDo = "EVOLVE"; } else { _timeToEvolve = 0; _timeStopped = 0; _whatToDo = "WALK"; } break; default: _whatToDo = "WALK"; break; } }
public Vector move(Vector actualPosition, Vector Target, double speed) { if (Keyboard.IsKeyDown(Key.Enter)) { speed++; } double angle = Measure2.AngleBetween(actualPosition, Target); double distance = Measure2.Distance(actualPosition, Target); double X = (speed < distance) ? Math.Cos(angle) * speed : Math.Cos(angle) * distance; double Y = (speed < distance) ? Math.Sin(angle) * speed : Math.Sin(angle) * distance; return(new Vector(X, Y)); }
private Food DecideFood() { List <double> foodPos = new List <double>(); List <double> foodSize = new List <double>(); List <Food> SuperFoods = new List <Food>(); List <Food> FoodsToCheck = new List <Food>(); Food targetFood, nearestFood; foreach (Food food in Foods) { if (food.IsSuperFood) { SuperFoods.Add(food); } } if (SuperFoods.Count > 0) { FoodsToCheck = SuperFoods; _targetIsSuperFood = true; } else { FoodsToCheck = Foods; _targetIsSuperFood = false; } foreach (Food food in FoodsToCheck) { foodPos.Add(Measure2.Distance(WhereAmI, Convert2.toVector(food))); } int nearestFoodID = foodPos.IndexOf(foodPos.Min()); nearestFood = FoodsToCheck[nearestFoodID]; targetFood = nearestFood; return(targetFood); }