2D Terrain Generation

Back Into the Code – Terrain Trouble, Weather Systems, and Visual Tweaks

Procedural Generation

Since my last post about returning to game development after a long break, I’ve been back in the thick of things. I’ve spent most of my time working on procedural terrain generation.  More specifically, trying to connect different terrain types smoothly using TileMapLayer.set_cells_terrain_connect() in Godot 4.3.  Let’s just say it didn’t go as planned.

The idea was to have nice seamless borders between terrain types, but the reality turned out to be full of edge cases. Whenever three or more terrain types meet in close proximity, things break down, visually and logically. The transitions look bad, and worse, the system is painfully slow. Loading terrain in real time for a chunk-based world is completely impractical with this method. So for now, I’ve put that approach on hold and will be revisiting it with a fresh strategy later.

Ambiance and Environmental Systems

In the meantime, I’ve shifted focus to some gameplay ambiance and environmental systems. I started laying the groundwork for a weather system, building a basic state machine to manage weather types. To complement that, I added a CanvasModulate layer to simulate a day-night cycle and hooked it up to a simple UI from a great tutorial I found. The plan is to eventually make the weather and time systems work together so that, for instance, the sky darkens more dramatically when it starts to rain or storm.

Speaking of rain, I’ve added some rain particles and a fog effect as a first pass.  They work… kind of. The rain is kind of hard to see so I need to work on that. One issue I’m currently debugging is that the rain moves in the wrong direction when the player moves, likely because the particles are tied too closely to the player’s position. It causes them to shift far more drastically than they should, which breaks the illusion. I’ll need to rethink how I position or simulate the weather visuals relative to the player or camera.

Grass Tile Art

Lastly, I’ve also begun adding some basic grass tiles, moving beyond the basic biome colors I started with. The world definitely needs more visual identity, and building out a consistent tileset will help me get there.  I just started to work on some alternate grass tiles as well as the edge tiles.  I went with more of a noise based style and  I am assuming it is a work in progress at this point.  

What’s Next?

Up next, I’ll probably focus on tile art and continuing to develop the procedural generation system. I want to start shaping how the chunk generation works in practice, as well as improve the overall look of the world. I’d also like to begin populating the environment with trees and other natural elements to give the map more life and variation.

Thanks for reading. Feel free to follow along or reach out if you’ve dealt with similar terrain headaches in Godot. More soon.

Back Into the Code – Terrain Trouble, Weather Systems, and Visual Tweaks Read More »

Procedural Terrain Generation Showing Different Biomes

Back to Building: Health, Recovery, and Procedural Worlds

It’s been nearly two years since my last update here on CodeBiome, and I wanted to take a moment to share what’s been going on, both in life and in development.

A while back, I mentioned dealing with some health issues, and at the time, I was hopeful things were improving. Unfortunately, that didn’t last long. I developed atrial fibrillation, which brought on a cascade of new complications and made it incredibly difficult to focus on anything outside of basic day-to-day life.

In November 2024, I had a pulse field ablation a procedure designed to correct the irregular heart rhythm. Thankfully, it was a success. Since then, I’ve been recovering well, feeling stronger, and finally getting back to the creative work I’ve missed so much.

Now that I’m on the mend, I’ve been diving back into Godot (currently using 4.3), and rekindling a long-standing passion project: building a procedurally generated 2D world game.

So far, I’ve set up a basic biome generation system driven by three layered noise maps (Height, Temperature, and Moisture):

These values combine to populate terrain with color-coded tiles representing different biomes. It’s still early, but it’s been exciting to watch a world begin to take shape. Right now, I’m focused on improving biome edges getting more natural-looking transitions between regions and refining the noise logic to support rivers and unique features down the line.

Between my full-time job and running my photography business at AstroMammoth.com, time is always limited. But I’ve committed to moving forward with this game project at my own pace. My goal is to post updates here whenever I can no pressure, just steady progress.

I may also experiment with recording some of my development sessions, both to track my own progress and to share a bit more of the behind-the-scenes process. If that sounds interesting, let me know, feedback is always welcome.

Thanks to everyone who stuck with the site through its long silence. It feels good to be back and even better to be building again.

