Пример #1
0
        /// <summary>
        ///		Setup the boundaries and position of this collider given a sprite
        /// </summary>
        /// <param name="theProxy"></param>
        public void SetupCollisonSpriteProxy(SpriteProxy theProxy)
        {
            SpriteBatch colliderBatch = SpriteBatchManager.Active.Find(SpriteBatch.Name.SpriteCollisions);

            // Remove previous SpriteCollisionProxy if any
            if (this.collisionSprite != null)
            {
                bool oldProxyRemoved = colliderBatch.Detach(collisionSprite.SpriteName, collisionSprite.Id);
                Debug.Assert(oldProxyRemoved, "The old collision sprite proxy wasn't removed upon setting a new proxy!");
                Debug.Assert(this.collisionSprite.SpriteName != Sprite.Name.UNINITIALIZED);
                SpriteCollisonProxyManager.Active.Recycle(collisionSprite.SpriteName, collisionSprite.Id);
                this.collisionSprite = null;
            }

            // Create a new proxy
            this.collisionSprite = SpriteCollisonProxyManager.Active.Create(theProxy.SpriteName, theProxy.Id);
            this.collisionSprite.SetId(theProxy.Id);
            this.collisionSprite.SetPosition(this.colliderBoundary.x, this.colliderBoundary.y);
            this.colliderBoundary.w = this.collisionSprite.ModelSprite.Width;
            this.colliderBoundary.h = this.collisionSprite.ModelSprite.Height;
            this.collisionSprite.SetColor(this.color);

            // Attach it to the batch
            colliderBatch.Attach(this.collisionSprite, this.collisionSprite.Id);
        }
Пример #2
0
        /// <summary>
        ///		Setup the boundaries and position of this collider given a width and height
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public void SetupCollisonSpriteProxy(float width, float height, uint newId)
        {
            SpriteBatch colliderBatch = SpriteBatchManager.Active.Find(SpriteBatch.Name.SpriteCollisions);

            // Remove previous SpriteCollisionProxy if any
            if (this.collisionSprite != null)
            {
                bool oldRemSuccess = colliderBatch.Detach(collisionSprite.SpriteName, collisionSprite.Id);
                Debug.Assert(oldRemSuccess, "Upon setting a new collider sprite proxy, the old one was not deleted!");
                Debug.Assert(this.collisionSprite.SpriteName != Sprite.Name.UNINITIALIZED);
                SpriteCollisonProxyManager.Active.Recycle(collisionSprite.SpriteName, collisionSprite.Id);
                this.collisionSprite = null;
            }

            // Create a new proxy
            this.collisionSprite = SpriteCollisonProxyManager.Active.Create(Sprite.Name.NULL, newId);
            this.collisionSprite.SetId(newId);
            this.collisionSprite.SetPosition(this.colliderBoundary.x, this.colliderBoundary.y);
            this.collisionSprite.Resize(width, height);
            this.colliderBoundary.w = width;
            this.colliderBoundary.h = height;
            this.collisionSprite.SetColor(this.color);

            // Attach it to the batch
            colliderBatch.Attach(this.collisionSprite, this.collisionSprite.Id);
        }
Пример #3
0
        /// <summary>
        ///		Changes the sprite reference
        /// </summary>
        /// <param name="newSprite"></param>
        public void SetSprite(SpriteBatch.Name newBatchName, SpriteEntity newSprite)
        {
            // Remove the old sprite from it's sprite batch
            SpriteBatch oldBatch = SpriteBatchManager.Active.Find(this.batchName);

            if (oldBatch != null)
            {
                bool su = oldBatch.Detach(this.sprite.SpriteName, this.sprite.Id);
                Debug.Assert(su, "The old SpriteBatch has to detach a valid (non-null) sprite.");
            }

            // Recycle old sprite
            SpriteProxyManager.Active.Recycle(this.sprite.SpriteName, this.sprite.Id);
            this.sprite = null;

            // Get new batch
            SpriteBatch newBatch = SpriteBatchManager.Active.Find(newBatchName);

            this.batchName = newBatchName;

            // If null, get null proxy and leave
            if (newBatch == null)
            {
                this.sprite = SpriteProxyManager.Active.NullSpriteProxy;
                return;                 // Leave
            }

            // Get new sprite and attach it
            this.sprite = SpriteProxyManager.Active.Create(newSprite.SpriteName, this.Id);
            newBatch.Attach(this.sprite, this.sprite.Id);

            this.collider.SetupCollisonSpriteProxy(this.sprite);
        }
        /// <summary>
        ///		Gets called when a Scene is loaded into memory.
        ///		Load all the stuff needed for Game Scenes
        /// </summary>
        protected override void OnSceneLoad()
        {
            // Get the green floor
            SpriteBatch  floorBatch  = this.ManagerForSpriteBatch.Find(SpriteBatch.Name.Shields);
            SpriteEntity floorSprite = SpriteEntityManager.Self.Find(Sprite.Name.Floor);

            floorBatch.Attach(floorSprite, floorSprite.Id);

            ///// GameObject Factories ////////////////////////////

            // Create all the shields
            ShieldFactory shieldFactory = new ShieldFactory(SpriteBatch.Name.Shields);

            shieldFactory.CreateShields();

            // Create all the Walls
            WallFactory wallFactory = new WallFactory();

            wallFactory.CreateWalls();

            // Create all the Aliens
            AlienFactory alienFactory = new AlienFactory(SpriteBatch.Name.Aliens);

            alienFactory.LoadResources();
            alienFactory.CreateAliens();

            // Create the player
            PlayerFactory playerFactory = new PlayerFactory(this);

            playerFactory.InitializeResources();
            playerFactory.CreatePlayer();

            // Create the UFO
            UFOFactory ufoFactory = new UFOFactory();

            ufoFactory.CreateObjects();
        }