예제 #1
0
    public void DoUpdateCollide()
    {
        hwmBox2D    collideAABB = hwmBox2D.BuildAABB(m_Head.GetPosition(), new Vector2(m_Head.Radius, m_Head.Radius));
        hwmSphere2D headSphere  = new hwmSphere2D(m_Head.GetPosition(), m_Properties.HeadColliderRadius);

        if ((slConstants.DAMAGETYPE_WALL & m_EnableDamageType) != 0 &&
            !slWorld.GetInstance().GetMap().GetMapBox().IsInsideOrOn(m_Head.AABB))
        {
            m_AliveState = AliveState.DeadHitWall;
            return;
        }
        hwmQuadtree <QuadtreeElement> .AABBEnumerator enumerator = new hwmQuadtree <QuadtreeElement> .AABBEnumerator(m_Head.OwnerQuadtree.GetRootNode()
                                                                                                                     , collideAABB);

        while (enumerator.MoveNext())
        {
            hwmQuadtree <QuadtreeElement> .Node iterNode = enumerator.Current;
            hwmBetterList <QuadtreeElement>     elements = iterNode.GetElements();
            for (int iElement = elements.Count - 1; iElement >= 0; iElement--)
            {
                QuadtreeElement iterElement = elements[iElement];
                if ((slConstants.DAMAGETYPE_SNAKE & m_EnableDamageType) != 0 &&
                    iterElement.Owner != m_Guid &&
                    iterElement.NodeType != slConstants.NodeType.Predict &&
                    (iterElement.GetPosition() - m_Head.GetPosition()).sqrMagnitude
                    <= ((m_Head.Radius + iterElement.Radius) * (m_Head.Radius + iterElement.Radius)))
                {
                    m_AliveState = AliveState.DeadHitSnake;
                }
            }
        }
    }
예제 #2
0
    protected bool IsHitPredict()
    {
        ms_SnakeQuadtreeNodes.Clear();
        slWorld.GetInstance().GetSnakeSystem().GetQuadtree().GetRootNode()
        .GetAllIntersectNode(ref ms_SnakeQuadtreeNodes, hwmBox2D.BuildAABB(m_Snake.GetHeadPosition(), new Vector2(m_Snake.GetHeadRadius(), m_Snake.GetHeadRadius())));

        for (int iNode = 0; iNode < ms_SnakeQuadtreeNodes.Count; iNode++)
        {
            hwmQuadtree <slSnake.QuadtreeElement> .Node iterNode = ms_SnakeQuadtreeNodes[iNode];
            hwmBetterList <slSnake.QuadtreeElement>     elements = iterNode.GetElements();
            for (int iElement = elements.Count - 1; iElement >= 0; iElement--)
            {
                slSnake.QuadtreeElement iterElement = elements[iElement];
                if (iterElement.Owner != m_Snake.GetGuid() &&
                    iterElement.NodeType == slConstants.NodeType.Predict)
                {
                    Vector2    predictCenter          = iterElement.GetPosition();
                    Quaternion predictRotationInverse = Quaternion.Inverse(iterElement.GetRotation());
                    Vector2    sphereCenter           = predictCenter
                                                        + hwmMath.QuaternionMultiplyVector(predictRotationInverse, (Vector2)m_Snake.GetHeadPosition() - predictCenter);
                    if (((slSnake.PredictNode)iterElement).Box.IntersectSphere(sphereCenter, m_Snake.GetHeadRadius() * m_Snake.GetHeadRadius()))
                    {
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
예제 #3
0
    protected bool IsSafe(Vector2 moveDirection, float distance, bool ignorePredict)
    {
        Vector2 start               = m_Snake.GetHeadPosition();
        Vector2 end                 = start + moveDirection * distance;
        Vector2 direction           = end - start;
        Vector2 directionReciprocal = hwmMath.Reciprocal(direction);

        if (!slWorld.GetInstance().GetMap().GetMapBox().IsInsideOrOn(end))
        {
            return(false);
        }

        for (int iNode = 0; iNode < ms_SnakeQuadtreeNodes.Count; iNode++)
        {
            hwmQuadtree <slSnake.QuadtreeElement> .Node iterNode = ms_SnakeQuadtreeNodes[iNode];
            hwmBetterList <slSnake.QuadtreeElement>     elements = iterNode.GetElements();
            for (int iElement = elements.Count - 1; iElement >= 0; iElement--)
            {
                slSnake.QuadtreeElement iterElement = elements[iElement];
                if (iterElement.Owner != m_Snake.GetGuid())
                {
                    if (iterElement.NodeType != slConstants.NodeType.Predict)
                    {
                        if (iterElement.AABB.LineIntersection(start, end, direction, directionReciprocal))
                        {
                            return(false);
                        }
                    }
                    else if (!ignorePredict)
                    {
                        Quaternion rotation = Quaternion.Inverse(iterElement.GetRotation());
                        Vector2    center   = iterElement.GetPosition();
                        start = hwmMath.QuaternionMultiplyVector(rotation, start - center);
                        end   = hwmMath.QuaternionMultiplyVector(rotation, end - center);
                        if (((slSnake.PredictNode)iterElement).Box.LineIntersection(start, end))
                        {
                            return(false);
                        }
                    }
                }
            }
        }
        return(true);
    }
예제 #4
0
        private void DoDrawGizomsElements(hwmQuadtree <T> .Node node)
        {
            if (node == null)
            {
                return;
            }
            hwmBetterList <T> elements = node.GetElements();

            for (int iElement = 0; iElement < elements.Count; iElement++)
            {
                hwmUtility.GizmosDrawBox2D(elements[iElement].AABB, m_GizmosZ);
            }

            if (m_GizomosDisplayChilderElement && !node.IsLeaf())
            {
                DoDrawGizomsElements(node.GetChilder(hwmQuadtreeChilderNodeIndex.LeftDown));
                DoDrawGizomsElements(node.GetChilder(hwmQuadtreeChilderNodeIndex.LeftUp));
                DoDrawGizomsElements(node.GetChilder(hwmQuadtreeChilderNodeIndex.RightUp));
                DoDrawGizomsElements(node.GetChilder(hwmQuadtreeChilderNodeIndex.RightDown));
            }
        }
예제 #5
0
    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);
                }
            }
        }
    }
