Rookie Awards 2024 - Open for Entries!
GreyLife
Share  

GreyLife

by lewisyates on 30 May 2019 for Rookie Awards 2019

Build, Destroy and construct tools from blueprints in this procedurally generated world. Make sure to plant trees and try not to pollute the planet. Game available to download from Itch.io at: https://lewisyates.itch.io/greylife

1 435 1
Round of applause for our sponsors

Grey Life was a solo project made in roughly 30 to 35 days. I found out about the competition just before starting and decided to use it as a challenge for my self.  I wanted to build a game in a genre i hadn't attempted before, with at least one feature i didn't know fully how to make upon starting the project.

Below are some screen shots from the game, as well as some of the code that i wrote for the terrain generation, as well as some information on how i achieved my item system using Unity's ScriptableObjects.

The Code below is a class called TileData. This class is used to store data for a tile type, the ID, the item, the texture and the health of the tile type is stored here. This class is a scriptable object which means i am able to set all these variables from the inspector in Unity.

This is the TileData object for my grass tile.

These TileData scriptableObjects are used in the LevelCreator class to assign the correct values when i am creating a tile.

The code below is a snippet from my Level Creator class. This method is responsible for generating the data that make up the game world. Simply put, this method generates data which is then stored in a chunk, when the chunk needs to be displayed on screen, the data is passed to a method that creates the tile GameObjects.

More In depth look

The method starts by creating a chunk GameObject that is used later in the method.

Next, I have defined a bunch of local variables that are assigned with random values, these variables are responsible for the cave generation, iron ore generation, and foliage generation.

As well as these variables, I also have a variable called height which makes use of PerlinNoise. This variable is the max height that a column will be built up to. This value, after each column is generated is altered in some way to add variety to the terrain generation. The value is altered at the end of this method.

Inside the for loop after the local variable definitions, I am performing a number of checks, firstly I am checking to see if the variable of Y is within the bounds of a cave, if it is, creation of the tiles data is skipped as its not needed.
Just after this I am checking if the Y value is below a certain depth, if it is, the tile has a random chance at becoming an iron tile.

I am then comparing the Y value to other values to determine what the tile should be. As the Y value gets lower, the tile type will go from grass, to dirt, to stone. If the tile is at the very bottom, i want to set the tiles data to be bedrock so that it can't be destroyed.

I kept these Y value checks basic as i knew i didn't want to add anymore tile types than the five featured in the method.
If i were to rewrite this method I would likely have created some kind of list or array that would store the Y value max and min values that the tile can be generated as well as the TileData. I would then compare the Y value to each entry in the list or array.

Finally, I am assigning the data created to the chunk that the tile belongs to. This data is then used later on when the chunk is required to be visible, the data generated here and stored in the chunk is then passed to another method called AssignTileListData where the tile is finally created.

As mentioned above, the AssignTileListData method is called from the chunks when tiles need to be displayed on screen.

For the game I created a very simple object pooling system which is utilised in this method.

This method very simply grabs a tile from the object pool and begins assigning the tiles ID, item, texture and health values.


Comments (1)