Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

C# c# bug game

Recommended Posts

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

 

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!