public void rotates() { //一定要睡覺,不然視窗會關不起來! (有close的按鈕下) //轉盤的主程序 switch (n) { case 1: if (!newt.Sec(3)) { cycle._Angle += 3 * t; t++; } else { n = 4; } break; case 2: if (!newt.Sec(4)) { cycle._Angle += 2 * t; t++; } else { n = 4; } break; case 3: if (!newt.Sec(5)) { cycle._Angle += t; t++; } else { n = 4; } break; case 4: if (t > 0) { cycle._Angle += t; t--; music.ContiPlayMusic("Anti_Loop.mp3"); } else { music.StopMusic("Anti_Loop.mp3"); music.StopMusic("Loop.mp3"); n = 0; gobtn.Size = 3f; if (cycle._Angle % 360 == 0 || cycle._Angle % 360 == 120 || cycle._Angle % 360 == 240) { n = ran.Next(1, 4); gobtn.Size = 4f; } else if (cycle._Angle % 360 > 240) { k = 3; // 結果數值。 Global.HP = 8; turnEnd = true; } else if (cycle._Angle % 360 > 120) { k = 5; Global.HP = 10; turnEnd = true; //MessageBox.Show(k.ToString()); } else if (cycle._Angle % 360 > 0) { k = 4; Global.HP = 9; turnEnd = true; //MessageBox.Show(k.ToString()); } } break; } }
//---------------- 加在 Form1.Paint 裡 ----------------// public void Paint(Graphics g) { background.Paint(g); holegrass.Paint(g); switch (step) { //遊戲進場 case 0: //------ 說明頁 if (explain != null && ExplainPlayBtn != null) { explain.Paint(g); ExplainPlayBtn.Paint(g); rNextBtn.Paint(g); lNextBtn.Paint(g); } break; case 1: case 4: //---------------- clouds Thread.Sleep(30); clouds.Paint(g, new Point(100, 100)); mainCharactor.Paint(g); blackDragon.Paint(g); //---------------- fire if (bluefire.widthsize >= 0 && bluefire.widthsize <= 1 && bluefire.heightsize >= 0.5 && bluefire.heightsize <= 1.5 && redfire.widthsize >= 0 && redfire.widthsize <= 1 && redfire.heightsize >= 0.5 && redfire.heightsize <= 1.5) { douwn = true; bluefire.widthsize += 0.01f; bluefire.heightsize += 0.01f; bluefire.Center = new Point(redfire.Center.X + Convert.ToInt32(redfire.img.Width * redfire.widthsize), redfire.Center.Y); redfire.widthsize -= 0.01f; redfire.heightsize -= 0.01f; } if (douwn) { bluefire.SetWidthHeight(g, bluefire.widthsize, bluefire.heightsize); redfire.SetWidthHeight(g, redfire.widthsize, redfire.heightsize); douwn = false; } else if (downCount == 0) { redfire.Center = new Point(385, 465); bluefire.Center = new Point(740, 465); bluefire.SetWidthHeight(g, 0.5f, 1); redfire.SetWidthHeight(g, 0.5f, 1); downCount++; } else { if (redfire.widthsize >= 1) { redfire.Center = new Point(redfire.Center.X + 30, redfire.Center.Y); redfire.SetWidthHeight(g, 1, 1.5f); if (redfire.Center.X >= 1000) { Global.target = 0; blackDragon.Motion(1); if (countTime.Sec(2) && step != 5) { if (Global.Mode == 2) { step = 4; } else { step = 2; } } } } if (bluefire.widthsize >= 1) { bluefire.Center = new Point(bluefire.Center.X - 30, bluefire.Center.Y); bluefire.SetWidthHeight(g, 1, 1.5f); if (bluefire.Center.X <= -100) { mainCharactor.Motion(7); if (countTime.Sec(2)) { step = 3; } } } } break; case 2: case 3: case 5: turn.Paint(g); break; } }
//-------------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; } }
//-------------- 放在 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; } }