01.blue-noise-project-overview

Generating random rocks

As game developers, we often want to place objects randomly to add variety to the players’ experiences. With randomized levels, the experience is different every time you play.

That’s what rogue-lites like The Binding of Isaac do.

In this project, you’ll learn to randomly place sprites in predefined areas without overlapping.

It is the first step to learn about Procedural Content Generation (PCG in short). It’s the process of generating game content like levels with a set of code rules. Games like Spelunky and Dead Cells and more use this approach.

What you’ll learn

You’ll learn:

We’ll start by placing rocks on a grid to learn about nested for loops.

We’ll then introduce a random offset for each rock inside their grid cell. This technique allows you to distribute objects evenly and naturally on a map without overlap.

We call this a blue noise distribution.

Lastly, we’ll place the rocks on a predefined area of a level using the TileMap node.

In the next lesson, we’ll start by using code to place random rock sprites on a grid.

Locating the Lesson Files

To get started, open the project “Learn to Code with Godot: Practices” in Godot and, in the FileSystem dock, expand the RandomRocks directory. We will create a scene together. See you in the lesson!