Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I have a question about the monster's movement during the shooting game

What should I do when I want to give random moves to these enemies as they’re coming down in a straight line?


        enemyOne.Top += enemySpeed;
        enemyTwo.Top += enemySpeed;
        enemyThree.Top += enemySpeed;
        bossMonster.Top += enemySpeed;
        ambulance.Top += enemySpeed;
        addBullet.Top += enemySpeed;

        if (enemyOne.Top > 500)
        {
            enemyOne.Top = -650;
            enemyOne.Left = rnd.Next(20, 450);
        }

        if (enemyTwo.Top > 500)
        {
            enemyTwo.Top = -650;
            enemyTwo.Left = rnd.Next(20, 450);
        }

        if (enemyThree.Top > 500)
        {
            enemyThree.Top = -650;
            enemyThree.Left = rnd.Next(20, 450);
        }

I want to give the direction of the enemy in a fluid way, not a fixed value.

I’d appreciate your help.enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you want the monster’s movement to match your movement, you can set a tag and turn the appropriate switch case.

     foreach (Control x in this.Controls)
            {
                if (x is PictureBox && (string)x.Tag == "zombie")
                { 
                    if (x.Left > player.Left)
                    {
                        x.Left -= enemySpeed;
                        ((PictureBox)x).Image = Properties.Resources.bossM;
                    }
                    if (x.Left < player.Left)
                    {
                        x.Left += enemySpeed;
                        ((PictureBox)x).Image = Properties.Resources.bossM;
                }              
            }       
        }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading