Level 06 Lesson 03 [Advanced Sprite Control]

Now that you know how to switch sprites around you have to learn how to plan and control the various sprite animations that you might assign to an object. In this lesson we will develop Ken, our supreme Street Fighter so his behaviour is more like the real Ken in the arcade. It will be an excellent review of conditions and variables mixed with sprite control.

Part A –Image Index
When animated sprites are playing, a variable called image_index is keeping track of which frame the animation is on. If the current image index is 4, and you switch to another sprite, you will switch sprites and still be on frame 4. This can have weird effects because if you switch to another sprite it will continue animating from frame 4 (and not the first frame, frame 0). Usually you will want to set the image index back to 0 when you switch sprites.

Watch the video: 06-03-A

 

Part B – Controlling Actions / Sprites
We are going to build on our street fighter so that we can control the way he fires, punches, kicks, crouches, and stands. It will require a combination of variables, well thought out conditions, and good sprite control.

Watch the video: 06-03-B
Done-File: L06-03-B-Done.gmk


Challenge 01 – Punch and Crouch
Start with the pre-made game project:
L06-03-X1-StartHere.gmk

So far you have Ken standing, kicking, and firing. Time for you to add the punch and crouch. Notice that crouching is a little different then the other actions. The player doesn’t press a key once to crouch, they hold down a key to crouch (so use keyboard event, not key press).

Challenge Solution
Watch the video: 06-03-X1Solution
Done-File: L06-03-X1-Done.gmk


Challenge 02 – All on Your Own

It might have been easy to add in punching and crouching when the kicking and firing are already in the file. Delete all your code and try to get all 5 moves working from a fresh file without following the videos! Re-watch the lesson video if you have trouble getting this working.


Challenge 03 – Getting Hit

Start with the pre-made project
L06-03-X3-StartHere.gmk
Watch the Preview Video: 06-03-X3Preview

Now that we have Ken making his moves properly, lets wrap up this project file with Ken getting hit by fire objects that are fired at him.
Notice the object called globs that creates a global hit point variable for Ken.
The globs object is also drawing the hit points to the screen.
There is also a tower object that is firing fire at Ken.

Now try and add the following behaviour:
If Ken is crouched, he won’t take damage. If Ken is firing he will take double damage (10 points). Any other position is normal damage (5 points).
Add an explosion object when Ken gets hit. The explosion sprite sheet is in the Level 06 resource folder. The explosion object should destroy itself when it’s animation is over.

Challenge Solution
Solution Video:  06-03-X3Solution
Done-File: L06-03-X3-Done.gmk