Exemplo n.º 1
0
        /// <summary>
        /// 允許頁面執行邏輯,例如更新環境、
        /// 檢查衝突、收集輸入和播放音訊。
        /// </summary>
        private void OnUpdate(object sender, GameTimerEventArgs e)
        {
            touchState = TouchPanel.GetState();

            // TODO: 在此處加入更新邏輯

            if (LOCAL == "遊戲")
            {
                if (PANEL_STOP.Visibility == System.Windows.Visibility.Visible)
                {
                    PANEL_STOP.Visibility = System.Windows.Visibility.Collapsed;
                }


                if (PANEL_MENU.Visibility == System.Windows.Visibility.Visible)
                {
                    PANEL_MENU.Visibility = System.Windows.Visibility.Collapsed;
                }

                if (R_LV == null)
                {
                    R_LV = new LV(HERO_LV);
                }


                R_LV.update();         //關卡怪物
                R_HERO.update();       //畫英雄
                R_MFired.update();     //怪物攻擊球
                R_BAR.update();
                R_MonsterThg.update(); //寶物
                R_BG.update();         //背景
            }
            else if (LOCAL == "遊戲暫停")
            {
                if (PANEL_MENU.Visibility == System.Windows.Visibility.Visible)
                {
                    PANEL_MENU.Visibility = System.Windows.Visibility.Collapsed;
                }

                if (PANEL_STOP.Visibility == System.Windows.Visibility.Collapsed)
                {
                    PANEL_STOP.Visibility = System.Windows.Visibility.Visible;
                }
            }
            else if (LOCAL == "選單")
            {
                if (PANEL_STOP.Visibility == System.Windows.Visibility.Visible)
                {
                    PANEL_STOP.Visibility = System.Windows.Visibility.Collapsed;
                }


                if (PANEL_MENU.Visibility == System.Windows.Visibility.Collapsed)
                {
                    PANEL_MENU.Visibility = System.Windows.Visibility.Visible;
                }

                if (tR_MENU)
                {
                    R_MENU.Update();//重新撈取 英雄資料
                    tR_MENU = false;
                }

                MENU_UPDATE();//不斷一直抓取資料
            }
            else if (LOCAL == "死亡")
            {
                R_MENU_DEAD.update();
            }
            else if (LOCAL == "離開遊戲")
            {
                myHERO SaveGame = new myHERO();
                SaveGame.Save();    //將所有要存檔的資料彙整
                MemoryStream ms = new MemoryStream();
                Serialize(ms, SaveGame);
                ms.Position = 0;
                ms.Close();


                byte[] by = ms.ToArray();


                //-------------------------------
                DBHandler tDBHandler = new DBHandler(DBHandler.DBConnection);


                var tContacts = from Contacts in tDBHandler.Contacts
                                where Contacts.CNAME == "HERO"
                                select Contacts;

                Contacts A = tContacts.First();
                A.XML = by;
                tDBHandler.SubmitChanges();

                GamePage.R_BAR.PowerLv = 0;//將英雄能源清除


                if (NavigationService.CanGoBack)
                {
                    NavigationService.GoBack();
                }
            }
            else if (LOCAL == "死亡離開遊戲")
            {
                GamePage.R_BAR.PowerLv = 0;//將英雄能源清除
                if (NavigationService.CanGoBack)
                {
                    NavigationService.GoBack();
                }
            }
            else if (LOCAL == "破關")
            {
                R_GAME_END.update();
            }
            else if (LOCAL == "新遊戲")
            {
                if (PANEL_NEWGAME.Visibility == System.Windows.Visibility.Collapsed)
                {
                    PANEL_NEWGAME.Visibility = System.Windows.Visibility.Visible;
                }



                if (PANEL_STOP.Visibility == System.Windows.Visibility.Visible)
                {
                    PANEL_STOP.Visibility = System.Windows.Visibility.Collapsed;
                }


                if (PANEL_MENU.Visibility == System.Windows.Visibility.Visible)
                {
                    PANEL_MENU.Visibility = System.Windows.Visibility.Collapsed;
                }
            }
        }
