Game Construction: Terraria and 2D Level Generation

Hello Reader!

Before we start I’d like to go on a bit of a tangent here about the concept and idea of a console developed by Valve.  This has been popularized as the ‘Steam Box‘.  What does this mean for future games and the future of the industry? Also these are the rumoured specs: Core i7 CPU, 8GB of RAM, and an NVIDIA GPU.

Rumoured Steambox

Valve is the world leader in PC/Mac video game online distribution. There are other services like this, EA has Origin but their customer service is a nightmare.  Steam on the other hand is loved by its community and is truly a great service.  With Sony, Nintendo and Microsoft (Big Three) pushing the market toward the consoles, Steam is keeping PC gaming alive.  Onlive tried releasing a cloud gaming console, however it is not doing so well.

This Steambox or ‘GabeCube’ would help drive PC game development and change the future of how we play video games.  Valve would offer better licensing fees to compete with the Big Three.  The most important element of the Steambox would be the sudden move to digital distribution.  The Steambox would help solve many issues that people have with consoles right now.  First of would be the limited technical specifications, overpriced games and the online gaming fees.

Here is a patent for a controller design that Valve applied for back in 2009/10.

Getting back on track with the main topic I wanted to cover today:


My post last week on Minecraft’s level generation was fairly abstract since I don’t have much knowledge of 3D noise generation and the use of voxels. This week I will try to conceptualize how the 2D level generation in Terraria works.


The technique that I have seen for 2D level generation works well when working with underground items like rocks, dirt and ore.  However things like grass, snowflakes and other biological entities are generated using a different method that is much more complex and harder to conceptualize.



We know we are dealing with just dirt and rocks that are below ground.  Lets get biblical and start dividing up the heavens from the earth.  The first step, similar to Minecraft is to take a function that can divide up our world and tell us what is solid and what is air.  This part is fairly easy because we all know a great function for diving things up into two parts linearly.

GRADIENT!  Given two points a gradient creates a line using parameters like: P1=(x1,y1,z1,w1,u1,v1) to P2=(x2,y2,z2,w2,u2,v2).  Here we have our points and our texture coordinates. But all we need is to set up a simple gradient from -1 to 1 and align it with the Y-axis.  Then we get something like this:

Simple Gradient

Using this as a starting point we can move onto our next part.  Similar to toon/cel shading we need a step function.  There are too many levels here to work with and we only need 2, solid or air.

After using the step function

Now this is much better.  We can clearly see what is air and what is ground.  Unfortunately this is boring.  We need to remove that horizontal divide in the middle because straight lines and linearity in games a boring.  The great thing is that we have another function that can help us with this.  However this is more of a technique then a function.

TURBULENCE! All this function does is translate points or translate the input coordinates of a function.  What we want to do is scatter that centre area given a range and offset of random numbers.  Now imagine the top part of our ‘level’ as y=1 and the bottom part is y=-1 leaving the centre to be y=0.  Given a range from y=0.25 and y=-0.25 we want to create come turbulence.  This would be the result of turbulence:

After Applying Turbulence

Better then having the flat line, however if a world had random blocks floating in the air we would have a serious problem.  This will not be our finished product, but it gives us something to work with.  Right now we have a messy chaotic pattern and we want a nice smooth terrain shape.  This is where it get complicated, we begin to use fractals.

The fractals I am talking about is a combiner of noise sources using different fractal methods.  First we have the basic noise groups like:

Value Noise – Generated by assigning a random value in the range (-1,1) at every lattice point in the image then using interpolation to generate corner values for each cell
Gradient Noise – This is Perlin’s original noise function using a similar method to Value noise. However it uses a wave-like pattern for generating the lattice points for a smoother output
Gradval Noise – This is a hybrid between Value and Gradient noise mainly created to hide artefacts that occur in the interpolation process in the Gradient Noise
Simplex Noise – Improved version of Perlin Noise using a ‘simplex’ instead of a hypercube. In 2D space a simplex is a equilateral triangle and in 3D it is a tetrahedron.
White Noise
White Noise – This is a more chaotic and random noise seen on many old TV’s. It generates a chaotic random signal with no pattern.

Just so we can get a better understanding of how noise is generated let us go through a few step-by-step examples:

All this image is, is Value noise without interpolating the values. You can easily see how each grid element has a value
Now if we add linear interpolation to the lattice coordinates we get something like this

You can experiment by using cubic and quintic interpolation to get varying results, but that is the process in a nutshell.

Getting back on track on how to implement fractals in our level design.  What we want to do is take our level begin distorting it so that each point gets randomly offset by a value determined by the fractal.

Fractal generated by a function

