88 - Back at game dev
Alright, good news! Finally started streaming game programming again. I only did an hour and half, but it's a start. I also didn't get much done, I spent half of the stream fucking around with Unity trying to remember how it works. There was also a bit of time I was getting pissy with how 0,0 is the center of the screen, but whatever, just need to get used to it. There is this grid and tileset thing in Unity, I tried messing with it, but made no headway. Luckily a viewer on stream linked me a youtube video and after streaming I watched part of the video then looked up some stuff about it. Anyways, so what did I work on today? I pretty much only worked on the Overworld generation. Just the basics though, adding water and island tiles to the game. I ended up slowly bringing down the amount of land tiles compared to the water ones. I started off at 50/50, then made it so all the edges are water, then made it so land could only have water around it, finally made it to about 1 in 9 or 10 tiles are land. Here's the code: public void Start () { for (int x = 0; x < Tiles.GetLength(0); x++) { for (int y = 0; y < Tiles.GetLength(1); y++) { GameObject temp; if (x == 0 || y == 0 || x == Tiles.GetLength(0) -1 || y == Tiles.GetLength(1) - 1) temp = Instantiate(WaterPrefab, Grid.transform); else if (Tiles[x - 1, y].tag == "Land" || Tiles[x - 1, y - 1].tag == "Land" || Tiles[x, y -1].tag == "Land" || Tiles[x - 1, y + 1].tag == "Land") { temp = Instantiate(WaterPrefab, Grid.transform); } else temp = GetRandomTile(); temp.transform.SetPositionAndRotation(new Vector3(x, y), Quaternion.identity); Tiles[x, y] = temp; } } Grid.transform.SetPositionAndRotation(new Vector3(-3.5f, -4f), Quaternion.identity); Grid.transform.localScale = new Vector3(.9f, .9f); } private GameObject GetRandomTile() { var temp = Random.Range(0, 10); if (temp == 1) return Instantiate(LandPrefab, Grid.transform); else return Instantiate(WaterPrefab, Grid.transform); } So first of all, let's ignore class level variables. I just set up some prefabs and a 2d array of type GameObject. Ok so in the Start method we start looping though the 2D array, nothing to crazy. Within the loops though we have some conditions. the first if basically is checking if we are on the edge of the array, if so, make it a water tile. Next we check a few positions to see if it's land, if so, we make it water. Because we know how we are looping though the array, and that the first if will cover all the edges, we know where to check and don't have to worry about index out of bounds. We check to the left, the bottom left, below, and to the upper left. Finally we get a random tile. After the loop we just move the grid (just a parent game object) around to get it in the screen. The random method really just gets a random number between 0 and 10, if it's 1 return a land, otherwise, return a water. So after reading some things about tile maps, and how to grammatically make them, I shouldn't have to change things around too much. So it's not like I wasted much time with making this code. Also I spent some time figuring out exactly how I want the overworld to be. I'm thinking I will have it bigger then the screen and have it move with the player. There will also be some fog of war system, but I'll have to play around with that, and most likely have it tied to some random stat. Well that's all for today. It felt good to get working on this again. Hopefully in a few weeks I'll get better with unity and speed up development so I'm not writing like 2 methods a stream.
7/16/2018 10:55:51 PM





Add Comment Auther

Comment