Hello everyone we're going to continue with building flappy bird in visual
basic last lesson you guys would have learned how to make an object fall using
gravity and we're going to continue from that so you should only follow this
tutorial if you have done the first tutorial and you know exactly what
flappy bird means okay it's a very popular game okay so the next thing
we're going to do is we're going to make it so that when we press the spacebar
the bird jumps or flies a little bit higher so the way you do that is you're
going to on your form you're going to click double click on it alright which
will bring you the bring you to the procedure that runs when the form loads
but instead of load you're going to click on the event and then you're going
to click on key down okay because we want to do something whenever the user
presses a key okay so what key do we want to respond to
well the key that we want to respond to is space so what we're going to do is
type in if statement if e.key code equals keys dot space then we're going
to change the Y speed of the bird to a negative number so why do we do that
because if you imagine a bird is falling down it will have a positive vertical
speed or positive Y speed of let's say 20 but as soon as you change
it to a negative number then what happens is it's going to instantly minus
the number of your top position which means it will suddenly jump 15 units and
then come down again slowly so if you run the program now and you press space
you can see that you can make it jump up 15 units every time you press space
which is what we want to do okay so this program is looking more and more like
flappy bird now okay now we're going to program the obstacles in flappy bird and
basically what we want to do is instead of dragging a new picture box into our
game we're going to dynamically generate a picture box okay so I'm going to
create my own function private sub okay so this is a function for creating
enemies
or I should say create pipes and I'm gonna accept an input on how many pipes
I should create so it's an integer input okay so dim I as integer equals
zero so I is just a variable I'm going to use pretty soon so using a for loop
for I is equal to zero to number so this number variable comes from the input
variable up here for I is equal to zero to number dim temp as new picture box so
we declare a variable temp as a picture box now because you're declaring this
variable what's going to happen is every time we run through this the temp
variable if there were something there before it will be wiped out because you
are declaring a new one okay so we make up a new picture box called temp we add
it to our screen add it to our program so you can see it on the screen and then
we specify the width of it we specify the height of it and then we also
specify
a border so we can see the border of the picture box let's change the color of it
to red let's change the top position of it and the left position let's make it
to start off let's just make it 300 I will show you how to change it soon okay
and then we're going to add this temp picture box to an array called pipe okay
so I'm going to scroll to the top where I'm declaring all the global variables
and I'm going to clear a variable called pipe and array
a pipe array with let's say two spaces
okay so then I'm gonna add it add the temp picture box to my pipe array and
I'm gonna make it visible okay so when I run the form I'm going to create one
pipe actually that might create two pipes anyway let's try it out so temp
dot left I'm gonna make it oh if we run the program now okay you
can see that there is one pipe at the end here
okay and so if we change it to let's say 100 the pipe is closer to us okay but if
we change it to I times 100 what's going to happen is we should see two pipes
okay but let's make it I times 100 I times 200 and then let's plus another
hundred at the end so what's going to happen is we should have two pipes and
there are more towards the right okay now let's move them all the way so that you
can't even see the second pipe okay so the second pipe is out of the screen
right now okay
okay so that's it for now I'll see you guys next time.