コード例 #1
0
        void TestBulletCollision()
        {
            int rowNum = 0;

            for (int i = 0; i < kNumberOfRows; i++)
            {
                TheInvaders = InvaderRows[i];
                rowNum      = i;
                int collisionIndex = TheInvaders.CollisionTest(TheBullet.GetBounds());

                if ((collisionIndex >= 0) && ActiveBullet)
                {
                    TheInvaders.Invaders[collisionIndex].BeenHit = true;
                    TheScore.AddScore(CalcScoreFromRow(rowNum));
                    PlaySoundInThread("0.wav", 1);

                    ActiveBullet = false;
                    TheBullet.Reset();
                }

                if (SaucerStart && ActiveBullet && CurrentSaucer.GetBounds().IntersectsWith(TheBullet.GetBounds()))
                {
                    CurrentSaucer.BeenHit = true;
                    if (CurrentSaucer.ScoreCalculated == false)
                    {
                        TheScore.AddScore(CurrentSaucer.CalculateScore());
                        CurrentSaucer.ScoreCalculated = true;
                        PlaySoundInThread("3.wav", 1);
                    }
                }
            }
        }
コード例 #2
0
        private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            for (int i = 0; i < kNumberOfShields; i++)
            {
                Shields[i].Draw(g);
            }

//			g.FillRectangle(Brushes.Black, 0, 0, ClientRectangle.Width, ClientRectangle.Height);
            TheMan.Draw(g);
            TheScore.Draw(g);
            TheHighScore.Draw(g);
            displayLives.Draw(g);
            if (ActiveBullet)
            {
                TheBullet.Draw(g);
            }

            if (SaucerStart)
            {
                CurrentSaucer.Draw(g);
            }

            for (int i = 0; i < kNumberOfRows; i++)
            {
                TheInvaders = InvaderRows[i];
                TheInvaders.Draw(g);
            }
        }
コード例 #3
0
 private void SetAllDirections(bool bDirection)
 {
     for (int i = 0; i < kNumberOfRows; i++)
     {
         TheInvaders = InvaderRows[i];
         TheInvaders.DirectionRight = bDirection;
     }
 }
コード例 #4
0
 void ResetAllBombCounters()
 {
     for (int i = 0; i < kNumberOfRows; i++)
     {
         TheInvaders = InvaderRows[i];
         TheInvaders.ResetBombCounters();
     }
 }
コード例 #5
0
 private void MoveInvadersInPlace()
 {
     for (int i = 0; i < kNumberOfRows; i++)
     {
         TheInvaders = InvaderRows[i];
         TheInvaders.MoveInPlace();
     }
 }
コード例 #6
0
 void InitializeInvaderRows(int level)
 {
     InvaderRows[0] = new InvaderRow(speeds[3], speeds[2], "invader1.gif", "invader1c.gif", 2 + level);
     InvaderRows[1] = new InvaderRow(speeds[3], speeds[2], "invader2.gif", "invader2c.gif", 3 + level);
     InvaderRows[2] = new InvaderRow(speeds[3], speeds[2], "invader2.gif", "invader2c.gif", 4 + level);
     InvaderRows[3] = new InvaderRow(speeds[3], speeds[2], "invader3.gif", "invader3c.gif", 5 + level);
     InvaderRows[4] = new InvaderRow(speeds[3], speeds[2], "invader3.gif", "invader3c.gif", 6 + level);
 }
