Perlin Noise

Nearly Infinite Procedural Terrain Generation

Chunk Edge Errors
Chunk Loading implemented with errors along the edges of the chunks

I know it has been a little over 4 weeks since my last update. But I have been very busy with my class and full-time job. I feel like I have not made much progress with the game. About 3 weeks ago I modified the terrain generation to work using chunks and changed the generation to be nearly infinite.

Chunk System:

The game world now is limited by the max size of a 32-bit integer. So, the terrain generation can only modify x and y values between -2147483648 and positive 2147483648. Which if my math is correct, makes my game world about 2 billion pixels in each direction from the center. I am not the best at math, but the map would have a lot of tiles before causing issues. So that is why I am calling it nearly infinite. It would take a long time to see all the tiles of the game world. Also, each time you start a new game the seed can change and generate another entirely different terrain. Or if you keep the same seed the game world would be the same at the start. This is like how Minecraft world generation works, except mine is 2D.

Major Changes:

Due to this massive change I modified my terrain generation edge checking code to check the edges on each chunk. However, currently along the edges of chunks because it does not know what type of tile is next to the edge, it draws incorrectly. I believe I need to rewrite the code now to have all the current chunks load on the screen and then calculate the edges of the tiles that are visible. That way there are not just some tiles that do not change to edge tiles. Because I am loading in 16×16 chunks of tiles, I am loading about 25 chunks total to fill my screen. I think the best way to solve my issue is to load the chunks and then calculate the edge changes. Hopefully, this solution will work after I get a chance to implement it.

When I am testing currently I have only one chunk load in which is what you see in the video. But I can have more load in, and then you will not see the transitions because they would be off the screen.

Video showing the chunk loading one chunk at a time. It also shows the errors around the edges.

Other Issues:

Another major issue currently is that the map is generated using Perlin noise and a seed. Which works great for the terrain generation because it can use the seed to get the next chunk of terrain data. However, all the other items like trees or entities I need to come up with a system to not just randomly place them. Currently the game draws these objects at random when the chunk loads. But when the chunk unloads, I have not yet programmed in to remove the entities in the chunk. I need to come up with a system to save this information. I am thinking I will need to create id’s for the chunks and check if they have already been seen by the player. If they have then I will need to load them from a file of chunks. This will also require me to be able to save this same data to a file each time a chunk is unloaded.

An additional part that needs to be implemented is saving the entire game and loading from a save file. I have not yet implemented this. I may need to get this working before starting to save chunks. The game should be able to save a game and then reload that point so you can come back and play at another time. Because the game world is so large, and I want it to be an adventure I need to be able to save the current game. Also, you should be able to start a new game if you so desire.

Game Outlook:

Because of the amount of work required I think I put myself in a tough spot and I lost some of my drive to work on the project. I am hopeful now that I can start working towards solving these problems and getting the project back on track. I started working on serialization code, but I have not really tested it yet. My hope is that saving this data will not cause issues with delays. I may need to separate this data into smaller files, but I think many chunks should be saved in each file. My only concern is that if I have multiple files, I will have to check each file to see if the player has seen the chunk before loading the chunk. Or I would need an index to reference which file that information was stored in. I’ve never coded anything like this before so it will be difficult.

I think if I start tackling one piece at a time, I will be able to overcome these issues. I just think that it is going to take me a long time. Winter Break at the college is fast approaching so that may help me be able to work more on the project. I will do my best to post more soon. Until next time.

Full Change List:

Coded: a chunk system to load tiles in a 16×16 grid to allow less to render at a time. Currently the game loads 25 chunks in total, a 5×5 grid of chunks to cover the entire screen.
Updated: The game map system to handle chunks and level data.
Updated: Replaced the original level generation with chunks to have a nearly infinite world.
Bug: Fixed attack animations and arrow shooting after the map update bugged the code.
Bug: Fixed the spawning system after the map update bugged the code.

Nearly Infinite Procedural Terrain Generation Read More »

Migration to LibGDX Framework Complete

Mountains Working Again
Two layers of mountains are procedurally generating into the world.

This week I was able to complete coding everything from my previous version into the new LibGDX version. So, now I should be able to start implementing new things.  I was able to get two layers of mountains procedurally generating again in the game world.  There are still a few bugs where I am not checking some special cases but overall, it is looking pretty good.  Additionally, I was able to fix the rabbit animation problems I was having from the previous week. 

 I recently made a list of the next items on my list to work on.  It is very long but I would like to start working on attack animations and sprites.  Then I would like to work on adding an inventory system and an item system.  I would also like to work on animated tiles to make the world look more alive.  Every week I seem to talk about working on a noise algorithm for placing objects around the world better,  but I keep putting that on hold.  Hopefully, I can start working on that soon as well. 

Hopefully the next post will have something more interesting to talk about. I spent most of my time this week working on fixing unexpected bugs and getting everything working as good as or better than before. I am looking forward to starting work on the next pieces of the project.

