Game Complete?

A lot of work (and time) has happened since the last update. I have completed the game to the point that it works as a prototype for a real game if I wanted to continue it down the line.

What does it include?

Well as promised in the last update we have lazers!!! You can shoot lazers from your ship at the turrets, but watch out, they will be shooting back at you!

Not only that but I have gone so far as to include lazer and explosion sounds. Did I also mention collision detection? I guess thats pretty important or the explosion sounds wouldn’t make sense.

There were a lot of physics and geometry calculations added so that the lazers shoot in the right direction (with some random spread for inaccuracy) and with the bounce when you hit a turret.

Also I have added gameplay elements like the shield discharging when shot (and recharging after 2 seconds of not being shot or colliding with turrets) the player ship only having a limited number of hits before it explodes and its game over, also winning game over when you kill all the turrets.

And to give it some atmosphere I have also got some cool background music that plays.

So its all done then?

Well why the game code is complete there are just 2 things that I want to do before I publish it.

  1. Allegro sound closing issue
  2. Windows build

Allegro sound closing issue

There is a problem with the Allegro library that when you try and unload the sound extension it locks up the game.

It seems to be a problem with cleaning up the default mixer so I might experiment with adding my own mixer and see if I can fix it.

If I can’t fix this it means that the game doesn’t quit (although I close the window so you can kill it with the force quit easily).

Windows build

I would like to build a Windows version due to the number of people who still use Windows, but to do that I have to setup an environment that I can build it in.

Visual Studio is out of the question as I mentioned in an earlier post due to its lack of c99 support.

That leaves me with setting up either a cygwin or mingw environment.

Having previous experience with cygwin and conflicts between the cygwin1.dll released with the app and one that might already be in the system directories I would prefer to not use it.

That means that over the next day(s) of free time I will be trying to setup a mingw environment and trying to get a build ready.

Screenshots (yay)

Everyone likes screenshots so here are a couple:

Screenshot 1 Screenshot 2

Looks quite different from the last screenshots right?

Now were getting somewhere

Flying Spaceship with shield

After my disastrous Windows experience, I have some new work-in-progress screenshots:

Spaceship with shield Now were getting somewhere

Not only do I now have a cool spaceship with a shield, it can be flown around the map nicely, also note the image with the thrusters on also causes the back of the ship to glow (oooh nice).

The longer you hold the up key the faster it gets until it hits top speed. If you let go of the up key it slows down and eventually stops.

Rotation is controlled by the left and right keys, but don’t expect it to instantly shift the new direction, its existing force keeps going in the same direction until it slows off or an opposing force slows it down.

Stop key? Nope! There is no stop, unless you let it gradually slow and stop or suddenly turn right around and use the thrusters in the opposite direction.

You might also notice the stars are smaller and there are no planets anymore. The planets were ugly and weren’t really that important, since the stars git it enough indication of “space” anyway.

So thats it for this update, up next: LASERS!!!

Compiling for Windows & destroying motivation

A few days ago I tried to set-up a Windows 7 build vm and compile SpaceShooter in VisualStudio.

This resulted in a massive drop in my motivation due to a real depressing discovery: the Visual Studio compiler has horribly obsolete support for C.

Microsoft Visual Studio and (lack of) C standards

I set up the Visual Studio project and tried to compile and what awaited me was about 50 errors, way more then I would expect for a simple program.

Worse, the errors were cryptic and didn’t really explain the problem.

After searching the net for what these errors mean, I found the problem wasn’t really the code, it was the compiler.

It turns out that the Visual Studio doesn’t support either the C11 or C99 standards leaving it left with only c90 support.

Now the C90 standard is 24 years old (25 if you count the fact that it was actually developed in 1989) and quite a few things have been changed and added since then.

Microsoft also have stated that they will not add support for C99 (and C11) as they consider C to be a dead language.

What does that mean for me?

What it meant was that if I planned on compiling with Visual Studio I had to adapt my code to support the C90 standard.

For me it meant a few things, firstly all instances where I was assigning values to structs I had to do it property by property instead of using a quicker syntax.

For example:

pos = (struct Point){5,6};

had to be changed to:

pos.x = 5;
pos.y = 6;

This might not seem to be a big issue, but when you have a struct with 8 properties, 3 of which are structs with 2 properties that ends up being 11 lines of code instead of 1.

