I am creating a game for a college job, this game consists of several Picturebox
, one is the main character who walks, jumps and shoots, PictureBox
of shots and PictureBox
of monsters (randomly generated by a Random
), currently, when the program detects the picturebox's collision of the shots with that of the monster, the monster is deleted and the shot as well.
What I would like to do is to let these monsters have a "life", for example, take 3 shots for the monster to die, but for this I have to create a variable "int life" and correlate it with% of the monster that was created and I do not know how to do it
This is the part of the code where monsters are created:
Random random = new Random();
int a = random.Next(0, 300);
if (a == 150)
{
NovoMonstro();
}
This is the New Monster Method:
PictureBox monstro = new PictureBox();
Bitmap imagem;
imagem = Properties.Resources.monstro;
monstro.Image = imagem;
monstro.Size = new Size(51, 85);
monstro.SizeMode = PictureBoxSizeMode.StretchImage;
monstro.Tag = "monstros";
monstro.Left = 1024;
monstro.Top = 555;
monstro.BackColor = Color.Transparent;
this.Controls.Add(monstro);
monstro.BringToFront();
This is the part of the crash program between the shot and the monster:
foreach (Control y in this.Controls)
{
foreach (Control j in this.Controls)
{
if (y is PictureBox && (y.Tag == "bulletD" || y.Tag == "bulletE"))
{
if (j is PictureBox && (j.Tag == "monstros" || j.Tag == "monstrosinvertidos"))
{
//detecta se teve colisão entre as picturebox
if (y.Bounds.IntersectsWith(j.Bounds))
{
this.Controls.Remove(j);
this.Controls.Remove(y);
contador++;
}
}
}
}
}
The generation of monsters is within a PictureBox
and the collision as well.