Archive for category Game Programming

Embarassing Code

Like any art – As we game programmers grow in our skills and abilities more often that not we can look at our past projects and be embarrassed at some of our ideas and implementations.

Most people don’t get to look at your code, unless you’ve released open source software of course. Infact, I’ve heard a good reason to make your project open source is just because other people can look at it, for that reason alone, you are compelled to make it good.

I’ve had a few “what the hell was I thinking?” moments which each of my finished games, and that’s just the finished ones. Some of the unfinished projects that never saw the light of day had horrendous ideas – like that time I tried to implement my own scripting language and parser in VB 6 with a whole lot of select statements and if-then-else trees that ended up wider than the Mississippi.

I would still like to program my own scriping language (or Domain Specific Language or DSL as all the cool kids are calling them these days.) But now at least I know it’s a difficult problem that involves a lot of Hardcore Computer Science™

So here are a few things in my finished projects that I implemented bady

  1. Star Cars – My first serious attempt at becoming an independant game developer was a 3D arcade title that I no longer advertise on this site due to vista incompatabilities and requiring a hardware transform and lighting supported video card. It had this had a really long, really complex collision detection algorithm that got to the point where I didn’t actually know how it worked. It got that way by me trying to solve the problem, attempting a solution, where-in the implementation would cover 80% of the cases, then I would just hack it until it worked. There was one edge case that I could never figure out – It turned out that it was easier to change the level mesh, than try to debug that horrible code.
  2. Caverns of Underkeep – Most of the design decisions for Caverns of Underkeep turned out very well, infact most of the game engine structure is being ported to my current project, but there is one part of the code thats just downright bad. And that’s how I implemented the modal dialogs – I did this weird thing where I would put the gamestate into a “modal mode” and all events would be routed from the active game state into the modal dialog class and then I would poll an object until its value was non-null which would return the gamestate back into its normal state, passing the newly created object back to the client gamestate – Don’t worry if you didn’t follow that, it’s kinda hard to explain without pictures and flow charts and things, which kind of illustrates my point. Now this method worked, but it was stupidly complex, my new method of rendering modal dialogs is to do a hit detection against GUI elements before they can process events, and simply masking the background so only the dialogs elements are exposed to the hit detection.
  3. Attack of the Meeplings – Originally Attack of the Meeplings was going to have powerups and I had this cool idea for a spread gun, unfortunately I couldn’t track down a bug in my code that was not allowing for symmetric vectors for the bullet paths, ie if v is a vector then v mirrored would not have an angle symmetric with v which gave it this lopsided look – I played with this for a day before just giving up and cutting the idea of powerups. I think it had something to do with the location of the centre pixel of the bullet, the spawn location of the bullet relative to the player, and the fact that I was rendering at discrete values (ie pixels) on the screen. Really this problem shouldn’t have been all that hard to solve, but I decided at the time it just wasn’t worth it to fix.

1 Comment

48 Hour Game Jam

The 48 hour game jam is winding down to a close (at least in my timezone)

I’m tired, dispite having slept 8 hours each night – I guess the floor wasn’t that comfortable after all?

The restrictions for the game where pretty hard to fit into the design, they were:

  • Game session has to last 5 minutes
  • “As long as we have each other, we’ll never run out of problems”
  • Choose one: Blank, Cold, Modern

I’ve finished my entry (A maze based retro shooter) and uploaded it to the global game jam website

You can download my game and all the other entries from that site. I’ll put it up for download on this blog sometime over the next few days. My entry requires .net 3.5 and XNA 3.0 – So I’ll include some more specific details to download those frameworks considering most people probably don’t have them installed.

But for now, here is a screenshot

robofortress_screen1.png

1 Comment

Should I Learn Flash?

Ever since I made Attack of the Meeplings and Caverns of Underkeep – I’ve been wondering if it would make€ sense to invest my time in learning Flash to develop browser-based games.