예제 #6
0
        public void OnGUI()
        {
            while (m_Current == null)
            {
                if (m_LastNodes.Count > 0)
                {
                    m_Current = m_LastNodes.Pop();
                }
                else
                {
                    m_Current = m_Quadtree.GetRootNode();
                    break;
                }
            }

            if (m_Current == null)
            {
                EditorGUILayout.HelpBox("not found any node", MessageType.Error);
                return;
            }

            hwmQuadtree <T> .Node displayNode = GetDisplayNode();
            EditorGUILayout.LabelField("Depth:", displayNode.GetDepth().ToString());
            EditorGUILayout.LabelField("Element Count:", displayNode.GetElements().Count.ToString());
            EditorGUILayout.LabelField("Element Count In Self&Childers :", displayNode.GetAllElementCount().ToString());

            EditorGUILayout.Space();
            if (m_Current.GetParent() == null &&
                m_ChilderIndex == NOTSET_CHILDER_INDEX)
            {
                GUILayout.Button("No Parent");
            }
            else if (GUILayout.Button("Parent"))
            {
                if (m_ChilderIndex != NOTSET_CHILDER_INDEX)
                {
                    m_ChilderIndex = NOTSET_CHILDER_INDEX;
                }
                else
                {
                    m_Current = m_LastNodes.Pop();
                }
            }
            EditorGUILayout.BeginHorizontal();
            OnGUI_ChildersButton(hwmQuadtreeChilderNodeIndex.LeftUp);
            OnGUI_ChildersButton(hwmQuadtreeChilderNodeIndex.RightUp);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            OnGUI_ChildersButton(hwmQuadtreeChilderNodeIndex.LeftDown);
            OnGUI_ChildersButton(hwmQuadtreeChilderNodeIndex.RightDown);
            EditorGUILayout.EndHorizontal();
            if (m_Current.IsLeaf() || m_ChilderIndex == NOTSET_CHILDER_INDEX)
            {
                GUILayout.Button("Cant Enter Childer");
            }
            else if (GUILayout.Button("Enter Childer: " + m_ChilderIndex.ToString()))
            {
                m_LastNodes.Push(m_Current);
                m_Current      = m_Current.GetChilder(m_ChilderIndex);
                m_ChilderIndex = NOTSET_CHILDER_INDEX;
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Gizmos");
            m_GizmosColor = EditorGUILayout.ColorField("Color", m_GizmosColor);
            m_GizmosZ     = EditorGUILayout.FloatField("Z", m_GizmosZ);
            m_GizomosDisplayChilderElement = EditorGUILayout.Toggle("Display Childer Element", m_GizomosDisplayChilderElement);

            if (GUI.changed)
            {
                GetWindow <SceneView>().Focus();
            }
        }