On the end of the post every week I am going add a list of changes that I made during the week and add them to the end of the post.

Full Change List:

  • Fixed Bug: particle spawner had a null pointer exception because there was no sprite for the spawner.  (put spawners into a new type of entity called non render entities) 
  • Fixed Bug: particle spawner not removed during cleanup after it is used. (Empty object was still in memory)
  • Fixed: Rabbit movement animations.  Each rabbit needed its own copy of the animation sprites.
  • Implemented: Mountain Tiles have been added to the game world. (2 layers)
  • Code change: Moved Rendering into each class.  Many calls instead of one giant one.
  • Code change: Created a class for levels.  Moved a lot of the level data out of the game class.
  • Implemented: Entity Sorting for rendering.
  • Fixed Bug: Entity Sorting crashing when sorting Trees.  (Trees at same y height caused the crash)

Migration to LibGDX Framework Complete Read More »

Game Migration into the LibGDX Framework

After watching a lot of indie game developers’ videos and checking out their websites I came across a java game framework called LibGDX.  I decided to look into it, and I think it is the best way for me to go on with my current game project.  LibGDX is a free open source game development framework written in the Java programming language with some C and C++ components for performance dependent code.  It allows for development of desktop and mobile games by using the same code base.  It also has cross platform development. 

LibGDX First Map Rendering
LibGDX First Map Rendering. Each tile is 1 pixel for testing the noise algorithm.

Framework vs Game Engine:

LibGDX is a framework not a game engine.  A framework is essentially a code base that handles important aspects of games, usually hardware interfacing and input, but come with no predetermined rule set.  A game engine is a set of tools and mechanisms prepared to make a certain type of game. Good examples of game engines are Unreal Engine and Unity.

Teaching Schedule:

I figured switching to LibGDX would be the best option for me, since I was already coding the project in Java. In about a month I will be teaching on top of my full-time job for the fall semester. So, this should allow me to design the game, but not have to code everything. Hopefully, saving me time in the development process.

LibGDX Version Work:

LibGDX Game Map Scaled
LibGDX Game Map scaled up to size. Default tiles and Player rendering.

First, I imported the framework into an Eclipse project and started working on switching over my current project into the LIbGDX framework. Then I was able to figure out rendering the tiles to the screen as well as setting up the player and the movement animations. I first tested the setup by rendering each tile as 1 pixel. After I had that done I scaled up to 16 pixels per tile. Then I scaled everything by 3 for the view window. Today I was able to also get tile-based collision done, and I setup for entity collision for the future.

So far I only worked on printing the game maps default tiles. But, I should be able get the others working quickly since I already have working Java code for that. I will need to figure out the rendering process using the framework, but it shouldn’t be much different than the default tiles. I don’t think it will take me too long before I have everything working that I had working before. The framework should allow me to be able to get more done in less time. At least that is the idea.

This week I didn’t work on anything new. I mostly worked on learning the new framework and getting the project back to where I was originally. There is still a lot of work to do in order to get back to where I was. I think in the long run though, this transition will help speed up development. I wish I had known about this framework about 10 weeks ago. Hopefully over the next week or two I will be back to creating new content for the game and back on track. Until next time.

Game Migration into the LibGDX Framework Read More »

Week 5 Game Engine Progress

Game Engine Work:

This week I continued working on the generation of the 2D map for the game. I spent a lot more time working on coding the edge checking system. Currently I have pretty much figured out how to make it work. I have a few special cases that I seem to be finding that I did not check for. One is featured in the image below that shows if the edge is closer to another edge it does not know to handle it properly. It only finished the edge on one side. The error is just above the character to the left. To fix this I need to add art assets for each case and check it in the code. Currently I also have most of the grass edge working. I need to finish checking some of the special cases just like in the water section.

Water Tile Special Cases
Water Edge Tile bug that will be fixed soon

After the edge system is done for the water and grass, I need to work on the other sections with edges. In the future I want to change the water tile and make it animate. I also don’t want the tile to just be blue water. Also, soon I want to add more detailed tiles to the map to make it look much more interesting.

In the map generation right now, I marked an area in dark green that would be the denser forest area. The dense forest would be made up of much denser tree placement and taller grass and shrubs. Some of these areas would be inaccessible without cutting the objects down. I also marked out terrain with a grey area for mountains and a white area for snow. In these areas I want it to look like they are a higher elevation and I believe that I will be able to make it look higher using edge sprites. Instead of replacing the edge with a one tile change, I would need to probably use at least 2 tiles to make it look like it is higher up. Also, once I add collision the player would not be able to just walk into these areas without a ladder or ramp or something.

Water and Grass Edge Done
Water and Grass Edges are working for the most part.

Future Game Engine Work:

I would like to add elevation changes to other areas as well down the road. I have been thinking a lot about what I would like to have in the game, and I think I would like to have cave entrances spawn on the map in the elevated areas. Then if you enter a cave, I could generate a below ground map that would resemble caving and dungeon exploration. I think by adding this element it would make the game much more interesting and would make the game very repayable due to all the procedural generation changing every time you play the game.

