2010-05-12

More on Joysticks

Slowly working through the Options menu. I really hate UI design.

The good news is the UK election is sorted. I'm not convinced it will last more than a couple of years, and things aren't exactly how I'd like them, but they'll do. We shouldn't be running off invading any more countries illegally for the time being anyway. :oP


Anyway, Joysticks.
I have Joystick support implemented and working. It feels fine to me, but I don't like joystick controls on this sort of game personally.
I edited the OpenTK source to implement it in the end with a semi-clumsy hack.
I'm fairly certain it's badly optimised, but it work for now. I'm not looking to break any optimisation records with Hoshi. ;o)

I'm not extensively testing it. Random unplugs etc are undefined. It's mostly there as a testbed for future projects among which will probably be platformers, for which joystick support is a must.

2010-05-11

Another update

I've spent the afternoon avoiding the Options menu. I really hate UI coding, it's so full of potentially tricksy pieces.

Instead I've fixed all the niggly bugs and added explosions to ship deaths, including the player, with a seconds worth of delay after dying so you can watch the remains of your ship fly into the unknown.

So yes, everything is now drawn correctly at the edges of the Arena and I've removed those horrible red lines. Passage between one edge and another should be unnoticeable.

I've made some minor changes to balance.
Enemy ships now have a variable amount of shield power depending on the wave. Up to wave 5 you'll always insta-kill them. At wave 6 they'll take 2 shots, at wave 11 they'll take 3, 16 they'll take 4, etc.

I don't think there's anything else to add at all to the game itself now. Balancing tests still need to be done, but I think that should be fair enough. Getting past Wave 11 will require considerable skill I suspect, but that was true on the original Foray as well. I think the furthest I ever got on that was around wave 15.

Hoshi video

Managed to finally take a video of Hoshi.
As I said before, this is near finished game-play. There's still cleaning up to do and I'm still having performance issues in full-screen for some reason, which is why this is an 800x600 recording, not a 1280x800 as I'd like, but it still gives a good example of what the final game will look like.

I die rather suddenly at the end and accidentally start a new game immediately. Will have to look at that.

Nearly done!

Hoshi is finished for all intents and purposes. With the exception of the Options menu.
All other bugs are niggling:
 - Boss AI currently gets confused and sometimes lost due to lacking position-correction. This only happens whilst escort ships are still around, once they're dead the AI works. The position correction is easy to fix, hopefully the AI is as well.
 - Stars are still somewhat confused from my X axis mix-up, this is easy to fix.
 - Enemy AI does still get confused with arena borders. This should be easily fixable.

Additionally I'm having second thoughts about the 3-shots-to-kill enemies. It shows off the shield animation better, but they're a bit of a pain to kill.
I may drop it to two shots and make it so only 3 need to crash into you in rapid succession to kill you instead of the current 4.

So, I should have an RC tech demo by the end of the day.

2010-05-10

Quick Hoshi update

Obviously the election stuff has dragged on a lot longer than I thought it had and in between a friend's birthday party and the Spanish Grand Prix I got near enough no code done this weekend.

However, today I've had quite a productive afternoon, so I'll outline what now works in addition to before.
Firstly there's a menu:

Which is fairly basic, but will do for now.
Options still doesn't work, but most of the basic framework is in there, just needs fully implementing.

I've finished adding the final few pieces of game code, which means the game actually plays now as it will when finished, that means all AI (including boss), special bullets and wave re-plays are implemented.
However there's no indication what wave you're on, nor score indicator (although both are stored internally).
I'm expecting to have everything implemented either tomorrow afternoon or Wednesday at which point I'll have a choice.

First, I could just release it at that point, however there will be no sound implemented. Sound is a bit of a funny area with OpenTK. It uses OpenAL, which is a separate download on Windows and may require the player to go do download and ./configure things on Linux, which is less than ideal.
Also, OpenAL breaks 64-bit support on Windows, which means telling the application to run in 32-bit mode. There's no 64-bit version of OpenAL for Windows as of this moment and it's possible there won't be in the foreseeable future.
I may be able to get round these at some point in the future but right now it's a bit of a show stopper for sound effects.

I do have a solution, but it's not ideal.
Distribute multiple binaries.
It's fairly easy for me to create a non-sound binary alongside one with sound. I just don't call OpenAL in the no sound one and so it will run with most compatibility.

There's a further solution to all this, and that is compiling and distributing an OpenAL DLL and linux shared object alongside the executable. I'd rather not go this route just yet though as compiling OpenAL soft under Windows is somewhat daunting, but it would fix the 32/64-bit issue.