Back to Building: Health, Recovery, and Procedural Worlds Read More »

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 »

Item and Inventory System Started

Item Pickup System
Gif showing the items being auto picked up when walking over them

I realize that it has been two weeks since posting the last update.  But college has started the fall semester and my work schedule has increased.  Besides my full-time job at the college I also am teaching a class this fall.  So, I must spend a little more time working on my class, leaving less time for me to work on my game.  But I will still be working on the game it will just be at a slower pace.

Item and Inventory System:

Over the last two weeks I started working on an Inventory System and an Item system.  The inventory is working in code.  I can put items into the inventory and remove them.  However, I have not worked on a graphic interface yet for this.  I also added the item system so items can be placed in the game world and can be picked up by the player. The items can also be rendered into the game world.  But for now, that most items I do not have icons for I just rendered in a black square.  Once I get more sprites, I will add them. 

Campfire Animation and Sprites:

After working on the item and inventory systems I decided to test it by creating a campfire sprite.  From there I realized I would need a way to animate it, so I worked on the art for each frame of the animation.  I am satisfied with the way it turned out so far but I think I will modify it a bit.  I also may investigate adding particle effects to make it look like smoke is coming off.  But overall, I think it looks good so far. 

Campfire
Gif showing the animated campfire

Attack Animations:

I also started thinking about how to handle the attack animations of the main character.  But so far, I am not sure how I want this to work.  I did start making animations for it, but I am no where near done with that work.

While I was working out the player attack animations, I decided I would first create idle animations for each direction that the player can stand.  I was able to finish them, but I want to do more work with them, so the clothes and hair are more responsive to the player movement.  But it was a good start. 

One last project I worked on was creating long grass sprites for adding grass that the player can walk through.  I only created the sprites at this point, and I have not implemented it into the game at this point. 

It has been a slow two weeks and I am hoping as the semester progresses, I find more time to work on my project.  Currently, I am doing a lot of art for the game and it is taking a lot of hours just to get the sprites done.  I believe once I get the attack sprites created then I will still need to implement them into the game.  I am probably going to be posting every two weeks for a while.  But, depending on how much I can get done I may post more often.                

Full Change List:

Coded: the start of an inventory system for the player and other mobs.

Coded: the start of the item system (player can pick up items and store them in inventory)

Created: a campfire sprite and animations for use as a placeable item.

Created: Sprites for the player idle animation frames

Added: Player idle animations to the game.

Created: Sprites for long grass

Item and Inventory System Started Read More »

Animated Water Tiles Started

Water Tile Animations Working
Image showing the water tile animations

This week the first thing I worked on was getting the animated water tile animations setup. I created a universal animated tile class that I am using to handle all the animated tiles. So, all my water tiles are setup as tiles of the animated tile class. Basically, my animated tile class is setup to take in a sprite sheet and separate each sprite into different frames of the overall animation. Each animated strip is made up of 8 sprites. By using the class with different sprite sheets, I can now add all the different edge water tiles into the game using the same class.

Reconfigured Tile Classes:

While figuring out how to create the animated tile class I changed the way I was making my tiles. I originally had a class for each one, mountain, water, grass, etc. Now I created a class called basic tile that handles all the standard tiles. I also set a Boolean variable that is set upon using the class that determines if the tile should be solid (can collide with it). This change helped simplify my code and remove a lot of unnecessary classes.

Animated Tile Error:

I did run into a crazy bug while working out the animated tile class. As I would move around with the player the more water tiles that would show on the screen the faster the animation would play. After a lot of debugging I was able to figure out that I was adding the delta time variable to the state time to many times. The variable was continually adding to the state time 60 times for each tile visible each loop of the game. So, I just needed to move where I was adding the delta time so it would only change once every game loop. That fixed the crazy looking bug where the animation would speed up so fast it would just look like glitches.

Dark Water Tiles Working
Image showing the difference between water tiles

The last work I did for the week was getting the dark water also animating. For now, I decided not to calculate the edge between the dark water and the regular water. So, the tiles just have a squared edge. But the animation is the same, and the only difference is that the water is slightly darker.

Screen Resizing Error:

