Example #1
0
        //---------------- 加在 Form1.Thread 裡 ----------------//
        public void Move()
        {
            switch (step)
            {
            //遊戲進場說明
            case 0:
                Thread.Sleep(80);
                if (explainPage == 1 && Global.Mode > 0)
                {
                    mainCharactor.Action();

                    //敵人的動作
                    if (!isAttackOrange)
                    {
                        orangeDragon.Action();
                        if (newt.MilSec(500))
                        {
                            orangeDragon.Motion(1);
                        }
                    }
                    //敵人丟骨頭
                    bone._Angle += 9;
                    bone.Move(-15 - speed, 0);

                    if (mainCharactor.isClick(bone.Center.X, bone.Center.Y))
                    {
                        //如果沒防禦
                        if (!escaption)
                        {
                            music.PlayMusic(1);
                            mainCharactor.Motion(2);
                            canPaintHp01 = true;
                        }
                        bone.Center = new Point(orangeDragon.Center.X - 50, orangeDragon.Center.Y - 20);
                        music.PlayMusic(3);
                    }
                }
                break;

            //遊戲開始
            case 1:

                newt.StartT();
                Thread.Sleep(50);

                //----------------  背景移動
                mountains.Action(-200, new Point(1800, 600), -3, 0);
                grasses.Action(-150, new Point(1200, 658), -3 - speed, 0);
                clouds.Action(-150, new Point(1300, 150 + 80 * randomizer.Next(1, 5)), -3, 0);

                if (orangeDragon.Enemys > 0)
                {
                    // 黃色小鳥 : 會丟石頭或生命蛋
                    yellowBird.Action();
                    // 黃色小鳥移動與刷新
                    if (yellowBird.Center.X < 0 && (stone.Center.X < 0))
                    {
                        yellowBird.HP = 2;
                        yellowBird.Motion(0);
                        yellowBird.Center = new Point(1300, 100);
                        stone.Center      = yellowBird.Center;
                    }
                    else
                    {
                        yellowBird.Move(-8 - speed, 0);
                    }

                    // 黃色小鳥丟石頭與否
                    if (yellowBird.HP > 0)
                    {
                        //當小鳥超過主角會自動釋放物體
                        if (yellowBird.Center.X <= mainCharactor.Center.X - (-3 - speed) * (20 + speed))
                        {
                            //當石頭砸到主角
                            if (stone.isClick(mainCharactor.Center.X, mainCharactor.Center.Y - 50))
                            {
                                mainCharactor._Angle += 5;
                                Global.HP            -= 2;
                                music.PlayMusic(6);
                                stone.Center = new Point(-100, 0);
                                stone.t      = 0;
                                if (Global.HP <= 0)
                                {
                                    step = 3;
                                }
                            }
                            //石頭落下狀態
                            if (stone.Center.Y < 700)
                            {
                                music.ContiPlayMusic("Stonrfalling.mp3");
                                stone.GMove(-3 - speed, 1);
                            }
                            else
                            {
                                stone.Move(-5 - speed, 0);
                            }
                        }
                        else
                        {
                            //石頭沒超過主角,和鳥一起移動
                            stone.Center = new Point(yellowBird.Center.X, yellowBird.Center.Y + 70);
                        }
                    }
                    else
                    {
                        //小鳥被點到,石頭自然釋出
                        if (stone.isClick(orangeDragon.Center.X, orangeDragon.Center.Y))
                        {
                            music.PlayMusic(1);
                            orangeDragon.HP -= 4;
                            orangeDragon.Life();
                        }
                        if (stone.Center.Y < 700)
                        {
                            music.ContiPlayMusic("Stonrfalling.mp3");
                            stone.GMove(-3 - speed, 1);
                            if (stone.Center.Y > 680)
                            {
                                music.PlayMusic(6);
                            }
                        }
                        else
                        {
                            music.StopMusic("Stonrfalling.mp3");
                            stone.Move(-5 - speed, 0);
                        }
                    }
                }

                //主角的動作
                mainCharactor.Action();
                if (mainCharactor._Angle > 0)
                {
                    mainCharactor._Angle -= 1;
                }
                if (orangeDragon.Enemys <= 0 && rainbow.isClick(mainCharactor.Center.X - 250, mainCharactor.Center.Y))
                {
                    mainCharactor.Move(-2 - speed, -5 - speed);
                    if (mainCharactor.Center.Y <= 100)
                    {
                        step = 2;
                    }
                }

                if (orangeDragon.Enemys > 0)
                {
                    //敵人的動作
                    orangeDragon.Action();
                    orangeDragon.Move(-5 - speed, 0);
                    bone._Angle += 9;
                    bone.Move(-20 - speed, 0);

                    if (orangeDragon.Center.X <= 0)
                    {
                        orangeDragon.Center = new Point(1200, 600);
                        bone.Center         = new Point(orangeDragon.Center.X - 50, orangeDragon.Center.Y - 20);
                    }

                    //點主角防禦骨頭攻擊
                    if (mainCharactor.isClick(bone.Center.X, bone.Center.Y))
                    {
                        //如果沒防禦
                        if (!escaption)
                        {
                            music.PlayMusic(1);
                            Global.HP -= 1;
                            if (Global.HP <= 0)
                            {
                                step = 3;
                            }
                            mainCharactor.Motion(2);
                        }
                        bone.Center = new Point(orangeDragon.Center.X - 50, orangeDragon.Center.Y - 20);
                        music.PlayMusic(3);
                        orangeDragon.Motion(1);
                    }
                    else if (!orangeDragon.isClick(bone.Center.X, bone.Center.Y) && orangeDragon.images.Count == 3)
                    {
                        orangeDragon.Motion(0);
                    }

                    healthyellow.Health(yellowBird.HP, 2);
                    healthorange.Health(orangeDragon.HP, 10);
                    healthyellow.Center = new Point(yellowBird.Center.X, yellowBird.Center.Y - 100);
                    healthorange.Center = new Point(orangeDragon.Center.X, orangeDragon.Center.Y - 100);
                }

                //怪物打完一定數量啟動換關卡機制
                if (orangeDragon.Enemys <= 0)
                {
                    Form1.labelx.Invoke((Action) delegate { Form1.labelx.Text = Global.TIME.ToString("000.0") + " Sec            " + "              X " + Global.target; });
                    Thread.Sleep(25);
                    rainbow.Move(-4 - speed, 0);
                    mainCharactor.Move(4 + speed, 0);
                }
                else
                {
                    newt.EndT();
                }
                speed = 9 - orangeDragon.Enemys;
                break;

            //遊戲勝場
            case 2:
                turn.TurnWin(pageName.level01);
                break;

            //遊戲敗場
            case 3:
                turn.TurnGameOver(pageName.mainPage);
                break;
            }
        }
