Tuesday, March 29, 2005

Aliens can't fly straight

So now there are hordes of aliens raining from the top of the screen. You can shoot 'em, but that is about all that happens.

Shooting them does give some energy back, and the game keeps score too. So that is all good. I got that all going about a week ago, but got stuck on the flight patterns of the first aliens.

Most shooters seem to get the aliens looping and circling down the screen, so I thought I'd have a look at that too. It took me a while to figure out how to draw a circle, but I found a simple algorithm on the web using cos and tan.

It took me ages to get an alien going in a smooth circle, but I finally got it going. Now I have to find some way to get the aliens to randomise the patterns a bit, and to change direction so sometimes they drift left, sometimes right, sometimes looping right around or something.

I am sure there is a simple algorithm using percentages for each possible type of action that will result in a good alien flight pattern, but it hasn't occured to me yet. It must be simple as all those old arcade games didn't have a lot of space or time to do this stuff in!

I have noticed that having two guns going (one under each "wing") is very inefficient of the ship's energy. Most of the time one of the two shots travels uselessly off the top of the screen, not hitting anything but taking your energy with it. I need to think about it - there is no point having all these weapons if they do more harm to you than the alien hordes.

Saturday, March 19, 2005

Blowing stuff up

I spent this evening tidying up the Sprite class, making the player's ship a subclass of Sprite, and implementing collision detection.

The collision detection is a brute force algorithm at present. When you ask one sprite if it is in collision with another, it first checks whether their "bounding boxes" overlap at all. If not, they cannot have collided so you can exit early.

The Y coordinates are checked first because in a vertical scroller these are most likely to tell you there cannot be a collision as quickly as possible because there is more room in the Y coordinate than the X, so less chance of an overlap in the bounding boxes in that direction.

I added a test sprite to the game with just this bounding box checking and it went pretty well so I thought I'd push ahead and try to get the image overlap check going too.

If there has been some overlap the algorithm figures out which parts of each sprite may have collided and then checks the alpha values for just those positions. If both alpha layers show a non-zero value (ie not completely transparent) at any pixel then a collision has occured.

The Popcap framework makes it simple to get at the alpha values for the image, and these are cached by each sprite during its construction. My C++ skills, such as they are, let me down here and I couldn't get the Ship subclass to call the Sprite's most useful constructor so it has to call the alpha caching method itself. I'll figure out why this didn't work later. The code works as it is, it just isn't as clean as it should be.

Happily the alpha layer checking has passed the couple of tests I have given it so far, after 5 minutes drawing on a piece of paper to get a general idea of how to determine the sub-rectangles of each sprite that need to be checked.

So now the game can detect when "bullets" hit other things. This is obviously vital for a shooter and things are looking up. If I get time tomorrow I'll try and implement the first of the alien hordes!

Friday, March 18, 2005

Initial ideas

I want to do a simple but addictive puzzle game. But I haven't thought of one yet so that will have to wait. Then I went through things like horizontal platform games - Pitfall, Rick Dangerous, etc. I couldn't think of anything cool there either. I moved onto a simple fantasy RPG, perhaps using simple mechanics like the boardgames Dungeoneer or DragonQuest, but they really need two or more players...

In desparation I reverted to the old vertically scrolling shoot-em-up.

If you know Galaxians, Galaga, Space Invaders, or any number of other games, you know what a vertically scrolling shoot-em-up is. It isn't clever or sophisticated. You don't need much in the way of a background, you don't need much of a world or a story, you don't even need very clever adversaries. Those Space Invader bad guys don't throw out many surprises. You don't really need much more than guns and hordes of aliens.

But (and some people, perhaps even people I know, will strongly disagree with this), you do need something more than guns and hordes of aliens. Even if the guns are really big.

It needed another angle. But what?

I was getting a bit down on the idea because I couldn't figure out what would make a vertical scroller much fun, or add tension to it.

I always had the idea being able to plug different guns and equipment into the player's ship, and of a simple power system where different weapons and other pieces of equipment require different amounts of power, but hadn't got far with the idea. Then on the way home last night I though about draining the power so the player might run out if they played too badly, and then couldn't shoot.

I implemented a simple test of this last night and it immediately seemed to give the almost empty game something extra. I think this idea, or something derived from it, may give the game a slightly different twist and add some interest.

At the moment every shot takes as much power as all the guns require. More or bigger guns need more power per shot. When you run out of power, you can't fire anymore. It just occured to me that I first saw this idea in Elite, which I spent many hours playing back in the 80s.

The power regenerates automatically (the ship has solar cells or something), and perhaps shooting aliens will also boost the ship's power slightly, so if you're shooting well you probably won't run out of power, but if you're missing a lot you'll eventually have to slow your rate of fire.

Other equipment such as shield generators, tracking devices, etc, will also be constant drains on the power if you have them installed.

Writing games an hour at a time

It felt good when the first game I finished (written with my friend Rod) was finally playable and made available via SourceForge. SpaceHulk-SP has had a reasonable number of downloads, certainly more than we expected, but we've called a halt to development as it is too hard to maintain and extend. It was started back in 1996(!) in VB4, and the best it got was VB6. It is a mess in there.

We worked on various ideas and started prototyping a few, but then along came my first son and an increase in work load in my real job, and various things happening in Rod's life, and time has been short ever since.

However, seeing the Slashdot story about Popcap releasing their games framework for free made me think it might be time to have a go at another game, this time with the aim of getting it published.

Of course, having to write it an hour at a time either just before going to sleep or before getting my son out of bed means it has to be a simple minded thing! Just what the online game companies seem to specialise in. That isn't to say they're trivial to write or produce, but they aren't Half-Life2 either.

I have played most of Popcap's current games and found most of them to be fun, but I have not been able to think of a great, simple idea like Bejewelled, Zuma, or Bookworm. It must be cool when you get a simple idea like that and know it will be fun.

So while waiting for the great idea to come I'm going to create an old fashioned vertial scrolling shoot-em-up to learn the framework, and translate my C and Java coding skills into C++.

I'll use this blog to track progress and post screenshots, to make a record of whether you can develop a game an hour at a time.