254: GameDev: How To Use Noise To Procedurally Generate Maps And Landscape.
Listen now
Description
How do you create unique and random game worlds and maps? Unique and random game maps and worlds can be created procedurally in code using noise. The noise is good for simulating nature because it produces values that change randomly in small amounts with no abrupt changes and provides realistic curves to rivers or hills. Noise is not good for straight or square items. What does noise look like? We normally think of noise as something we hear. Something is noisy or loud. That’s not the type of noise I’m talking about. This noise is sometimes called Perlin Noise after Ken Perlin who created a computer algorithm to generate the noise. The noise is really a map of values that gradually change. It’s possible to assign colors to the values and then they form an image that looks a lot like wispy clouds. This is a picture of noise that I posted on Facebook. But we don’t use the noise directly by drawing it to the screen. The values are used to control other things such as the height of the world map or the boundaries of a forest. Anything that needs to look random with no noticeable pattern is a good choice for noise. If you’d like to improve your coding skills, then browse the recommended books and resources at the Resources page. You can find all my favorite books and resources at this page to help you create better software designs. Listen to the full episode for more details or read the full transcript below. Transcript This episode explains how I started creating game worlds by hand and now plan to generate them in code instead. When I started teaching programming, I knew that I needed to make it fun and interesting in order for you to get the most benefit. So I decided to use games. I taught the first few students how to build simple text-based games that we could build in just a few hours. By text-based, I mean a game that only needs text output to display and a keyboard for a player to type. Something like Tic-Tac-Toe is a perfect example. The board can be drawn over several lines using dashes and vertical lines to draw the borders. And letters to show the occupied squares. These were simple and allowed students to focus on the language and what it means to program. I still use these types of games in my classes. But now, I do have something a little more exciting and that’s a racing game. It still uses simple text such as dots for the outline of the race track and the letter V for the race car. The idea is to move the car left or right to stay on the road as the dots scroll by to make it look like the car is moving. But I know you want more than this. So I started building a two dimensional or 2D side scroller game that uses graphics. It has a character that animates so it looks like it’s walking, running and jumping. When it jumps, it waves its arms to keep balance. A side scroller game lets you move the character left or right and the background shifts to make it seem like the character is moving. The character can also jump onto floating platforms or fall into pits where the game ends. I decided to use a 2D game mainly to keep things simple so you could focus more on the programming instead of learning all the details of a full three dimensional or 3D game engine. It’s a bit old school but sure looks a lot better than a black text screen with some dots and a few letters. A side scroller game like this needs to know where the ground is and where the floating platforms are and where the pits are. It needs a map. It’s a simple map because everything can be built using square tiles. There’s a tile for grass with a bit of dirt showing under the grass. Or maybe it could be a stone tile that looks like bricks. Or ice. The tiles can be anything as long as they’re square so they can be placed next to each other to build a ground for the player to walk on and jump onto. The game usually has multiple levels t
More Episodes
This is the first in a series of comments about the book “How To Code C++ From a Simple Idea To a Game You’ll Understand!” Each episode will be short and focused. You can watch the video versions on YouTube at https://www.youtube.com/channel/UC4K_WBflLr2Cz0Sje_xTXkA You can also get your own copy...
Published 01/28/22
This is an interview with Conor Hoekstra about C++ algorithms and ranges. Conor presented my favorite talk at CppCon 2019 called Algorithm Intuition. I asked him to talk about algorithms on this podcast and he agreed. This just proves again why CppCon is the best place to be when you want to...
Published 09/25/19
Published 09/25/19