Writing a book on coding games for Playdate with Lua

Hi there! I'm writing a book titled Make Games for Playdate with Lua that's about, you guessed it, coding games for Playdate in Lua using the Playdate SDK. :open_book:

Playdate Book Cover - Opt

It's currently in Early Access. I'm actively writing the book and am releasing it early so that I can get feedback from readers throughout. This is the book I wish I had when I started digging into making games with Playdate. I've written a couple of other technical programming books before, and I think the Playdate community would really benefit from having a comprehensive, beginner-focused book on how to get started.

Inside Playdate is absolutely an essential reference, but something a bit more guided will help get more people just started out into making games for Playdate. :heart:

You can get the book here:

There's a free sample available that includes the first three chapters! :nail_care: The web version of the sample can be read here.

Make Games for Playdate with Lua is primarily targeted at beginners with no experience writing code or making games. It covers the fundamental concepts of programming from functions to variables to tables to conditionals. If you're an experienced programmer looking to learn how to make games for Playdate, you'll fly through the book and find the examples of how to use the Playdate SDK helpful.

In each chapter you'll code a different small game, learning new concepts that build upon that last chapter. Throughout the chapters there are Bonus suggestions that encourage you to experiment and learn on your own.

All of the source is available on GitHub, broken down by section in each chapter:

Table of Contents

Here's what's completed and what's planned:

  1. Introduction :white_check_mark: — get yourself and your computer ready for making games for Playdate
  2. Hello, Playdate! :white_check_mark: — display text and move it around the screen
  3. Tennis :white_check_mark: — make a simple single-player Pong clone that uses the crank to move the paddle
  4. Clock :white_check_mark: — coding a simple clock app
  5. Snake :white_check_mark: — homage to the Nokia classic
  6. Soaring :white_check_mark: — crank-powered infinite flying game :crank:
  7. Sokoban :white_check_mark: — with level parsing from text files
  8. Dungeon Crawler :writing_hand: — making a turn-based RPG where you progress through dungeon floors
  9. Playdate by Example :writing_hand: — focused examples on how to use various parts of the SDK

This is very subject to change, but I'm aiming for about 10 chapters, with each chapter being its own project.

Topics covered so far:

  • Drawing text
  • Drawing shapes
  • Game loop
  • Screen positioning
  • Variables
  • Tables
  • Conditionals
  • Playing sounds with the MIDI synth
  • Player input with buttons and crank
  • Functions
  • Refactoring code
  • Save data
  • Adding a Playdate menu option
  • Parsing and rendering custom levels
  • Scene switching
  • Menus
  • Organizing code into multiple files

Topics I want to cover:

  • Drawing & animating sprites
  • Combat systems
  • Playing music
  • Debugging code
  • Polish / juice

Bonus

Here are games from the book that I've polished up and released separately as reference:

What's Next

I'm going to keep writing new chapters for the book! I've got a pretty clear sense of what I'd like to cover in the book. I'll post updates in this topic as I publish new chapters and have news to share.

If Make Games for Playdate with Lua is received well and there's interest, I'd like to record video versions of the chapters and explore making a print edition. Let me know what you'd like to see! Are there any specific topics you'd like to see covered or styles of game that'd be helpful to have explained in depth?

I'll post updates when new chapters are published or there's significant news with the project. Feel free to report any issues here. Thank you!

14 Likes

Yesterday I added and published a new chapter in the book called Clock :mantelpiece_clock: that goes over how to read the time from the system, respect user preferences for 24-Hour Time display, get battery percentage, and use a custom font!

I also figured out how to get nice looking gifs made using MP4 recording from the Simulator then converting with Gifski. :sparkles: Here's the crank-controlled paddle version of Tennis from chapter 2.

Playdate Tennis Demo

Next up is adding a chapter on coding Snake :snake: from scratch, including high score tracking (and reseting), scenes like main menu, and setting custom metadata for the game.

1 Like

