Beispiel #1
0
        // switch state
        public override void Handle()
        {
            // if not initialied, do nothing
            if (privInstance == null)
            {
                return;
            }

            GlobalPlayerStats.Player2.life--;
            GlobalPlayerStats.reduceLife();
            ProjectileTracker.Reset();

            // if player two is not over, switch to player two
            if (GlobalConfiguration.isTwoPlayers && GlobalPlayerStats.Player1.life > 0)
            {
                TimerManager.SwapInstance();
                ColliPairManager.SwapInstance();
                SpaceInvaders.currentState = ToPlayer1State.getInstance();
            }
            else if (GlobalPlayerStats.Player2.life > 0) // continue play
            {
                SpaceInvaders.currentState = ToPlayer2State.getInstance();
            }
            else // switch to score screen
            {
                SpaceInvaders.currentState = GameOverState.getInstance();
            }
        }
Beispiel #2
0
        // switch state
        public override void Handle()
        {
            this.hitcount = 0;

            // if not initialied, do nothing
            if (privInstance == null)
            {
                return;
            }
            else
            {
                GlobalPlayerStats.reset();
                if (GlobalPlayerStats.isPlayer1Playing)
                {
                    PlayerOneState.getInstance().LevelUp();

                    TimerManager.SwapInstance();
                    ColliPairManager.SwapInstance();

                    PlayerTwoState.getInstance().LevelUp();

                    TimerManager.SwapInstance();
                    ColliPairManager.SwapInstance();
                }
                else
                {
                    PlayerTwoState.getInstance().LevelUp();

                    TimerManager.SwapInstance();
                    ColliPairManager.SwapInstance();

                    PlayerOneState.getInstance().LevelUp();
                }

                SpaceInvaders.currentState      = StartScreenState.getInstance();
                GlobalConfiguration.modeChoosed = false;
            }
        }
Beispiel #3
0
        // Visitor logic
        // TODO: can be simplified using strategy
        public override void Accept(Visitor v)
        {
            if (this.category == Category.Wall)
            {
                if (this.mGameSprtName == GameSprite.Name.LeftWall)
                {
                    v.VisitLeftWall();
                }
                else if (this.mGameSprtName == GameSprite.Name.RightWall)
                {
                    v.VisitRightWall();
                }
                else
                {
                    v.VisitWall();
                }
            }
            else if (this.category == Category.Alien)
            {
                v.VisitAlien();
            }
            else if (this.category == Category.Shield)
            {
                v.VisitShield();
            }
            else if (this.category == Category.Missile)
            {
                if (ProjectileTracker.MissileFlying)
                {
                    v.VisitMissile();

                    // Reset location
                    this.pProxy.x = 0f;
                    this.pProxy.y = -10f;
                    this.pProxy.Update();
                    // Flip Missile Handle
                    ProjectileTracker.MissileHandle();
                }
            }
            else if (this.category == Category.Ship)
            {
                v.VisitShip();
            }

            // If hit by missile, start self-destruction process
            if (((GameObject)v).category == Category.Missile || (((GameObject)v).category == Category.Bomb && this.category != Category.Missile))
            {
                // Play explosion animation
                Debug.Print(this.category + " hit by" + ((GameObject)v).category);

                // If ship, trigger next round
                if (this.category == Category.Ship)
                {
                    SoundUtility.getInstance().playExplosion();
                    SpaceInvaders.currentState.Handle();
                    return;
                }

                // If Alien, incremente score
                if (this.mGameSprtName == GameSprite.Name.Octopus)
                {
                    GlobalPlayerStats.incrementScore(10);
                }
                else if (this.mGameSprtName == GameSprite.Name.Crab)
                {
                    GlobalPlayerStats.incrementScore(20);
                }
                else if (this.mGameSprtName == GameSprite.Name.Squid)
                {
                    GlobalPlayerStats.incrementScore(20);
                }

                // set itself as not collidable, if it's not wall
                if (this.category != Category.Wall)
                {
                    if (this.category == Category.Alien)
                    {
                        SoundUtility.getInstance().killed();
                        this.mGameSprite.ShowExplosion();
                    }
                    else if (this.category == Category.UFO)
                    {
                        SoundUtility.getInstance().killed();
                        ((UFOProxy)this.pProxy).reset();
                        GlobalPlayerStats.incrementScore(300);
                        return;
                    }
                    else
                    {
                        SoundUtility.getInstance().playExplosion();
                    }



                    this.collidable = false;
                    // Remove itself from active
                    GameObjectManager.getInstance().Remove(this);
                }
            }
        }