예제 #1
0
        public static Ship ActivateShip()
        {
            //ensure call Create() first
            ShipMan pShipMan = ShipMan.GetInstance();

            Debug.Assert(pShipMan != null);

            // create ship
            Ship pShip = new Ship(GameObject.Name.Ship, GameSprite.Name.Ship, 440, 90);

            pShipMan.pShip = pShip;

            // attach sprite to correct sprite batch
            SpriteBatch pSB_Ships = SpriteBatchMan.Find(SpriteBatch.Name.Ships);

            pSB_Ships.attach(pShip.getProxySprite());

            // attach ship to ship group
            GameObject pShipGroup = GameObjectMan.Find(GameObject.Name.ShipGroup);

            Debug.Assert(pShipGroup != null);

            // add to GameObject
            pShipGroup.add(pShipMan.pShip);
            pShip.activateCollisionSprite(SpriteBatchMan.Find(SpriteBatch.Name.Boxes));

            return(pShipMan.pShip);
        }
        public override void execute()
        {
            Ship pRealShip = (Ship)this.pShip;

            pRealShip.setState(ShipMan.State.End);
            pRealShip.setPositionState(ShipMan.State.Stay);
            pRealShip.getProxySprite().setGameSprite(GameSpriteMan.Find(GameSprite.Name.Ship_Explosion1));
            AnimationExplosion pAnimExplosion = new AnimationExplosion(pRealShip, 1.0f);

            pAnimExplosion.attach(Image.Name.Ship_Explosion2);
            pAnimExplosion.attach(Image.Name.Ship_Explosion1);
            TimerMan.Add(TimeEvent.Name.ExplosionEvent, pAnimExplosion, 0.3f);

            //this.pShip.remove();
        }
        public override void execute(float deltaTime)
        {
            this.remainTime -= deltaTime;

            if (this.remainTime > 0)
            {
                // get next image
                ImageHolder pImageHolder = (ImageHolder)this.pCurrImage.pNext;

                // if at the end of the list, set first image back
                if (pImageHolder == null)
                {
                    pImageHolder = (ImageHolder)this.poFirstImage;
                }

                this.pCurrImage = pImageHolder;

                // change image
                this.pGameObject.getProxySprite().getGameSprite().swapImage(pImageHolder.getImage());

                // Add itself back to TimerMan
                TimerMan.Add(TimeEvent.Name.ExplosionEvent, this, deltaTime);
            }
            else
            {
                Ship pShip = (Ship)this.pGameObject;
                pShip.reduceLife();
                if (pShip.getLife() < 0)
                {
                    pShip.remove();
                    Scene pScene = SceneMan.GetScene();
                    pScene.unLoadContent();
                    pScene.setState(SceneMan.State.GameOverScene);
                    pScene.loadContent();
                }
                else
                {
                    pShip.setState(ShipMan.State.Ready);
                    pShip.setPositionState(ShipMan.State.Normal);
                    pShip.bMarkForDeath = false;
                    pShip.getProxySprite().setGameSprite(GameSpriteMan.Find(GameSprite.Name.Ship));
                }
            }
        }