Here is an example of a fractal in the scope of our level. So how is this useful to us? Lets say the black areas represent -0.25 and white represents 0.25.  So anywhere where the fractal is at its darkest black we move the point -0.25 downward and upward if it is white.  Values in the middle will have interpolated values.  Why is this good? This will give us smooth hils because of the gradient of the fractal and we can get floating islands and overhangs with this.

Fractal Distortion Applied

There is a lot more we can do still to this image, its just a matter of adding more filters and functions to tweak in how you want.  We can take a horizontal gradient and create a heightmap if you want to get rid of the floating islands and want different types of terrain.

Horizontal Gradient

Taking this gradient we can apply a similar offset technique to move our terrain up or down as needed.

After Heightmap Adjustment

Closing Remarks

This process is very similar to the idea of shaders. Each point is just data and we can manipulate it as we want.  If we want to add caves we can create a fractal like:

Cave Shape

And using a step function and offset we can apply this to our level and get:

Smooth Cave System

Now if you want to make that cave system smoother, just add another fractal to perturb each area a bit.

Final Cave Shape


Source – []

Thank you for reading
– Moose

Game Opinion: Japanese Culture and Western Game Design also RPG’s


The next blog posts will be in preparation for a game idea I have had sitting in a dark corner for a while waiting to be let out to roam free and changed.  In order to do that, I have to go over two topics.  One is the East vs West culture differences pertaining to games which I will be blogging about today.  The other topic I wanted to talk about is how I think RPG’s should be cultivated.


Why do Japanese games do so horrible in the western market?  Why are so few eastern titles seen on the top selling charts in the Japense market? Can we make games for both audiences or do we have to make independent games for each region?



Lets start out by looking at the differences between Japanese anime and North American Cartoons.  Famous Japanese anime like Bleach, Naruto, One Piece and Fairy Tail all have huge epic stories that have been going on since 1999 and are still published weekly to this date.  Also, Japanese anime all have very deep stories and characters that can be enjoyed by many different age groups.

  • Bleach – Protagonist is a very strong and serious teenage boy.  The story is about how this boy turns into a “death god” that is able to walk among and interact with the afterlife.  The protagonist is only able to advance through the many antagonist’s by developing his hidden power only to protect his friends.  The most notable aspects of this anime is the depth at which they choose to portray the afterlife.
  • Naruto – Protagonist is a comical young boy with a very troubled past having persevered through lots of hate and animosity from others because of a demon monster that lives inside him.  This anime takes place in a large fictional land inhabited by ninjas.  The main plot that drives this anime is the protagonist trying to reclaim his best friend from the dark side or the evil side.  This anime has many great underlying themes.  The most notable is the cycle of hatred and revenge.  Since the protagonist has survived through a decade of hate he is constantly trying to remove hate and revenge from the world.  The anime tries to define hate in many ways and it also shows how the cycle starts and begins several times over the course of the anime.
  • One Piece – This is truly one of my favourite shows of all time.  It is an epic tale of a very comedic and amiable protagonist that can create a bond greater then friendship with almost everyone on the show.  The setting is a giant world where pirates roam free to pillage the unexplored seas of this fantasy realm.  The main plot is that a great Pirate King left a great treasure in the most dangerous sea and whoever get it will be able to become the next pirate king.  The reason why I love this anime is the cast of the protagonists allies.  His pirate crew is filled with the most interesting characters that eventually you feel as a viewer immersed that you are laughing as if you are on that crew with them.  Most notably they use a word to describe the crews relationship with one another that is “nakama“.  Many people translate this Japanese word to friend, however there is no real word in the English language that can properly state the meaning of this word.  A Nakama is someone who is greater the a friend but not blood related, it is someone who is essentially your family and the bonds you share cannot be broken.  This concept of brotherhood is really the best part about the anime, it shows the most perfect group of friends that I have seen on screen.
  • Fairy Tail – This show is essentially a magical version of One Piece.  Whereas rather then a pirate crew, we have a guild of magicians

While this montage does not to justice to the many hilarious moments on One Piece, it gives you a good idea of the show and Anime.  There is a lot of slapstick type comedy in many anime and One Piece uses it a lot in the delivery of their jokes. (The guy with the straw hat is the protagonist Luffy).

The main point I wanted state was that their shows have a lot of depth to them in comparison to the North American cartoons.  Look at Family Guy, Futurama/Simpsons, Archer then the more childish shows like Spongebob, Fairly Odd Parents and so on.  These shows are primarily episodic that reference pop culture and current events.  The mature shows are more humorous rather then going for deep stories.  The childish shows have short 15 minute skits that rely on cheap morals driving the plot to teach kids basic morality and ethical lessons.  Japanese anime don’t have these “morals” driving their plot, instead they show deep and emotional scenes through their characters.

