Ejemplo n.º 1
0
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (isGameOver == false) //遊戲是否已結束
            {
                if (bulletList.Count > bulletamount)
                {
                    return;                                  //玩家子彈是否已達上限
                }
                CBullet bullet;

                if (bullettype == 0) //攻擊10的子彈
                {
                    bullet = new CBullet(Properties.Resources.bullet, new Point(0, 0), 1, 0, 10);
                }
                else
                {
                    bullet = new CBullet(Properties.Resources.bullet2, new Point(0, 0), 1, 0, 20); //攻擊20的子彈
                }
                bullet.pt.X   = airplane.pt.X + (airplane.rec.Width / 2) - (bullet.rec.Width / 2);
                bullet.pt.Y   = airplane.pt.Y - bullet.rec.Height;
                bullet.isLive = true;
                bulletList.Add(bullet);
                this.Invalidate();
                laser.Play();
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
 public bool Checkdie(CBullet bm) //檢查是否被射死
 {
     if (rec.IntersectsWith(bm.rec))
     {
         life -= bm.damage; //生命減子彈的攻擊數
         if (life <= 0)
         {
             bm.isLive = false;
             isLive    = false;
             return(true);
         }
         bm.isLive = false;
     }
     return(false);
 }
Ejemplo n.º 4
0
 public bool CheckBoom(ArrayList boomList) //有沒有射到子彈
 {
     for (int i = 0; i < boomList.Count; i++)
     {
         CBullet bm = boomList[i] as CBullet;
         if (rec.IntersectsWith(bm.rec))
         {
             bm.isLive = false;
             boomList.Remove(bm);
             isLive = false;
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 5
0
        private void Form1_KeyDown(object sender, KeyEventArgs e) //鍵盤輸入
        {
            if (e.KeyCode == Keys.Space)                          //空白鍵-發射子彈
            {
                if (isGameOver == false)
                {
                    if (bulletList.Count > bulletamount)
                    {
                        return;
                    }
                    CBullet bullet;
                    if (bullettype == 0)
                    {
                        bullet = new CBullet(Properties.Resources.bullet, new Point(0, 0), 1, 0, 10);
                    }
                    else
                    {
                        bullet = new CBullet(Properties.Resources.bullet2, new Point(0, 0), 1, 0, 20);
                    }
                    bullet.pt.X   = airplane.pt.X + (airplane.rec.Width / 2) - (bullet.rec.Width / 2);
                    bullet.pt.Y   = airplane.pt.Y - bullet.rec.Height;
                    bullet.isLive = true;
                    bulletList.Add(bullet);
                    this.Invalidate();
                    laser.Play();
                }
            }
            if (e.KeyCode == Keys.Left) //左移
            {
                airplane.KeyMove(1);
                this.Invalidate();
            }

            if (e.KeyCode == Keys.Right) //右移
            {
                airplane.KeyMove(2);
                this.Invalidate();
            }
        }
Ejemplo n.º 6
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(); //畫圖
        }