Tutorial: How to write games part 2

Go to page << 1 2 3 4 5 6 7 8 9 10 11 >>

How to write games using Basic4GL - Part 2

Right then!

This is the second part of the game programming tutorials series for Basic4GL. It's pretty much going to carry on from where part 1 left off, so obviously I advise reading part 1 first. It all fits together!

This tutorial will introduce just one concept: "arrays".
It turns out that arrays, and how to use them effectively gives us enough material for an entire tutorial, so I wont try to squeeze anything else in (it was hard enough to squeeze it down to its current length, and it's still pretty long.).

Arrays although simple in concept are actually extremely powerful. They can be used to apply the same lines of code to different data, which we will put to use to show that the same lines of code that move 1 alien can move 50 of them!

Back to the space alien game

The challenge is thus:

Take the simple space alien game from the previous tutorial and extend it to handle multiple space aliens.
For completeness, we might as well make them shoot back too.


...How would we approach this?

Based on what we've learned so far, we might consider doing this:

This would give us a complete working set for a second space alien.

This would work fine. Infact there's nothing wrong with this approach, so long as you have a small number of space aliens. But if we wanted say 50 aliens, we would have to do a lot of cutting and pasting and the program would get very long very quickly.
Also if we later wanted to change the alien code (which we will later when we make them shoot back) we would have to make the same change 50 times!

So we're going to take another approach, which (surprise, surprise) involves introducing our new concept, called "arrays".

Go to page << 1 2 3 4 5 6 7 8 9 10 11 >>