C# Tutorial – Create a Simple Punch Out Style Boxing Game in Visual Studio

Welcome to this Punch Out Style Boxing game tutorial. This is the video tutorial tutorial version of the written tutorial we have done before. You can access the written punch out boxing game tutorial here.

In this tutorial we will be making something very exciting. Classic Mike Tyson Punch Out was one of my most favorite game on my old school Nintendo and I loved playing it.¬† This was a difficult tutorial to get off the ground because most of the algorithm for the game had to be written ground up and made simple so it’s easier for a beginner to pick up and start learning. In this tutorial we will learn how to create a simple punch out game where you the player will be boxing it out with the Tough Rob the opponent. ¬†Both characters have their own health bars and can block attacks from their opponents. For this tutorial we are going to use Visual Studio 2017, Windows Form Application using the Visual C# programming language. You can use any version of visual studio to follow this tutorial because we are not going to use any external classes or game engines to make this punch out game.

Lesson Objectives –

  1. Create a simple punch out game in visual studio using c# programming language
  2. Using progress bars to show the health of player and opponent
  3. Using Selection to determine the hit test between player and opponent
  4. Using LIST to create variety of moves for the opponent which is controlled by the CPU
  5. Using Picture Boxes and Resources to show dynamic images for the player and the opponent
  6. Determining the who won the round and who lost the round using integers linked to the progress bars
  7. Using Key Down and Key Up events to control the player

 

Video Tutorial –

 

Download The punch out game images here

 

Source Code

 

namespace Simple_Punch_Out_Game_MOO_ICT
{
    public partial class Form1 : Form
    {

        // created by MOO ICT 2022
        // for educational purpose only

        bool playerBlock = false;
        bool enemyBlock = false;
        Random random = new Random();
        int enemySpeed = 5;
        int index = 0;
        int playerHealth = 100;
        int enemyHealth = 100;
        List enemyAttack = new List { "left", "right", "block"};



        public Form1()
        {
            InitializeComponent();
            ResetGame();
        }

        private void BoxerAttackTImerEvent(object sender, EventArgs e)
        {

            index = random.Next(0, enemyAttack.Count);

            switch (enemyAttack[index].ToString())
            {
                case "left":
                    boxer.Image = Properties.Resources.enemy_punch1;
                    enemyBlock = false;

                    if (boxer.Bounds.IntersectsWith(player.Bounds) && playerBlock == false)
                    {
                        playerHealth -= 5;
                    }

                break;

                case "right":

                    boxer.Image = Properties.Resources.enemy_punch2;
                    enemyBlock = false;

                    if (boxer.Bounds.IntersectsWith(player.Bounds) && playerBlock == false)
                    {
                        playerHealth -= 5;
                    }
                break;

                case "block":

                    boxer.Image = Properties.Resources.enemy_block;
                    enemyBlock = true;

                break;
            }


        }

        private void BoxerMoveTimerEvent(object sender, EventArgs e)
        {
            // set up both health bars
            if (playerHealth > 1)
            {
                playerHealthBar.Value = playerHealth;
            }
            if (enemyHealth > 1)
            {
                boxerHealthBar.Value = enemyHealth;
            }


            // move the boxer

            boxer.Left += enemySpeed;

            if (boxer.Left > 430)
            {
                enemySpeed = -5;
            }
            if (boxer.Left < 220)
            {
                enemySpeed = 5;
            }

            // check for the end of game scenario

            if (enemyHealth < 1)
            {
                BoxerAttackTimer.Stop();
                BoxerMoveTimer.Stop();
                MessageBox.Show("You Win, Click OK to Play Again", "Moo Says: ");
                ResetGame();
            }
            if (playerHealth < 1)
            {
                BoxerAttackTimer.Stop();
                BoxerMoveTimer.Stop();
                MessageBox.Show("Tough Rob Wins, Click OK to Play Again", "Moo Says: ");
                ResetGame();
            }


        }

        private void KeyIsDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Left)
            {
                player.Image = Properties.Resources.boxer_left_punch;
                playerBlock = false;

                if (player.Bounds.IntersectsWith(boxer.Bounds) && enemyBlock == false)
                {
                    enemyHealth -= 5;
                }
            }
            if (e.KeyCode == Keys.Right)
            {
                player.Image = Properties.Resources.boxer_right_punch;
                playerBlock = false;

                if (player.Bounds.IntersectsWith(boxer.Bounds) && enemyBlock == false)
                {
                    enemyHealth -= 5;
                }
            }
            if (e.KeyCode == Keys.Down)
            {
                player.Image = Properties.Resources.boxer_block;
                playerBlock = true;
            }
        }

        private void KeyIsUp(object sender, KeyEventArgs e)
        {
            player.Image = Properties.Resources.boxer_stand;
            playerBlock = false;
        }

        private void ResetGame()
        {
            BoxerAttackTimer.Start();
            BoxerMoveTimer.Start();
            playerHealth = 100;
            enemyHealth = 100;

            boxer.Left = 400;
        }
    }
}




Comments are closed.