コード例 #1
0
        private void Form1_Paint(object sender, PaintEventArgs e) //畫圖
        {
            if (stbn == 1)
            {
                e.Graphics.DrawString("Score : " + score, new Font("標楷體", 24), Brushes.Red, new Point(0, 0));
            }

            if (isGameOver)
            {
                if (stbn == 0)
                {
                    if (score >= highscore) //設定 HighScore
                    {
                        highscore = score;
                    }
                    e.Graphics.DrawString("Highscore : " + highscore, new Font("標楷體", 24), Brushes.Red, new Point(0, 0));
                }
                timer1.Stop();
                if (isGameCleared)
                {
                    isGameCleared = false;
                }
                return;
            }
            airplane.Draw(e.Graphics);
            if (isBoss)
            {
                boss.Draw(e.Graphics);
                e.Graphics.DrawString("Boss : " + boss.life, new Font("標楷體", 24), Brushes.Red, new Point(200, 0));
            }
            for (int i = 0; i < bulletList.Count; i++)
            {
                CBullet bm = bulletList[i] as CBullet;
                bm.Draw(e.Graphics);
            }
            for (int i = 0; i < enemyList.Count; i++)
            {
                CEnemy em = enemyList[i] as CEnemy;
                em.Draw(e.Graphics);
            }
            for (int i = 0; i < bossbullet.Count; i++)
            {
                CBullet bb = bossbullet[i] as CBullet;
                bb.Draw(e.Graphics);
            }
            if (item.isLive == true)
            {
                item.Draw(e.Graphics);
            }
        }
コード例 #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            int test = rd.Next(0, 100);

            if (isBoss)               //BOSS 出場
            {
                if (setboss == false) //設定BOSS等級
                {
                    if (stage == 1)
                    {
                        boss = boss1;
                    }
                    else if (stage == 2)
                    {
                        boss = boss2;
                    }
                    else
                    {
                        boss = boss3;
                    }
                    setboss = true;
                }

                if (stage == 1) //第一級BOSS
                {
                    if (test < 10)
                    {
                        CBullet bullet;
                        bullet        = new CBullet(Properties.Resources.bossbullet, new Point(0, 0), 2, 0, 10);
                        bullet.pt.X   = boss.pt.X + (boss.rec.Width / 2) - (bullet.rec.Width / 2);
                        bullet.pt.Y   = boss.pt.Y + bullet.rec.Height;
                        bullet.isLive = true;
                        bossbullet.Add(bullet);
                    }
                }
                else if (stage == 2) //第二級BOSS
                {
                    if (test < 10)
                    {
                        CBullet bullet;
                        bullet        = new CBullet(Properties.Resources.bossbullet2, new Point(0, 0), 2, 0, 10);
                        bullet.pt.X   = boss.pt.X + (boss.rec.Width / 2) - (bullet.rec.Width / 2);
                        bullet.pt.Y   = boss.pt.Y + bullet.rec.Height;
                        bullet.isLive = true;
                        bossbullet.Add(bullet);
                    }
                }

                else if (stage == 3) //第三級 BOSS
                {
                    if (test < 10)
                    {
                        CBullet bullet;
                        bullet        = new CBullet(Properties.Resources.bossbullet3, new Point(0, 0), 2, 5, 10);
                        bullet.pt.X   = boss.pt.X + (boss.rec.Width / 2) - (bullet.rec.Width / 2);
                        bullet.pt.Y   = boss.pt.Y + bullet.rec.Height;
                        bullet.isLive = true;
                        bossbullet.Add(bullet);
                    }
                }

                enemyList.Clear(); //清空敵人小飛機
                airplane.Move();   //移動
                boss.Move();       //移動


                for (int i = 0; i < bulletList.Count; i++) //玩家子彈
                {
                    CBullet bm = bulletList[i] as CBullet;
                    bm.Move();

                    if (boss.Checkdie(bm)) //打到BOSS
                    {
                        score += 10;
                        bossbullet.Clear();
                        enemyList.Clear();
                        bulletList.Clear();

                        if (stage == 1) //進入下一關
                        {
                            this.BackgroundImage = Properties.Resources.bg2;
                        }
                        else if (stage == 2)
                        {
                            this.BackgroundImage = Properties.Resources.bg3;
                        }
                        else if (stage == 3)
                        {
                            isGameOver        = true;
                            ReturnBtn.Visible = true;
                            ReturnBtn.Enabled = true;
                            label3.Visible    = true;
                            isGameCleared     = true;
                        }
                        stage++;
                        gametime = 20; //重設BOSS出場時間
                        isBoss   = false;
                        setboss  = false;
                    }
                    if (!bm.isLive)
                    {
                        bulletList.Remove(bm);
                    }
                }

                for (int i = 0; i < bossbullet.Count; i++) //BOSS 子彈
                {
                    CBullet bb = bossbullet[i] as CBullet;

                    if (stage == 3)
                    {
                        bb.Move2();
                    }
                    else
                    {
                        bb.Move();
                    }
                    if (bb.CheckCrash(airplane.rec)) //是否打到玩家
                    {
                        explosion.Play();
                        isGameOver        = true;
                        label2.Visible    = true;
                        ReturnBtn.Visible = true;
                        ReturnBtn.Enabled = true;
                    }
                    if (bb.CheckBoom(bulletList)) //是否打到玩家子彈
                    {
                        bossbullet.Remove(bb);
                    }
                }
            }
            else //敵人小飛機
            {
                if (test < 10) //10%機率出現敵人小飛機
                {
                    CEnemy em = new CEnemy(Properties.Resources.rredplane, test);
                    enemyList.Add(em);
                }

                if (changebullet == 1) //道具掉落
                {
                    if (isItem == false)
                    {
                        item   = new CEnemy(Properties.Resources.item, test);
                        isItem = true;
                    }
                }
                airplane.Move();
                for (int i = 0; i < bulletList.Count; i++) //玩家子彈
                {
                    CBullet bm = bulletList[i] as CBullet;
                    bm.Move();
                    if (!bm.isLive)
                    {
                        bulletList.Remove(bm);
                    }
                }
                for (int i = 0; i < enemyList.Count; i++) //敵人小飛機
                {
                    CEnemy en = enemyList[i] as CEnemy;
                    en.Move();
                    if (en.CheckCrash(airplane.rec)) //撞到玩家飛機
                    {
                        explosion.Play();
                        isGameOver        = true;
                        label2.Visible    = true;
                        ReturnBtn.Visible = true;
                        ReturnBtn.Enabled = true;
                    }
                    if (en.CheckBoom(bulletList)) //撞到玩家子彈
                    {
                        enemyList.Remove(en);
                        score++;
                        explosion.Play();
                    }
                }

                item.Move2();                                             //道具移動
                if (item.CheckCrash(airplane.rec) && item.isLive == true) //玩家吃到道具
                {
                    bullettype  = 1;
                    item.isLive = false;
                }
                else if (item.isLive == false && bullettype == 0) //道具沒被吃到
                {
                    isItem       = false;
                    changebullet = 0;
                }
            }
            this.Invalidate(); //畫圖
        }