Java applets have almost completely disappeared where as Flash has become so synonymous with in-browser games that a few people who have tagged my games on StumbleUpon as a ‘Cool Flash Game’

At first I chose java because – Well, I already knew it and I wasn’t that concerned with making money by putting my games on the various Flash aggregate portals, I just wanted to draw some traffic to my own site with some fun free games.

The unfortunate thing is that it is very, very hard to draw traffic to your site, just by having a couple of free games to play.

And for a while I didn’t actually mind that I didn’t make much money through google adsense, because I made some pretty cool games that I was proud of and I thought where quite fun.

But now I’m thinking about a couple of small game ideas that I wouldn’t mind persuing and I think the best platform for delivering small freeware games is in the browser on the web. Leave the downloadable delivery mechanism for more ambitious titles.

So here I am wondering if I should learn Flash?

A couple of years ago I didn’t like Flash one bit – But that was when I had a p4 with 256mb of ram and a geforce2. On a modern PC it actually has good performance and over the last year or two there have been a number of flash games that have actually impressed me.

Also I have heard that Actionscript 3.0 is a much improved programming language with all the OO features you can shake a stick at. And many of the Flash tools are now more focused at developers, rather than only at our right-brained brethren.

So, maybe I should learn Flash? Stay tuned for updates.

5 Comments

7DRL Challenge

A Seven-Day-Roguelike, as the name would suggest, is a complete roguelike game created in no more than seven days.

The 7DRL Challenge has turned into an annual event and this year the contest is running between March 8th and March 16th – I’ve been thinking very hard if I wish to enter or not, you’re allowed to leverage existing code/graphics and any framework or library code you might have lying around. The emphasis is after all, on creating and releasing a game.

Unfortunately during the week of the contest I have a full set of classes – But, if I manage to get hold of a laptop I might be able to find enough time to join the challenge…

I’ve got a couple of ideas for another roguelike similar to Caverns of Underkeep but about half the length and located in a different setting. I’d like to try out some changes to combat to make it a little more like some of the table-top skirmish games that are played with minatures.

I’ll see if I’ve got the time, otherwise I might just start on a new roguelike game in my spare time, independant of the contest.

More information on the 7DRL Challenge avalible at Temple of the Rougelike

2 Comments

Random Name Generator Algorithm

I spent the morning creating a random name generator which will be added to the ‘create character’ section of Caverns of Underkeep.

I’ll explain how it works in a minute. But for now, here is an example list of names:

  • Yivha
  • Ilhalo
  • Xagloh
  • Pojlo
  • Xifei
  • Coxfo
  • Cedtiz
  • Digja
  • Emrapo
  • Aygoh
  • Omgez

So not bad, sorta could be real-made-up fantasy character names maybe. This is how the algorithm works:

First of all, I did a little bit of research reading about syllables on wikipedia

I decided to create two different name types – Those that start with a vowel, and those that don’t. For the names that start with a vowel I use the form VCC-VCV

Where C = consonant and V = Vowel

For names that start with a consonant I use the form CVC-CVC

In each case I randomly determine if the name length is 5 or 6 characters long. If the length is 5 characters, then I just leave off the last letter in the string.

Thats it!

Obviously it’s very simple and I don’t do any weightings against uncommon letters like x or z or anything like that. But it gets the job done :)

If anyone is interested the java source code is avalible here

6 Comments

Browser Based Games

My roguelike game Caverns of Underkeep is coming along rather swimmingly and I’m confident I’ll get the game to version 1.0 before March 2008 – Which is when I’m due back at University.

I’ve been taking a bit of time to think about the next game I want to make. A week ago I made a list of 5 or so game designs and then ranked them according to difficulty, which ran along the lines of how much content, ie how many art assets would be needed. And how complicated it would be to program, ie was there anything that I didn’t know how to do or hadn’t implemented in the past?

