Warning: Undefined array key "keywords_en" in /mnt/web218/a3/28/510129628/htdocs/main.php on line 234 Warning: Undefined array key "description_en" in /mnt/web218/a3/28/510129628/htdocs/main.php on line 235 Warning: Undefined array key "commercials" in /mnt/web218/a3/28/510129628/htdocs/main.php on line 261 Tutorial 4

Tutorial 4

GL (very) Basic Tutorial

aka "so, you want to write a game, do you?"
© 2008 PeeJay

Lesson 4 - The Hot Shoe Shuffle!

Now let's get our man moving properly then. Take another look at the player.bmp file. Wow - just look at all those images now! 128 images - 16 stages of animation in each direction. And yes, we're going to use the lot!
So, we're going to need some form of counter so we know what frame of animation we are drawing, as well as which direction we are facing, so, we'll add another global variable
GLOBAL planim=0
With 16 frames of animation in each direction, that means that this figure will want to be between 0 and 15 inclusive.
There's a change in the updateplayer function:
IF dirx<>0 OR diry<>0
	planim=planim+1
	IF planim>15 THEN planim=0
ENDIF
Here's a new idea - IF ..... ENDIF. This quite simply let's GL do a number of things if a certain decision is true. So, we are saying that if we are trying to move in the x direction or the y direction then do the following:-
add 1 to the animation counter
check the counter - if it is over 15, then set it back to 0
Easy huh? But why are we checking dirx and diry? Well, if the player hasn't moved, we don't want the walking animation to continue, now do we?
So, the only other change is in the drawthescreen function, namely
DRAWANIM 0,16*pldir+planim,px,py
If you look at the imagestrip again, you'll see that images 0 to 15 are all for the player moving in pldir=0, and so on. So, this little bit of maths will set the image pointer to the proper place, taking into account both the direction the player is facing, and the animation counter.
Go on, run it. Is it starting to look any good yet? I'll bet you're now feeling that programming in GL isn't so bad after all!

http://www.glbasic.com/files/tutorial/ImgLesson4.png
Next off, we'll start thinking about enemies - and introducing one of the most powerful features (and most frightening!) in GL Basic.
Download the Source Code and Media Files
Previous Lession
Next Lession