public void OnTriggerEnter(Collider other) { Herd herd = other.GetComponent <Herd>(); if (herd != null) { MergeHerd(herd); } }
// Use this for initialization private void Start() { controller = GetComponent <Herd>(); startTime = Time.time; beatInterval = 60.0f / bpm; previousBeat = startTime - beatInterval; music.time = offset; music.Play(); }
public void Start() { Game.OnGameStart += () => DisableUI(); voisin = GetComponent <Voisin>() as Voisin; herd = HerdList.Instance.NewHerd(this); endangeredVisuals_TR = endangeredVisuals.transform; endangeredVisuals_TR.SetParent(transform.parent); }
public override void OnInspectorGUI() { DrawDefaultInspector(); Herd herd = (Herd)target; if (GUILayout.Button("RandomizePath")) { herd.RandomizePath(); } }
public EnemyPlayer(GameObject car,Transform visualFoodTransofrm,Transform[] krillVis) { newTrace = new Dictionary<int, bool>(); for(int i = 1; i <= 5; i++){ newTrace[i] = false; } this.carTransform = car.transform; drivetrain = car.GetComponentInChildren<Drivetrain>(); herd = new Herd(carTransform,krillVis,visualFoodTransofrm); }
public void SetController(GameObject theController) { Controller = theController; Herd herdController = Controller.GetComponent <Herd>(); minVelocity = herdController.minVelocity; maxVelocity = herdController.maxVelocity; randomness = herdController.randomness; chasee = herdController.chasee; inited = true; }
public float radius = 100f; // the radius of the circle public override Vector3 CalculateMove(HerdAgent agent, List <Transform> context, Herd herd) { Vector3 centerOffset = center - agent.transform.position; float t = centerOffset.magnitude / radius; if (t < 0.95) { return(Vector3.zero); // if within 95% of the circle, don't move towards the center } return(centerOffset * t * t * t); // stronger the further from the center }
public EnemyPlayer(GameObject car, Transform visualFoodTransofrm, Transform[] krillVis) { newTrace = new Dictionary <int, bool>(); for (int i = 1; i <= 5; i++) { newTrace[i] = false; } this.carTransform = car.transform; drivetrain = car.GetComponentInChildren <Drivetrain>(); herd = new Herd(carTransform, krillVis, visualFoodTransofrm); }
public void SpawnHerd(string herdAnimalID, Vector3 worldLocation, int herdSize) { if (playerTransform == null) { playerTransform = GameAccesPoint.Instance.mainGameState._playerController._playerTransform; } BaseHerdAnimal animalType = (BaseHerdAnimal)parent._gameItemDatabase.GetItem(herdAnimalID); Herd newHerd = new Herd(this, animalType, worldLocation, herdSize); herds.Add(newHerd); }
// returns a herd to the list of available herds. public void HerdIsAvailable(Herd herd) { List <Herd> herdList = null; if (!availableHerds.TryGetValue(herd.type, out herdList)) { herdList = new List <Herd>(); availableHerds.Add(herd.type, herdList); } herdList.Add(herd); }
private static Herd ParseXmlToObject(string filePath) { var herdObject = new Herd(); string xmlString = System.IO.File.ReadAllText(filePath); using (TextReader reader = new StringReader(xmlString)) { XmlSerializer serializer = new XmlSerializer(typeof(Herd)); herdObject = (Herd)serializer.Deserialize(reader); } return(herdObject); }
public void SetHerd(Herd newHerd) { if (newHerd == herd) { return; } if (herd != null) { herd.RemoveMember(this); } herd = newHerd; }
// Start is called before the first frame update void Start() { myHerdBox = GetComponentInChildren <HerdBox>(); if (GetComponent <PlayerProperties>()) { playerNum = GetComponent <PlayerProperties>().playerNum; myHerd = GameObject.Find("Herd " + GetComponent <PlayerProperties>().teamColor).GetComponent <Herd>(); } else if (GetComponent <ThirdPersonController>()) { playerNum = GetComponent <ThirdPersonController>().PlayerNum; } }
public bool EditHerd(Herd herd) { try { _db.Entry(herd).State = EntityState.Modified; _db.SaveChanges(); return(true); } catch { return(false); } }
// GET: Herds/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Herd herd = _dairyFarmService.GetHerdById((int)id); if (herd == null) { return(HttpNotFound()); } return(View(herd)); }
public bool AddHerd(Herd herd) { try { herd.Active = true; _db.Herds.Add(herd); _db.SaveChanges(); return(true); } catch { return(false); } }
// GET: Herds/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Herd herd = _dairyFarmService.GetHerdById((int)id); if (herd == null) { return(HttpNotFound()); } ViewBag.IdCattleType = new SelectList(_dairyFarmService.GetCattleTypes(), "IdCattleType", "Label", herd.IdCattleType); return(View(herd)); }
private Vector3 Calc() { Vector3 randomize = new Vector3((Random.value * 2) - 1, (Random.value * 2) - 1, (Random.value * 2) - 1); randomize.Normalize(); Herd herdController = Controller.GetComponent <Herd>(); Vector3 flockCenter = herdController.flockCenter; Vector3 flockVelocity = herdController.flockVelocity; Vector3 follow = chasee.transform.localPosition; flockCenter = flockCenter - transform.localPosition; flockVelocity = flockVelocity - rb.velocity; follow = follow - transform.localPosition; return(flockCenter + flockVelocity + follow * 2 + randomize * randomness); }
public void LeaveHerd(GameObject shep) { sheep.Remove(shep); GameObject newHerdObj = new GameObject("New Herd"); newHerdObj.transform.position = shep.transform.position; Herd newHerd = newHerdObj.AddComponent <Herd>(); newHerd.sheep = new List <GameObject>(); newHerd.GetComponent <Herd>().sheep.Add(shep); newHerd.leaderDirectionWeight = leaderDirectionWeight; newHerd.leaderResetRate = leaderResetRate; //shep.GetComponent<SheepAI>().herd = newHerd; RecalculateHerd(); }
public Herd GetHerdForType(Animal animal) { List <Herd> herdList = null; if (!availableHerds.TryGetValue(animal.type, out herdList)) { // doesn't exist, create a new one. herdList = new List <Herd>(); Herd herd = new Herd(); herd.type = animal.type; herdList.Add(herd); availableHerds.Add(animal.type, herdList); return(herd); } else { if (herdList.Count == 0) { Herd herd = new Herd(); herd.type = animal.type; herdList.Add(herd); return(herd); } else { float smallestDistance = float.MaxValue; Herd closestHerd = null; float dist; for (int i = 0; i < herdList.Count; i++) { dist = (herdList[i].GetHerdCenter() - animal.GetPosition()).sqrMagnitude; if (dist < smallestDistance) { smallestDistance = dist; closestHerd = herdList[i]; } } if (closestHerd == null) { Debug.LogError("Wut, no this cant actually happen."); } return(closestHerd); } } }
void Start() { if (herdAnimal) { herd = AnimalMap.animalMap.GetHerdForType(this); herd.AddMember(this); } hunger = Random.Range(0f, 5f); if (behaviour == null) { behaviour = BuildTree(); } behaviour.SetTarget(this); age = 0; behaviour.Start(); }
void EatSheep() { if (sheepDetector != null) { if (sheepDetector.sheepsInRange.Count > 0) { Herd herd = sheepDetector.GetHerd(); if (herd.MemberCount() <= maxSheepEaten) { GameObject instantiatedScratch = Instantiate(scratchAnimation); instantiatedScratch.transform.position = herd.GetMiddle(); herd.Eat(transform.parent.GetComponent <PlayerInfo>()); Game.Instance.sfx.PlayWolfBiteSound(); } } } }
public void HerdExampleShouldWork() { using (StringWriter sw = new StringWriter()) { TextWriter stdout = Console.Out; Console.SetOut(sw); Herd herd = new Herd(); herd.AddToHerd(new Organism(57, 66)); herd.AddToHerd(new Organism(73, 56)); herd.AddToHerd(new Organism(46, 52)); herd.AddToHerd(new Organism(19, 107)); Console.WriteLine(herd); Console.SetOut(stdout); string example = "x: 57; y: 66\nx: 73; y: 56\nx: 46; y: 52\nx: 19; y: 107\n"; StringAssert.Contains(example, sw.ToString().Replace("\r\n", "\n"), "The examples should work as such!"); } }
public async Task <IActionResult> Update([FromBody] Herd herd) { var currentHerd = await this.repository.GetAsync <Herd>(true, x => x.HerdId == herd.HerdId); if (currentHerd == null) { throw new Exception("Herd not found."); } currentHerd.KindOfFishId = herd.KindOfFishId; currentHerd.DateOfBirth = herd.DateOfBirth; currentHerd.PoolIdNow = herd.PoolIdNow; currentHerd.AverageWeightOfAnIndividual = herd.AverageWeightOfAnIndividual; currentHerd.Quantity = herd.Quantity; await this.repository.UpdateAsync <Herd>(currentHerd); return(this.Ok()); }
public void MovingHerdExampleShouldWork() { using (StringWriter sw = new StringWriter()) { TextWriter stdout = Console.Out; Console.SetOut(sw); Herd herd = new Herd(); herd.AddToHerd(new Organism(57, 66)); herd.AddToHerd(new Organism(73, 56)); herd.AddToHerd(new Organism(46, 52)); herd.AddToHerd(new Organism(19, 107)); herd.Move(5, 6); Console.WriteLine(herd); Console.SetOut(stdout); string example = "x: 62; y: 72\nx: 78; y: 62\nx: 51; y: 58\nx: 24; y: 113\n"; StringAssert.Contains(example, sw.ToString().Replace("\r\n", "\n"), "Moving a herd should move the whole herd!"); } }
public ActionResult DeleteConfirmed(int id) { Herd herd = _dairyFarmService.GetHerdById(id); herd.Active = true; var popup = new MessageInfo { State = 1, Message = "Troupeau bien supprimé" }; if (_dairyFarmService.EditHerd(herd) == false) { popup.State = 0; popup.Message = "Erreur dans la suppression"; } return(RedirectToAction("Index", new { message = popup.Message, state = popup.State })); }
public Herd GetHerd() { Herd minHerd = null; int minCount = int.MaxValue; for (int i = 0; i < sheepsInRange.Count; i++) { HerdMember member = sheepsInRange[i].GetComponent <HerdMember>() as HerdMember; Herd herd = member.GetHerd(); int count = herd.MemberCount(); if (count < minCount) { minHerd = herd; minCount = count; } } return(minHerd); }
public async Task <IActionResult> Add([FromBody] Herd herd) { var pool = await this.repository.GetAsync <Pool>(true, x => x.PoolId == herd.PoolIdNow); string whoIsInThePool = pool.WhoIsInThePool;//fish herd none if (whoIsInThePool == "none") { await this.repository.AddAsync <Herd>(herd); pool.WhoIsInThePool = "herd"; } else { throw new Exception("The pool is full"); } await this.repository.UpdateAsync <Pool>(pool); return(this.Ok()); }
public override Vector3 CalculateMove(HerdAgent agent, List <Transform> context, Herd herd) { // if no neighbors, maintain current alignment if (context.Count == 0) { return(Vector3.zero); } // add all neighbor's alignment together and average Vector3 alignmentMove = Vector3.zero; List <Transform> filterContext = (filter == null) ? context : filter.Filter(agent, context); // this is a filtered behavior foreach (Transform item in filterContext) { alignmentMove += item.GetComponent <Rigidbody>().velocity; // add the facing direction } alignmentMove /= context.Count; // average, alignmentMove is now the destination alignment return(alignmentMove); }
public void ModifiedHerdExampleShouldWork() { using (StringWriter sw = new StringWriter()) { TextWriter stdout = Console.Out; Console.SetOut(sw); Herd herd = new Herd(); herd.AddToHerd(new Organism(7, 6)); herd.AddToHerd(new Organism(6, 2)); herd.AddToHerd(new Organism(57, 66)); herd.AddToHerd(new Organism(3, 6)); herd.AddToHerd(new Organism(73, 56)); herd.AddToHerd(new Organism(46, 52)); herd.AddToHerd(new Organism(9, 7)); herd.AddToHerd(new Organism(19, 107)); Console.WriteLine(herd); Console.SetOut(stdout); string example = "x: 7; y: 6\nx: 6; y: 2\nx: 57; y: 66\nx: 3; y: 6\nx: 73; y: 56\nx: 46; y: 52\nx: 9; y: 7\nx: 19; y: 107\n"; StringAssert.Contains(example, sw.ToString().Replace("\r\n", "\n"), "Herd should work regardless of the size!"); } }
public JsonResult InsertHerd(HDB context, Herd herd) { if (context.Herds.Count() > 0) { if (context.Herds.Select(h => h.ID).Contains(herd.ID)) { return(Json(new InsertionOutcome { outcome = "Found", ID = herd.ID.ToString() })); } } if (herd.ID < 0) { herd.ID = 0; } context.Herds.Add(herd); context.SaveChanges(); return(Json(new InsertionOutcome { outcome = "Success", ID = herd.ID.ToString() })); }
public static void Main(string[] args) { //Inicjalizacja okna window = new RenderWindow(new VideoMode(1280, 720, 32), "Praca inzynierska", Styles.Close); window.Closed += (o, e) => window.Close(); window.KeyPressed += (o, e) => { if ( e.Code == Keyboard.Key.Escape ) { window.Close(); } }; origWindowSize = window.Size; DisplayTitle(); WriteLine("Title displayed!"); //inicjalizacja mapy WriteLine("Start map creating!"); const int mapSize = 50; map = new Map.Map(mapSize, new MapSeed((int)(mapSize / 5.0), (int)(mapSize / 10.0), (int)(mapSize / 15.0))); window.MouseMoved += map.Map_MouseMoved; window.MouseWheelScrolled += map.Map_MouseWheelScrolled; WriteLine("Map created!"); WriteLine("Start creating GUI!"); //Tworzenie GUI gui = new GUI() { new Button { Name = "Close Button", IsActive = true, ButtonTexture = new Sprite(NormalButtonTexture), ButtonText = new Text("Zamknij!", font) { CharacterSize = 20, Color = Color.Black }, Position = new Vector2f(20, window.Size.Y - 60), MouseButtonPressedHandler = (s, e) => { if ( Mouse.IsButtonPressed(Mouse.Button.Left) ) window.Close(); } }, new BuildButton() { Name = "Build Button", IsActive = true, ButtonTexture = new Sprite(NormalButtonTexture), ButtonText = new Text("Buduj", font) { CharacterSize = 20, Color = Color.Black }, Position = new Vector2f(20, window.Size.Y - 120) } }; window.KeyPressed += gui.Window_KeyPressed; window.KeyReleased += gui.Window_KeyReleased; window.MouseButtonPressed += gui.Window_MouseButtonPressed; window.MouseButtonReleased += gui.Window_MouseButtonReleased; window.MouseMoved += gui.Window_MouseMoved; window.MouseWheelScrolled += gui.Window_MouseWheelScrolled; WriteLine("GUI created!"); WriteLine("Start creating colony!"); Colony colony = new Colony(map, window); map.UpdateTime += colony.UpdateTime; colony.AddColonist(new Men() { Name = "Adam", MoveSpeed = 5, Location = map[10, 20], TextureSelected = new Sprite(MenTextureSelected), TextureNotSelected = new Sprite(MenTexture), IsSelected = false, HP = new FuzzyHP(50f) { MaxHP = 50f }, Strength = 5f, Mining = 3f, Constructing = 4f, Accuracy = 4.5f, }); colony.AddConstruct(new Construct(2, 3, map[3, 3], Color.Magenta) { MaxConstructPoints = 200 }); WriteLine("Colony created!"); /*WriteLine("Start creating path!"); WriteLine("Searching for start and end point!"); //tymczasowe sprawdzenie wyznaczanie sciezki IList<MapField> path; MapField start = null, stop = null; //Wyszukanie pierwszego dostepnego pola foreach ( MapField field in map.Where(field => field.IsAvaliable) ) { start = field; break; } //wyszukanie ostatniego dostepnego pola foreach ( MapField field in map.Reverse().Where(field => field.IsAvaliable) ) { stop = field; break; } WriteLine("Sstart and end point found!"); try { //próba wyznaczenia sciezki miedzy wyznaczonymi polami path = PathFinding.AStar(start, stop, PathFinding.Metric.EuclideanDistance); } catch ( FieldNotAvaliableException ) { WriteLine($"Texture [{start.MapPosition.X}, {start.MapPosition.Y}] is avaliable = {start.IsAvaliable}"); WriteLine($"Texture [{stop.MapPosition.X}, {stop.MapPosition.Y}] is avaliable = {stop.IsAvaliable}"); WriteLine("But path between this field dose not exists!"); path = null; } WriteLine("Path created!");*/ WriteLine("Start creating herd!"); MapField mapField; int center = map.Size / 2; do { int x = rand.Next(center - center / 2, center + center / 2); int y = rand.Next(center - center / 2, center + center / 2); mapField = map[x, y]; } while ( !mapField.IsAvaliable ); WriteLine($"Start from - {mapField}"); Herd herd = new Herd(mapField, 5); map.UpdateTime += herd.UpdateTime; foreach ( Animal animal in herd ) { map.UpdateTime += animal.UpdateTime; } WriteLine("Herd created!"); time.Start(); //Główna petla gry while ( window.IsOpen ) { window.DispatchEvents(); window.Clear(); time.Stop(); map.Update(time.Elapsed); time.Restart(); window.Draw(map); /*if ( path != null ) { foreach ( Sprite val in path.Select(field => new Sprite(SelectedTexture) { Position = field.ScreenPosition }) ) { window.Draw(val); } }*/ window.Draw(colony); window.Draw(herd); //window.Draw(an); window.Draw(gui); window.Display(); } }