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

Time:11-10

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

CodePudding user response:

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;
                }              
            }       
        }
  •  Tags:  
  • c#
  • Related