well I have decided to go back to working on my bug invaders game. I have made some progress. I am able to draw a row of bugs and then shoot at them with a bullet. however when the bullet hits the bug it draws a collision image. I want it to clear the collision image after it has been drawn. I am so close to solving this problem.
public class Bug
{
public int px;
public int py;
public bool drawflag = true;
public bool collision = false;
public int timer = 0;
};
IList<Bug> bugs = new List<Bug>() {
new Bug() { px=120, py=0 },
new Bug() { px=180, py=0 },
new Bug() { px=240, py=0 },
new Bug() { px=300, py=0 },
new Bug() { px=360, py=0 },
new Bug() { px=420, py=0 },
new Bug() { px=480, py=0 },
new Bug() { px=540, py=0 },
new Bug() { px=600, py=0 },};
public void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(ship, 350 + x, 530);
e.Graphics.DrawImage(bullet, 375 + x, 520 + y);
foreach (Bug bug in bugs)
{
if (y <= -510 && x >= -15 && x <= 15)
{
bug.collision = true;
bug.drawflag = false;
bug.px = 360;
}
if (y <= -510 && x >= -75 && x <= -45)
{
bug.collision = true;
bug.drawflag = false;
bug.px = 300;
}
if (bug.collision==true)
{
e.Graphics.DrawImage(coll, bug.px, bug.py);
}
else if(bug.drawflag==true)
{
e.Graphics.DrawImage(bug_one, bug.px, bug.py);
}
}
}