The book has sold 6 copies in the first day of being on sale in Early Access. :tada: It's been neat seeing people being excited. I appreciate the support. I'll be as transparent as I can about the statistics and process of publishing the book alongside actually writing it. :smile:

My goal is to sell 100 copies within the first six months of it being available. I think that seems realistic!


Made good progress on the Snake :snake: chapter this evening. It reminds me how much fun Snake is to play while also being really beginner-friendly to make.

Hey there! Looking forward impatiently for it to be released, I'd be the first one (or one of the first ones if I don't get to the correct timing heh) in buying it no doubt! Keep up the good work man, I'll stay tuned!

1 Like

Thanks so much for your support!


Got some updates from about a week into the book being released in Early Access!

I just published a new version where I finished the first draft of the Snake chapter. Still a ton of fun to play. :snake: The new chapter covers a lot of topics: saving and loading high-score from the console, adding a menu option, advanced logic, loops, and working with nil.

Here's Snake in its minimalist glory:

Snake Demo

It was so easy to add a menu option to reset the high-score. The Playdate SDK being so friendly and simple really makes writing tutorials a joy. :heart:

Sales Update: The book has sold 26 copies so far. :tada: I wasn't expecting much at this point, so I am surprised and thrilled. It's been really motivating to see people excited about the book and supporting it. The feedback from r/PlaydateConsole and r/PlaydateDevelopers has been great.

Next up is Flappy Crank! :bird::crank:

I just released a new version of the book in Early Access with a chapter where we make a game called Soaring. You control a bird by turning the crank (or pressing up and down), avoiding trees.

I started to code Flappy Crank (a Flappy Bird clone), but it just wasn't clicking or feeling good with the crank. But it led me to this idea for a game where you're a bird soaring through sky, which I think ultimately served the book better as I was able to explain how to make an infinite runner and introduce some new key concepts.

Soaring Demo

The new chapter introduces a few new key concepts:

  • Scenes and switching between them; e.g. main menu, gameplay, and game over
  • Breaking up code into multiple files
  • Relying less on global variables
  • Showing the crank indicator if the crank is docked

Next up is making Mini Survivors—a simple action game inspired by Vampire Survivors. I want to tie together the concepts so far into a fun and more polished game. After that, it's on to drawing sprites and digging into some more advanced topics.

Sales update: The book has sold 32 copies so far. :playdate_heart:

Bought, thanks @brett !

1 Like

Back at it with working on the book after taking a bit of a break. :smile:

The latest addition in the update I just published is a new chapter titled Playdate by Example which contains concise examples on how to use the SDK. Lots of programming languages and libraries have a Learn X by Example site (or page), and I find that to be extremely helpful. Here's an example of a section from that chapter:

Audio

Play a Sound Effect from WAV File

Given you have a sound effect file apple.wav in the sounds folder, it can be played it like this:

local sfxApple <const> = playdate.sound.sampleplayer.new("sounds/apple.wav")

function eatApple()
    sfxApple:play()
    -- other stuff happens too
end

Creating a Sound Effect Table Module

A slighty more advanced way of working with sound effects is to create an sfx table in sfx.lua that contains a play method and the various sampleplayers:

sfx = {}

sfx.apple = playdate.sound.sampleplayer.new("sounds/apple.wav")
sfx.death = playdate.sound.sampleplayer.new("sounds/death.wav")

sfx.apple:setVolume(0.5)
sfx.death:setVolume(0.5)

sfx.play = function(sound)
	if sound == nil then
		print("ERROR: nil sound provided")
		return
	end

	-- optionally check whether or not sound effects should be played (if you have a global settings.playSfx value)
	if settings.playSfx then
		sound:play()
	end
end

-- then call it
sfx.play(sfx.death)

function eatApple()
	sfx.play(sfx.apple)
end

This approach is more resilient because of a few reasons:

  • Logic can be added for whether the sound effect should be played.
  • If you pass in a sound effect that doesn't exist, you can print an error to the console.
  • You can use sfx anywhere throughout your game code, keeping all of the sampleplayer creation in one spot.

