Wednesday, May 22, 2013

On Video Game Programming


I haven't really had much time in the last few years to spend time programming something for fun, and I think it's really starting to get to me. In an attempt to fix this, I've set myself a fairly ambitious goal. I'm going to attempt to program a fully functional 3D game, or at least a working prototype of one. The catch is that I'd like to release the game under a GNU General Public Licence, or something similar, and so any libraries or engines that I use need to be compatible with that licence. Even so, I'm strictly limiting myself to using only free and open source software to develop the game. That means I'm not even going to use my Windows laptop to make backups. The game will stay strictly between my Linux netbook and desktop (This is also to prevent me from being tempted to do anything on this project while I'm at work). However, I'd like the final game to be cross-platform if I ever release it.


    1. My Game Programming History


My experience with creating games is fairly limited. I completed my first "real" PC game about 10 years ago. It was a simple text-based fighter with a combat system fairly similar to that of the Game Boy's Pokemon games. I've made a couple of attempts at games since - all ridiculously simple - a vertically scrolling space shooter (where balls start falling from the sky that get progressively faster), a pointless game where you control a grim reaper figure and try herd one of several balls into various baskets on variously shaped fields. One of the most promising games I've made was a horizontal scrolling platform game inspired by Contra. You controlled a figure that resembled the guy from the toilet signs (I'm sorry. I drew all the sprites pixel-by-pixel in MS Paint), and the object was to make your way through the rooms of some form of hostile building. I finished the first level, started prototypes for the second and third, and realised that I had no clue about balancing difficulty. The result was... well, it's probably better if you just try it for yourself.


    2. The Concept


So, what am I going to try and make now? The concept is one that I think is really simple to implement. I want something that makes use of (at least approximtely) real life physics, but in an environment that is completely unfamiliar. I want people with an understanding of physics to be able to understand the game mechanics, but I want a person who works off of everyday experience to be thrown off, and hopefully spark a curiosity as to why things happen that way.

When it comes to physics, there are two phenomena that more or less govern all of our intuition when it comes to judging how things behave. Those two phenomena are gravity and physical resistance (be it friction, air resistance, whatever). So, getting rid of these two things will change the way everything behaves, and the behaviour will be physically possible, yet completely unfamiliar. You can see where I'm going with this. The game will be set in space. Or at least, on a space station in space.

When I was a teenager, I played a game called Descent. While I was never particularly good at the game, the game's unconventional use of 3D movement in an enclosed zero-gravity environment stuck with me. I was always fascinated with the way my mind would always pick a direction as "down" based on visual clues, and I would always needlessly try and orient my ship in that direction, even wasting time during combat to do so.

When I read Orson Scott Card's Ender's Game, I could not help remembering playing Descent, always needing to orient myself according to those visual clues. "Remember- the enemy’s gate is down" is a well known quote from the book - and refers to the fact that ignoring the visual clues, and over riding your instinct with a different concept of direction could give you a strategic advantage. I always wondered about how it would feel if I was in a Battle Room, with no ability to change direction or velocity until I touch an object, and with no sure way to stop myself. I've always toyed with the idea of programming something based on that concept. I've finally decided that I will make it into a game.

So, to sum it up, the game will consist of a room, with obstacles, in which players will float free from any effects of gravity or air resistance. The only means of controlling ones motion will be through physical interaction with the walls, obstacles, and other players. In this, I will incorporate a combat element, and hopefully later a team combat element, as well as a certain level of puzzle solving. I don't want to take the concept too far until I see how everything works.


    3. Starting Off


Programming a game is not easy. There are a lot of aspects that need to be taken care of, and the one thing that's always stood in my way is not knowing where to begin. In the past, I've falling into the trap of designing the GUI, the main menu, writing the help files, character design, and all the wrong things to start with. I know where to begin now. A prototype. I need a rectangular room with a sphere, and very basic camera controls. I can then make the sphere move, and then make it bounce off walls. Then I can worry about adding controls to allow the player to control how the sphere bounces. Once I've got that, I'll have a basic prototype. I'll then start thinking about how to add other players. Only once I have that am I going to try put in models, textures, a GUI, and all the rest.


    4. The Language Question


The first thing I need to decide is what language I'm going to write the game in. This section is going to have to start with a bit of a rant, and I apologise for that. Without a doubt, Python is my favourite language. Despite criticisms against it, it's actually not such a terrible language to use to make a decent game. The one thing I hate though is the general attitude some people seem to have toward Python. "Its slow because it's a scripting language!" It can be used as a scripting language, but it's got so many other uses. Also, it can call C libraries, which is almost as fast as if the entire game was written in C/C++ anyway. "But Python sucks with graphics!" Yes, but once again, C libraries... Personally, I can write code far quicker in Python than in any other language I've dealt with, and it's not just because I've got more Python experience. I also get fewer bugs with Python, and I find those bugs easier to find. I've often written a quick Python program to do menial tasks. I've never written a C++ code for anything other than university projects, and even then, I only used C++ because the choice of language was made for me. I'm not a big fan of C++. I love almost everything about Python.

