Ever since I started working on Rose of Eternity games, while I have definitely squeezed as much as I possibly could out of the Aurora & Eclipse engines, there were always limitations. There were so many times were I was like, “Shit, if only the engine exposed this functionality” or “Man, I wish I could change the look of this character sheet UI”.
On the other side of the coin, I was given so much out the gate. Conversation editors, level/area creation tools, scripting languages… And that’s not even counting all the stuff under the hood. Rendering, physics, and who knows how many other systems. I never had to think about it. I was able to just sit back and do what I do. Implement combat systems, create semi-branching story lines, a little level design, and tie it all up with a nice, shiny bow.
Now, I have to start from the bottom. But where? That was one of the biggest lingering questions I had in my mind over the past few months.
Well, being a turned based RPG, I figured I would start out with implementing the map system that the combat will take place on. After a lot of googling around, I realized that what I wanted to implement was a Tilemap system.
Now, one thing I knew from the jump was that I didn’t want to just integrate some existing asset package that had a tilemap system in it. I knew going in that I needed to implement it myself. I’m going to always need to have 100% control over it. One thing I’ve learned over the past 12 years, as both a game developer, and a software engineer, is that sometimes putting your future in the hands of other people doesn’t always work out so well.
So with that said, I went about looking for tutorials. And boy, did I hit the jackpot. There is this guy named quill18 who has one hell of a YouTube channel where he does these in depth tutorials on coding solutions for Unity (there may be non-Unity stuff there too). The one that got me started was his Unity 3d: TileMaps series. All I can say about it is it’s a master class in how to do a video tutorial.
I’ve never been a fan of them, as I’d normally rather written ones. What separates him from the rest is his tone, his delivery, his knowledge, and the way he explains things. I mean, look, some people got it, and some people don’t. He does. I could sit there and watch a tutorial about some subject I don’t care about, and be totally fine. His voice simply captivates you, and you get sucked in. And at the end, you will have learned a lot. In fact, I learned more than just how to implement a Tilemap, as he was always throwing in little tidbits here and there about the Unity engine in general. It was a great experience, something I’ll always remember when I look back at the early days of the development of this game.
So, with this newly gained knowledge, and set about my task. It went… pretty smoothly. There were really only 2 ways to create the tilemap. One was with using Unity game objects, one per tile, which is pretty easy to implement, but doesn’t scale well once you’re getting into larger maps. The other way, which quill18 did most of this tutorial on, was implementing it uisng a Unity mesh. Instead of all of these game objects with a texture drawn on each one, I just use a single mesh that has a single texture on it, and draw everything on it.
The actual math and components involved in creating a mesh were all new to me, including learning about quads, triangles (2 per quad), vetices, uv, normals, etc. It was at this time that I knew I was in the big leagues.
The first thing I did was take a 4 sprite sprite atlas, and randomly populate the map with them. That’s essentially that garbage image you see at the top. The sprite sheet (which was taken from the quill18 demo) includes water, grass, mountains, and desert. See below:
So, I created a 50×25 Tilemap, and then randomly fed it these sprites, which produced the following:
I also had to do some work to make sure that every time a Tilemap was generated, the camera would calculate the center of it, and move there. I have some work to do with regards to the math and how some of the tiles are chopped off on the edges, but in terms of generating my first mesh based Tilemap, I was pretty happy. But I needed to do more… I started thinking about how I wanted to actually store this data.
As stated above, I want to create my own Tilemap system, for the reasons I mentioned above, and for other reasons I cannot get into at the moment. But another reason I want to create my own system is because of the way I want to serialize/deserialize them. Or, save/load, if you will.
For every map in this game, I want to dynamically load it from a file. Let’s say the format is, oh, I don’t know… JSON. There will be a directory of JSON files that contain all the data needed to generate the map. The positiion of the tile, the type of tile, the sprite associated to it, and all sorts of other things I may add down the road. Is the tile walkable? Is it destructible? Is there some benefit from standing on this tile, versus another? Maybe you walk slower in the desert. Maybe your ranged accuracy goes down in the forest. Just spit balling ideas here. And I realize as I’m typing this that I sound very much like Sean Murray and his now infamous interviews about No Man’s Sky. Because I’m neither confirming nor denying these elements will be in the game, I’m just throwing things out there. So yeah, please don’t hold me to anything I say here, because anything can (and will) change at any time. Such is game development.
Anyway, knowing that I needed to load this data, I knew I needed a new class, something I ended up calling TileMapDataLoader. Now, I didn’t want to go too crazy, so I actually created a CSV file, which each value ranging from 0-3, corresponding to the sprite atlas. Then, by hand, I set all the numbers in a fashion to at least make something resembling a less shittier, random tilemap. The CSV file would end up looking like this:
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 0 0 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 0 0 0 3 3 3 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 3 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 3 3 3 0 0 0 1 1 1 1 1 1 1 1 1 1 1 2 2 2 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 0 0 0 0 0 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 0 0 0 0 0 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2
And the Tilemap that was produced looked like this:
So, going from south to north, we have some mountains, some grassy plains in front of them, a river, followed by more grassy plains, smaller mountain range, and then the beginning of the sahara desert (or whatever).
Those looking closely at the CSV and the Tilemap will know that everything is flipped upside down. It’s because in Unity, the 0,0 coordinate starts at the bottom left, but the way I’m reading in the CSV file, the 0,0 coordinate is actually at the top left. But besides that, everything looked good.
So all in all, it’s been a very productive few days. I’ve:
Learned a shit ton about Tilemaps and meshes
Implemetned said mesh based Tilemap
Created a simple CSV data loader so I could at least make the maps look like something other than static on an old ass TV
Next on the agenda? I don’t know, actually… It’s all going to depend on how much time I have. I’d like to expand on my TileData class (well, I haven’t created it, but that is what it’ll probably be called), and start adding some attributes to it, like the aforementioned “is this walkable”, or “does this slow you down”.
I would also like to get a tile selection icon in there, something I can scroll around in order to see the various tile statuses. In fact, shit, I want to get scrolling in general going. You know, panning around the map and whatnot.
Yeah, that sounds like a plan.
Heh, I was chatting with an old buddy of mine who was helped with these projects since like 2006, and I told him that I’m in the honeymoon stage of development right now. Everything is fun. Bouncing around from one cool idea to implement to another is great. But I know all too well how it ends. So, I’m going to enjoy this while it lasts:)