๐ŸŽฎ My First Defold Game ยท Episode 2 of 6 ยท See All Episodes
๐Ÿ Episode 2 ยท Grid Logic ยท Game States

Snake
Classic Snake in Defold

Build the classic Snake game with grid-based movement, food spawning, body growth and game-over states. Master Lua tables and state management!

๐Ÿ‘ถ Ages 10+ โฑ๏ธ ~1.5 Hours ๐ŸŽฎ Defold โœ“ Free
๐Ÿ“Š Tables ๐Ÿ”ฒ Grid Logic ๐Ÿ”„ Game States ๐ŸŽ Spawning ๐Ÿ“ Body Growth โฑ๏ธ Timing
โญ
0 XP
Level 1
๐Ÿ”ฅ0
Your Progress0 / 10 steps
Build it in our Defold Studio too: lay out your scene, add real Lua scripts and export a Defold project in the browser, with no install. Open the Defold Mod Studio →
๐Ÿ“ฆ
Reference project files: download the finished Defold files used in this workshop: โฌ‡ defold-snake-reference.zip. Every code block also has a Copy button.
๐Ÿ’ป
How to run: Open Defold and load your project, then press Ctrl+B to build and run!
๐ŸŒ
How it works: write the code in each step, and the canvas on the right shows what your code does. It is a live preview that builds the game as you go, so you can play every step along the way. Type to see it update, or press Apply to Canvas to test it straight away.
๐ŸฆŠ
Lumo says: every step adds one feature to the same game. Type a little, click Apply to Canvas, and play it straight away. There is no wrong answer you can't undo.

Build Snake Step by Step

Each step adds one feature. Write the code, watch it come alive in the canvas, then make it your own.

Step 1 / 6
A snake moving around a grid
๐ŸŽ‰๐Ÿ๐ŸŽฎ๐ŸŽŠ๐Ÿ†
You Built a Snake Game!

Amazing, you've made a complete Snake game with grid movement, food growth, collision detection, game states and persistent high scores!

0
Total XP
1
Level
0
Best Streak
0%
Accuracy
๐Ÿฐ Episode 3: Dungeon Crawler โ†’ โญ View My Progress
๐Ÿงฉ
Code Order: Defold Lua Update
+20 XP
Drag these Lua lines into the correct order for a Defold update function that moves a game object.
local pos = go.get_position()
function update(self, dt)
go.set_position(pos)
if self.moving_right then
    pos.x = pos.x + self.speed * dt
end