There is no 'right' way to write a game. Different programmers use a wide range of techniques, each with their own benefits and drawbacks.
These are roughly the steps I go through when writing a game. These are based on my own experience, so will probably be wildly different from the way other programmers write games.
Feel free to ignore them...
1) Create a framework for the game
This typically involves putting the game into graphics mode, loading some graphics, setting up the main game loop and providing a 'Quit' key.
2) Get some background scenery happening
This could be anything from a simple 'TileBlock' to an 8-way scrolling tile-map.
3) Add some good guys
This includes the actual player, player missiles and so on. This may also include detecting collisions with the backdrop, especially for platform style games.
4) Add some bad guys
This includes bad guy bullets and so on.
5) Add collision code
Once you have some collision code going, you can start adding things like 'score' and 'lives' to the game.
6) Play the game and tweak it
Adjust difficulty levels and so on.
7) Add other game elements
These include power-ups, special effects, high-score tables, intro screens and anything else you can think of!
8) Goto 3
If you find yourself spending a lot of time on step (6), then your game is probably coming along quite nicely!
Here are some tips for improving the speed of your game:
- Let Blitz decide the screen depth for you. Some graphics cards go much slower at certain screen depths.
- If you're clearing the screen with an image, you don't need to 'Cls' as well.
- Don't use any command starting with 'Load' in your main game loop!
- Avoid the following commands within the main game loop: Text, GetColor, Line. For ultra-fast text, use images instead of fonts.
- Avoid using string variables within the main game loop as much as possible.
- Avoid using images wider than the graphics mode you're in. This is a peculiarity of the way PC's work that I wont go into here, but such 'wide surfaces' suffer from slowdown on some - but not all - PCs.
And some general advice:
- I always find it useful to divide game logic up into separate 'update' and 'render' chunks. This is useful for game timing, and can also make for cleaner code.
- I prefer the use of custom types over arrays for game elements such as players, aliens etc. This is very much a personal preference, and many people new to Blitz may find custom types a little strange, but I can thoroughly recommend them!
- I also prefer the use of functions over gosubs, but again, this is a personal preference thing. It's true that functions are fractionally slower than Gosubs, but I feel the extra readability and flexibility they add are worth it.
- Don't get too carried away with low-level optimization, or 'code tweaking'. The most important optimizations you can make are usually algorithmic in nature - ie: finding a better way to do something. An example of this might be collision detection. If you are writing a game with 100 aliens and 10 bullets on the screen at once, you end having to make 10X100=1000 collision checks! Now, if you can think up some clever way of reducing this figure significantly, that will be a HUGE performance gain - almost certainly better than any gain you could possibly hope to make by tweaking code.
But, more than anything else, enjoy yourself.
If you end up ignoring all the above advice, and write some huge, kludgy behemoth of a game, it doesn't really matter as long as it was fun.Because if you enjoyed writing the game, there's a very good chance people will enjoy playing it!