I also added a Style Guide chapter that I've been using for my own projects, largely inspired by what's in the Playdate SDK. I hope to continue to expand upon that further and publish it separately from the book.

The book is at 54 sales so far. :playdate_heart_eyes:

After about a 6 month break due to personal reasons (being overwhelmed with young children and a new-ish job), I've picked back up on the book! Here's the latest update I sent to purchasers:

I added most of a new work-in-progress chapter where we make Sokoban, a box-pushing puzzle game. It's unedited, but I thought best to send some sort of pulse for this project!

See the source for each section here:

I was originally going to do a chapter making a game like Vampire Survivors, but I wasn't excited about it, and the Sokoban chapter is perfect foundations for the last quarter of the book.

Thank you everyone for your support and patience between updates. It's been six months since I last published a new version. I'm in a good groove right now, working on it during a dedicated time weekly. I started writing this book when my son was born, and having two little kids growing up is far more challenging than I could have imagined. I appreciate your patience.

I'm going to finish the Sokoban chapter (parsing levels and rendering sprites). Then the final 25% of the book will be dedicated to building a dungeon crawler RPG. That's something I'm genuinely excited about, and it'll be a nice capstone project for the book.

Once the first draft is complete, I'll edit the book and refine it. Then explore print if anyone's interested.

One aspect on my mind is AI... When I started writing this book, I was quite uninterested in using AI for programming. But in the months since, especially by using AI Agents at work, I find myself wondering if anyone's interested in even just a section in the book on how to effectively plan and guide AI Agents for Playdate game programming. Let me know if you have any feedback on this, as I've done some exploring with promising results.

But also on this note, the book and project code is written entirely without AI, as it's more fun for me and what I want to do.

If you have any questions or feedback, let me know! Thanks again.

First, I completely get it. I have three children myself (which I know many consider child's play - sorry, I had to), and trying to raise kids, work a full time job AND do something on the side is quite the challenge.

I'm a bit sad to hear that the Vampire Saviors section wasn't working for you, mainly because I'm a huge fan of that game, but I love a good dungeon crawler as well, so I'm good either way.

Not sure how I feel about the AI thing. I keep telling myself I need to get into it, because I am, after all, an IT guy, but the thought just gives me the willies. I mean I do use ChatGPT - barely - but otherwise I've tried to avoid it to this point. Maybe this would be what would finally get me into it!

1 Like

Just wanted to thank you for writing this book. I have minimal coding experience (well I've been doing it a long time but at very basic levels and quite off-and-on) and your book has gone a long way to demystifying this cute little yellow handheld!

1 Like

Thank you for this feedback! I’ll consider returning to it, maybe as an “Expansion Pack” to the book once I get the initial version complete. :vampire:

Thank you so much! :playdate_heart_eyes:


I just published a new version of the book on Leanpub and itch.io with the complete Sokoban chapter. I also fixed some typos throughout the book.

Playdate Book - Sokoban

I’m really proud of the Sokoban chapter for a few reasons: it’s the first time readers get to do some game design! The code is not overly complex, but it contains everything a non-trivial game has: level loading, a form of scoring, and a main menu. Building blocks that I hope people can use for pursuing their own games.

The levels are defined in multi-line strings that then get parsed and rendered:

local levels <const> = {
    [[
    #####
    #@BT#
    #####
    ]],
    [[
    #######
    #     #
    #     #
    #@B#T #
    #  ####
    ]]
}

Where @ is the player, B is a box, T is a target spot, and # is a wall.


Next up is the Dungeon Crawler three chapter special. :crossed_swords: I’m excited for this, as it’ll be a good jumping off point for anyone interested in making an RPG for Playdate. The book is 153 pages now, and I’m thinking it’ll settle in at around 200 pages when all is said and done.

The Dungeon Crawler game will build upon everything in the book so far, dig into rendering sprites, developing a combat system, and more.

I’ve found my rhythm writing it. I go to a cafe every Sunday for a few hours and hack away at it. Having fun and enjoying the process, which is really important to me.

3 Likes