Advertisement

bug invaders

Started by April 13, 2019 12:26 AM
59 comments, last by Tom Sloper 5 years, 10 months ago

well I have solved my collision problem but when I draw a row of bugs when the bullet hits them all of them disappear, I only want one of them to disappear. here is my updated code


        int count = 102;
        bool collision = false;
        public void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImage(ship, 350 + x, 530);
            e.Graphics.DrawImage(bullet, 375 + x, 520 + y);
            if(collision)
            {
                return;
            }
            e.Graphics.DrawImage(bug_one, 120, 0);
            e.Graphics.DrawImage(bug_one, 180, 0);
            e.Graphics.DrawImage(bug_one, 240, 0);
            e.Graphics.DrawImage(bug_one, 300, 0);
            e.Graphics.DrawImage(bug_one, 360, 0);
            e.Graphics.DrawImage(bug_one, 420, 0);
            e.Graphics.DrawImage(bug_one, 480, 0);
            e.Graphics.DrawImage(bug_one, 540, 0);
            e.Graphics.DrawImage(bug_one, 600, 0);
            if (y <= -510 && x >= -15 && x <= 15 && count > 0)
            {
                e.Graphics.DrawImage(coll, 360, 0);
                count = 0;
                collision = true;
            }
            if (y <= -510 && x >= -75 && x <= -45 && count > 0)
            {
                e.Graphics.DrawImage(coll, 300, 0);
                count = 0;
                collision = true;
            }
        }
        public void timer1_Tick(object sender, EventArgs e)
        {
            y -= 5;
            Invalidate();
        }
        public void timer2_Tick(object sender, EventArgs e)
        {
            count--;
            Invalidate();
        }
    }

 

A flowchart might be helpful here. It would highlight your early out when collision is a true value.

edit : My definition of 'early out' = controlled discontinue at that point of the iteration 

(ie: break, return or continue flow (modifiers))

@8Observer8 would you like to try again with our friend?

Dev careful. Pixel on board.
Buckle up. Everything will be revealed.

Advertisement

cool I like flowcharts

I  did some flowcharts , but I am unsure of how to proceed.

OMG that is incredible. Please we need to see those...this is your key. Don't worry if you get the symbols wrong. Map what you want to do in a very small section of code that you like and works. When you want to add functionality, check what you want to do against your map and see how it fits. I think this is a good exercise, if I have to do it, then I think I would prefer to map my own thoughts and game ideas.

nice one phil...

Dev careful. Pixel on board.
Buckle up. Everything will be revealed.

maybe I can post some pseudocode, I am unsure of how to post flowcharts

Advertisement

you're the boss...I'd like to just pause for the moment to remind you that removing the return statement in the condition collision is true will remove that behavior of erasing all the bugs on the single bug hit.

but if pseudocode is something you wish to try for some additional discussion, I'm cool with that.

Dev careful. Pixel on board.
Buckle up. Everything will be revealed.

here is my pseudocode

draw  ship

draw bullet 

move bullet up

if collision is true

draw collision 

clear collision

reset bullet

move bullet up 

let me know what  you think

 

 

I think there is hope. Do it inside code tags and I think we get mono spaced while introducing indenting for branch logic. I'm going to set mine to [no syntax highlighting]


draw  ship                    #okay
draw bullet                   #okay
move bullet up                #sure...you bet.

if collision is true          #yes?
   draw collision             #okay 
   // clear collision         # NO NOT DOING THIS
   reset bullet               #sure...lets do this

// move bullet up             # NO NOT IN THIS ITERATION (don't do it twice) 

these are my notes. please try to continue. 

 

python push

Dev careful. Pixel on board.
Buckle up. Everything will be revealed.

 ok nice  pseudocode, what should I do next?

This topic is closed to new replies.

Advertisement