예제 #1
0
        //-------------Thread 裡面的 動作-------------//
        public void Move()
        {
            switch (step)
            {
            //遊戲進場
            case 0:
                Thread.Sleep(70);
                if (WingL != null)
                {
                    WingL.Action();
                }
                if (WingR != null)
                {
                    WingR.Action();
                }
                break;

            //遊戲開始
            case 1:
                //在Thread裡面的動作記得要睡覺。
                countTime.StartT();
                Thread.Sleep(70);

                //角色的翻轉動作。
                if (Cloud._Angle >= 0)
                {
                    mainCharactor.Action();
                }
                else
                {
                    mainCharactor.ReAction();
                }

                //角色的動態圖
                if (WingL != null)
                {
                    WingL.Action();
                }
                if (WingR != null)
                {
                    WingR.Action();
                }
                yellowBird.Action();

                //翅膀是否碰到
                if (WingL != null)
                {
                    if (WingL.isClick(mainCharactor.Center.X, mainCharactor.Center.Y))
                    {
                        music.ContiPlayMusic("getWings.mp3");
                        Global.target -= 1;
                        WingL          = null;
                    }
                }
                if (WingR != null)
                {
                    if (WingR.isClick(mainCharactor.Center.X, mainCharactor.Center.Y))
                    {
                        music.ContiPlayMusic("getWings.mp3");
                        Global.target -= 1;
                        WingR          = null;
                    }
                }

                if (WingL == null && WingR == null)
                {
                    music.PlayMusic("change.wav");
                    mainCharactor.Motion(3);
                    if (Global.Mode == 1)
                    {
                        step = 4;
                    }
                    else
                    {
                        step = 2;
                    }
                }

                // 黃色小鳥移動與刷新
                if (yellowBird.Center.X < 0 && (stone.Center.Y > 500))
                {
                    yellowBird.HP = 2;
                    yellowBird.Motion(0);
                    yellowBird.Center = new Point(1300, 100);
                    stone.t           = 0;
                    stone.Center      = yellowBird.Center;
                }
                else
                {
                    yellowBird.Move(-20, 0);
                }

                // 黃色小鳥丟石頭與否
                if (stone.Center.Y <= yellowBird.Center.Y + 100)
                {
                    //當小鳥超過主角會自動釋放物體
                    if (yellowBird.Center.X <= mainCharactor.Center.X && stone.Center.X > 0)
                    {
                        if (!countTime.Sec(1))
                        {
                            music.ContiPlayMusic("Stonrfalling.mp3");
                        }
                        stone.GMove(0, 1);
                    }
                    else
                    {
                        //石頭沒超過主角,和鳥一起移動
                        stone.Center = new Point(yellowBird.Center.X, yellowBird.Center.Y + 50);
                    }
                }
                else
                {
                    //石頭自然釋出
                    if (stone.isClick(mainCharactor.Center.X, mainCharactor.Center.Y - 50))
                    {
                        if (countTime.MilSec(500))
                        {
                            Global.HP -= 2;
                            music.PlayMusic(1);
                        }
                        music.StopMusic("Stonrfalling.mp3");

                        if (Global.HP <= 0)
                        {
                            step = 3;
                        }
                    }
                    if (Cloud.isClick(stone.Center.X, stone.Center.Y - 50))
                    {
                        music.PlayMusic("punch.mp3");
                        if (stone.Center.X > Cloud.Center.X)
                        {
                            Cloud._Angle += Convert.ToInt32(Math.Sqrt(Math.Pow(stone.Center.X - Cloud.Center.X, 2) + Math.Pow(stone.Center.Y - Cloud.Center.Y, 2)) / 60);
                        }
                        else
                        {
                            Cloud._Angle += -Convert.ToInt32(Math.Sqrt(Math.Pow(stone.Center.X - Cloud.Center.X, 2) + Math.Pow(stone.Center.Y - Cloud.Center.Y, 2)) / 50);
                        }
                    }

                    stone.GMove(0, 1);
                }

                if (mainCharactor.Center.Y + Convert.ToInt32(-a * Math.Tan(mainCharactor.Sita)) > 900)
                {
                    Global.HP--;
                    if (Global.HP <= 0)
                    {
                        step = 3;
                    }
                    a  = 0;
                    t1 = t2 = 0;
                }

                //當板子開始有角度的時候
                if (Cloud._Angle > 0)
                {
                    //角色在板子上的(加)速度
                    a -= Convert.ToInt32(10 * Math.Sin(mainCharactor.Sita)) * t1 / 2;
                    //角色的速度為零時,時間參數歸零,避免角色暴衝
                    if (Convert.ToInt32(10 * Math.Sin(mainCharactor.Sita)) * t1 / 2 == 0)
                    {
                        t1 = 0;
                    }
                    //另一側的時間參數歸零
                    t2 = 0;
                    //時間參數是隨著執行次數而增加的
                    t1++;

                    //角色在斜面上移動,y的位置利用角度去算出確實位置,以保證角色維持在斜面上移動。
                    mainCharactor.CloudMove(Cloud.Center, -a, Convert.ToInt32(-a * Math.Tan(mainCharactor.Sita)));
                    //角色和斜面同角度。
                    mainCharactor._Angle = Cloud._Angle;
                }
                else if (Cloud._Angle < 0)
                {
                    a -= Convert.ToInt32(10 * Math.Sin(mainCharactor.Sita)) * t2 / 2;
                    if (Convert.ToInt32(10 * Math.Sin(mainCharactor.Sita)) * t2 / 2 == 0)
                    {
                        t2 = 0;
                    }

                    t1 = 0;
                    t2++;
                    mainCharactor.CloudMove(Cloud.Center, -a, Convert.ToInt32(-a * Math.Tan(mainCharactor.Sita)));
                    mainCharactor._Angle = Cloud._Angle;
                }
                else if (Cloud._Angle == 0)
                {
                    mainCharactor._Angle = Cloud._Angle;
                    mainCharactor.CloudMove(Cloud.Center, -a, Convert.ToInt32(-a * Math.Tan(mainCharactor.Sita)));
                    t1 = t2 = 0;
                }
                countTime.EndT();
                break;

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

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

            //遊戲過關
            case 4:
                music.PlayMusic("Pass.mp3");
                Ranker ranker = new Ranker();
                ranker.Load();
                ranker.Clear();
                ranker.ShowRank(1);
                step = 5;
                break;

            case 5:
                turn.TurnWin(pageName.mainPage);
                break;
            }
        }
예제 #2
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;
            }
        }