Another word on Joystick support. If you followed the link I made in my last post you'll not that Fiddler said the issue was fixed in OpenTK's svn. I've downloaded and compiled that and I'm still having the same issue at the moment. This is unfortunate but not seriously threatening. I still have my full keyboard support which will be fine on any keyboard that allows 3 keys to be used at once (all, else ctrl-alt-del wouldn't be usable ;o))

So that's where I stand. I'll go get Score and Wave notifications implemented so I can work on the Options screen tomorrow.

2010-05-06

Well that explains a lot.

All my X co-ordinates have been oddly reversed in Hoshi. Just worked out my camera wasn't orientated properly... Having text backwards isn't conducive to the user experience.
Bleh.

2010-05-05

Joysticks

OpenTK pulled the old joystick code near the end of last year without me noticing. This essentially means Hoshi won't have joystick support like I wanted unless I cobble together a custom version of OpenTK.

This isn't a disaster, but it's annoying as I wanted to introduce Joystick support for some of the other games I have planned as well.
This is the exact post detailing the new input methods. You'll note the last post is "this won't be ready for v1.0."
Unfortunately the old code was pulled as part of the process of implementing the new, so whilst OpenTK will wave a flag and say "look! I has a stick!" it won't let you actually read any useful information from the joystick.

So that's about half a day wasted on that. :o(
Arse. And I drew a joystick icon as well.

2010-05-04

Work on Hoshi

Been busy watching election stuff again. :oP
That'll all be over on Thursday.

Anyway, I'm having a minor crisis with control mechanisms.
Essentially I wanted things to be as simple as possible. In the old versions there were a singular set of keys: Z, X, right shift and enter (for left, right, thrust and fire respectively). These are generally not considered "nice" keys under todays standards (although personally I still think they work fantastically for pretty much any game when you use ' and / for up/down as well, but anyway), so there's another keyset that in the tech demo is configured as left and right cursor, Z and X (I think). The fire/thrust aren't ideal really, but good enough for the tech demo.

So, what's the problem exactly? Well, I have a left, right and enter key, and even a potential "back", but no up/down.
Because I want an options screen, I need a basic menu. A basic menu ideally needs an up/down and definitely needs clear keys.

Initially I just thought "oh, I'll add an up/down", but that could confuse matters when the user goes "what do up/down in the game?" The answer would be "nothing, they're purely for menu navigation"... Seems a little silly.

Next thought was "I could do a left/right menu with cool slanty text", which would work but involves coding up another UI element and drawing the text sideways which will all take time which I'm running out of.

So, I've decided on this:
Menu navigation will all be done through the cursor keys. Game play will have custom keys definable in the options.
Oh, also I'm adding basic joystick support.
On the main menu they'll be a notice in the top-left of the screen with pictures of cursor keys, enter, escape and a joystick to indicate that's how you navigate the menu. Heading to the options screen will let you redefine the in-game keys.

The tech demo actually has the ability to redefine the keys in its options file, but that's not a lot of use unless you know the OpenTK keycodes. There's a few other options I forgot to mention that I'll go through now:
If you open the file that is in AppData (C:\Users\\AppData\Local on Vista/Win7, C:\Documents and Settings\\Application Data on XP I think) then you can change these options.

First off is 'fullscreen'. Changing this to 'true' will attempt a fullscreen mode.
Next you have an X and Y resolution, changing these will do the obvious.
Arenasize changes the size of the arena. Making it very, very small is untested, I don't suggest doing so. Making it very large will just mean it takes longer to catch up with the enemy ships. Again this is untested. The radars should still work, but again, untested. :oD
StarsInTheSky and Layers changes the number of stars on each of the parallax star layers and obviously the number of those layers.
StarSize is a value passed directly to OpenGL to change the size of points. I've not stuck to this everywhere in the code so changing it might not make a difference. Large values will look silly, 1 will make the stars hard to see and anything smaller than 1 will default to 1.
UseKeySet determines which set of keys to use. Currently 0 is the standard cursors with Z and X, 1 is the Z/X/enter/shift layout I mentioned previously that I prefer. 2 will default to the cursors with Z and X again and will become the 'custom' key set when implemented.
Once joystick support is implemented, this value will also support -1 for the joystick.
Back and pause will always be Escape and 'P'... Pause works but has a bug in that you can still rotate and fire in the tech demo.

2010-05-02

Design decisions

I said I'd talk about why I'd decided to use C# and OpenTK, so I'll do that here. Along with why I'm developing reusable code, which is something of a two-edged sword if you're not careful.

Why C#?
To be blunt, because I can get from clicking "start project" to a working OpenGL window in under 2 minutes. With OpenTK installed on the system there's minimal messing around with dependencies etc, etc.
On top of that, .NET has a very, very rich network of libraries. VB also has access, but it's not as flexible a language. There are other options for adding useful libraries to C/C++ but you have to take time to set things up, which can take a long time and there's also issues with linking things so they'll "just work" on other people's machines. C# with always "just work" on a Windows box and with mono installed will most likely "just work" on both Linux and OS X as well without requiring me to release 3 copies of the game.

Why OpenTK?
Once C# was decided on, there were several things I could use for games programming. The most obvious is XNA, which is Microsoft's release and is easily portable to the X-Box 360. However, it's Windows only and is based on DirectX, which I've never particularly liked.
SDL.NET was another possiblity, but this works in 2D and seems to be abandoned in recent years. It was more active around .NET 1.1 than any other time and much of the coding harks back to that era, C# and .NET have moved on since then.
Tao is another possibility and would be a solid choice, but again it looks abandoned.
So that brings me to OpenTK, which has almost direct calls to OpenGL, contains a very quick and easy class called "GameWindow" (which allows that 2 minute setup I spoke about), contains maths classes that are almost (but not quite) directly portable with XNA, has support for sound playback and has extensive input support for keyboards, mice and joysticks. It also supports these features across both Windows and Linux, with most supported on OS X (I think sound playback and joysticks are a bit iffy, but I have no Mac to test them on).

Also note, I'm discounting anything that isn't free here.

Reusable code
Working out how much of a game to make reusable is more complex than it first appears.
For example: You could build an entire game engine that could be used for multiple games, but it should be pointed out that this is a large project in and of itself and if you just want to write a game then it's advisable to write a game-specific engine which will be much less flexible, but you're more likely to complete.
For my Game-A-Month project I've hit somewhere in the middle ground. Certain parts of my games will be reusable, but the game itself will be built largely from scratch each time.
The main part that is reusable is are the user interface components. Specifically this is a lump of code that contains the decision making for what is happening in the game at the moment, making sure things that are supposed to be rendered are so and those that aren't, aren't, making sure when a key is pushed the game takes the right action, etc, etc.
In Whirligig it deals with where and what the mouse has clicked on, who's turn it is and what to display on the screen at any moment. It will also deal with the main menu and shop when those are implemented.
In Hoshi it just deals with the basic rendering right now and not a lot else, although it also knows when the player dies and deals with ending the game; this bit of user interface is particularly clever as internally user interfaces lie on a stack, the first on the stack is the 'main menu' then you stack whatever else the user visits as you need it. When the user finishes with the user interface it just pops the stack and the user is automatically returned to the previous interface. If the stack is empty the game ends.
This allows me to very quickly knock together a group of components I want rendering into a user interface, chuck it on the stack and have a game prototype. This is the stage both Hoshi and Whirligig are currently at. When I want to add a main menu, I just create the menu as a separate interface and when the user selects "play game" just push my 'prototype' interface onto the stack. When the game ends, the stack is popped and control drops back through to the main menu.

Other components are designed to work with this interface and mostly consist of fairly mundane things like windows, labels, buttons and progress bars (all showcased in Whirligig) which inherit an interface called IUIElement. This interface allows me to create and add a new element to a user interface very quickly. For example, the radars took ~30 minutes to knock up in the end and the energy bar not a lot longer, then I just use an AddControl() call on the interface and they're rendered the same as anything else.

This is all very useful, but I take some performance hits for it. Interfaces suffer some nasty performance problems and once I start developing more complex objects I will certainly start using less of them (right now every render object uses one for it's main render cycle, this is VERY BAD as it generates unnecessary allocation and therefore garbage collection calls for every object in every render cycle -- 60+ times a second -- which severely impacts performance and may be the reason I'm having issues recording a video). Hopefully project #3 (which I'm looking at a plaformer idea I have for) will have less of these.

There are other small elements that I'm making reusable, small things like the OpenGL texture upload code, which I'm just doing quick'n'dirty right now, text drawing is done through the .NET image subsystem to a texture then uploaded with a transparent mask, this isn't perfect (rapidly changing text would be bad for this method) but works for what I have right now.
When I write a simple audio subsystem (which I'll be doing in the next couple of weeks for Hoshi), that will be reusable as well.

Hoshi tech demo

Hoshi is moving rapidly, I've now got a tech demo ready which you can download here (557KB).

The aim is simply to kill all 20 ships. The AI is fully implemented but not properly balanced yet and they sometimes shoot in mysterious directions. However they do usually target your direction and despite having no swarm mechanics do tend to act in a swarm-like behaviour.
I've mostly been playing against 50 ships when doing testing and that can prove quite difficult. You shouldn't reach 50 ships for a long while in the main game though.

Tips are to just keep moving as much as possible, but not TOO fast or you'll outrun your bullets and run the risk of smashing into ships. If you die (energy bar is at the bottom) the demo will exit. You only get one life. ;o)
Currently things go a bit weird at the edges of the level. For one the AI will get confused and start flying in the opposite direction, ships on the opposite side won't be drawn and bullets don't have "move to correct side" parts attached. So, if you see a big red line, I suggest flying away from it, although nothing will go spectacularly wrong if you don't.

In other news, I did a fair bit of yesterday and today's development under Linux, where the game just runs. I'll write a post about my reasons for choosing C# and OpenTK (this being a main one) at some point. For now, you can see what it looks like here, ignore the tearing, that's just a vsync issue. I'd not quite got the radar implemented there, so no red spots.

I tried to take a video of the tech demo earlier but ran into some issues unfortunately. I'll try again later though.