aka "so, you want to write a game, do you?"
© 2008 PeeJay
© 2008 PeeJay
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
LOADANIM "player.bmp",0,32,32The LOADSPRITE has gone! Now we are loading an animated image - that is, it contains more than one frame. So, we must tell GL how big are frames are. In this case, the images are 32x32, and there are 8 frames in total (0 to 7 inclusive). Got that? Good - on with the show!
Global pldir=4Woohoo - a variable to hold the direction the player is facing. We'll start with direction 4 - image 4, or, in fact, the fifth image (bear in mind we start counting from 0) which is the player facing down - the one we are used to. Now look in the updateplayer function. We have a new chunk of code thus:-
IF diry=-1 AND dirx=0 THEN pldir=0 IF diry=-1 AND dirx=-1 THEN pldir=1 IF diry=0 AND dirx=-1 THEN pldir=2 IF diry=1 AND dirx=-1 THEN pldir=3 IF diry=1 AND dirx=0 THEN pldir=4 IF diry=1 AND dirx=1 THEN pldir=5 IF diry=0 AND dirx=1 THEN pldir=6 IF diry=-1 AND dirx=1 THEN pldir=7All this is doing is checking the direction we are trying to move in, and setting the pldir variable accordingly. Why? Because we need to know which image to draw according to the direction of movement. And onto the drawthescreen function Oooh, what's this?
DRAWRECT 0,0,640,480,RGB(0,150,0)Well, it was getting hard work seeing our man on a black background all the time, wasn't it? So, let's make him against a green background. The DRAWRECT command draws a rectangle - here, at position (0,0) - ie, the top left, with a width of 640 and a height of 480 (so, the whole screen!) and with a colour equal to RGB(0,150,0). There's just one more change:
DRAWANIM 0,pldir,px,pyYep, now our player is an imagestrip - not just a plain image, so we must tell GL which of the images of the strip to use.