Jump to content
  • Advertisement
phil67rpg

C# bug invaders

Recommended Posts

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

 

Share this post


Link to post
Share on other sites
Advertisement
Posted (edited)

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?
Edited by GoliathForge
interesting bug V I feel like a NN trainer needing to find the right inputs. Needs more/less? hidden layer :) umm, is the ground stable here?

Share this post


Link to post
Share on other sites
Posted (edited)

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...

Edited by GoliathForge
shift key.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

 

 

Share this post


Link to post
Share on other sites
Posted (edited)

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
Edited by GoliathForge
complete sentence anyone? I'm looking at you Tom#12 :) going after it real vocal like. Still working on the shift key.

Share this post


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

  • 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!