On the other hand having the properties set individually makes it easier when adding new properties and maintenance so it was probably a good idea to fix that anyway.

The other problem was that the C90 standard requires all variables to be defined at the top of the scope. This issue I have a problem with, I believe code is more readable/understandable when they are declared close to where they are used.

There was one last minor issue, the round() function that I was calling doesn’t exist in the C90 standard (it was added in the C99 standard), but it was easily fixed with a quick self-defined version of the function:

double round(double val) {
    return floor(val + 0.5);
}

 Compiling without Visual Studio

After I changed all the code to support C90, I then decided to not support C90 (yes a bit late I know). That meant finding an alternative compiler.

I decided to set an a MinGW environment and use gcc (a proper compiler) and a Makefile to build the Windows version.

But gcc didn’t like to compile because the version of the library I had was compiled under Visual Studio.

I could have easily gotten the correct version but because the versions available for gcc on MinGW but since the version number of the available binaries was lower then the one I was using on Mac OSX (5.0 and 5.1 respectively) and there were some slight differences, I chose to try and compile it from the source.

Again I was stopped, this time it was the DirectX SDK that wouldn’t install, and the error was saying that the Microsoft Visual C++ Redistributable was already installed.

Two issues here:

  1. It wasn’t installed
  2. So what if it was? Why does the installer for the DirectX SDK “need” to install the C++ Redistributable itself, if its already installed can’t it detect that and skip that step rather then dying???

Motivation destroyed

And so that was it, I had had enough of Microsoft and their motivation sucking stupidity. It had made me so frustrated that it stopped my progress.

I now have continued work on my game and will forget about a Windows version.

If I have enough time at the end of the month I might try again but for now the very though of trying again just makes me annoyed.

Game 1 – Space Shooter – The beginning

Setup

After signing up for the #1GAM the next thing was to decide on the three L’s: Language,  Library, Location (IDE).

I have been playing around with C/C++ for a while and decided that C would be a nice low-level language to work with, and a bit of a break from OO languages which I personally think over-complicates things sometimes when there is no need to. Also has the advantage that I could make it a lot more cross-platform rather then using something like Objective-C.

Location is also an easy choice, on OS X I haven’t really found an IDE that compares to XCode, not that I think XCode is the best IDE that I have used either, but for a native IDE it seems to be the best.

Now for the library.

Interestingly the inspiration for this seem to come out of nowhere. I was looking through the MacPorts devel category and I saw Allegro. I had briefly looked at Allegro probably around 6 years ago, but at the time I was using c#.net and I didn’t want to leave that language, and ended up using SDL.net which I think put me off SDL in general (or maybe it was the bad software rendering it did by default).

I played around with it and without too much hassle I had it installed and a test project up and running.

Choosing a game

So now I had my three L’s I just had to start coding… right?

Well, without an idea of sorts to base the game around there really is nothing I could start coding for.

What sort of a game would it be?

Side-scroller? Top-down? Action? Adventure? Sports? RPG? Platformer? First-person? Third-person? The options are endless.

The optional theme for #1GAM this month is money, but not money as in in-game money, money as in making money for the game. That doesn’t really help for designing the game and I don’t think I am ready to start monetising my games yet, that can wait until I get better at making games and building more worthwhile games.

I spaced out over this for a while, and then I realised, Space, a space shooter.

Its an easy choice for a 1st game working with a new framework, no need to find/build a level editor or handcraft levels instead, I could easily generate the maps programmatically very easily, after all, it’s just stars and planets randomly placed on-top of a black background.

If I have enough time I might add in-game resources and purchasable upgrades, but thats as close to the theme as I will get.

Progressing

Working with Allegro has been great and I have found it fairly easy so far. The only complaint I have is that there isn’t a docset for it in dash (an API browser that I quite like) and I have to use the online version, which can be a hassle since I do a lot of my coding on the train with little to no internet connection.

So far I have made an engine that loads all the required resources, builds the map, has a working and optimised render loop (only renders visible sprites), and has keyboard interaction that uses the dpad to scroll the viewport around the map.

Here is a screenshot of the current work-in-progress:

Space Shooter early days
Space Shooter early days

Next on the todo list is to add a space ship, bind the viewport to it, and work on the movement of the ship using a impulse/inertia control system.