Tile-Based Untitled Game

This was another project I started in MonoGame. The goal was to make a gigantic grid-based 2D game. I don’t remember many other specifics, but the basic premise of the project was pretty ambitious.

The basic camera code and grid generation code were the first things i completed.

Once i had a simple grid generated, i wanted to take it a step further and create a grid of grids.

The grid became an 8×8 2D array of chunks which are 256×256 tiles. At most, there were 4 chunks active (within camera view). All other tiles were considered inactive until the camera moved within their visible range.

The tiles were colored to show where chunks begin and end.

After getting the grid generation sorted out, i doubled the size of the tiles and added a cursor (the white square). I also implemented some basic selection code. In this example, i could turn a tile yellow by clicking it.

In the top left corner i placed a basic player pawn entity as well.

Next I started work on my pathfinding for actor entities.

When you select an actor then click a tile, it runs a pathfinding function which computes a path to the tile (in the form of a queue consisting of tile objects). Then the actor starts de-queuing each tile and transitioning from tile to tile until it empties the queue. If a tile becomes impossible to traverse, then the actor will stop and re-call the pathfinding function, rebuilding the queue of tiles.

At this point i had also added an asynchronous load screen since generating all the world tiles took a bit of time.

This is where this project hit a dead end. In this case it was just a lack of direction.

 

Learning MonoGame

It’s important to keep a log of the stuff you work on, even if it doesn’t pan out. I blogged about this game i was working on back in 2013 while i was in university, the following post is an amalgamation of everything i wrote pertaining to this game, edited for brevity and clarity.

This project started out in VS2010 using XNA and an open-source 2D physics engine called Farseer Physics but then VS2012 came along and Microsoft stopped developing XNA. XNA still works but it’s officially deprecated, so I migrated to Monogame which is basically a port of XNA that works on every platform (and works with VS2012 unlike XNA).

I didn’t really get any work done on this when i was messing around in VS2010. I had no idea what i was doing so most of my time was spent learning C# (which is a cool language) and figuring out the architecture of the Farseer Physics test samples. When I finally got around to installing VS2012 i had to figure out how to make Monogame work with Farseer Physics. After a while i sorted out the physics engine. The solution was trivial, just had to replace the XNA references with Monogame references and it built without any problems. So after I got that out of the way i hit my second road block. I couldn’t do anything with XNA content projects in VS2012. Monogame will soon support content projects but for now I have to use a separate content project in VS2010 and build that every time i add new assets (textures, etc) to my game.

So, once i got those two things out of the way i could actually start writing the game. I kind of cheated and used the Farseer Physics samples project as a reference when I started working on my game. So far I’ve implemented a similar screen management system (most games use multiple “screens” – menus and pause screens, etc.). And then there’s a lot of stuff behind the scenes that goes into actually setting up the “world” and spawning the low-gravity orange box you see in the first screenshot. It bounces around if you drag it with your mouse.

I guess my next task is to work on making the player object controlled by the WASD keys and make it so the player isn’t just a box that tumbles around (I assume i can just max out the damping on the box so it can’t rotate, or even just disable rotation). Then after that i suppose i’ll have to work on making the player object an animated entity with bones and joints and stuff.

In the picture there are 4 buttons in total, they support images and text (and a combination of both) but for now i’m just trying to get them to actually function like buttons. I think i’m just going to make my own text system using images for individual letters so i’m not actually drawing any actual text to the screen.

It’s hard to choose a starting point when you start from square 1, there are so many things to do and it’s hard to judge which features should take precedence. So for now I’m just going to try and get the basics of the interface sorted out and worry about everything later.

With some work I got the main menu and buttons working exactly how i wanted them to. Right now only the New Game and Exit buttons work. If you click New Game, it transitions to the game screen and spawns a player object. And the exit button speaks for itself. I think i’ll worry about getting a proper font and making the buttons look nice when it really matters. For now i want to flesh out the more important things.

This isn’t very exciting to look at but there’s a lot of stuff behind the scenes being completed! I wrote a basic EntityFactory and EntityManager class. Now i can go wild creating new entities.

I’ve also been working on a entity hierarchy. In my previous blogs i wasn’t actually using entity factories or my own entity classes so it took like 30 lines of code to just create one object, and then i had to write the code that renders the object on the screen. Now i can create an object in one line of code and I don’t have to worry about how it renders.

I need to figure out how to go about properly deleting entities. Right now, my EntityManager keeps a list of all the objects I’ve spawned into the world. If i delete an object then i also need to remove it from the EntityManager’s list (and if it’s a physics entity then i need to delete its physics object too).

Next, I finished an input helper component which should come in handy for several things. I can’t see how anyone can program a game without using a component-based architecture… It’s messy enough with everything compartmentalized, I can’t imagine how much of a mess it would be if it weren’t.

And here is more progress with player movement. Those two orange rectangles you see covering the blue bouncing rectangle are actually not colliding with anything, they are sensor bodies that tell me whether the player object is on the ground or touching a wall (which is why i can bounce off walls, that was intended). Normally they would be invisible, i’m just drawing them because i want to be sure they’re scaling properly based on the size of the physics entity they’re parented to.

I wrote an attribute system for entities and made them serializable. My next order of business is making a simple level editor. Instead of making a separate modding toolkit for this game i figure i might as well just build it in as a menu of its own.

I finished some concept art.

I Frankenstein’d the final product from several different sketches. I don’t own a scanner (i had to hold my webcam steady and take top down photos of each drawing) which explains the differences in color. If this looks like it was inspired by Earthworm Jim or something similar then that’s probably because it was.

For some reason i can’t draw normal hands to save my life. I also can’t draw hands directly from an arm, i have to draw them separately then splice them in and re-scale them using Photoshop. The gun in his left hand was also drawn like twice the size it needed to be.

The final product, converted in Photoshop and colorized without shading.

 

This is essentially all I really was able to complete on this little project before I lost interest. Around this time, Unity was growing in popularity and my university switched from MonoGame to Unity for all game development courses. Switching from MonoGame to Unity definitely helped highlight some of the things i disliked about MonoGame. Pretty much everything has to be programmed from scratch. This isn’t terrible if you know what you’re doing (I didn’t) and you want maximum control over every aspect of your game (I didn’t).

To say that I simply quit working on this solely because I lost interest would probably be an oversimplification. It was a combination of dislike for the game engine, lack of vision/direction for the game i wanted to make, and a lack of free time due to coursework. It was a good starting point for learning the architecture of games and figuring out how game engines really work under the hood.