Posted in MA Indie Game Development

GDD720 Week 2

 

For the next few weeks, my focus will be on learning how to create procedurally generated random zones, starting with a study of some recent games that use these techniques and trying to learn more about these methods through reference material in order to create a relatively simple but effective way to do so with Unity.

 

 

 

Procedural content generation for Fra Mauro

The terms “procedural” and “generation” imply that we are dealing with computer procedures, or algorithms, that create something, a method that can be run by a computer (perhaps with human help), and will output something; in this specific case, a piece of software  that creates interconnected rooms for an action adventure game on a futuristic complex settled on the Fra Mauro highlands on the Moon.

This is are two areas in which I am particularly interested (3.64530° S latitude, 17.47136° W longitude* and the procedural dungeon generation) so I have decided to spend all of my efforts on a prototype that focuses on a play space made up of distinct rooms or zones that are formed at random and may communicate with one another via connected pathways. 

The definition we will use is that PCG (procedural content generation) is the algorithmic creation of game content with limited or indirect user input. In other words, PCG refers to computer software that can create game content on its own, or together with one or many human players or designers. (Togelius 2016)

Perhaps the most obvious reason to generate content is that it removes the need to have a human designer or artist generate that content. It is not my goal at this time to create a mapping ‘by hand’ i.e. fully planned in advance, but to have it generated through some programming techniques which can create a basic structure that can later be polished with human intervention. There are a number of approaches to solve this problem; some more abstract than others, but all are based on the use of at least a couple of algorithms that work together to create the play area from the random generation of a path or ‘walk pattern’ to which then will be added the components of each room (walls, entrances, exits) and another that deals with connecting these areas.

In chapter 2.8 of ‘Procedural Content Generation in Games’ the authors present a clear example of this genre mentioning Roguelike games as a type of games that use PCG for level generation. ‘In fact, the runtime generation and thereafter the infinite supply of levels is a key feature of this genre. As in the original game Rogue from 1980, a roguelike typically lets you control an agent in a labyrinthine dungeon, collecting treasures, fighting monsters and levelling up. A level in such a game thus consists of rooms of different sizes containing monsters and items and connected by corridors. There are a number of standard constructive algorithms for generating roguelike dungeons such as:

  • Create the rooms first and then connect them by corridors; or
  • Use maze generation methods to create the corridors and then connect adjacent sections to create rooms.

The  phenotype of the dungeons should be 2D matrices (e.g. size 50 × 50) where each cell is one of the following: free space, wall, starting point, exit, monster, treasure.

Obviously, structuring them into two distinct parts is simply a matter of good practice and clarity. Unity offers a number of add-ons that provide a number of tools – both paid and free – that you can easily get hold of, implement them and move on to something else, but that is not my choice for this project. In my opinion, the interesting part of all this is to understand in more detail how to create an algorithm that randomly generates the game scenarios, even if not in a simple way.

To my great surprise, there are also many C language structures that provide interesting shortcuts when programming these algorithms.

Even within this solution, there are several possibilities such as considering that all rooms are of the same size, or that they are distributed within certain pre-established limits; or that they are of different shapes and sizes, with or without a predetermined area to occupy. All these variations undoubtedly require more complex algorithms to be programmed, so I think it is better to start with the simplest structures, although less attractive, but you have to start somewhere.

For a few days I worked with two different algorithms, one that makes extensive use of the benefits of the C# language to use data structures and recursion when creating mazes and another that is less refined, longer and more traditional, but much simpler to understand and reduce to its basic functions. 

I set out to ‘cut out’ all the superficial or non-essential functionalities for my purposes and I managed to have in a short time a simple and efficient piece of code that using few parameters generates interesting results. As you can see, every time the algorithm is used a small random map is created. My idea is that if I encapsulate this program inside a class or a method I can use it to create as many scenarios as I want, each of them could become a level of the game.

Unfortunately my lack of deep knowledge of complex data structures in C# of makes these solutions slightly difficult for me to approach, and it took me some time to implement.

After a few days of experimenting I decided to create some rooms using the Random Walk method and tile maps. The following example is the result of my research and coding.

For this example, my initial idea was to let the user decide the size of the map (by entering the x and y values before the generation of the room). Still, for some incomprehensible reason, the simple task of entering an integer value on the screen and using this input inside the script turned out absurdly complex. Having spent several hours trying to convert a string to numeric… I temporarily gave up, but this is not finished, dear Unity!

So, by now, you can choose between three possibilities: 3 x 5 , 10 x 10 or 10 x 15 grids.

Procedural room generation using the Random Walk algorithmic approach
Fig 1- Procedural room generation using the Random Walk algorithmic approach

 

Almost all existing approaches to PCG focuses on generating content for an existing game, where the core game itself could exist without the PCG mechanism. PCG is merely used to facilitate design and adaptation. In 2D Platformer level generation tools like Tanagra and Launchpad, the game level is generated by the tools and then applied to the game engine or platform by the game designer. Even in hugely successful games like Rogue, Spelunky and Diablo, where a key feature of the game is the endless variation in game content, all the levels could in principle have been generated offline and presented to the player without taking player choice into consideration. (Nwankwo: 2017)

 

This is a work in progress, more to come soon!

 

References

Shaker N, Togelius J, Nelson M. 2017 ‘Procedural Content Generation in Games‘. Springer International Publishing Switzerland

Nwankwo G, Sabah M, Fiaidhi J. 2017 ‘Procedural Content Generation for Dynamic Level Design and Difficulty in a 2D Game Using Unity’. International Journal of Multimedia and Ubiquitous Engineering Vol.12, No.9 (2017), pp.41-52

De Byl, Penny. 2017. ’Holistic Game Development with Unity Second Edition’. Taylor & Francis Group, pp. 239-250.

Schell, J. 2015. ‘The Art of Game Design A book of Lenses’. Taylor & Francis Group,‹ pp. 388-391.

Carey, E. 2005. ’Retro Game Programming Unleashed for the Masses’. Premier Press, a division of Course Technology.