Hey guys how you going this is Eddie the Magic Monk. Welcome to the first video in
our learn how to program games and visual basic series of videos and to
start on this series you probably need to have done the visual basic
programming videos before so that you can understand everything that we're
doing in the games programming series and if you're confused about what I'm
talking about it probably means that you haven't seen the basic programming
videos before this so I suggest you watch that before trying out this series
of videos so in lesson one all we want to achieve is have a character in
your game where you can use your arrow keys to move the player around on the
screen so right now I'm pressing up down left right to move the player and so
when you when I press down when I press the key down when I hold down the key
the player keeps moving in that direction until I let go of the key
alright by the way this character sprite the image was downloaded from
www.lostgarden.com if you wanted to download this picture and use it in your program. So yeh try to do this first before looking at the answers I am about to give you, so if you can already do that, then you can skip the rest of this
video otherwise keep watching okay so here's a coding that allows this to
happen firstly you need a form and you need the
character object I mean sorry a picture box object and so that's just a picture
box and you also need the timer one object so drag these two objects onto
the screen the timer one object timer object is here and the picture box
object is here drag them onto the screen oops added a new timer the picture box
object load up the picture into the into the into the image property here so
click on that and import the picture so that you can put it in your picture box
so this picture I just downloaded from lostgarden.com and then let's have a
look at the coding behind in the background so we have four variables
that you need to declare in the beginning you have a move right variable
move up move left move down all of these are boolean variables which means they
can only be true or false and the first event you're gonna program in is the
keydown event and that means that when someone presses the key this is what
happens if they press the right key then I'm gonna change the variable move right
to true if they press the up key then move up is going to be true, if they press
the move left key the sorry if they press the left key the move left will be true
and so on and then I also need the key up events what is the key up event it is
when you release the key so key down event is what you want the program to do
to execute when you press down the key when you hold the key down
sorry not hold the key down when you when you press the key this is gonna
happen and then this is what the program will execute as soon as you release the
key so this is what happens when as soon as you press the key and this is what
happens as soon as you release the key so when I release the right arrow key
the move right variable becomes false and that's why the character stops
moving right as soon as I let go of the key and then move up same thing the
variable be false for move up left arrow key down arrow key so so far from the
key down event to the key up event all we have done is changing the variables
true and false and it's not actually gonna move the picture so what we want
to do next is let me just cut this so what we want to do next is we want to
program the timer now let's have a look at the timer object the timer is an
object that ticks every 10 milliseconds every 10 milliseconds we're going to
execute these instructions so what are the instructions well if the move right
variable is true then it's going to execute this statement here to move the
picture box to the right by changing the left property
by adding five to the left property which is the left coordinate the the
x-coordinate of our picture box if the move left is true sorry if move left is
true we're gonna also change the same property except we're gonna minus five
instead of plus five moving up and down change the property you have to change
is the top property top if you do minus five it moves it upwards and if you do
plus five that moves it downwards so there's the instructions you have to put
in for the timer and lastly you want to stop the timer as soon as the form loads
so as soon as the form loads you're gonna start the timer and then and then
everything should work when you execute this program now this is the most basic
thing you can do in terms of games programming so if you can't do this it's
unlikely that you'll be able to do anything else in programming games so I
suggest that you guys master this part of the program before you continue to
the next section okay see you next time.