Example #2
0
        //-------------- 放在 Form1.Animate 裡 ---------------//
        public void Action()
        {
            switch (step)
            {
            //遊戲進場
            case 0:
                Thread.Sleep(80);
                //step = 1;
                break;

            //遊戲開始
            case 1:
                countTime.StartT();
                Thread.Sleep(70);

                //------ maincharator 被射線打到
                if (brownDragon != null && brownDragon.brownDragon.Center.X <= 950 && brownDragon.myEndPoint.X <= 300)
                {
                    if (mainCharator.isClick(brownDragon.brownDragon.Center.X - 800
                                             , brownDragon.brownDragon.Center.Y))
                    {
                        if (countTime.MilSec(1000))
                        {
                            mainCharator.Motion(6);
                            brownDragon.Motion(0);
                            music.PlayMusic(5);
                            Global.HP--;
                        }
                    }
                }

                //----------------  clouds
                cloudsCenter = new Point(1300, 150 + 100 * randomizer.Next(1, 5));
                clouds.Action(-150, cloudsCenter, -1, 0);


                //------  mainCharator
                mainCharator.Action();

                //------ brownDragon
                if (brownDragon != null)
                {
                    brownDragon.Fly();
                }

                //--------- fire & progressBar
                for (int i = 0; i < Fire_MaX_Num; i++)
                {
                    if (fires[i] != null)
                    {
                        fires[i].Action();
                        //music.PlayMusic("fireAttack.mp3");
                        fires[i].Center = new Point(fires[i].Center.X + 30, fires[i].Center.Y);

                        if (fires[i].Center.X >= 1100)
                        {
                            fires[i] = null;
                        }
                    }
                    if (fires[i] != null)
                    {
                        for (int j = 0; j < TINYDRAGON_NUM; j++)
                        {
                            if (healthPts[j] != null && tinyDragons[j] != null)
                            {
                                if (tinyDragons[j].isClick(fires[i].Center.X + 10, fires[i].Center.Y)) // 如果小恐龍碰到火焰則...
                                {
                                    fires[i] = null;                                                   // 火焰消失
                                    music.PlayMusic(6);                                                // 小恐龍發出燃燒的聲音
                                    tinyDragons[j].Motion(1);                                          // 小恐龍圖變成燃燒的恐龍圖
                                    tinyDragons[j].hp--;                                               // tinyDragon 被火焰打到 hp 值減一
                                    healthPts[j].hp--;
                                    healthPts[j].Health(tinyDragons[j].hp, 10);                        // 血條依 tinyDragon 的 hp 值做變化
                                    if (healthPts[j].hp == 0)                                          // 如果血條為 0, 則...
                                    {
                                        healthPts[j]   = null;                                         // 血條為 null
                                        tinyDragons[j] = null;                                         // 小恐龍為 null
                                        healthPtCount++;
                                    }
                                    break;
                                }
                            }
                        }
                    }


                    //------ 火焰打到 brownDragon
                    if (fires[i] != null && brownDragon != null)         // 如果 brownDragon 被火焰打到, 則...
                    {
                        for (int k = 0; k < brownDragonImgHeight / 4; k++)
                        {
                            if (fires[i].isClick(brownDragon.brownDragon.Center.X - (brownDragonImgWidth / 4),
                                                 brownDragon.brownDragon.Center.Y - (brownDragonImgHeight / 16) + k) && brownDragon.hp != 0)
                            {
                                music.PlayMusic(6);
                                brownDragon.Motion(1);                                          // browmDragon 受傷圖
                                brownDragon.hp--;                                               // brownDragon 生命值減少
                                brownDragonHealthPt.hp--;                                       // 血條減少
                                brownDragonHealthPt.Health(brownDragon.hp, BROWNDRAGON_Max_HP); // 血條依 brownDragon 比例調整
                                fires[i] = null;                                                // 火焰消失
                                if (brownDragon.hp == 0)
                                {
                                    brownDragon         = null; // 如果 brownDragon 生命值為 0 則設為 null
                                    brownDragonHealthPt = null; // 血條設為 null
                                }
                                break;
                            }
                        }
                    }
                }

                //-------- 血條跟著 brownDragon
                if (brownDragonHealthPt != null && brownDragon != null)
                {
                    brownDragonHealthPt.Center = new Point(brownDragon.brownDragon.Center.X - 80, brownDragon.brownDragon.Center.Y - 100);
                }


                //--------- tinyDragon
                for (int i = 0; i < TINYDRAGON_NUM; i++)
                {
                    if (healthPts[i] != null && tinyDragons[i] != null)
                    {
                        healthPts[i].Center = new Point(tinyDragons[i].Center.X - 10, tinyDragons[i].Center.Y - 60);
                    }

                    if (tinyDragons[i] != null)
                    {
                        tinyDragons[i].Action();
                        if (mainCharator.isClick(tinyDragons[i].Center.X - 47, tinyDragons[i].Center.Y) && tinyDragons[i].hp != 0)     // 利用 size 過濾碰撞條件
                        {
                            if (countTime.Sec(1))
                            {
                                mainCharator.Motion(6);
                                Global.HP -= 1;
                                music.PlayMusic(1);
                            }     // 等待一秒再扣 HP
                        }
                    }
                }

                //--------- tinyDragon 追蹤 maincharator
                for (int i = 0; i < TINYDRAGON_NUM; i++)
                {
                    if (tinyDragons[i] != null)
                    {
                        double dist = Distance(tinyDragons[i].Center, mainCharator.Center);     // 計算 tinyDragon 與 maincharator 的距離
                        if (tinyDragons[i].Center.X <= mainCharator.Center.X + 170)
                        {
                            tinyDragons[i].Center = new Point(tinyDragons[i].Center.X - 20, tinyDragons[i].Center.Y);
                        }
                        else
                        {
                            int r = randomizer.Next(8, 20);
                            tinyDragons[i].Center = new Point((int)(tinyDragons[i].Center.X + (mainCharator.Center.X - tinyDragons[i].Center.X) * r / dist),
                                                              (int)(tinyDragons[i].Center.Y + (mainCharator.Center.Y - tinyDragons[i].Center.Y) * r / dist));
                        }

                        if (tinyDragons[i].Center.X <= -30)
                        {
                            tinyDragons[i].Center = new Point(1000 + 50 * i * randomizer.Next(8, 20), 0 + 50 * i * randomizer.Next(0, 5));
                        }
                    }
                }

                // 如果 hp 為 0 則回到 turntablePage
                if (Global.HP <= 0)
                {
                    step = 3;
                }

                //------ 判斷轉場 進下一關
                if (brownDragon == null /*&& healthPtCount == 5*/)
                {
                    Global.target = 0;
                    step          = 2;
                }
                countTime.EndT();
                break;

            //遊戲勝場
            case 2:
                turn.TurnWin(pageName.level02);
                break;

            //遊戲敗場
            case 3:
                turn.TurnGameOver(pageName.mainPage);
                break;
            }
        }