But the fact remains, if I Google some problem I'm having in Python, I land up with a forum post swamped with useless comments like "learn a real language" and the like, even though the real solution is usually some really elegant and concise line of code, and it really gets on my nerves. When I Google the same problem for C++, I get several civilised answers on how to go about solving my problem.

So, for that reason, and because of the game engines available, I'm going to be programming this game in C++. Although I've read through and made minor modifications to bits of C++ code in the last couple of years, it's about 6 years since I did any serious C++ programming from scratch, but hopefully I'll pick it up quickly again. Project Euler time again, I guess.


    5. The Engine Question


So, I also mentioned that I'd be using C++ because of the engines available. If I was using Windows, I'd probably use Unity. I've heard a lot of good things about Unity, but it doesn't meet the constraints that I've set myself. I need something with a decent free software licence, and preferably something that works nicely on Ubuntu. The first engine I started looking into was Panda3D. It's a 3D library for Python, made available under a modified BSD license. However, after a week of messing around with it, I found it clumsy and messy. I also found it difficult to learn. The closest thing I could find to a tutorial are a set of poorly commented sample programs, which I had to manually read through to find what was relevant to what I wanted to do. I grew frustrated quickly and decided to start looking elsewhere.

There are a surprising number of 3D engines out there, but very few work well with Python. Once I broadened my search to include engines for other languages, I had better luck. I eventually settled on OGRE, which is made available under an MIT license, and seems to have a decent set of tutorials available. The advantage of OGRE is that it apparently works quite well with Bullet, an open source physics engine that looks like a good bet.


    6. Conclusion


I'm pretty sure this project will take me a while. It's possibly one of the most ambitious projects I've ever undertaken. That said, I'm hoping that once I get some sort of working prototype, the rest will be easy. I've written this for three reasons. The first is to get my plans down in a coherent form that I can follow. It forces me to iron out the concept, in a way that can be explained simply, and this gives me a solid foundation on which to start developing. Secondly, it makes a commitment that I will do this. It gives me some level of accountability, and hopefully my readers will remind me if I forget about the project (although, that's never really worked in the past). Thirdly, it exposes my idea to much needed criticism. If you have any improvements to the idea, or if you think it's rubbish and I should do something else altogether, please tell me.

If you enjoyed this post, then don't forget to like, tweet, +1, or upvote on reddit. If you have any questions, comments or complaints, post them using the form below.
. . . . . . . . . . . . . . . . . . . . . . . .



Tuesday, April 30, 2013

On Why Resigning is not Usually the Honourable Thing


Recent events in the news have lead to certain people saying "She should just resign and let someone else take over," and "at least he did the honourable thing and stepped down." I've always thought that resigning is precisely the opposite of the honourable thing. This is best explained with an analogy.

Imagine a party at someone's house. Things get a little out of hand, and someone is being stupid, messing around, doing stuff that they probably shouldn't be doing, and eventually, somehow, a table with several glasses and drinks gets sent flying. Imagine that you're the host, and you're staring down the culprit. If he said, "Sorry, here's some cash to cover the cost of the glasses, and where's the mop so I can help you clean up?", would that be the honourable thing? What if he said, "I'm not saying I'm the one who knocked over the table, but I'm going home"?

Another example. Imagine you have a daughter, and she winds up pregnant, and you weren't even aware that she was even seeing anyone, but you've got a pretty good idea who the father is. If this boy says "I may or may not have gotten your daughter pregnant," and then leaves town, is that really the honourable thing?

What I'm trying to say is that we shouldn't be calling for people to resign in the face of a scandal. We should be calling for people to take responsibility, and fix whatever mess they've created.

If you enjoyed this post, then don't forget to like, tweet, +1, or upvote on reddit. If you have any questions, comments or complaints, post them using the form below.
. . . . . . . . . . . . . . . . . . . . . . . .



Tuesday, April 2, 2013

On What I Could Contribute if I had to Build Society from Scratch


Imagine you're suddenly transported somehow into another planet Earth in some other universe. Everything in that universe is exactly like ours in every way except that, technologically, the inhabitants are around ten thousand years behind us. Luckily, their languages have magically and inexplicably managed to evolve the same ways as ours, so they understand everything you tell them, and you understand everything they tell you. They've got a pretty good idea of how to start fires, make sharp tools, and they're not too bad with farming, but they have little more than that. While their quaint rural lifestyle would probably seem nice and relaxing for the first few days, no doubt you'd start to miss some of your modern comforts after a while. You have all the knowledge of a late twentieth/early twenty-first century education. How much of ten millennia worth of technological advancement could you reproduce in the remainder of your lifetime?


    1. So... What am I starting from?