At that time I was planning on doing a shareware style downloadable game. But now I’ve decided my next title is going to be another browser based game. And like Caverns of Underkeep, the next game will be also be free*

The reason for doing another free browser based game was two-fold.

  1. I think people expect less from a browser game (or any free game for that matter) the corollary to this is that if you can make a really good browser game, people will notice. It also means I can focus on a smaller scoped title. And theres none of that having to get people to download and install the game stuff, just click on the link and the game automatically loads.
  2. Having unique online content drives webtraffic, and in a web 2.0 world, there are many vendors competing for attention. Creating games that people care about will help enormously in the long term. And when I do get around to making downloadable games, hopefully there will already be a sense of community around the free games I have made.

I still think that Java as a technology could be improved for creating browser based games. When I first started on Caverns of Underkeep, I was cursing Sun Microsystems at least once a day. Now however, I’ve kinda worked around what I perceive as the kinks in Java Applet programming.

Unfortunately the alternatives to Java are not that clear. Flash looks kinda bulky to work with, and whats up with not being able to right click? I haven’t used flash first hand so I don’t want to speculate too much as to what it can/and can’t do, but most flash games I’ve played seem to run like a dog, which is unfortunate because vector graphics are just so cool.

Microsoft’s Silverlight looks rather interesting, But I’m just not sure if the technology is going to be mature enough – Thats always the risk with new technologies. But having the .net framework and an awesome programming language like C# in the browser is pretty exciting.

If Sun Microsystems would just allow me to poll the keyboard and mouse I would be a much happier man!

Edit : It just occured to me that I forgot about php, mySQL and DHTML to make browser based games. These types of games tend to me more stats and text based than arcade-like, so that’s probably why I forgot about them.

* I reserve the right to change my mind at any time :)  

4 Comments

Random Dungeons

I’ve been working on algorithms for randomly generating dungeons.

My project Caverns of Underkeep is a Roguelike, and one of the features of all roguelikes is that they have randomly generated dungeons. There are two different flavors of dungeon generation and I’ll explain how they work in this article – Surprisingly the simplest algorithms can often produce the best results.

Here is a screenshot from a typical Cave map

The way this type of dungeon is generated is as follows:

  • Start with a completely unwalkable surface, then draw some randomly sized circles in random places – These circles are going to be water areas.
  • Perform a couple of random walks from the centre of the map, if we fall off the side of the map stop walking.
  • Locate tiles that are dead ends. (Any tile that has only one walkable tile as a neighbour) At these dead ends place a circular style room. Use a basic turbulence* algorithm to alter the shape of the room.
  • Locate a few other tiles that are part of a corridor – And not part of a room (To do this just work out how many unwalkable tiles are in the area immediately surrounding the tile you selected – If the number is greater than 2, then the tile must be part of a room and not part of a corridor) and randomly place some more circular rooms at these locations.

*A basic turbulence algorithm for drawing a shape is if say – You are going to draw a rectangle, then draw it as normal but determine randomly if you are going to draw N more rectangles with slight x and y offsets to give a more interesting shape to your rooms. See the image below for an example.

The second type of map is a Citadel – A typical screenshot is bellow.

This algorithm is pretty much the exact opposite of the one above.

  • Instead of starting with some random walks, I divide the map into 10×10 sections. Doing this gives it that more deliberate man made look to it.
  • Determine if I want to place a room here – If I do, note it’s location in a big list of rooms.
  • Draw a random rectangular room (with turbulence)
  • Once all the rooms have been drawn, consult my list of rooms. For each room draw a corridor between that room and the nearest room. Once a corridor has been drawn from a room, remove it from the list of candidates for nearest neighbour (otherwise we could get stuck in an infinite loop)

Both algorithms are guaranteed to be completely connected – Which is a really important thing to have in a roguelike. There’s nothing worse than not being able to complete the game because of the random generator – Bad computer, no biscuit!

