示例#1
0
        // when bomb hits missile
        public override void VisitMissile()
        {
            if (this.category == Category.Bomb)
            {
                // reset bomb location
                ProjectileTracker.ResetProjectile(this);

                // Explode
                if (this.pProxy.pSprite.name == GameSprite.Name.DaggerBomb)
                {
                    this.dropID = (new Random().Next(0, 10));
                    ProjectileTracker.DaggerHandle();
                }
                else if (this.pProxy.pSprite.name == GameSprite.Name.RollingBomb)
                {
                    this.dropID = (new Random().Next(0, 10));
                    ProjectileTracker.RollingHandle();
                }
                else if (this.pProxy.pSprite.name == GameSprite.Name.ZigZagBomb)
                {
                    this.dropID = (new Random().Next(0, 10));
                    ProjectileTracker.ZigZagHandle();
                }
            }
        }
示例#2
0
        public override void VisitShip()
        {
            Debug.Print(this.pProxy.pSprite.name + " hits ship!");

            // Explode
            // ReDrop immediately
            if (this.pProxy.pSprite.name == GameSprite.Name.DaggerBomb)
            {
                this.dropID = (new Random().Next(0, 10));

                ProjectileTracker.DaggerHandle();
            }
            else if (this.pProxy.pSprite.name == GameSprite.Name.RollingBomb)
            {
                this.dropID = (new Random().Next(0, 10));
                ProjectileTracker.RollingHandle();
            }
            else if (this.pProxy.pSprite.name == GameSprite.Name.ZigZagBomb)
            {
                this.dropID = (new Random().Next(0, 10));
                ProjectileTracker.ZigZagHandle();
            }

            // reset bomb location
            this.pProxy.x = -10f;
            this.pProxy.y = -10f;
            this.Update();
        }
示例#3
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();
            }
        }
示例#4
0
        // shoot a missile
        public void Shoot()
        {
            // missile should be fast
            this.setDelta(10.0f);

            // for missile
            if (this.direction == 1f && !ProjectileTracker.MissileFlying)
            {
                ProjectileTracker.MissileHandle();
            }
        }
示例#5
0
 // For Missile object use
 // When missile hits Alien
 public override void VisitAlien()
 {
     if (this.category == Category.Missile)
     {
         // Explode
         //Debug.Print("Missile exloded!");
         // Reset location
         this.pProxy.x = 0f;
         this.pProxy.y = -10f;
         this.pProxy.Update();
         // Flip Missile Handle
         ProjectileTracker.MissileHandle();
     }
 }
示例#6
0
        // Up the level
        // --rebuild collision and timer manager
        // --reload alient grid and shield grid
        // --regroup sprites into spritebatch
        public void LevelUp()
        {
            TimerManager.DiscardInstance();
            ColliPairManager.DiscardInstance();
            SpriteBatchManager.getInstance().FindSpriteBatchByName(SpriteBatch.Name.Player1).RecycleNodes();
            SpriteBatchManager.getInstance().FindSpriteBatchByName(SpriteBatch.Name.Player1).Wash();


            this.load();
            GlobalPlayerStats.Player1.alienLeft = 55;
            ProjectileTracker.Reset();

            SpaceInvaders.currentState = ToPlayer1State.getInstance();
        }
示例#7
0
        // When projectile hits Wall
        public override void VisitWall()
        {
            if (this.category == Category.Missile)
            {
                // Explode
                // Reset location
                this.pProxy.x = -10f;
                this.pProxy.y = -10f;
                this.pProxy.Update();
                // Flip Missile Handle
                ProjectileTracker.MissileHandle();
            }
            else if (this.category == Category.Bomb)
            {
                // reset bomb location
                this.pProxy.x = -10f;
                this.pProxy.y = -10f;
                this.pProxy.Update();

                // Explode
                // ReDrop immediately
                if (this.pProxy.pSprite.name == GameSprite.Name.DaggerBomb)
                {
                    this.dropID = (new Random().Next(0, 10));
                    //Debug.Print("Bomb Drop ID: " + this.dropID.ToString());
                    ProjectileTracker.DaggerHandle();
                }
                else if (this.pProxy.pSprite.name == GameSprite.Name.RollingBomb)
                {
                    this.dropID = (new Random().Next(0, 10));
                    ProjectileTracker.RollingHandle();
                }
                else if (this.pProxy.pSprite.name == GameSprite.Name.ZigZagBomb)
                {
                    this.dropID = (new Random().Next(0, 10));
                    ProjectileTracker.ZigZagHandle();
                }
            }
            else if (this.category == Category.AlienGrid)
            {
                //Debug.Print("Alien Grid collides Wall");

                float oldDelta = this.pProxy.delta;

                this.CompositeSetDelta(oldDelta * -1f);
            }
        }
