Creating Some Enemies
It’s time to get some enemies in this game! Last time we made the player actor and plopped him into the map. This time we’re going to add an enemy, and make it so you can kill each other.
Preparing the animations..
Just like the player, an actor will need animations first, so lets go to the animation tab and make an animation, in the “Sprites” folder and call it elfwalk_r. Then click on the three elf walking frames. You’ll have to drag him (or her? It’s hard to tell) in the preview so each of the three frames is standing upon the red “ground” line.

Our first enemy.. An annoying little Elf.
While we’re here in the animation tab we may as well create all the other animations we’ll need. A snowball and snow splat animation. Repeat the process from above with a couple of modifications.

For snowsplat we set the delay to longer so that it stays on screen for a little longer, and tell the animation to “destroy_actor” when it’s complete. Attaching codeblocks to animations/frames like this is one of the most powerful ways of easily scripting actors. Finally setting Prevent Move and Prevent Collision will stop the snowball from hurting the enemies once it’s already splatted.

By setting the delay to “0” it won’t cycle frames of animation, it’ll stay on this one. Also note that the snowball and splat are not “on top” of the red line, as they’re not supposed to stand on the ground, it makes most sense for their 0,0 point to be at the centre.That’s the animations done.
Now let’s make the actors! In the actor tab, press + (top left) and add Elf to the Actors folder.

There’s a lot to take in on this screen. I’ve set the actor’s local “Var4” to be 2 (not 3 as I put in the screenshot, oops!), to represent it’s health. He’s a CPU_Platform actor.. At the edges of platforms I’ve set him to Flip on the X axis (change directions) and I’ve set him to “Jump_Actor” every 4 seconds (200 ticks) – we might end up turning it off later but it’ll be a fun way of showing how the timers work.. For left and right Wall Collisions (top right) he bounces, so he’ll turn around then too. We have “show Collbox” enabled so we can arrange the collision box (the green rectangle) to a logical position for the little elf. (you want it slightly smaller than the elf, except under his feet)
Now the same for the snowball.

Notice I’ve called it “Snowballa” not Snowball. You can only have one thing called the same thing, so when I have an actor and an animation that are the same I do this, but you could use some other naming scheme. In the top I’ve clicked each of the direction arrows and disabled the directions we don’t need. (the snowball will only fly straight left/right) I’ve also ticked “projectile”. In the Top Right – Wall Collisions Left and Right are set to expiretimer. This won’t make any sense yet but it’s how you attach custom code to wall collisions. (we want the snowballs to splat, we just haven’t made the codeblock yet!)
Over in the Actor tab again, back to the snowman, lets set his default projectile.

First, set the projectile to Snowballa (middle bottom) then enable “Show Projectile” (top left). Choose each of the 6 directions in the top left and move the snowball in the preview window so it’s coming out of the front of the snowman. (this sets the origin point for the projectile)
Now go back to the Maps tab, select level1 and press “edit map” – In Tiled, use the stamp tool to place the elf actor around the map (wherever you like really!) and save the map (top left)

Out of curiosity, lets try the game now, back in Scorpion’s Project Tab press Run In WinUAE!

The elfs slowly congregate toward the bottom of the map but they all jump nicely. The player can shoot snowballs, but they stick around forever. It’s getting there!
Codeblock Time!
We need a tiny amount of logic to make the game work now. Refer back to the other parts of the tutorial if you need any help remembering anything, but we’ll need 3 new codeblocks:
“SnowHitsEnemy” “EnemyHitsPlayer” and “SnowSplats” in a new “Code” folder. Before adding stuff to those though lets revisit the Startup Codeblock and add some lines.

We’re creating two custom global variables (actually.. all custom variables are global, and it doesn’t matter which codeblock you create them in, but I like declaring them at the start of the project) – You can press “D” as a shortcut to declare a new variable, or just use the usual Enter/+ button and go “Variables and Constants/Variable”
Now in the new codeblock SnowSplats:

In the codeblock SnowHitsEnemy:

Notice I play snowsplat on the Actor and in the other codeblock we play snowsplat on the Projectile. Playing snowsplat on the Actor (elf) is effectively killing and removing it, and that only activates when the elf health is 0.
And finally for “EnemyHitsPlayer”:

A Gosub, a conditional, and a Palette/Fade Out command. It’s going to black out the game as soon as we get a game over but it’s fine for illustration purposes!
Now time to connect all these codeblocks to the necessary actors.
“Enemyhitsplayer” goes into “On Collide with Player” in top right of the Elf Actor tab and “Snowhitsenemy” goes into the “On Hit By Projectile” box.

For the snowball Actor you need to add “snowsplats” to its “On Timer Expired” event, bottom right, and set the timer for something ridiculous like 9999 (it will never happen by timer, but it will be triggered by the wall collisions).
Next time I’ll do small additions to wrap things up by adding a bottom panel to display score and lives etc, win conditions, and game over screen. You have the beginnings of a game now if you press Run In WinUAE! You can die, and shoot the elves! I hope this has been fun and helpful so far!