コード例 #7
0
        void TestBombCollision()
        {
            if (TheMan.Died)
            {
                NumberOfMen--;
                if (NumberOfMen == 0)
                {
                    TheHighScore.Write(TheScore.Count);
                    TheScore.GameOver = true;
                    GameGoing         = false;
                }
                else
                {
                    TheMan.Reset();
                    ResetAllBombCounters();
                }
            }

            if (TheMan.BeenHit == true)
            {
                return;
            }

            for (int i = 0; i < kNumberOfRows; i++)
            {
                TheInvaders = InvaderRows[i];
                for (int j = 0; j < TheInvaders.Invaders.Length; j++)
                {
                    for (int k = 0; k < kNumberOfShields; k++)
                    {
                        bool bulletHole = false;
                        if (Shields[k].TestCollision(TheInvaders.Invaders[j].GetBombBounds(), true, out bulletHole))
                        {
                            TheInvaders.Invaders[j].ResetBombPosition();
                            Invalidate(Shields[k].GetBounds());
                        }


                        if (Shields[k].TestCollision(TheBullet.GetBounds(), false, out bulletHole))
                        {
                            ActiveBullet = false;
                            Invalidate(Shields[k].GetBounds());
                            TheBullet.Reset();
                        }
                    }

                    if (TheInvaders.Invaders[j].IsBombColliding(TheMan.GetBounds()))
                    {
                        TheMan.BeenHit = true;
                        PlaySoundInThread("2.wav", 1);
                    }
                }
            }
        }
コード例 #8
0
        private int TotalNumberOfInvaders()
        {
            int sum = 0;

            for (int i = 0; i < kNumberOfRows; i++)
            {
                TheInvaders = InvaderRows[i];
                sum        += TheInvaders.NumberOfLiveInvaders();
            }

            return(sum);
        }
コード例 #9
0
 void TestForLanding()
 {
     for (int i = 0; i < kNumberOfRows; i++)
     {
         TheInvaders = InvaderRows[i];
         if (TheInvaders.AlienHasLanded(ClientRectangle.Bottom))
         {
             TheMan.BeenHit = true;
             PlaySoundInThread("2.wav", 1);
             TheScore.GameOver = true;
             TheHighScore.Write(TheScore.Count);
             GameGoing = false;
         }
     }
 }
コード例 #10
0
        private int CalculateLargestLastPosition()
        {
            int max = 0;

            for (int i = 0; i < kNumberOfRows; i++)
            {
                TheInvaders = InvaderRows[i];
                int nLastPos = TheInvaders.GetLastInvader().Position.X;
                if (nLastPos > max)
                {
                    max = nLastPos;
                }
            }

            return(max);
        }
コード例 #11
0
        private void MoveInvaders()
        {
            bool bMoveDown = false;

            for (int i = 0; i < kNumberOfRows; i++)
            {
                TheInvaders = InvaderRows[i];
                TheInvaders.Move();
            }

//			if (InvaderSoundCounter % 5)
            PlaySoundInThread("4.wav", 3);


            if ((CalculateLargestLastPosition()) > ClientRectangle.Width - InvaderRows[4][0].GetWidth())
            {
                TheInvaders.DirectionRight = false;
                SetAllDirections(false);
            }

            if ((CalculateSmallestFirstPosition()) < InvaderRows[4][0].Width / 3)
            {
                TheInvaders.DirectionRight = true;
                SetAllDirections(true);
                for (int i = 0; i < kNumberOfRows; i++)
                {
                    bMoveDown = true;
                }
            }

            if (bMoveDown)
            {
                for (int i = 0; i < kNumberOfRows; i++)
                {
                    TheInvaders = InvaderRows[i];
                    TheInvaders.MoveDown();
                }
            }
        }
