Tuesday, 29 July 2014

How I Started My First Game

It wasn't even a video game!

Let's go back to the summertime of 2008, at least I'm pretty sure that's the year. A good six years ago now, at the very least. I was on holiday with my family in northern Portugal, somewhere I thoroughly recommend for both the cuisine, landscape and a very decent selection of beverages.

There were downsides though. My family likes walking. Hiking, even. Now, I'm not really opposed to it at all, and at the time I was very in shape, but it basically leaves my mind incredibly bored for several hours at a time as we trekked up a dusty trail, seemingly with no end. When I was a lot younger, my brother and I would invent fantasy scenarios and sometimes act them out, but by the age of 19 this was a bit . . . well I probably shouldn't even say childish. Not approved of by social conventions by our age? So I resorted to doing a similar thing in my head.

Spoiler: details of Avatar: The Legend of Aang follow. It's a great animated TV show with humour and panache for adults as well (at least, young adults). I recommend it!


I was thinking about The Legend of Aang (TLA, ATLA or A:TLA), and about how neat the concept of a set of elemental societies in their own cohesive world was. Unlike Pokemon, which restricts itself to a particular region at a time and didn't do a fantastic job of worldbuilding in general until the number of regions got excessive enough for them to realise they might want to connect the dots (there are only so many cruise ships in the world, yo). In TLA, there are four elements, Earth, Water, Wind and Fire, and each of these corresponds to a specific nation that the envoy of the World Spirit (or somesuch spirit) called the Avatar is destined to keep in check. Each nation has a specific style of shaping the elements (known as bending), inspired by certain classical forms of Real Life™ martial arts. It's set in a vaguely medieval period (late medieval into renaissance, as far as I can work out) and each of the individual cultures contrast fantastically (that's a lesson in itself) as the show is about building tolerance between these nations as well as averting a way/beating the Big Bad/doing awesome elemental stunts.

I was inspired thinking of a similar setting. Originally, I was simply wondering how the series would evolve into modern-day terms (something the sequel, The Legend of Korra, as worked on by advancing the setting into the industrial era), and then I got distracted thinking about if they could form proper weapons out of their elements (instead of just focusing it like a whip or blade), and then what our Earth would be like if people had similar abilities.

This is an opportune time to mention a good, recent Polygon article on stealing vs. re-inventing parts of another franchise - click here if you want to read it. The general gist, though obvious to some, is not to copy things wholesale, but to find the things that make that piece of media great and emulate that.

A pad of paper (once we'd gotten back from the hike), a pen and a few hours later, and I had a rough idea of this world, this parallel Earth (done to death, I know), but one where humans had the ability to harness core elements from the start. I modified some of them, at the time mainly in name only (but not theme) just to avoid direct comparisons. I later expanded on the reasoning for these changes and justified them. Even to this day I've been refining them, redrawing the base icons for each element and wondering if I could do something better. They are Fire, Ice (fire and ice have various links in mythologies, and I find it a better parallel than fire and water), Metal and Air (or Wind, I keep swapping them).

The main difference I had come up with was the ability to combine elements. Now, bear in mind this was before Magicka, or at the very least before I'd touched (or really heard of) that game. Probably not the first to do it, but I've played quite a bit of that game now and it's one of the first games that lets me combine elements in a neat and sensible (ish) manner. Open to suggestions if other games like it exist! This system went through years of revisions and updates, and isn't really relevant to this blog post, but I just wanted to mention it as the first major divergence from "The Legend of Aang in our world". A lot of the basic tenets, like the combining of elements, was thought up during this holiday to Portugal (it's amazing I found time to actually socialise and sunbathe, really) and I even starting on worldbuilding (as an avid reader and even amateur fiction writer, I've found the idea of a solid background setting extremely appealing when playing a game or even watching a movie or TV series), rewriting key areas of history from the point of humans having these newfound powers.

This continued for some time, undergoing at least one or two major lore revisions in the following year at university, before eventually it was something I shared with friends and acquaintances. In my final year I used the setting as a basis for my first actual game (in Unity 3.5) and this blossomed into a rough, unpolished but still high-scoring module. The general strengths were the character creation and the thought that had gone into the setting even considering it was a basic RPG template at the time. I look to continue this at some point, but I've gotten sidetracked by further work on this setting, or Phantasmagoria as I've come to call it. I've even been building a 2D sprite-based game based on the setting in Java to continue building my skills as both a programmer and a game designer. More on that in a later post :)

Games Development Project, Main Menu
Games Development Project, Main Menu

A random musing on a popular cartoon show turned into a project I've invested quite a bit of time into! It's taken several years to get to this point, but I don't mind that at all. I can't afford to work on it full-time, and I quite enjoy the relaxed pace at which I develop it.

Next time, the evolution of the Java project of Phantasmagoria, and why I struggle with Java even considering it's detractors in the world of programming!

Monday, 14 July 2014

Building Game Tech

So, I said a week before a post on making games. For me, within a month is a pretty good deadline for a blog post. Fantastic, right?

Warning: this post contains a lot of specialist language and abbreviations. Familiarity with programming or project design is recommended.


I do everything from scratch. This is not wise, and unless you want to get a thorough understanding of everything that annoys you about your programming language of choice, I do not recommend it.

Why? I like building stuff. I like finding out how stuff works. While I often lose interest with the nitty-gritty parts of, say, the JVM (Java Virtual Machine), I take an almost perverse pleasure in exposing why a particular part of Java's Swing library is behaving like a spoilt child. Below is a case in point:


This was for something simple; organising a game's scoreboard into something that was more visually appealing than a simple text string. Got it working in the end, the result I'm quite happy with:

Score List for WarGames Offline
Score List for WarGames Offline

But it took me something close to half a day to track down (I do this in my spare time; my real job is web development). A lot of people (probably rightly, hah) would blame me for using Java. But to be fair, a lot of language have issues like this. Every language has a list of long-standing issues that haven't yet been fixed (this issue has been documented, as early as 2005, but still not fixed). Maybe Java has more than most, who knows. It's the language I work with at work, it was the one I was taught at university, and I'm too invested in my projects (in Java) to have the time to move even to something as similar as C# (even if Visual Studio is a beautiful, appealing piece of software).

Back to building game tech, which I'm loosely-defining as "anything you can regularly use to help build a game project". Finding these little idiosyncrasies in whatever programming language you use is critically important. I adhere to the adage of "get it working, then get it working nicely", but you do need to ensure that the basic stuff does, in fact, work, and won't fall over when you forget the code it contains and use it for something avant garde later on in your project. I have an IOCore class that I've used in pretty much every single project so far, and all it does it wrap file read/write operations in a single class for ease of use. I first made it four years ago now and it's still managed to go through numerous revisions, optimisations and feature creep (like adding support for read/write byte arrays for hex-editing file headers).

Documentation
Always document your classes. Every time, all the time.

You have to be sure it works. Otherwise you get fun stuff like your program creating a folder structure four levels deep in My Documents because you accidentally forced it to always create the folder structure if it didn't exist, instead of simply not creating the file in the first place.

  • Don't build things from scratch. Unless you really want to, or you're really bored.
  • Libraries are not bad things. They're usually made by very good people and do really handy things. Like Google's GSON project - invaluable and let me tell you writing an XML or JSON parser by hand is an awful lot of work. I'd know, I made an XML parser myself. Then I trashed it and rewrote the project to use JSON with GSON.
  • Thoroughly test the classes you're relying on.

A lot of this may seem like common sense (and is), but this is a cautionary tale. I've learned a lot from my mistakes, and I'm competent enough with Java that sometimes writing stuff from scratch is actually easier than sourcing an obscure library. I'm currently looking at hit detection, and the only source for convex hull generation I've found is written in C++. The guy didn't give his variable pretty names either (a common trait, I find, with C++ programmers!).

You'll know once you've made a useful class, or a useful piece of tech. Because you'll find yourself using it everywhere. I've got a simple ComboBoxRenderer that I use because the default renderer is ugly as sin. I've got a custom WindowSnapper class for JFrames that closely emulates the native Windows behaviour for it's components. Not sure how it plays out on Mac and Linux, mind. These things are games tech, and will feature in all three (or four) of the projects I'm working on. They're useful. Share them, plug them in blog posts (am I right?), because other people will find them useful as well!

At least, I hope they do. Next time, a showcase on one of my games projects.