People may think that Japanese anime are all the same, however the thing that defines each show are their characters.  Luffy from One Piece is a funny, approachable and likeable leader yet when shit goes down he turns into a complete badass that forces you to sit on the edge of your seat to see him fight.  Naruto from Naruto is a rebel with a harsh past and a long history of bullying because of a demon that lives inside him.  However his strength is the ability to look past that and still fight and ‘love’ everyone equally and fight for the sake of the village that ridiculed him as a child.  Ichigo from Bleach is more a serious character that is always fighting to save his buddies.

Overall, the point is that Japanese media is more focused on creating a long and epic story built on the backbone of its characters whereas American media is more populated by shows giving the viewer an emotional response through episodic shows.  This is also because of the way these shows are produced.  Japanese shows will have one writer and a team of artists working on a project for years at a time but American shows change writers almost every episode.


Looking at some of the more famous Japanese games like Final Fantasy, Dragon Quest, Monster Hunter, Persona 3, Tales of Series, Dark/Demon Souls, etc.  The majority of these games have very large and expansive worlds that follow a fairly linear plot structure but for the most part have very difficult gameplay mechanics and/or very deep and satisfying stories. These games are heavily focused on narrative and want their players to follow this linear plot they have created.  If you look at almost every major Japanese RPG developer (Squaresoft, Enix, Koei, Falcom) they all started out making visual novels for their RPG genre.  All their games after that use those visual novels as a template for creating their future games. In essence they take a dynamic like an action RPG, turn based RPG and take a long story like a visual novel and create a game.

Looking at western RPGs like Mass Effect, Dragon Age, Skyrim, Fallout, etc.  These games also have very large and expansive worlds however their stories are not the driving force of the game.  The most important aspect of WRPGs is the player experience.  They try to build a player centric RPG where the player is free to either play the story, kill NPC’s altering plot lines or explore the world.

The guys over at Extra Credits bring up a valid point about the whole JRPGs vs Western RPGs.  As an industry/community we end up lumping both JRPGs and WRPGs in the same genre but the reality is that they are two completely different genres.  It is like calling both apples and oranges, bananas.  When in reality they are both fruits they have their own sub classification as either an apple or an orange.  That was most likely the worst analogy ever.

Personally I was fairly surprised that I am a fan of Japanese animation however I prefer the WRPGs.  I like the freedom and ability to do whatever I want in a game, JRPGs are fairly restrictive.


What was the point of the past 1300 words? Why do Japanese games do so horrible in the western market?  Why are so few eastern titles seen on the top selling charts in the Japense market? Can we make games for both audiences or do we have to make independent games for each region?

First of the rant was a large intro that will allow me to answer these next few questions.

Take a look at VgChartz software and hardware sales for North America and Japan for a second. For now you should notice a bit of a trend.  Japan’s consumers like handheld consoles, mainly the 3DS and the North American consumers prefer the home console.  So unless Mass Effect 3 comes out with an amazing PS Vita or 3DS port, their eastern audience is fairly limited.  Aside from the business aspect of why WRPGs don’t sell in Japan, I think that Japanese consumers are looking for an indepth RPG experience on a handheld device.  Most of the great WRPG’s are console based and there has not been a huge effort to make a similar game experience on a handheld device.  This is primarily because the horsepower on the consoles is greater then that of most of the handheld devices.  As I stated above, WRPG’s are more about creating a great innovative gameplay experience that require more processing power.

At the top of the 2011 Japanese charts we see Mario Kart 7 (3DS), Super Mario Land (3DS), Monster Hunter 3G (3DS), Monster Hunter Freedom 3 (PSP), Final Fantasy Type (PSP).  The first eastern game on that chart is Just Dance (Wii) in 17th place. Skyrim has sold about 200,000 units in Japan and Mass Effect 2 has sold about 90,000.  I think this goes back to the idea of making handheld games geared to the Japanese market.  However, there are hundreds of JRPGs already attempting this strategy and this is evident by the number of 3DS  and PS Vita games released.

Closing Remarks

Overall, the idea of WRPGs vs JRPGs should not be a head to head competition of which one is better.  Each one is a genre on their own.  It is like comparing a FPS with a puzzle game.  I do not think it is possible to make a RPG game that can satisfy both regions equally. One may argue by bringing up Final Fantasy, Pokemon and Super Mario.  However those games have insane teams of marketing and game developers with million dollar budgets and a strong foundation in those markets after developing for many years.

Thank you for reading,