0

Made a Flappy Bird type game. There are 2 pipes, 1 on top, 1 on bottom. I have applied a random function to change the height of the pipes. When the height changes, it changes from the bottom. So my code worked for the top pipe, but doesn't work for the bottom pipe because it goes into the ground, or above the ground. How to fix it? (PipeBottom and PipeTop are the pictureboxes)

            Bird.Top += gravity;
            PipeBottom.Left -= pipespeed;
            PipeTop.Left -= pipespeed;
            scoreBox.Text = "Score: " + score;

            Random r = new Random();
            int j = r.Next(-100, 100);

            if (PipeBottom.Left < -100)
            {
                PipeBottom.Left = 800;
                PipeTop.Height -= j;
                score++;
            }

            if (PipeTop.Left < -100)
            {
                PipeTop.Left = 800;
                PipeTop.Height += j;
                score++;
            }

2 Answers2

0

Yes, that's how it is.

0,0 is in the top left corner. A control placed at location 100,200 will appear to be approximately twice the distance away from the title bar as it is from the left edge of the window. If you set the height to 300 then the bottom of it will be 500 pixels away from the title bar. If you then set the height to 600, then the bottom will be 800 pixels away from the title bar. The top of the control doesn't move

If you want something at location 100,200 to go from height 300 to height 400 and look like it has moved 100 pixels closer to the top of the window, you set its height to 400 and it's location to 100,100 (you move it and grow it)

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
0

Nevermind guys, I figured it out. Used Picturebox.Top to subtract the amount from the y-axis that I was adding to the height.

  • Is that not what I said? https://learn.microsoft.com/en-us/dotnet/framework/winforms/controls/how-to-position-controls-on-windows-forms – Caius Jard Aug 30 '20 at 06:25