L-Systems in Games Part 1: Basics

Introduction

A nice and powerful way to specify 2D fractals like we do in our Android game The Last Dimension are L-Systems or Lindenmayer systems. They can be implemented as a context-free grammar, meaning that there is just a set of substitution rules which get applied when a certain zoom factor is reached. The result therefore provides a more detailed description of the local fractal, which basically resembles the self-similarity a fractal is known for.

This part should give a small introduction to these systems. Now, three components are necessary for simple fractals:

  • The axiom
  • The angle
  • The rules

The turtle

But first to understand how L-Systems draw fractals, you should try to imagine a creature called ‘turtle’ that goes through each symbol step-by-step and executes its meaning. Therefore, first some important symbols in L-Systems:

  • letters F, G, H, I, ..: turtle goes forward and draws a line
  • +: turtle turns left
  • -: turtle turns right
  • often small f: turtle goes forward without drawing a line

Thats all commands we need in the beginning!

Axiom and angle

Now we can start with the axiom. The axiom is also a rule, but unique in that way that it does not describe the transformation for zooming but the inital shape of the fractal. But the axiom alone does not specify the final form. As + and – do not specify the angle, we need to give it to the turtle in the beginning. With these two we can draw the first shapes!

axiom: F-F-F-F angle: 90

square

and that’s a square! Now we can go further and you might guess what this is…

axiom F-F-F angle: 120

triangle

Yep, a triangle! Nevertheless, zooming isn’t very spectacular…

triangle zoomed
Is this how I die?

so we need rules!

Rules

Finally! You might already have seen the statements F=FF and G=GG in the screenshots. Those are the simplest rules one could have: If we zoom into the fractal, at one point, the lines will get divided into half, which will obviously look perfectly the same.

But what if we do the following: We could split one line of the triangle in half, but after drawing the first F (red) draw a smaller triangle with -G (orange). Then we jump around with -f-f (yellow&green) and finish with a G (blue). Note that we are limited with the current angle in rotating. So F always draws step 2 (here orange) while the G lines do nothing.

Therefore, we also need to adapt the axiom a bit:

axiom: F-G-G rule 1: F-G-f-fG rule 2: G=GG angle: still 120

What does this result in?

result1

Exactly, we can zoom into the corner and get an endless stream of small triangles!

Changing the axiom to F-F-F puts these fractal corners in every corner:

result2
This reminds me of another game…

Now this is basically the process of working with L-Systems! One could now tweak a bit, and with certain extensions to the system, one can create famous basic fractals like the SierpiΕ„ski triangle. Try it out yourself at e.g. https://onlinemathtools.com/l-system-generator!

result3

With the color, this now already looks very similar to the first level of The Last Dimension, Natural Logarithm! If you look carefully, you can see an additional command in the axiom. But those extensions are a topic for another post. I hope that I was able to give a nice overview over L-Systems. See you πŸ˜‰

Lean Approach and The Last Highscore

Thank you all for testing the first public version of TLD πŸ™‚ ! I got a lot of helpful feedback. My most interesting observation was the fact that everyone sent me screenshots with their highscore, so according to the Lean Startup approach, this must be a user need. Therefore, I finished a global, weekly leaderboard for the next update today. Some fixes are still missing so stay tuned πŸ™‚

highscore TLD
Who is Stefan Rupfen?

Halloween Special 2020

Omg! I didn’t believe it will be approved in the store so fast, but thanks to Google Play, The Last Dimension and its Halloween 2020 update are available today! Play it on this special day to get the full spook :)) Happy Halloween πŸŽƒ

Other… Linux-like Experiments

Today, I upgraded the Android IDEs of my two workstations to the latest Android Studio 4.1. The first one had version 3, and second one even version 2, but apart from some Gradle errors (repositories and versions had to be updated), everything went out fine and I was able to compile my old code. I was even able to build everything with the new 29 SDK and still run it on my old Samsung S3 mini! Thats quite impressive compability. What I am working on? The Last Dimension, as you might have noticed on the website. Of course, soon we have a special date…

Super MX Linux Experiments

It was 2013 when I first tried to port Super MX to Linux. Back then, only the Pyramid Demo quest existed, there were no savegames and the dialogue control behaved strangely. However, I created a makefile which was able to build Super MX on Ubuntu.

Recently, I finished implementing the main quest of MX, so I thought it would be a good idea to review some goals of the underlying engine, and voila – I was able to port the 2020 version of Super MX.

It seems that not only the original Pyramid Demo levels are working, but also the new ones like the Shadow Temple.

TIL there is a linux distro PopOS!

However, there are two downsides. Fullscreen is not working yet, as well as the sound. I am currently thinking about solutions which affect the underlying subsystem. I will do some more experiments.

If this does still not scare some of you Linux-friendly users, feel free to download the new Pyramid Demo Build under this temporary Google-Drive link (language is German for now) and find out if it starts:

https://drive.google.com/drive/folders/1THOebjdR8tgswhPFWZ7SasKh7iIwNjVq

Movable Mirrors

Currently, the level design of the shadow district is being implemented. Especially interesting for this month are the new mirror mechanics. With movable mirrors, MX is able to change the direction of the Illumination beam as described as in the original mirror post.

Changes the direction of light!

Brainstorming about the Shadow Temple

A lot of cool puzzle mechanics were made for the Shadow Temple as you can see in the old posts πŸ˜€ Now, a shadow district, a second floor and the boss fight are missing from the planned temple. I am currently thinking about new enemies and puzzles.
Which type of puzzles and enemies would you like to see? Tell me in the comments πŸ™‚ !

Light and Mirrors

Got some progress with the level “wiring”, as I call the scripting of the dungeon.
A nice idea for the puzzles of the dungeon was to add mirrors. They are either static or can be rotated and reflect the trajectory of the illumination beam.

The right angle…