Advertisement

c# bug game

Started by April 29, 2019 09:56 PM
3 comments, last by JTippetts 5 years, 9 months ago

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);
                }
            }
        }

 

image.thumb.png.4686640005fda2dc262b92bf36d04239.png

Advertisement
1 hour ago, phil67rpg said:

I am so close to solving this problem.

That's great news. Keep at it.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

Closing this as a duplicate of previous posts. @phil67rpg you have been warned about posting these non-question code dumps. People have given you answers over and over and over to these same exact issues, so don't post about this again unless you have a new question to ask.

This topic is closed to new replies.

Advertisement