Deconstructing The Spiral - Part 2

Tuesday 12 April 2011 at 5:00 pm

So what is needed for a tile engine, anyway? That depends, of course, on what its function is. So the first thing to do is identify what your needs are. The RPG Starter Kit tile engine fit several of my basic needs: multiple drawing layers, collision data, portal information to jump between maps. But my total set of needs were still different than what it offered.

The first thing that it did, that I had to work to overcome, was the way that it handled movement. With the starter kit, it has a freeform movement ARPG style, which I didn't want because I was trying to go for the classic CRPG style, moving the characters along the grid of tiles. This ended up leading to quite a bit of work for me to add, as I ended up with all kinds of behaviors along the way before it was stable: map coordinates becoming out of sync, sprites not lining up along the grids anymore when scrolling, multiple direction inputs causing it to move in more then one direction and getting off grid, and even the entire collision detection being fooled by their movement and walking right through walls! Adding to the fact that the input system was bound to the tile engine, so having to work with it like that to fix things whever keyboard would break gamepad input or vice/versa, when I should have completely separated the input entirely. 

Another difficulty was the way it drew things, which led to several different unusal problems. As it is, since it is just meant to be an example, the kit draws the entire map, including a lot of wasted draws off-screen. The world map for Spiral Island is 200x200 tiles, leading to - with a 96x96 tile size at 1080p (I adaptively selected tilesets depending on resolution) - a whopping 368 Million pixels being drawn every frame to a space thats only about .5% that size. Obviously we couldn't be having that, so I rewired it to only draw what was on the screen and the small overflow for scrolling. However, the other problem that led to was when I came to corners where the screen stopped scrolling, as I found that it didin't draw tiles based on an absolute position, but instead relative to where the player was. So if the character is in the bottom left corner of the screen, and its only drawing 20 tiles across the screen, half of the screen would be blank because there was only half the tiles on the screen at the time. So not only does that have to be adaptive to the aspect ratio, it leads to the additional problem of not being able to script a separate camera for cutscenes without hiding the PC and moving it along as the camera, and having to store their position so you can then return them.

There were a couple minor things as well, such as the particular way the portals worked, which ended up leading me to alter the map format to support a more streamlined set of information, as well as adding the ability to extend with additional data (such as zone information for random encounters). It also was designed to combine all of the NPC data together on the map, which I wasn't particularly pleased with, because I didn't want to lose both map and NPC data all at once if one particular edit became corrupted, and also it didn't make multiple script sets (for translation and alternate New Game+ script sort of scenarios) very feasible. And so that was where I fist began to implement my changes, by creating a new NPC data structure. Which led to a whole lot more mistakes.

Deconstructing The Spiral - Part 1

Friday 08 April 2011 at 1:27 pm

So it's been a couple years now, since I decided to move my core project to XNA. A lot has happened since then: the project grew from XNA Game Studio 2.0 to 4.0, a new XNA platform came out, I've started several more projects with varying levels of completeness and failure, and over all that time I've missed my deadlines for Spiral Island. Not that it's all for naught, mind you, as of right now the bulk of the work left is just art and music, which aren't my key fields. Now I've already done some entries on my personal blog about how the game came to be, as well as posting the story's introduction, and that's not what I'm going to talk about here. These entries will be about the technical side of the game.

So let's rewind to 2008 for a moment. XNA Game Studio 2.0 was the current tech level at the time. I had just placed a different XNA project on the shelf, Phobia: Genome Prototype, because I wasn't going to be adequately able to tell that story the way I wanted. I had only been using XNA for a few months at that point, and only been programming in C# and .NET for a year altogther. Now I'm not going to claim that I'm an expert today, but I have learned a lot in those years since. And, as I look back, I realized that I made some major mistakes back then that have left me in a mess today, by taking shortcuts. And the first shortcut I took was the tile engine.

The App Hub, as it's called nowadays, has an amazing set of learning resources for beginners. One of those, the RPG Starter Kit, is one I looked to for building Spiral Island, not for the purpose of a tutorial, but because I wanted a quick way out of writing the tile engine. I had remembered how much of a pain it was for me years back writing a tile engine in C++/DirectDraw, and wanted to just get up and running and avoid that. So I took the steps from the second tutorial for that kit, and started my project with that tile engine. Which, all these years later, has brought me to the problem I am at now.

The main thing about that is its meant to be a tutorial. It's not meant to fit every need, and my needs were very different from what it offered, and so over the years I began to just hack things into the tile engine where I thought they fit to get the behavior I wanted, leaving my tile engine code compared to the original a horrid mess. I first noticed the problem when I forked off the Spiral Island code to make a Roguelike, attempting to make the entire thing in 7 Days as a challenge but finding myself having to quit halfway in because the code was such a mess now that getting it to work for the new purpose was nigh impossible. Then came converting the code to XNA 4.0, which took a day's work to get working on PC and XBox because of all the changes, only to find when I tried to build for WP7 that it was going to be completely impossible because of some fundamental storage diffences on that platform making some methods I had hacked together completely impossible.

So that's where I'm left now. Code that can't build, code that's a hackish mess, and code that, nowadays, even with my comments, I can't tell up from down anymore in the older sections of it. And so, I think it's best to start over, trash it all and rewrite the entire codebase from scratch, the way I should have done it from the beginning, both to clean up the mess I left it in, as well as to make it much simpler to port to other platforms when I get to the point I actually can release the game. And it will have to begin all the way at the base: the tile engine.