示例#8
0
        // switch state
        public override void Handle()
        {
            this.hitcount = 0;

            // if not initialied, do nothing
            if (privInstance == null)
            {
                return;
            }
            else
            {
                GlobalPlayerStats.isPlayer1Playing = true;
                TimerManager.getInstance().RefreshTimer();
                ProjectileTracker.Reset();
                SpaceInvaders.currentState = PlayerOneState.getInstance();
            }
        }
示例#9
0
        // When missile hits Shield
        public override void VisitShield()
        {
            if (this.category == Category.Missile)
            {
                // Explode
                // Reset location
                this.pProxy.x = 0f;
                this.pProxy.y = -10f;
                this.pProxy.Update();
                // Flip Missile Handle
                ProjectileTracker.MissileHandle();
            }
            else if (this.category == Category.Bomb)
            {
                // reset bomb location
                this.pProxy.x = -10f;
                this.pProxy.y = -10f;
                this.pProxy.Update();

                // Explode
                // ReDrop immediately
                if (this.pProxy.pSprite.name == GameSprite.Name.DaggerBomb)
                {
                    this.dropID = (new Random().Next(0, 10));
                    ProjectileTracker.DaggerHandle();
                }
                else if (this.pProxy.pSprite.name == GameSprite.Name.RollingBomb)
                {
                    this.dropID = (new Random().Next(0, 10));
                    ProjectileTracker.RollingHandle();
                }
                else if (this.pProxy.pSprite.name == GameSprite.Name.ZigZagBomb)
                {
                    this.dropID = (new Random().Next(0, 10));
                    ProjectileTracker.ZigZagHandle();
                }
            }
        }
示例#10
0
        // drop a bomb
        public void Drop(float x, float y, int level)
        {
            if (this.direction == -1f)
            {
                if (this.pSprite.name == GameSprite.Name.DaggerBomb && !ProjectileTracker.DaggerFlying)
                {
                    this.setDelta(7.0f + 0.2f * level);
                    // Final: Should be dropping from an alien pro
                    // PA6: get a random dropping point
                    this.x = x;
                    this.y = y;

                    ProjectileTracker.DaggerHandle();
                }
                else if (this.pSprite.name == GameSprite.Name.RollingBomb && !ProjectileTracker.RollingFlying)
                {
                    this.setDelta(5.0f + 0.2f * level);
                    // Final: Should be dropping from an alien pro
                    // PA6: get a random dropping point
                    this.x = x;
                    this.y = y;

                    ProjectileTracker.RollingHandle();
                }
                else if (this.pSprite.name == GameSprite.Name.ZigZagBomb && !ProjectileTracker.ZigzagFlying)
                {
                    this.setDelta(6.0f + 0.2f * level);
                    // Final: Should be dropping from an alien pro
                    // PA6: get a random dropping point
                    this.x = ProjectileTracker.pShip.pProxy.x;
                    this.y = y;

                    ProjectileTracker.ZigZagHandle();
                }
            }
        }
示例#11
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);
                }
            }
        }