In Caverns of Underkeep I also take a hybrid approach to generate the sewer levels. Basically I combine the two algorithms to produce another style of dungeon – See if you can work this one out for yourself :)

4 Comments

Java Applet Programming Tip

My newest project is a Java Applet game (still hush hush on the details tho…) and I thought I’d share a nice little tip for securing a java applet so that it can only be run from within your webpage and not from anybody elses.

This is particularly useful if you don’t want others to profit by embedding your game in their site.

The code is simple

// check host
String hostname = getDocumentBase().getHost();
if (hostname.equals("www.peachysoft.com"))
{
// All is well run the applet
}
else
{
// dont run the applet
}

1 Comment

Lessons Learnt from Starcars – A Post-Mortem

I’m a big fan of reading post-mortems on game development. If that sounds somewhat morbid to you, a post-mortem is basically a post-production overview of what went right and what went wrong. And any insights gained after the product has shipped out the door. Whether your product was an amazing success or an absolute bomb, either way, there is always something to learn. Enough time has transpired that I figured I would reflect upon my debut game Starcars.

Starcars – The History.
I came up with the idea to do a skyroads inspired game sometime in 2003 when I was looking for a small scale game that I could produce by myself, with no money and no previous experience. It seemed (at the time) that it would be a fairly easy project to do, but how little did I know back then. Game programming is not trivial and there are challenges present in even the most seemingly innocuous of ideas. It was going to be the first (and so far the only) game that I would see through to the end – hopefully that will change one day as I get started on the next project – albeit with more experience this time round ;)

I released the game sometime in 2004 (I was really bad at keeping dates or recording any kind of logs) with the intention of selling the game online. Due to a pretty poor performance in this regard in 2006 I decided to just release the game for free.

The game was written in Visual Basic 6.0 with DirectX 8.0 using the Bass.dll for music and SFX.

Before we continue I’d like to thank Daniel Radford for providing testing and contributing some levels to Starcars as well as some of the 3D models that are in the game.

What Went Right.

The game got finished
- This seems rather obvious but I would like to point out that just finishing can sometimes show that you’re in a different league. After all anyone can start a project. Finishing on the other hand is a completely different story. And ultimately, that’s what counts. Similar to the “you can’t succeed if you don’t try vein” – If you don’t finish you can’t succeed either. I am happy I actually managed to finish the game to release upon the world.

I learnt a lot – Programming a 3D game can be a bit of a brain bender. Especially since I started Starcars before I had ever taken any university level math classes. In fact, I still don’t know how the collision detection code works ;) Its patched together and hack-it-till-it-works ugly. But that gives it a kind of amateur allure that I’m rather fond of – although I would do it properly if I had to do it again.

The game really tested a lot of my programming skills – which where pretty poor back then on retrospection. GUIs are not trivial to program – yet I managed to hack one together; In my next project I’m spending a lot of time reading up on how to create effective GUIs, both in design and in code.

Global variables are all over the place and there’s very little in terms of object oriented design. In other words the code base is a mess and is very unwieldy – in other words its probably quite representative of anyone’s first attempt at programming a game.

I also learnt a lot of other things that have almost nothing to do with the programming side of game development which are important in other ways, like how to setup a website and get an account with a payment provider, how to get a press release done and how to setup a pad file for download site submissions.

I got a small budget retail run – This was a rather random experience, based on the initial press release I was contacted by someone who represented a game publisher in Russia, they handled all the localisation and converted the game into Russian. In return I was paid a modest upfront fee – $1000 US which came in very handy as I used it to purchase my bass that I play in my band.

What Went Wrong.

It didn’t sell - I guess this is the big one, I only sold a handful of copies through direct downloads from my site. I never did try soliciting to portals, but I have the feeling that I probably would have been required to do more polishing to the game anyhow. There are numerous reasons why the game never took off or made me much money, but the main reason I think would just simply be inexperience, much like it is highly unlikely that the first song you ever write is going to be a number one hit, the first game that you ever make (even if you finish it) is probably not going to be very good.

