{"id":70,"date":"2024-12-02T17:32:01","date_gmt":"2024-12-02T17:32:01","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/codedcat\/?p=70"},"modified":"2024-12-02T17:32:01","modified_gmt":"2024-12-02T17:32:01","slug":"developing-procedural-terrain-for-sim-firefighter","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/codedcat\/2024\/12\/02\/developing-procedural-terrain-for-sim-firefighter\/","title":{"rendered":"Developing Procedural Terrain for Sim Firefighter"},"content":{"rendered":"\n<p>Hey everyone! I&#8217;m so excited to share what I&#8217;ve been working on for Sim Firefighter: procedurally generated terrain! As you know, this game is still in its early stages, but one of the key features I&#8217;m tackling is creating dynamic maps that feel natural and engaging. Terrain isn&#8217;t just a backdrop in Sim Firefighter \u2014 it&#8217;s a major gameplay element that impacts fire behavior and player strategy. <\/p>\n\n\n\n<p>To make this happen, I&#8217;ve been diving into Perlin Noise, an amazing tool for generating smooth, organic patterns. The process has been challenging but so rewarding, and I&#8217;m thrilled to take you behind the scenes and show you how it all works!<\/p>\n\n\n\n<hr>\n\n\n\n<h2 class=\"wp-block-heading\">What is Perlin Noise?<\/h2>\n\n\n\n<p>Perlin Noise creates smooth gradients of random values, perfect for generating terrains, clouds, or even fire spread patterns. It&#8217;s widely used in games because it avoids the harsh randomness of pure noise, resulting in more natural-looking outputs.<\/p>\n\n\n\n<hr>\n\n\n\n<h2 class=\"wp-block-heading\">How I&#8217;m Using Perlin Noise in Sim Firefighter<\/h2>\n\n\n\n<p>The goal is to procedurally generate a map where each tile is assigned a terrain type \u2014 like grass, shrubs, or water \u2014 based on Perlin Noise values. Here&#8217;s how I&#8217;m building it:<\/p>\n\n\n\n<p>1. Choosing the Right Tool<\/p>\n\n\n\n<p>To generate Perlin Noise, I&#8217;m using the <a href=\"https:\/\/github.com\/josephg\/noisejs\">noisejs<\/a> library. It&#8217;s a straightforward JavaScript implementation of Perlin Noise that supports 2D and 3D noise and allows for seeding \u2014 important for creating reproducible maps during development.<\/p>\n\n\n\n<p>2. Generating the Noise Grid<\/p>\n\n\n\n<p>The terrain map in Sim Firefighter is structured as a grid. Each grid cell represents a tile, and I use Perlin Noise to assign values to each cell. Lower values might represent water, mid-range values, grass, and higher values trees. Here&#8217;s a pseudocode example of how the noise grid is generated:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>Initialize PerlinNoise with width, height, scale, and seed\nFor each Y coordinate in the grid:\n    For each X coordinate in the grid:\n        Generate Perlin noise value at position (X, Y)\n        Store the noise value in the grid\nEnd For<\/code><\/pre>\n\n\n\n<p>3. Mapping Noise to Terrain<\/p>\n\n\n\n<p>The generated Perlin Noise value range for -1 to 1. We map these values to terrain types like water, grass, and trees. Here&#8217;s how the mapping is done:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>For each value in the noise grid:\n    If value &lt; -0.5: Assign \"water\"\n    Else if value &lt; 0: Assign \"grass\"\n    Else if value &lt; 0.5: Assign \"shrub\"\n    Else: Assign \"tree\"\nEnd For<\/code><\/pre>\n\n\n\n<p>4. Rendering the Map<\/p>\n\n\n\n<p>Once the terrain is generated, the next step is to render it visually. Each tile corresponds to a terrain type, and we render the corresponding graphic for each tile.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>For each tile in the terrain grid:\n    Create a sprite at (X, Y)\n    Assign the terrain image based on the tile type (water, grass, etc.)\nEnd For<\/code><\/pre>\n\n\n\n<hr>\n\n\n\n<h2 class=\"wp-block-heading\">What I&#8217;m Learning Along the Way<\/h2>\n\n\n\n<p>1. Tuning Noise Parameters:<\/p>\n\n\n\n<p>The scale and noise thresholds have a huge impact on the map&#8217;s look. Fine-tuning these values is a key part of the process.<\/p>\n\n\n\n<p>2. Debugging with Visualization:<\/p>\n\n\n\n<p>Visualizing the noise grid as colors or grayscale tiles has made it easier to identify issues with the terrain generation.<\/p>\n\n\n\n<p>3. Reproducibility with Seeds:<\/p>\n\n\n\n<p>Using a seed ensures I can regenerate the same map, which has been essential for testing.<\/p>\n\n\n\n<hr>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p>Sim Firefighter is still in its early stages, so there&#8217;s a lot more to do. Next steps for procedural terrain include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Making the tiles interactive so players can inspect and interact with different terrain types.<\/li>\n\n\n\n<li>Exploring layered noise techniques to create more complex and realistic landscapes.<\/li>\n\n\n\n<li>Improving the map generation performance for larger grids.<\/li>\n<\/ul>\n\n\n\n<p>Implementing Perlin Noise has been a rewarding challenge, and I&#8217;m excited to see how this feature evolves as the game develops further!<\/p>\n\n\n\n<hr>\n\n\n\n<p>Thanks for following along with this journey! And as always, here&#8217;s a cat pic for good luck:<\/p>\n\n\n\n<figure class=\"wp-block-image wp-duotone-unset-1\"><img loading=\"lazy\" decoding=\"async\" width=\"1168\" height=\"1169\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8085\/files\/2024\/12\/Cider-edited.jpg\" alt=\"\" class=\"wp-image-75\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8085\/files\/2024\/12\/Cider-edited.jpg 1168w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8085\/files\/2024\/12\/Cider-edited-300x300.jpg 300w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8085\/files\/2024\/12\/Cider-edited-1024x1024.jpg 1024w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8085\/files\/2024\/12\/Cider-edited-150x150.jpg 150w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/8085\/files\/2024\/12\/Cider-edited-768x769.jpg 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption class=\"wp-element-caption\">My bengal cat, Cider, went on an adventure to the grocery store parking lot recently and was loving watching all the activity around us.<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey everyone! I&#8217;m so excited to share what I&#8217;ve been working on for Sim Firefighter: procedurally generated terrain! As you know, this game is still in its early stages, but one of the key features I&#8217;m tackling is creating dynamic maps that feel natural and engaging. Terrain isn&#8217;t just a backdrop in Sim Firefighter \u2014 &hellip; <a href=\"https:\/\/blogs.oregonstate.edu\/codedcat\/2024\/12\/02\/developing-procedural-terrain-for-sim-firefighter\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Developing Procedural Terrain for Sim Firefighter&#8221;<\/span><\/a><\/p>\n","protected":false},"author":14468,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-70","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/codedcat\/wp-json\/wp\/v2\/posts\/70","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/codedcat\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/codedcat\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/codedcat\/wp-json\/wp\/v2\/users\/14468"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/codedcat\/wp-json\/wp\/v2\/comments?post=70"}],"version-history":[{"count":4,"href":"https:\/\/blogs.oregonstate.edu\/codedcat\/wp-json\/wp\/v2\/posts\/70\/revisions"}],"predecessor-version":[{"id":76,"href":"https:\/\/blogs.oregonstate.edu\/codedcat\/wp-json\/wp\/v2\/posts\/70\/revisions\/76"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/codedcat\/wp-json\/wp\/v2\/media?parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/codedcat\/wp-json\/wp\/v2\/categories?post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/codedcat\/wp-json\/wp\/v2\/tags?post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}