示例#12
0
文件: Game.cs 项目: Arnold-2/SInvader
        //-----------------------------------------------------------------------------
        // Game::LoadContent()
        //		Allows you to load all content needed for your engine,
        //	    such as objects, graphics, etc.
        //-----------------------------------------------------------------------------

        public override void LoadContent()
        {
            // Load Shared Elements
            TextureManager texMgr = TextureManager.getInstance();
            ImageManager imgMgr = ImageManager.getInstance();

            // Load Textures
            texMgr.AddTexture(Texture.Name.Alien, "Invaders_0.tga");
            texMgr.AddTexture(Texture.Name.Shield, "birds_N_shield.tga");
            texMgr.AddTexture(Texture.Name.Font, "Consolas36pt.tga");

            // Load Glyphs
            GlyphManager.getInstance().AddXml(Glyph.Name.Consolas36pt, "Consolas36pt.xml", Texture.Name.Font);

            // Load Images
            imgMgr.AddImage(Image.Name.Squid_1, Texture.Name.Alien, 610.0f, 25.0f, 119.0f, 122.0f);
            imgMgr.AddImage(Image.Name.Squid_2, Texture.Name.Alien, 610.0f, 173.0f, 119.0f, 122.0f);
            imgMgr.AddImage(Image.Name.Crab_1, Texture.Name.Alien, 316.0f, 25.0f, 166.0f, 119.0f);
            imgMgr.AddImage(Image.Name.Crab_2, Texture.Name.Alien, 316.0f, 180.0f, 166.0f, 119.0f);
            imgMgr.AddImage(Image.Name.Octopus_1, Texture.Name.Alien, 57.0f, 16.0f, 197.0f, 132.0f);
            imgMgr.AddImage(Image.Name.Octopus_2, Texture.Name.Alien, 57.0f, 170.0f, 197.0f, 132.0f);
            imgMgr.AddImage(Image.Name.Ship, Texture.Name.Alien, 50f, 331f, 193f, 126f);
            imgMgr.AddImage(Image.Name.Missile, Texture.Name.Alien, 417f, 698f, 19f, 60f);
            imgMgr.AddImage(Image.Name.Nothing, Texture.Name.Alien, 21f, 480f, 341, 14f);
            imgMgr.AddImage(Image.Name.Brick, Texture.Name.Shield, 20, 210, 10, 5);
            imgMgr.AddImage(Image.Name.BrickLeft_Top0, Texture.Name.Shield, 15, 180, 10, 5);
            imgMgr.AddImage(Image.Name.BrickLeft_Top1, Texture.Name.Shield, 15, 185, 10, 5);
            imgMgr.AddImage(Image.Name.BrickLeft_Bottom, Texture.Name.Shield, 35, 215, 10, 5);
            imgMgr.AddImage(Image.Name.BrickRight_Top0, Texture.Name.Shield, 75, 180, 10, 5);
            imgMgr.AddImage(Image.Name.BrickRight_Top1, Texture.Name.Shield, 75, 185, 10, 5);
            imgMgr.AddImage(Image.Name.BrickRight_Bottom, Texture.Name.Shield, 55, 215, 10, 5);
            imgMgr.AddImage(Image.Name.DaggerBomb, Texture.Name.Alien, 275, 795, 43, 88);
            imgMgr.AddImage(Image.Name.RollingBomb, Texture.Name.Alien, 486, 639, 50, 106);
            imgMgr.AddImage(Image.Name.ZigzagBomb, Texture.Name.Alien, 570, 639, 50, 106);
            imgMgr.AddImage(Image.Name.AlienExplosion, Texture.Name.Alien, 567, 484, 197, 125);
            imgMgr.AddImage(Image.Name.ShipExplosion, Texture.Name.Alien, 558, 334, 228, 120);
            imgMgr.AddImage(Image.Name.MissileExplosion, Texture.Name.Alien, 698, 796, 94, 121);
            imgMgr.AddImage(Image.Name.UFOExplosion, Texture.Name.Alien, 40, 643, 295, 112);
            imgMgr.AddImage(Image.Name.UFO, Texture.Name.Alien, 76, 501, 240, 107);

            
            SpriteBatchManager.getInstance().AddSpriteBatch(SpriteBatch.Name.Shared, 2);

            GameSprite Ship = GameSpriteFactory.CreateGameSprite(GameObject.Category.Ship, GameSprite.Name.Ship, SpriteBatch.Name.Shared, 400f, 150f, 40.0f, 25.0f, Image.Name.Ship);
            GameSprite Missile = GameSpriteFactory.CreateGameSprite(GameObject.Category.Missile, GameSprite.Name.Missile, SpriteBatch.Name.Shared, 400f, -40f, 4f, 10f, Image.Name.Missile);
            GameSprite WallTop = GameSpriteFactory.CreateGameSprite(GameObject.Category.Wall, GameSprite.Name.TopWall, SpriteBatch.Name.Shared, 448f, 940f, 896f, 0.1f, Image.Name.Nothing);
            GameSprite WallBottom = GameSpriteFactory.CreateGameSprite(GameObject.Category.Wall, GameSprite.Name.BottomWall, SpriteBatch.Name.Shared, 448f, 137.5f, 1000f, 0.1f, Image.Name.Nothing);
            GameSprite WallLeft = GameSpriteFactory.CreateGameSprite(GameObject.Category.Wall, GameSprite.Name.LeftWall, SpriteBatch.Name.Shared, 30f, 512f, 0.1f, 1024f, Image.Name.Nothing);
            GameSprite WallRight = GameSpriteFactory.CreateGameSprite(GameObject.Category.Wall, GameSprite.Name.RightWall, SpriteBatch.Name.Shared, 866f, 512f, 0.1f, 1024f, Image.Name.Nothing);

            GameSprite DaggerBomb = GameSpriteFactory.CreateGameSprite(GameObject.Category.Bomb, GameSprite.Name.DaggerBomb, SpriteBatch.Name.Shared, 900f, 800f, 7f, 15f, Image.Name.DaggerBomb);
            GameSprite ZigzagBomb = GameSpriteFactory.CreateGameSprite(GameObject.Category.Bomb, GameSprite.Name.ZigZagBomb, SpriteBatch.Name.Shared, 900f, 800f, 7f, 15f, Image.Name.ZigzagBomb);
            GameSprite RollingBomb = GameSpriteFactory.CreateGameSprite(GameObject.Category.Bomb, GameSprite.Name.RollingBomb, SpriteBatch.Name.Shared, 900f, 800f, 7f, 15f, Image.Name.RollingBomb);
            GameSprite UFO = GameSpriteFactory.CreateGameSprite(GameObject.Category.UFO, GameSprite.Name.UFO, SpriteBatch.Name.Shared, 960f, 900f, 50f, 20f, Image.Name.UFO);

            ProjectileTracker.setMissile(Missile.pGameObject, Ship.pGameObject);
            ProjectileTracker.setBombs(DaggerBomb.pGameObject, ZigzagBomb.pGameObject, RollingBomb.pGameObject);
            ProjectileTracker.setWalls(WallLeft.pGameObject, WallRight.pGameObject, WallTop.pGameObject, WallBottom.pGameObject);
            ProjectileTracker.pUFO = UFO.pGameObject;

            // Bind keys events
            SubjectManager subjectMgr = SubjectManager.getInstance();
            subjectMgr.CreateAllSubjects();
            subjectMgr.FindSubjectByName(Subject.Name.LeftKey).Subscribe(Ship.pGameObject);
            subjectMgr.FindSubjectByName(Subject.Name.RightKey).Subscribe(Ship.pGameObject);
            subjectMgr.FindSubjectByName(Subject.Name.SpaceKey).Subscribe(Missile.pGameObject);


            // Load Start and score screen
            StartScreenState.getInstance().load();
            ToPlayer1State.getInstance().load();
            ToPlayer2State.getInstance().load();
            GameOverState.getInstance().load();

            // Load player1
            PlayerOneState.getInstance().load();
            
            // Swap timer instance to load player2
            TimerManager.SwapInstance();
            ColliPairManager.SwapInstance();

            // Load Player2
            PlayerTwoState.getInstance().load();

            //Swap back to start with player 1
            ColliPairManager.SwapInstance();
            TimerManager.SwapInstance();

            
        }