private void EatFood(slFood food) { if (m_CanEatFood) { m_Power += food.BeEat(m_Head.Node.transform); } }
public void DoUpdateFoodSystem() { int canCreateFoodCount = slConstants.FOOD_SYSTEM_MAXCREATE_PREFRAME; int createEventCount = Mathf.Min(m_CreateEvents.Count, canCreateFoodCount); while (createEventCount-- > 0) { CreateEvent createEvent = m_CreateEvents.Dequeue(); CreateFood(createEvent.FoodType, createEvent.Position, createEvent.Color, createEvent.Power); } canCreateFoodCount -= createEventCount; int needCreateFood = Mathf.Min(m_MaxFood - m_FoodCount, canCreateFoodCount); while (needCreateFood-- > 0) { CreateFood(slConstants.FoodType.Normal , hwmRandom.RandVector2(m_FoodMinPosition, m_FoodMaxPosition) , hwmRandom.RandColorRGB() , slConstants.NORMAL_FOOD_POWER); } for (int iFood = 0; iFood < m_DestroyEvents.Count; iFood++) { slFood food = m_DestroyEvents[iFood]; DestroyFood(food); } m_DestroyEvents.Clear(); m_Quadtree.MergeAndSplitAllNode(); }
private void DestroyFood(slFood food) { slFoodPresentation foodPresentation = food.GetPresentation(); if (foodPresentation != null) { foodPresentation.gameObject.SetActive(false); m_FoodPresentationPools[(int)foodPresentation.FoodType].Push(foodPresentation); } m_Foods.Remove(food.GetIndex()); food.DeactiveFood(); m_FoodPool.Push(food); m_FoodCount--; }
private void CreateFood(slConstants.FoodType foodType, Vector3 position, Color color, float power) { slFoodProperties foodProperties = m_FoodPropertiess[(int)foodType]; slFood food = m_FoodPool.Pop(); int foodIndex = food.GetIndex(); if (foodIndex == slConstants.FOOD_NOTSET_INDEX) { foodIndex = ++m_LastFoodIndex; } m_Foods.Add(foodIndex, food); slFoodPresentation foodPresentation = m_FoodPresentationPools != null ? m_FoodPresentationPools[(int)foodType].Pop() : null; if (foodPresentation != null) { foodPresentation.gameObject.SetActive(true); foodPresentation.SetColor(color); } food.ActiveFood(foodIndex, foodProperties, foodPresentation, position, color, power); m_FoodCount++; }
public void EatFood(float radius) { ms_FoodQuadtreeNodes.Clear(); hwmBox2D eatAABB = hwmBox2D.BuildAABB(m_Head.GetPosition(), new Vector2(radius, radius)); slWorld.GetInstance().GetFoodSystem().GetQuadtree().GetRootNode().GetAllIntersectNode(ref ms_FoodQuadtreeNodes, eatAABB); hwmSphere2D headSphere = new hwmSphere2D(m_Head.GetPosition(), radius); for (int iNode = 0; iNode < ms_FoodQuadtreeNodes.Count; iNode++) { hwmQuadtree <slFood> .Node iterNode = ms_FoodQuadtreeNodes[iNode]; hwmBetterList <slFood> foods = iterNode.GetElements(); bool inHeadSphere = headSphere.IsInside(iterNode.GetLooseBox()); for (int iFood = foods.Count - 1; iFood >= 0; iFood--) { slFood iterFood = foods[iFood]; if (inHeadSphere || (iterFood.GetPosition() - m_Head.GetPosition()).sqrMagnitude <= radius * radius) { EatFood(iterFood); } } } }
public void AddDestroyFoodEvent(slFood food) { m_DestroyEvents.Add(food); }