It took a long time - 18 months all up. That was part-time and in-between studies with large breaks where I had exam periods, or just didn’t feel like working on it. Large blocks of that was just working out how to do one particular aspect of the game – such as collision detection, projecting the ships shadow, or implementing the GUI – All three of which had to be re-searched, re-written and re-worked several times over.

Game design flaws - There are quite a few design flaws that I can ultimately take the blame for. One was doing the UI graphics myself, the fonts and menus have the distinct mark of an amateur. A professional designer can work wonders in this area. If you have downloaded any of the recent casual games you can see examples of just how good some people are at making menus. However I had no budget, nor any previous experience with even getting an interface working in code, so I got by on what I had.

Two other game flaws were locking the frame rate at 25 fps – I wanted all computers to run the game at the same speed and I should have used frame rate independent motion. But it was too difficult to retrofit after I realized that [that] was a far better option – blame my difficult to manage code. The other mistake was not providing a windowed mode option. Before I was working on a 17″ CRT and the game looked fine. But after moving to a 19″ LCD I can see the benefits of providing a windowed mode. Not providing a windowed mode runs the risk of annoying the player by not letting them play on their own grounds – something you don’t want to run the risk of doing.

A few of the online reviews commented on the lack of any physics within the game. It was my intention from the beginning to create an arcade game more than a spaceship/racing simulation game and I deliberately left out inertia, and kept in ability to move left and right whilst in the air to keep the ‘responsiveness’ factor up. This would have suffered if there was more inertia involved.

Unclear target market – The Field of Dreams – ‘Build it and they will come’ is not a very good marketing strategy. Although I don’t really know what I would have done differently should I have made the same game again. Maybe designed some kind of mascot as the main character? Who knows, it doesn’t really matter anyway as my next project is going to have a lot more thought going into ‘who the player is and what would they like to see’ right from the beginning – at the game design stage. This will let me focus on the game design as well as the marketing at the same time.

Summary
Hopefully this post-mortem didn’t come across as too depressing – It’s easy to point out flaws after the fact. I enjoyed working on Starcars, making a website and attempting to dominate the world. And even though the game didn’t make me much money, it gave me good experience and I learnt things that I would never have learnt had I not at least attempted a game.

My next game is going to do a lot better ;)

The full version of Starcars can be downloaded for free at http://www.peachysoft.com/?p=4

1 Comment

XNA Game Development

Yesterday I attended a seminar given by Microsoft Student Representitives. I forget their official title, but basicly they go around to Universities and show off Microsoft technology – evangelists maybe?

The topic was on XNA game development.

Usual presentation technology hickups aside (like trying to access the internet through the universities firewall via a wireless laptop connection without testing it beforehand…) I got to get a pretty good look at XNA. Nothing that I didn’t already know, but I got to see the racing demo that comes with the development suite. And boy, did that look cool.

I don’t have an xBox360 or even a DX9.0c capable videocard (Working on it.) So I haven’t to played with XNA, but as soon as I get a sufficent upgrade (and some free time) I’m going to have to muck around with it. You get the full source code to the racing game, so that alone will probably keep me entertained even though I’m not planning on doing any kind of professional next-gen 3D development.

As I’ve mentioned before I really like the C# language, and XNA directly intergrates with the express version of Visual C# (Which is free to all) So in a very untraditional Microsoft fashion, Microsoft has given away a very powerful tool. There are very good economic reasons why these tools are free, Microsoft has always known how to appeal to programmers and developers and it just means that in the next couple of years there will be alot of developers more familiar with xBox360 hardware, and more developers means more games for Microsoft to publish.

The only real downside to XNA is that it only works on Microsoft platforms. Which sadly cuts XNA from my requirements for 3rd party libraries.

If you’re interested in XNA and what it has to offer head over to www.xna.com

No Comments