How to make a PICO-8 game: Part 10

The last animation

It’s time to put the final touches to our game, namely animating the player sprite. Previously I’ve shown you how to do this for the enemies, and also how to create the enemies as objects, so we’re combining those for this task.

Part 10: Player Animation

As before, we need to draw some frames of animation to use. I’ve created some additional frames in sprite slots 2, 3 and 4 to carry on from 1.

Again, it’s pretty simple but is just for illustration.

Now, we need to create the player as an object. We could have a function to house this, make_player() like we have make_enemy(), but we only need to create one player so that’s overkill. Instead, we’ll create it in one go in the _init() function, replacing the x and y we had there before:

You’ll notice I’ve put a player.draw function in there, which works just like the enemy draw function from last time.

Now we need to replace all references to x and y in the code, with player.x and player.y. You’ll find some in the button press check code (e.g. if btn(0) and x > 0 then…), in the collision check routine (if checkcol(x,y,en.x,en.y)) and in the en.move function (if x < this.x then…).

Finally, we need to replace the code in _draw() that drew the player sprite. It was spr(1,x,y), but now we just call:

Save, deep breath, run!

And that’s it. We have a complete, working game with enemies, movement, collisions and animation. Sure, we don’t have any sound, a title screen, lives or a game over sequence, but the game logic is there and you can see it’s a place to build from.

Here’s the final code. Skip past it to play the actual game!

Leave a Reply