Lets set the stage. We're talking the equivalent of roughly 8000 BCE in our world, which is the middle of the Neolithic Era. People are still using stone tools - this is about a thousand years before the first copper came on the scene (and about three thousand more before it's use is widespread), bronze tools are still five thousand years away, and iron tools will only start appearing a couple thousand years after that. However, they're getting quite advanced with stone technology. They're not just bashing rocks until they have a sharp point any more. They're taking the time to grind and polish their tools, and getting pretty good at it too.

Domestic dogs, sheep, and pigs are pretty widespread, but the idea of domesticated cattle is a fairly new one. Farming plants is also a pretty new idea, and is mainly limited to annuals like pulses, grains and gourds. If you want fruit, you'd most likely have to find a wild tree or bush. There are lots of farms, and a handful of villages. There are even a couple of towns in the most developed parts of the world - with walls and towers and everything - although they only have a few thousand inhabitants each.

Not having to go hunting for food actually frees up a surprising amount of time, and these people are just starting to discover recreation. They're already carving crude statues and making jewellery from brightly coloured stones, but concepts like wheels and pottery are still 1500 years away.


    2. Why would I be able to contribute?

I supposedly have all the knowledge that comes from being educated in the last decade of the twentieth century. I have an engineering degree from the first decade of the twenty-first century. Lets assume that I'm a quick enough negotiator so that they don't consider me a threat and kill me, and that I somehow manage to convince them to listen to me. What can I offer to this backward civilisation?


    3. The Basics.

Well, the wheel is a pretty obvious place to start. I could also teach them them that mud can be used for more than just mud huts and teach them to use clay to do some basic pottery. Not that I'm particularly knowledgeable about pottery, but I'm sure I could convey some of the basic ideas.

Another obvious, and probably essential technology would be writing. They'd actually be about five thousand years away from inventing written language on their own. However, starting with very young children, and trying to mimic the methods that are used in millions of our own schools across the world, I feel I could have children reading, writing and understanding within about six to eight years. Following on from that, I see no reason why I couldn't introduce a crude wooden printing press, even though they're almost nine and a half thousand years from inventing it on their own.

Once that's out the way, a crash course in Western philosophy may be appropriate. It would be wonderful if I could somehow get deductive logic to be a permanent feature in the education system from the very start. And naturally, I could follow with mathematics. I feel that with my knowledge, I could teach them basic arithmetic, quite a bit of algebra, some introductory statistics, and I think it may even be a good idea to introduce some very elementary calculus. Of course, I'd have to start teaching some Newtonian mechanics to make it all make sense, and then I could teach them some basic engineering design to make it all useful.

I also think I'd have to teach ethics from very early on. In fact, I should probably lead with that.


    4. What Could I Contribute From My Education?

Well... I did spend two years in university specialising in metallurgy. Is that useful at all? They're not far off from working out how much you can do with copper. I could easily teach them everything they need to know to build a simple clay copper smelter, and how to work the copper to make tools. I could even bypass the whole copper age, and show them how to introduce tin to make bronze. I could tell them all about alloys, and how you can affect the properties of metals by mixing them in different ratios. There's one catch though, and it's a fairly big and embarrassing one. I actually have no idea how to differentiate copper ore in a pile of rock. I wouldn't be able to identify any metal ore, in fact. So unless they know what copper ore is, but just haven't figured out what to use it for, none of my metallurgy knowledge is going to be particularly useful at all.

I spent the following four years studying aeronautical engineering. Obviously they're not quite ready for aircraft, but there are some pretty important things I could teach them that they could put to immediate use. Windmills are incredibly useful for grinding grain. I could also probably teach them a bit about propellants, and maybe make some crude rockets, but I'm not sure if this would be a good idea. In fact, most of what I could teach them from my university education would have only military uses to a civilisation like theirs. I think I should most definitely lead with teaching them ethics.


    5. What Would Actually Happen?

The course of events that would actually take place becomes pretty obvious, the more I think about it. I would arrive in their world. I would encounter the first tribe, and convince them not to kill me. Knowing people, I'd presumably have to do this by demonstrating that I can provide some military advantage over their rivals. They'd be terrified that I'd be captured by their rivals, so they'd kill me to prevent my knowledge falling into the wrong hands. Progress would resume as if I'd never been there.


    6. Conclusion - What Should I Do?

The answer is simple. Remain isolated. Live as a hermit. Avoid all contact with the humans that inhabit that planet. Never reveal anything. Unfortunately, I'm too much of a show off, so even then, I'd probably try something stupid and get myself killed. So the safest thing to do is to avoid being transported to a universe whose human inhabitants are ten thousand years behind ours.

What would you do? What could you contribute?


[Editor's note: Proof-reading this post made me realise that it sounds like a very generic blog topic. In fact, it probably sounds like it came straight from a random writing prompt. It didn't. As usual, I've probably been playing too much Minecraft, and it got me thinking. This is not too far off what that game is all about.]

If you enjoyed this post, then don't forget to like, tweet, +1, or upvote on reddit. If you have any questions, comments or complaints, post them using the form below.
. . . . . . . . . . . . . . . . . . . . . . . .