Furthermore, I started thinking that maybe most of the enemies on the surface will be forest animals. I really enjoy nature and wildlife photography so I figure a game with wild animals would be cool. To start I would like to implement some animals that would be non-aggressive and others that would attack the player. I would probably start with sprites for bears, wolves, rabbits, and foxes. I think it would be real fun if the player could tame these animals or trap them. But this work would be something that I am no where near ready to implement.

For now, I think I am going to focus heavily on the procedural generation of the world. Then I will work more on the game play aspects. It has taken me longer than I thought it would to figure out how to calculate all the edge checks, but I am starting to get the hang of it. The next step is to try using cellular automata or another method to produce more random placement of detailed tiles. Then I would like to work on the elevation changes.

Game Art Work:

Over the period of the week I worked a lot getting the proper tiles for all the edge cases. With the grass edge I was able to use less tiles because of the way I created the tile set. So, it was easier to complete than the water. I will most likely use the new method to complete the other areas, so I don’t have to make as many assets. Other than making a few edge tiles I really did not work much on art assets this week. I want to add more randomness to all areas on the map because currently the blank colors are boring. So, this week I will work on adding more detail tile sprites to each area. Once there is more randomization the map will start to look a lot more interesting.

In the future I would like to add a rivers and path system. So, I will need to create art assets for this as well. The other problem I might encounter is if a river intersects with an elevation change. In that case I would need tiles that look like a waterfall to now throw of the aesthetic. I am sure that I will encounter all kinds of problems as I work on this, but I am hoping I can figure them all out and make everything work as intended.

Week 5 Game Engine Progress Read More »

Start of 2D Terrain Generation and Perlin Noise

Initially when I started working with Perlin noise I was using grey scale values to display elevation. So the darker the area the lower the elevation. I also played around with smoothing the noise. The smoother the noise the less differentiation occurs in the height. But I figured for now I wanted to show more on one screen. Check out the images below for the different maps.

Since I currently do not have a chunk loading system or any way to move around the map, I have no way to test generating more than one screen worth of data. In the future I want to have a chunk loading system in place. Initially I would load 9 chunks of the map. The center map where the player is and its 8 neighbor chunks. Then as the character moves I would need to load and unload chunks from memory. This may lead to some problems with the edges of the chunks not matching up with terrain height and biome type. I am not sure of that until I get to that point. I have not started work on the chunk system yet but I think it is one of my next steps.

So, my initial maps just show different noise levels in grey scale. Then I added some color in the next maps to show that water would be the lowest elevation, then sand for beaches, then grass was green, and the grey area for mountains, and white for snow caps. From there I moved onto generating another noise map for moisture levels. I had to use another random seed of noise so the maps were not identical. Then I also changed the increment to smooth out the moisture differently than the elevation map. Most of which will change again once I can produce smaller sections of the overall map using chunks. Once I had both maps setup I merged the outputs together into my algorithm. Then I created different biomes based on the elevation and the moisture level at a specific location. I gave a specific color to each biome. Then I started to get some weird outputs. It took a long time before I realized that I was not adding the different octaves of the noise. Octaves are the number of levels of detail you want your Perlin noise to have. I was only generating one level. Now that I am using a higher number of octaves and adding them together, I am getting a much better result.

Current Biomes:

The biomes currently are: ocean / water, beach, scorched earth, bare, tundra, temperate desert, shrubland, grassland, temperate deciduous forest, temperate rain forest, subtropical desert, tropical seasonal forest, tropical rain forest, snow, and taiga. Each biome is represented by a different color on the map. I may raise or lower the number of biomes in the future. For now this was for testing purposes.

In the near future I am probably going to add more layers of abstraction to the final map. I need a way to produce rivers effectively as well as a way to place trees, bushes, stones, and other objects. I also would like to add a temperature / latitude map to make biomes limited by the temperature as well. This may be harder because I want the map to load dynamically. I will most likely have to determine what the max map size would be in order to add poles and equators. Then I would need a system to chose the starting point of the map, so that the player was not always starting in a specific biome or temperature based solely on the latitude. I also need to work on the system of not only generating the terrain data but then taking that data and translating each pixel to a tile. Currently my maps are not very detailed and don’t include all the data. But, I think I will start working on the basic system to going from a pixel map of colors to a map of tiles that will most likely be 16 pixels wide by 16 pixels tall. I may make it 32 but I have not decided yet.

I have worked a lot so far this week on the noise generation for the maps. But I will also continue to work on some art for the game. I have been working on the character art but I still have to finish the front and back views in grey scale before I move to coloring the character. I also need to work on more tiles for the map. Including more ground tiles for different biomes. Tiles for rock, snow, water, etc. I will also need to work on a tile system and an animated tile system. The game is in such early stages that I basically need to build everything, and as I do I will be adding the progressions here.

Screenshots of the map work so far:

Start of 2D Terrain Generation and Perlin Noise Read More »