private void EatFoodFromTile(TileFood tile) { // Take food from food tile if (tile.foodAmount > 0 && this.foodAmount < this.maxFoodAmount) { // Eat 0.1f or the amount to get to maxFoodAmount (if the second is less than 0.1f ofcourse) float amountToEat = this.maxFoodAmount - this.foodAmount >= 0.1f ? 0.1f : this.maxFoodAmount - this.foodAmount; tile.foodAmount -= amountToEat; this.foodAmount += amountToEat; } }
public void OnTriggerStay2D(Collider2D collider) { if (this.dead) { return; } TileFood foodTile = collider.GetComponent <TileFood>(); if (foodTile) // Eat food from food tile when colliding with it { if (Random.value > this.nextEatProbabillity) { this.EatFoodFromTile(foodTile); } } }
public Simulator(RenderWindow app, int dimmension) { Height = dimmension; Width = dimmension; _clock = new Stopwatch(); _lastTimeSimulate = -10000; _tilePheromone = new TilePheromone(); _tileAntHill = new TileAntHill(); _tileAnt = new TileAnt(); _tileAntQueen = new TileAntQueen(); _tileAntFighter = new TileAntFighter(); _tileBg = new TileBackground(); _tileMapHalo = new TileMapHalo(); _tileMap = new TileMap(); _tileChickenMeet = new TileFood(); World = new World(dimmension, dimmension); _panelBottom = new PanelBottom(app); _panelTop = new PanelTop(app); Active = false; _didSelectField = false; _modeZoom = false; _app = app; _option = new OptionSimulator(); var view = _app.GetView(); view.Center = new Vector2f(0, dimmension * 25); // var size = new Vector2f(view.Size.X * 2.0f, view.Size.Y * 2.0f); // view.Size = size; _app.SetView(view); _app.KeyReleased += OnKeyRelead; _app.KeyPressed += OnKeyPressed; _app.MouseButtonPressed += OnMouseButtonPressed; _app.MouseButtonReleased += OnMouseButtonReleased; _clock.Start(); _app.SetFramerateLimit(160); }