Just today I was also able to figure out a rendering issue when the screen size would change. The error would cause the screen edges to show the edge of the screen being removed from rendering because it should have been off the screen, but it was not. I was using the wrong size for the screen resolution and it was causing the screen edges to appear smaller than they should with bars on the sides. I still need to figure out a way to limit the screen changes to stay in the same aspect ratio, so the sprites do not distort depending on the screen size. But that will have to wait till a later time.

Next Pieces of the Project:

The next parts I would like to start working on are more animation for the player. Attack animations being the first I would like to work on. The problem is I need to figure out how I plan to handle them, and I also need to create the sprites. I also want to start working on a user interface and inventory system.

Change List:

Added: water edge and corner sprites
Created: water tile animation sheets for each edge animation and regular water.
Created: dark water tile animation sheet for the dark water.
Added: animated tile class to handle all different animated tiles.
Added: basic tile class to replace all my standard tiles with one tile class.
Removed: separate tile classes (water, mountain, grass, sand, etc.).
Fixed Bug: water animations speeding up depending on how many were on the screen. (updating state time in the wrong location)
Fixed Bug: screen size when getting smaller would not render properly. (I was using the wrong numbers to calculate the screen size when rendering the map tiles)

Animated Water Tiles Started 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 »

Continued Game Migration into the LibGDX Framework

Grass Details and Edges Working Again
Grass Details and Edges Working Again

Over this week I continued working on getting the project to work in the LibGDX framework. I encountered a lot of problems with sprite rotation that I was using for shooting arrows and would probably use quite a bit in the future. But after many hours I did figure out what I was doing wrong. Basically, it came down to the way I was rendering did not handle the rotation so even though I was processing the rotation it would not show it. I still may have some errors with the shooting but for now it is good enough.

Map Generation:

After figuring out those problems I continued working on getting the map tiles back to where they were in the previous project. I have everything done but the mountains and the water. But I figured I am going to be animated the water tiles, so I don’t really need to complete that now. I can skip it and implement the animated tiles. This week I need to get the mountains and the mobs spawning in correctly.

Rabbit:

Over the last couple of days, I started working on the rabbit mob. I encountered some issues with the way the animation is handled. Once I got the movement working, I realized the way I created the animation would not work. Each rabbit needs its own animation. I set up just one and it made it so all the rabbits would move but follow the same animation. They looked like they were skating on ice. It looked funny but was not going to work. I am hoping that over the next day or so I can get them working correctly. Then I will be back to where I was for the most part.

Tree Spawning and Future Work:

Trees Rendering Again
Trees Rendering Again. Entity sorting still needs to be done

I also worked on spawning trees back in this week. I did not run into too many problems getting that to work. Soon I will need to work on sorting the entities though, so they don’t render like they are floating. Once I finish the mountains and the mobs everything should be back to where it was. My goal is to have it all done this week. After that I would like to work on a noise function to produce better looking sprite placement for trees and grass. I think that is the next big step for this project. Then of course I need to add in more animals to make the game feel alive. Hopefully all will go well. Until next time.

Continued Game Migration into the LibGDX Framework 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 9 Game Engine Progress

Game Engine Work:

This week was a great week. I was able to get started on the procedural mountain generation. For the most part I was able to use a lot of the same code from the edge detection to generate the mountains. I only have one layer of mountains currently, but I plan on adding several different layers, so it looks like mountains instead of a one high wall.

Mountain Inner Corner Test
Image showing the inner corner checking system before the proper tiles were put in.
Mountain Inner Corners Done
Image showing the mountain generation after the corner checking was done.

Also this week I was able to get the first tree rendered in the game. I first rendered just one tree. Then I added a bunch. When I initially added them randomly in the forest area all over the world map the games fps went to almost zero. It was unplayable. I knew that I needed to find a way to limit what entities would render. After a little tinkering I was able to limit the rendering all the entities not just trees.

I calculated the distance the entities were from the current player position and then anything further than off the screen does not render. I also tested this on the Rabbits, and it worked for them too. Currently the movement of entities is still calculated, but not rendered if they are off the screen. In the future I may need to also not calculate their movement if they are for say on the other side of the map.

