213: How To Start Building a Video Game. Part 3.

Take Up Code - Un pódcast de Take Up Code: build your own computer games, apps, and robotics with podcasts and live classes

Categorías:

What role will data play in your game? It doesn’t matter what type of application you’re building. Data will be important. You need to decide what parts will be driven by data and what will be driven by code. Now, it would be possible to specify in code that a tree should be located at some location. Maybe the constructor for the tree class takes coordinates right from the beginning. There’s probably going to be lots of trees in the game. So the code could go through a loop and read coordinates from an array of data points specified in the code. This is using data but listen to the full episode for a better way. You can also read the full transcript below. And if you like this podcast and want more, then you can select a reward level at Patreon. Every patron gets access to a special episode each month and you can even help choose the topic. Click the link at the top of the page to “Become a Patron.” Thank you! Transcript It doesn’t matter what type of application you’re building. Data will be important. You need to decide what parts will be driven by data and what will be driven by code. But first, why is this important? I mean, you’re programming so shouldn’t everything be written in code? And what do I mean by having parts of your application driven by data? Data by itself is just a bunch of numbers or maybe some strings, dates, and flags that can tell if something is true or false. You can’t build an application of any kind with just data. You wouldn’t be able to make any sense of it. There needs to be code. But you don’t have to do everything in code. As an example, consider the maps that I described in the previous episode. These aren’t the map data structure but a map showing the location of towns, roads, trees, and mountains in a game. Now, it would be possible to specify in code that a tree should be located at some location. Maybe the constructor for the tree class takes coordinates right from the beginning. There’s probably going to be lots of trees in the game. So the code could go through a loop and read coordinates from an array of data points specified in the code. This is using data but I’ll explain a better way in just a moment. Another way using just pure code is to calculate the coordinates each time a tree is created. This could be done using a random number generator and you would end up with trees spread through your map as if you had manually specified the placement of each tree. The player probably won’t notice the difference. Unless, of course, you manually placed trees in a recognizable pattern. It would be hard to duplicate a specific pattern using only a random number generator. If you want some trees to be lined up neatly in a row, then you’ll have to either place them there by specifying their coordinates or write code that takes a line and a spacing and drops trees onto the line at regular points. The problem with all this is that code a lot more difficult to change than just changing some list of numbers. If your trees are placed in your world by code and you want to rearrange them, then you have to write new code just for that purpose. But instead, if your code just loops through a list of coordinates and reads the values where each tree should be placed, then it’s easier to rearrange the trees. I mentioned just now that you could put this list of coordinates in your source code. You can declare an array of ints and give that array a bunch of values that you type right into your source code. This is certainly a lot better than writing thousands of methods like createTreeAtFrontGate, createTreeAtGardenCenter, createTreeAtGardenLeftEntrance, etc. Instead you have a method called createTrees that takes as one of its parameters an array of x and y coordinates. Each coordinate would be an integer number and you give the entire list of coordinates to the method and it just goes through each coo

Visit the podcast's native language site