Esempio n. 1
0
        protected void baseUpdateBoundingBox(/*Component pStart*/)
        {
            //GameObject pNode = (GameObject)pStart;

            // point to ColTotal
            CollisionRect ColTotal = GetCollisionObject().poCollisionRect;

            // Get the first child
            GameObject pNode = (GameObject)Iterator.GetChild(this);

            // Initialized the union to the first block
            ColTotal.Set(pNode.GetCollisionObject().poCollisionRect);

            // loop through sliblings
            while (pNode != null)
            {
                ColTotal.Union(pNode.GetCollisionObject().poCollisionRect);

                // go to next sibling
                pNode = (GameObject)Iterator.GetSibling(pNode);
            }

            //this.poColObj.poColRect.Set(201, 201, 201, 201);
            this.x = this.GetCollisionObject().poCollisionRect.x;
            this.y = this.GetCollisionObject().poCollisionRect.y;

            //  Debug.WriteLine("x:{0} y:{1} w:{2} h:{3}", ColTotal.x, ColTotal.y, ColTotal.width, ColTotal.height);
        }
Esempio n. 2
0
        protected void BaseUpdateBoundingBox()
        {
            // Go to first child
            Component  pComponent = (Component)this;
            GameObject pNode      = (GameObject)ForwardIterator.GetChild(pComponent);

            Debug.Assert(pNode != null);

            CollisionRect ColTotal = this.pCollisionObject.GetCollisionRect();

            ColTotal.Set(pNode.GetCollisionObject().GetCollisionRect());

            // loop through sliblings
            while (pNode != null)
            {
                ColTotal.Union(pNode.GetCollisionObject().GetCollisionRect());

                // go to next sibling
                pComponent = ForwardIterator.GetSibling(pNode);

                if (pComponent != null)
                {
                    pNode = (GameObject)pComponent;
                }
                else
                {
                    pNode = null;
                }
            }

            this.x = this.GetCollisionObject().GetCollisionRect().x;
            this.y = this.GetCollisionObject().GetCollisionRect().y;

            //Debug.WriteLine("x:{0} y:{1} w:{2} h:{3}", ColTotal.x, ColTotal.y, ColTotal.width, ColTotal.height);
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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 override void Execute(float deltaTime)
        {
            GhostManager       pGhostManager       = GameStateManager.GetGame().GetStateGhostManager();
            GameObjectManager  pGameObjectManager  = GameStateManager.GetGame().GetStateGameObjectManager();
            SpriteBatchManager pSpriteBatchManager = GameStateManager.GetGame().GetStateSpriteBatchManager();


            Composite  pCoreCannonGroup = GameStateManager.GetGame().GetStateCompositeManager().Find(Composite.CompositeName.CoreCannonGroup);
            GameObject pGameObj         = pGhostManager.Find(GameObject.Name.CoreCannon);

            // Remove game object from ghost manager
            pGhostManager.Detach(pGameObj);

            // Reset position
            pGameObj.SetX(200);
            pGameObj.SetY(100);

            // Reset Collision Object
            Azul.Rect       pSpriteProxyScreenRect = pGameObj.GetSpriteProxy().GetSpriteScreenRect();
            CollisionObject pCollisionObject       = pGameObj.GetCollisionObject();

            pCollisionObject.GetCollisionRect().Set(pSpriteProxyScreenRect);
            pCollisionObject.GetCollisionSpriteBox().Set(SpriteBox.Name.Box, 200, 100, pSpriteProxyScreenRect.width, pSpriteProxyScreenRect.height);

            // Add to GameObjectManager
            Debug.Assert(pGameObj != null);
            pGameObjectManager.Attach(pGameObj);

            // Add to Composite
            pCoreCannonGroup.Add(pGameObj);

            // Attach to SpriteBatch
            pGameObj.ActivateSprite(pSpriteBatchManager.Find(SpriteBatch.Name.CoreCannon));
            pGameObj.ActivateCollisionSprite(pSpriteBatchManager.Find(SpriteBatch.Name.CollisionBox));
        }
Esempio n. 6
0
        public void Recreate(Alien.Type type, float posX, float posY)
        {
            GameObject        pGameObj           = null;
            GhostManager      pGhostManager      = GameStateManager.GetGame().GetStateGhostManager();
            GameObjectManager pGameObjectManager = GameStateManager.GetGame().GetStateGameObjectManager();

            switch (type)
            {
            case Alien.Type.Crab:
                pGameObj = pGhostManager.Find(GameObject.Name.CrabAlien);
                break;

            case Alien.Type.FlyingSaucer:
                pGameObj = pGhostManager.Find(GameObject.Name.FlyingSaucer);
                break;

            case Alien.Type.JellyFish:
                pGameObj = pGhostManager.Find(GameObject.Name.JellyFishAlien);
                break;

            case Alien.Type.Squid:
                pGameObj = pGhostManager.Find(GameObject.Name.SquidAlien);
                break;

            default:
                // something is wrong
                Debug.Assert(false);
                break;
            }

            // Remove game object from ghost manager
            pGhostManager.Detach(pGameObj);

            // Reset position
            pGameObj.SetX(posX);
            pGameObj.SetY(posY);

            // Reset Collision Object
            Azul.Rect       pSpriteProxyScreenRect = pGameObj.GetSpriteProxy().GetSpriteScreenRect();
            CollisionObject pCollisionObject       = pGameObj.GetCollisionObject();

            pCollisionObject.GetCollisionRect().Set(pSpriteProxyScreenRect);
            pCollisionObject.GetCollisionSpriteBox().Set(SpriteBox.Name.Box, posX, posY, pSpriteProxyScreenRect.width, pSpriteProxyScreenRect.height);


            // Add to GameObjectManager
            Debug.Assert(pGameObj != null);
            pGameObjectManager.Attach(pGameObj);

            // Add to Composite
            pComposite.Add(pGameObj);

            // Attach to SpriteBatch
            pGameObj.ActivateSprite(this.pAlienSpriteBatch);
            pGameObj.ActivateCollisionSprite(this.pCollisionBoxSpriteBatch);
        }
Esempio n. 7
0
        public override void Notify()
        {
            //Debug.WriteLine("RemoveFlyingSaucerObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB);

            // This cast will throw an exception if wrong
            this.pAlien = (FlyingSaucer)this.pSubject.pObjA;

            pAlien.GetCollisionObject().GetCollisionRect().Set(0, 0, 0, 0);
            pAlien.Update();

            if (!pAlien.IsMarkedForDeath())
            {
                pAlien.MarkForDeath();

                // Delay - remove object later
                RemoveFlyingSaucerObserver pObserver = new RemoveFlyingSaucerObserver(this);
                GameStateManager.GetGame().GetStateDelayedObjectManager().Attach(pObserver);
            }

            TimerManager.Add(TimeEvent.Name.DeployFlyingSaucer, new DeployFlyingSaucerCommand(), r.Next(30, 61));
        }
Esempio n. 8
0
        public GameObject Recreate(ShieldCategory.Type type, GameObject.Name gameName, float posX = 0.0f, float posY = 0.0f)
        {
            GhostManager      pGhostManager      = GameStateManager.GetGame().GetStateGhostManager();
            GameObjectManager pGameObjectManager = GameStateManager.GetGame().GetStateGameObjectManager();

            GameObject pShield = null;

            switch (type)
            {
            case ShieldCategory.Type.Brick:
                pShield = pGhostManager.Find(GameObject.Name.ShieldBrick);
                break;

            case ShieldCategory.Type.LeftTop1:
                pShield = pGhostManager.Find(GameObject.Name.ShieldBrick_LeftTop1);
                break;

            case ShieldCategory.Type.LeftTop0:
                pShield = pGhostManager.Find(GameObject.Name.ShieldBrick_LeftTop0);
                break;

            case ShieldCategory.Type.LeftBottom:
                pShield = pGhostManager.Find(GameObject.Name.ShieldBrick_LeftBottom);
                break;

            case ShieldCategory.Type.RightTop1:
                pShield = pGhostManager.Find(GameObject.Name.ShieldBrick_RightTop1);
                break;

            case ShieldCategory.Type.RightTop0:
                pShield = pGhostManager.Find(GameObject.Name.ShieldBrick_RightTop0);
                break;

            case ShieldCategory.Type.RightBottom:
                pShield = pGhostManager.Find(GameObject.Name.ShieldBrick_RightBottom);
                break;

            case ShieldCategory.Type.Root:
                pShield = pGhostManager.Find(GameObject.Name.ShieldRoot);
                pShield.SetCollisionObjectLineColor(0.0f, 0.0f, 1.0f);
                break;

            case ShieldCategory.Type.Column:
                pShield = pGhostManager.Find(GameObject.Name.ShieldColumn);
                pShield.SetCollisionObjectLineColor(1.0f, 0.0f, 0.0f);
                break;

            default:
                // something is wrong
                Debug.Assert(false);
                break;
            }

            // Remove game object from ghost manager
            pGhostManager.Detach(pShield);

            // Reset position
            pShield.SetX(posX);
            pShield.SetY(posY);

            // Reset Collision Object
            Azul.Rect       pSpriteProxyScreenRect = pShield.GetSpriteProxy().GetSpriteScreenRect();
            CollisionObject pCollisionObject       = pShield.GetCollisionObject();

            pCollisionObject.GetCollisionRect().Set(pSpriteProxyScreenRect);
            pCollisionObject.GetCollisionSpriteBox().Set(SpriteBox.Name.Box, posX, posY, pSpriteProxyScreenRect.width, pSpriteProxyScreenRect.height);

            // Add to GameObjectManager
            GameStateManager.GetGame().GetStateGameObjectManager().Attach(pShield);

            // add to the tree
            this.pTree.Add(pShield);

            // Attached to Group
            pShield.ActivateSprite(this.pSpriteBatch);
            pShield.ActivateCollisionSprite(this.pCollisionSpriteBatch);

            return(pShield);
        }