Now that I have the trees rendering, I can start working on an algorithm to better place them in the game world. Currently I am only using the built-in rand function to place them. I need to investigate other better algorithms for placement.

I will also need to work on the rendering order for entities. Currently the player is always on top of the trees, and rabbits run under them. I need take all the entities and take their y coordinates and then sort all of them based on there height on the map. Then depending on the height, it will draw them in order from highest to lowest on the screen. This will be accomplished from sorting the array of entities and then drawing them in order. I hope I can figure out how to implement it this week.

This week I also started working on the beginning of the GUI system for the game. Currently it is just a couple of boxes and components. But I will be working more on it this week if I have time.

Game Art Work:

Trees Rendering for the First Time
Image showing the trees rendering for the first time. Photobombed by the rabbit.

I wanted something that I could render easier. With the current tiles it would just be one tile high instead of several like my previous tiles. But as I add more layers, they should look ok. Now, that I made the current mountains for my game they render in for the most part in one tile. Then I calculate the inner corners to make it look correct. I’m very happy with the way they are turning out so far.

In order to render the trees I needed to have a sprite for it so I made my first tree sprite for the game. I was failing miserable making trees, so I went to YouTube to watch tutorials on pixel art. After watching several tutorials I was finally able to make a decent looking tree. I am sure with more practice I will be able to implement many different trees into the game.

Work Planned for the Upcoming Week:

This upcoming week I plan to continue working on the mountains. I want to add several layers and see how they look from there. I also want to work on an algorithm for placing game objects around the world in a much better pattern. Once I have the trees worked out then I can start adding patches of grass and other objects.

I don’t think I will work on River generation this week, but we shall see. I will be working on getting an animated tile class working hopefully. Once I have that working, I will be able to add my animated water tiles and see how they look. I am happy with the progress so far, and I can’t believe it has been 9 weeks since I started working on this. Let me know your thoughts on the project and any suggestions you may have. Until next time.

Week 9 Game Engine Progress Read More »

Week 8 Game Engine Progress

Game Engine Work:

Rabbits spawning in from the same point on the map at startup

I spent a lot of my time this week working on cleaning up my code and optimizing some things in the game engine. I also did a little work with my mob / npc classes. Last week I created a class for a mob spawner, so I decided to put it to use this week and added some rabbits to my game. I implemented the class for the rabbits and then I worked out some basic movement for them. I just wanted them to be peaceful mobs that would occasionally move around for now. In the future obviously I want to be able to interact with them.

Later in the week I worked on implementing the A* pathfinding algorithm to use for mob pathfinding in the game. It seems to work well at this point, but I need to do more tests with the collision system. It seemed to bug sometimes if the player collides with a solid tile. Other than that, I spent my other time working on art for the project.

Game Art Work:

This week I created the art for the first mob in the game the Rabbit. Because my player sprite is 32 pixels I decided that I needed to make the rabbit 16 pixels. I found it very hard to create a 16 pixel sprite and get the details in to make it look like a rabbit. I was happy with the way the up and down animations looked but the side to side animations might need some work. Let me know what you think in the comments. I also need to create idle animations for all my characters so when they stop moving, they are not just standing still.

Rabbit Mob Sprite Sheet
Rabbit Mob Sprite Sheet

I also started working on some tiles for giving the illusion of height. I modeled the sprites heavily after The Legend of Zelda: A Link to the Past and I will probably add more details to the sprites later. For now, I just needed sprites so I could work out how to procedurally add them to the world generation without causing a lot of bugs.

2D Cliff Tiles
2D Cliff Tiles

Work Planned for the Upcoming Week:

This upcoming week I would like to work on procedurally generating the elevation change tiles into the world. I think it is going to take a lot of work to figure it all out. With a bit of luck, I hope it will be easier than I think. After I figure out terrain height changes, I can work on adding rivers. Then I will need to work out spawning entities like trees through out the world. I will most likely work on some art for new mobs just to break up all the coding this upcoming week. Hopefully after this week the map will start looking more interesting so I can start focusing on gameplay aspects. Until next time.

Week 8 Game Engine Progress Read More »