コード例 #12
0
        private int CalculateSmallestFirstPosition()
        {
            int min = 50000;

            try
            {
                for (int i = 0; i < kNumberOfRows; i++)
                {
                    TheInvaders = InvaderRows[i];
                    int nFirstPos = TheInvaders.GetFirstInvader().Position.X;
                    if (nFirstPos < min)
                    {
                        min = nFirstPos;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }

            return(min);
        }
コード例 #13
0
ファイル: Form1.cs プロジェクト: brayanrp215/Recursos
 void TestForLanding()
 {
     for (int i = 0; i < kNumberOfRows; i++)
     {
         TheInvaders = InvaderRows[i];
         if (TheInvaders.AlienHasLanded(ClientRectangle.Bottom))
         {
             TheMan.BeenHit = true;
             PlaySoundInThread("2.wav", 1);
             TheScore.GameOver = true;
             TheHighScore.Write(TheScore.Count);
             GameGoing = false;
         }
     }
 }
コード例 #14
0
ファイル: Form1.cs プロジェクト: brayanrp215/Recursos
        void TestBulletCollision()
        {
            int rowNum = 0;
            for (int i = 0; i < kNumberOfRows; i++)
            {
                TheInvaders = InvaderRows[i];
                rowNum = i;
                int collisionIndex = TheInvaders.CollisionTest(TheBullet.GetBounds());

                if ((collisionIndex >= 0) && ActiveBullet)
                {
                    TheInvaders.Invaders[collisionIndex].BeenHit = true;
                    TheScore.AddScore(CalcScoreFromRow(rowNum));
                    PlaySoundInThread("0.wav", 1);

                    ActiveBullet = false;
                    TheBullet.Reset();
                }

                if (SaucerStart && ActiveBullet && CurrentSaucer.GetBounds().IntersectsWith(TheBullet.GetBounds()))
                {
                   CurrentSaucer.BeenHit = true;
                    if (CurrentSaucer.ScoreCalculated == false)
                    {
                        TheScore.AddScore(CurrentSaucer.CalculateScore());
                        CurrentSaucer.ScoreCalculated = true;
                        PlaySoundInThread("3.wav", 1);
                    }

                }
            }
        }
コード例 #15
0
ファイル: Form1.cs プロジェクト: brayanrp215/Recursos
        void TestBombCollision()
        {
            if (TheMan.Died)
            {
              NumberOfMen --;
              _livesIndicator.DecrementLives(); // also show on lives indicator
              Invalidate();
                if (NumberOfMen == 0)
                {
                    TheHighScore.Write(TheScore.Count);
                    TheScore.GameOver = true;
                    GameGoing = false;
                }
                else
                {
                  TheMan.Reset();
                  ResetAllBombCounters();
                }
            }

            if (TheMan.BeenHit == true)
                return;

            for (int i = 0; i < kNumberOfRows; i++)
            {
                TheInvaders = InvaderRows[i];
                for (int j = 0; j < TheInvaders.Invaders.Length; j++)
                {
                    for (int k = 0; k < kNumberOfShields; k++)
                    {
                        bool bulletHole = false;
                        if (Shields[k].TestCollision(TheInvaders.Invaders[j].GetBombBounds(), true, out bulletHole))
                        {
                            TheInvaders.Invaders[j].ResetBombPosition();
                            Invalidate(Shields[k].GetBounds());
                        }

                        if (Shields[k].TestCollision(TheBullet.GetBounds(), false, out bulletHole))
                        {
                            ActiveBullet = false;
                            Invalidate(Shields[k].GetBounds());
                            TheBullet.Reset();
                        }
                    }

                    if (TheInvaders.Invaders[j].IsBombColliding(TheMan.GetBounds()) )
                    {
                      TheMan.BeenHit = true;
                      PlaySoundInThread("2.wav", 1);
                    }
                }
            }
        }
コード例 #16
0
ファイル: Form1.cs プロジェクト: brayanrp215/Recursos
 private void SetAllDirections(bool bDirection)
 {
     for (int i = 0; i < kNumberOfRows; i++)
         {
             TheInvaders = InvaderRows[i];
             TheInvaders.DirectionRight = bDirection;
         }
 }
コード例 #17
0
ファイル: Form1.cs プロジェクト: brayanrp215/Recursos
 void ResetAllBombCounters()
 {
     for (int i = 0; i < kNumberOfRows; i++)
     {
         TheInvaders = InvaderRows[i];
         TheInvaders.ResetBombCounters();
     }
 }
コード例 #18
0
ファイル: Form1.cs プロジェクト: brayanrp215/Recursos
 private void MoveInvadersInPlace()
 {
     for (int i = 0; i < kNumberOfRows; i++)
     {
         TheInvaders = InvaderRows[i];
         TheInvaders.MoveInPlace();
     }
 }
コード例 #19
0
ファイル: Form1.cs プロジェクト: brayanrp215/Recursos
        private void MoveInvaders()
        {
            bool bMoveDown = false;

            for (int i = 0; i < kNumberOfRows; i++)
            {

                TheInvaders = InvaderRows[i];
                TheInvaders.Move();

            }

            //			if (InvaderSoundCounter % 5)
                PlaySoundInThread("4.wav", 3);

            if ((CalculateLargestLastPosition()) > ClientRectangle.Width - InvaderRows[4][0].GetWidth())
            {
                TheInvaders.DirectionRight = false;
                SetAllDirections(false);
            }

            if ((CalculateSmallestFirstPosition()) < InvaderRows[4][0].Width/3)
            {
                TheInvaders.DirectionRight = true;
                SetAllDirections(true);
                for (int i = 0; i < kNumberOfRows; i++)
                {
                    bMoveDown = true;
                }
            }

            if (bMoveDown)
            {
                for (int i = 0; i < kNumberOfRows; i++)
                {

                    TheInvaders = InvaderRows[i];
                    TheInvaders.MoveDown();

                }
            }
        }
コード例 #20
0
ファイル: Form1.cs プロジェクト: brayanrp215/Recursos
 void InitializeInvaderRows(int level)
 {
     InvaderRows[0] = new InvaderRow("invader1.gif", "invader1c.gif", 2 + level);
       InvaderRows[1] = new InvaderRow("invader2.gif", "invader2c.gif", 3 + level);
       InvaderRows[2] = new InvaderRow("invader2.gif", "invader2c.gif", 4 + level);
       InvaderRows[3] = new InvaderRow("invader3.gif", "invader3c.gif", 5 + level);
       InvaderRows[4] = new InvaderRow("invader3.gif", "invader3c.gif", 6 + level);
 }
コード例 #21
0
ファイル: Form1.cs プロジェクト: brayanrp215/Recursos
        private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            for (int i = 0; i < kNumberOfShields; i++)
            {
                Shields[i].Draw(g);
            }

            //			g.FillRectangle(Brushes.Black, 0, 0, ClientRectangle.Width, ClientRectangle.Height);
            TheMan.Draw(g);
            TheScore.Draw(g);
            TheHighScore.Draw(g);
            _livesIndicator.Draw(g);

            if (ActiveBullet)
            {
              TheBullet.Draw(g);
            }

            if (SaucerStart)
            {
              CurrentSaucer.Draw(g);
            }

            for (int i = 0; i < kNumberOfRows; i++)
            {
                TheInvaders = InvaderRows[i];
                TheInvaders.Draw(g);
            }
        }
コード例 #22
0
ファイル: Form1.cs プロジェクト: brayanrp215/Recursos
        private int CalculateSmallestFirstPosition()
        {
            int min = 50000;

            try
            {
                for (int i = 0; i < kNumberOfRows; i++)
                {
                    TheInvaders = InvaderRows[i];
                    int nFirstPos = TheInvaders.GetFirstInvader().Position.X;
                    if (nFirstPos < min)
                        min = nFirstPos;
                }

            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }

            return min;
        }
コード例 #23
0
ファイル: Form1.cs プロジェクト: brayanrp215/Recursos
        private int TotalNumberOfInvaders()
        {
            int sum = 0;
            for (int i = 0; i < kNumberOfRows; i++)
            {
                TheInvaders = InvaderRows[i];
                sum += TheInvaders.NumberOfLiveInvaders();
            }

            return sum;
        }
コード例 #24
0
 private void StartGame()
 {
     player = new Player();
     UIObjects.PlayerList.Add(Player);
     invRow = new InvaderRow(Playground);
 }
コード例 #25
0
ファイル: Form1.cs プロジェクト: brayanrp215/Recursos
        private int CalculateLargestLastPosition()
        {
            int max = 0;
            for (int i = 0; i < kNumberOfRows; i++)
            {
                TheInvaders = InvaderRows[i];
                int nLastPos = TheInvaders.GetLastInvader().Position.X;
                if (nLastPos > max)
                    max = nLastPos;
            }

            return max;
        }