Generating maps

Amazeing maps with game assets

Our journey begins here...

https://www.kenney.nl/assets/cartography-pack

Stepping away from random.choice(): writing an algorithm to generate patterns

In order to generate patterns in a non-random way, we might want to move around through our canvas in a non-linear way, to make the patterns a bit more complex.

moving through the canvas

Each character on our "canvas" has a specific position and thus is connected to a x and y coordinate.

How can we do that?

We will use a list-of-lists... or in other words:

we make one big list, that contains a # of rows (the y axis, or height of the canvas), with a # of characters (the x axis, or width of the canvas).

To make this list-of-lists, we will use a loop-in-a-loop:

Let's print the canvas row for row, to make it easier to see it as a x-y canvas:

And let's bring it back into an plain text pattern: turn this list-of-lists into a multiline string:

Let's save this as a function that we can reuse later!

Now, we can work with the x and y axes of the canvas, by slicing the canvas:

My first algorithm

Now let's write a short algorithm, to generate a map.

We will start by writing the rules of our algorithm.

Let's first think of these rules without writing them in code.

How would you like to generate a pattern?

For example:

Characters

Rules

.....
..░..
.░░░.
..░..
.....
.....
.▒░..
▒░░░.
.▒░..
.....

Let's try this!

First we create a new canvas and fill it with .'s.

Now let's add the light shade...

Now let's add the darker shade...

Could we make a maze generator with the cartographypack now?

:---)