static public void Collide(GameObject pSafeTreeA, GameObject pSafeTreeB) { // A vs B GameObject pNodeA = pSafeTreeA; GameObject pNodeB = pSafeTreeB; while (pNodeA != null) { // Restart compare pNodeB = pSafeTreeB; while (pNodeB != null) { // who is being tested? //Debug.WriteLine("ColPair: test: {0}, {1}", pNodeA.name, pNodeB.name); // Get rectangles CollisionRect rectA = pNodeA.GetCollisionObject().poCollisionRect; CollisionRect rectB = pNodeB.GetCollisionObject().poCollisionRect; // test them if (CollisionRect.Intersect(rectA, rectB)) { // Boom - it works (Visitor in Action) pNodeA.Accept(pNodeB); break; } pNodeB = (GameObject)Iterator.GetSibling(pNodeB); } pNodeA = (GameObject)Iterator.GetSibling(pNodeA); } }
//---------------------------------------------------------------------- // Static methods //---------------------------------------------------------------------- public static void Collide(GameObject pSafeTreeA, GameObject pSafeTreeB) { // treeA vs treeB GameObject pNodeA = pSafeTreeA; GameObject pNodeB = pSafeTreeB; while (pNodeA != null) { // restart compare pNodeB = pSafeTreeB; while (pNodeB != null) { //Debug.WriteLine("ColPair: test: {0}, {1}", pNodeA.getName(), pNodeB.getName()); // get rectangles CollisionRect rectA = pNodeA.poCollisionObject.poCollisionRect; CollisionRect rectB = pNodeB.poCollisionObject.poCollisionRect; if (CollisionRect.Intersect(rectA, rectB)) { // when rectA and rectB are intersected pNodeA.accept(pNodeB); break; } pNodeB = (GameObject)Iterator.GetSibling(pNodeB); } pNodeA = (GameObject)Iterator.GetSibling(pNodeA); } }
static public void Collide(GameObject pSafeTreeA, GameObject pSafeTreeB) { // A vs B GameObject pNodeA = pSafeTreeA; GameObject pNodeB = pSafeTreeB; while (pNodeA != null) { pNodeB = pSafeTreeB; while (pNodeB != null) { // Get rectangles CollisionRect rectA = pNodeA.GetCollisionObject().GetCollisionRect(); CollisionRect rectB = pNodeB.GetCollisionObject().GetCollisionRect(); if (CollisionRect.Intersect(rectA, rectB)) { pNodeA.Accept(pNodeB); //break; } pNodeB = Iterator.GetSiblingGameObject(pNodeB); } pNodeA = Iterator.GetSiblingGameObject(pNodeA); } }
public void Collide() { GameObject currentHost = this.treeHost; GameObject currentVisitor = this.treeVisitor; // It is not possible to hit column before grid // There's no standalone column if (currentHost.isComposite) { // if current host collide with the current visitor, go next level if (CollisionRect.Intersect(currentHost.colliRect, currentVisitor.colliRect)) { // Go to column level currentHost = (GameObject)currentHost.pChildHead; while (currentHost != null) { if (CollisionRect.Intersect(currentHost.colliRect, currentVisitor.colliRect)) { // Go to leaf level currentHost = (GameObject)currentHost.pChildHead; while (currentHost != null) { if (currentHost.collidable && CollisionRect.Intersect(currentHost.colliRect, currentVisitor.colliRect)) { Debug.Print("<CollisionPair>: Collided!"); // Visitor visits host currentHost.Accept(this.treeVisitor); return; } currentHost = (GameObject)currentHost.pNextSibling; } } if (currentHost != null) { currentHost = (GameObject)currentHost.pNextSibling; } else { break; } } } } else { if (this.treeHost.collidable && (CollisionRect.Intersect(currentHost.colliRect, currentVisitor.colliRect))) { this.treeHost.Accept(this.treeVisitor); } } }
public static void Collide(GameObject gameObject1, GameObject gameObject2) { GameObject go1 = gameObject1; GameObject go2 = gameObject2; while (go1 != null) { go2 = gameObject2; while (go2 != null) { CollisionRect collisionRect1 = go1.pCollisionObject.pCollisionRect; CollisionRect collisionRect2 = go2.pCollisionObject.pCollisionRect; if (CollisionRect.Intersect(collisionRect1, collisionRect2)) { go1.Accept(go2); break; } go2 = (GameObject)go2.pSibling; } go1 = (GameObject)go1.pSibling; } }
static public void Collide(GameObject pTreeA, GameObject pTreeB) { GameObject pNodeA = pTreeA; GameObject pNodeB = pTreeB; while (pNodeA != null) { pNodeB = pTreeB; while (pNodeB != null) { CollisionRect rectA = pNodeA.pColObject.pColRect; CollisionRect rectB = pNodeB.pColObject.pColRect; //Debug.WriteLine("Collision Pair : {0} <----------> {1}", pNodeA.name, pNodeB.name); if (CollisionRect.Intersect(rectA, rectB)) { pNodeA.Accept(pNodeB); break; } pNodeB = Iterator.GetSiblingGameObject(pNodeB); } pNodeA = Iterator.GetSiblingGameObject(pNodeA); } }
public static void Collide(GameObject pSafeTreeA, GameObject pSafeTreeB) { GameObject NodeA = pSafeTreeA; GameObject NodeB = pSafeTreeB; while (NodeA != null) { NodeB = pSafeTreeB; while (NodeB != null) { CollisionRect rectA = NodeA.CollisionObj.Rect; CollisionRect rectB = NodeB.CollisionObj.Rect; if (rectA.Intersect(rectB)) { NodeA.Accept(NodeB); break; } NodeB = (GameObject)Iterator.GetSibling(NodeB); } NodeA = (GameObject)Iterator.GetSibling(NodeA); } }