I'm Coding a Game - Part 3

In this installment, I added animation to the main character(Chester Deadeye Killingsworth III) for when he runs, and jumps. That may not sound like a lot; a simple four cell animation, and a two cell jumping motion, but there is quite a bit of code to make that all come alive. So let’s start with the artwork.
 
For the running I created and animated a four cell GIF.

Look at him go!!!

I used a simple GIF editor online, and made it 48 x 48 pixels. When I first started I thought, All I need to do is draw four cells of a guy running, how are could that be? Two hours later I was pulling my hair out screaming, “Why must I fail at everything I have ever tried?” but I digress. Eventually I got an animation that didn’t look like it came from straight out of my nightmares. For the jumping I only used two cells, and did not animate them. One would be used when jumping towards the heavens, and the other would be used when falling towards the earth. After all the fun drawing was done, it was off to code it.

Ladies, if this code gets you too hot and bothered, perhaps you should COIL elsewhere.

Okay, let me see if I can break down the code. Again I apologize if I make a mistake, I’m still learning this as well.
 
The first IF statement:
 
If (!place_meeting(x,y+1, Owall)
 
This states that if the sprite(Chester) is not touching the ground go to the subroutine below. The subroutine is as follows:
 
{
sprite_index = SplayerA;
image_speed = 0;
if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
 
This code follows the IF statement. If the sprite going up in the air, use the jumping picture. If not, than use the falling picture.
 
Now to follow up the original IF statement is the ELSE statement:
 
else
{
image_speed = .125;
if (hsp == 0)
{
sprite_index = Splayer;
}
else
{
sprite_index = SplayerR;
}
}
 
What this states is that if the character is not in the air, run this routine. This routine sets the animation speed, and if the sprite is moving switch to the run GIF.
 
Lastly there was this little bit of code:
 
if (hsp != 0) image_xscale = sign(hsp);
 
This line of work cut my work in half. If you noticed up top Chester is running to the right. I didn’t need to animate him running to the left because of this code. What it this line states is flip the animation depending on which direction he is running.
 
Next I will be adding a weapon system, so good ol’ Chester will have arms. Stay tuned!