Exemplo n.º 2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // 設定圖形裝置的共用模式,以開啟 XNA 呈現
            SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(true);

            // 建立可用來繪製紋理的新 SpriteBatch。
            spriteBatch = new SpriteBatch(SharedGraphicsDeviceManager.Current.GraphicsDevice);


            //音效******************

            effectgetHP      = contentManager.Load <SoundEffect>("music/getHP");
            effectgetPower   = contentManager.Load <SoundEffect>("music/getPower");
            effectgetThunder = contentManager.Load <SoundEffect>("music/getHP");


            effectballM2       = contentManager.Load <SoundEffect>("music/ball_M2");
            effectMonsterfired = contentManager.Load <SoundEffect>("music/mFired");
            effectMonsterfires = contentManager.Load <SoundEffect>("music/mFires");
            effectMonsterDead  = contentManager.Load <SoundEffect>("music/mDead");

            effectHerofired = contentManager.Load <SoundEffect>("music/hFired");
            effectHerofires = contentManager.Load <SoundEffect>("music/hFires");
            effectHeroDead  = contentManager.Load <SoundEffect>("music/hFired");//與扣血相同

            picOneP  = new Texture2D[] { contentManager.Load <Texture2D>("oneP1"), contentManager.Load <Texture2D>("oneP2_A"), contentManager.Load <Texture2D>("oneP3") };
            picOneP2 = new Texture2D[] { contentManager.Load <Texture2D>("oneP2_A"), contentManager.Load <Texture2D>("oneP2_B"), contentManager.Load <Texture2D>("oneP2_C") };

            picOneP4 = new Texture2D[] { contentManager.Load <Texture2D>("oneP4_A"), contentManager.Load <Texture2D>("oneP4_B") };

            picStarBar = new Texture2D[] { contentManager.Load <Texture2D>("starS1"), contentManager.Load <Texture2D>("starS2") };



            picGAMEEND = contentManager.Load <Texture2D>("GAMEEND");
            picSCORE   = contentManager.Load <Texture2D>("SCORE");

            picBOSS1 = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS1_A"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS1_B"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS1_C") };
            picBOSS2 = contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS2");


            picBOSS3       = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS3_A"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS3_B") };
            picBOSS4       = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS4_A"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS4_B"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS4_C"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS4_D") };
            picBOSS4_LEFT  = contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS4_LEFT");
            picBOSS4_RIGHT = contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS4_RIGHT");

            picBOSS5    = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS5_A"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS5_B"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS5_C"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS5_D"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS5_E"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS5_F") };
            picBOSS5_G  = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS5_G1"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS5_G2"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS5_G3") };
            picBOSS51_G = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS51_G1"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS51_G2"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS51_G3") };


            picBOSS6 = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS6_A_A"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS6_A_B"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS6_A_C"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS6_B_A"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS6_B_B"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS6_B_C"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS6_C_A"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS6_C_B"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS6_C_C") };


            picBOSS7 = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS7_A"), contentManager.Load <Texture2D>("MONSTER/BOSS/BOSS7_B") };


            picMONSTER1_A = contentManager.Load <Texture2D>("MONSTER/MONSTER1/MONSTER1_A");
            picMONSTER1_B = contentManager.Load <Texture2D>("MONSTER/MONSTER1/MONSTER1_B");
            picMONSTER1_C = contentManager.Load <Texture2D>("MONSTER/MONSTER1/MONSTER1_C");
            picMONSTER1_D = contentManager.Load <Texture2D>("MONSTER/MONSTER1/MONSTER1_D");


            picMONSTER3_A = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_A_A"), contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_A_B") };
            picMONSTER3_B = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_B_A"), contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_B_B") };
            picMONSTER3_C = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_C_A"), contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_C_B") };
            picMONSTER3_D = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_D_A"), contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_D_B") };



            picMONSTER31_A = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_A_A"), contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_A_B") };
            picMONSTER31_B = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_B_A"), contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_B_B") };
            picMONSTER31_C = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_C_A"), contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_C_B") };
            picMONSTER31_D = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_D_A"), contentManager.Load <Texture2D>("MONSTER/MONSTER3/MONSTER3_D_B") };



            picMONSTER4_A = contentManager.Load <Texture2D>("MONSTER/MONSTER4/MONSTER4_A");
            picMONSTER4_B = contentManager.Load <Texture2D>("MONSTER/MONSTER4/MONSTER4_B");
            picMONSTER4_C = contentManager.Load <Texture2D>("MONSTER/MONSTER4/MONSTER4_C");
            picMONSTER4_D = contentManager.Load <Texture2D>("MONSTER/MONSTER4/MONSTER4_D");


            picMONSTER41_A = contentManager.Load <Texture2D>("MONSTER/MONSTER4/MONSTER41_A");
            picMONSTER41_B = contentManager.Load <Texture2D>("MONSTER/MONSTER4/MONSTER41_B");
            picMONSTER41_C = contentManager.Load <Texture2D>("MONSTER/MONSTER4/MONSTER41_C");
            picMONSTER41_D = contentManager.Load <Texture2D>("MONSTER/MONSTER4/MONSTER41_D");


            picMONSTER5_A = contentManager.Load <Texture2D>("MONSTER/MONSTER5/MONSTER5_A");
            picMONSTER5_B = contentManager.Load <Texture2D>("MONSTER/MONSTER5/MONSTER5_B");
            picMONSTER5_C = contentManager.Load <Texture2D>("MONSTER/MONSTER5/MONSTER5_C");
            picMONSTER5_D = contentManager.Load <Texture2D>("MONSTER/MONSTER5/MONSTER5_D");


            picMONSTER7_A = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/MONSTER7/MONSTER7_A_A"), contentManager.Load <Texture2D>("MONSTER/MONSTER7/MONSTER7_A_B") };
            picMONSTER7_B = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/MONSTER7/MONSTER7_B_A"), contentManager.Load <Texture2D>("MONSTER/MONSTER7/MONSTER7_B_B") };
            picMONSTER7_C = new Texture2D[] { contentManager.Load <Texture2D>("MONSTER/MONSTER7/MONSTER7_C_A"), contentManager.Load <Texture2D>("MONSTER/MONSTER7/MONSTER7_C_B") };



            //英雄子彈種類
            picBallA = new Texture2D[] { contentManager.Load <Texture2D>("ballA1"), contentManager.Load <Texture2D>("ballA2"), contentManager.Load <Texture2D>("ballA3") };
            picBallB = new Texture2D[] { contentManager.Load <Texture2D>("ballB1"), contentManager.Load <Texture2D>("ballB2"), contentManager.Load <Texture2D>("ballB3") };
            picBallC = new Texture2D[] { contentManager.Load <Texture2D>("ballC1"), contentManager.Load <Texture2D>("ballC2"), contentManager.Load <Texture2D>("ballC3") };

            picBall   = picBallC[2];
            picBallM2 = new Texture2D[] { contentManager.Load <Texture2D>("BallM2_A"), contentManager.Load <Texture2D>("BallM2_B"), contentManager.Load <Texture2D>("BallM2_C") };
            picBallM3 = new Texture2D[] { contentManager.Load <Texture2D>("BallM3_A"), contentManager.Load <Texture2D>("BallM3_B"), contentManager.Load <Texture2D>("BallM3_C") };


            //-----------
            picHERO     = contentManager.Load <Texture2D>("HERO");
            picBAR      = contentManager.Load <Texture2D>("BAR");
            picBAR2     = contentManager.Load <Texture2D>("BAR2");
            picLOVE     = contentManager.Load <Texture2D>("LOVE");
            picLOVE2    = contentManager.Load <Texture2D>("LOVE2");
            picLOVES    = contentManager.Load <Texture2D>("LOVES");
            picLOVES2   = contentManager.Load <Texture2D>("LOVES2");
            picLOVESS   = contentManager.Load <Texture2D>("LOVESS");
            picLOVESS2  = contentManager.Load <Texture2D>("LOVESS2");
            picLEVEL    = contentManager.Load <Texture2D>("LEVEL");
            picGAMEOVER = contentManager.Load <Texture2D>("GAMEOVER");

            picStar1 = contentManager.Load <Texture2D>("STAR1");
            picStar2 = contentManager.Load <Texture2D>("STAR2");
            picStar3 = contentManager.Load <Texture2D>("STAR3");
            picStar4 = contentManager.Load <Texture2D>("STAR4");
            picStar5 = contentManager.Load <Texture2D>("STAR5");
            picStar6 = contentManager.Load <Texture2D>("STAR6");
            picStar7 = contentManager.Load <Texture2D>("STAR7");
            picStar8 = contentManager.Load <Texture2D>("STAR8");


            for (int i = 0; i < picHERO_DEAD.Count(); i++)
            {
                picHERO_DEAD[i] = contentManager.Load <Texture2D>("P/p" + (i + 1).ToString());
            }

            for (int i = 0; i < picNum.Count(); i++)
            {
                picNum[i]  = contentManager.Load <Texture2D>("lib/number2/num" + i.ToString());
                picNum2[i] = contentManager.Load <Texture2D>("lib/number3/num" + i.ToString());
            }


            // TODO: 在此處使用 this.content 載入遊戲內容



            //主要角色*******************
            if (_BG != null)
            {
                R_BG = _BG;
            }
            else
            {
                R_BG = new BG(picStar1);
            }

            if (_BAR != null)
            {
                R_BAR = _BAR;
            }
            else
            {
                R_BAR = new BAR();
            }

            if (_HERO != null)
            {
                R_HERO = _HERO;
            }
             
            else
            {
                R_HERO = new HERO(HERO_LOC);
            }


            if (_LV != null)
            {
                R_LV = _LV;
            }

            if (_MENU != null)
            {
                R_MENU = _MENU;
            }
            else
            {
                R_MENU = new MENU(); PANEL_MENU.Children.Add(R_MENU);
            }



            if (_MENU_DEAD != null)
            {
                R_MENU_DEAD = _MENU_DEAD;
            }

            if (_GAME_END != null)
            {
                R_GAME_END = _GAME_END;
            }



            if (_MFired != null)
            {
                R_MFired = _MFired;
            }
            else
            {
                R_MFired = new MonsterFired();
            }

            if (_MonsterThg != null)
            {
                R_MonsterThg = _MonsterThg;
            }
            else
            {
                R_MonsterThg = new MonsterThg();
            }



            R_STOP = new STOP();
            if (PANEL_STOP.Children.Count == 0)
            {
                PANEL_STOP.Children.Add(R_STOP);
            }



            // 啟動計時器
            timer.Start();

            base.OnNavigatedTo(e);
        }