One of the things I remember from old arcade games is the curved shield in Gorf.
And while working on Galactic Gladiators, I had one of those thoughts that is becoming increasingly dangerous:
Could I do something like that in Visual FoxPro?
Not just display a picture of a shield.
I wanted a curved energy barrier that could actually be damaged. Fire at it and part of the shield disappears. Fire through the resulting hole and the missile should pass straight through.
I had absolutely no idea whether this was practical.
So I decided to try it.
Starting with an arc
The first experiment was ridiculously simple.
Could Visual FoxPro draw a curved line?
Using VFP’s drawing functions and a little trigonometry, I generated points around part of a circle and joined them together.
And there it was.
A very thin, very unimpressive black arc.
But it was an important little black arc.
It meant the shield didn’t have to be a bitmap or a pre-drawn animation. FoxPro could generate the geometry itself.
I increased the line thickness, adjusted the size and started experimenting with the shape.
The original circular arc was too tall, so I changed it into an ellipse by using different horizontal and vertical radii.
Suddenly it began to look much more like a barrier stretching across the playfield.
Can you shoot holes in it?
This was the bit I was really interested in.
I divided the arc into 20 separate sections and gave each section a simple state: it either exists or it doesn’t.
Conceptually, it’s little more than:
ThisForm.aShield[1] = .T.
ThisForm.aShield[2] = .T.
ThisForm.aShield[3] = .T.
and so on.
If a section is .T., FoxPro draws it.
If it’s .F., it doesn’t.
I manually switched one section off.
There was a hole.
Then I switched three separate sections off.
Three holes.
Then three adjacent sections.
That produced something that actually looked like a chunk had been blown out of the barrier.
At this point I was getting rather excited.
Making it look less like mathematics
The shield worked, but it still looked like a thick line drawn on a form.
So I tried drawing the same geometry three times.
First a thick dark-blue line, then a narrower brighter blue line, and finally a very thin pale-blue centre.
That simple trick gave the shield something resembling an energy glow.
It was still sitting on an ugly white FoxPro test form, but I could already imagine what it would look like against the scrolling starfield in Galactic Gladiators.
There was now just one rather important question.
Can a missile actually hit it?
Drawing a damaged shield is one thing.
Having the game understand that a missile has hit a particular part of a curved shield is another.
This is where the maths became somewhat more interesting than I was expecting.
The collision code takes the position of the missile relative to the centre of the ellipse and determines where it has crossed the shield.
From that, it can calculate which of the 20 shield sections the missile has encountered.
The first proper test produced:
HIT SECTION 6
That was a rather satisfying moment.
The missile had travelled up the screen and stopped exactly when it reached the curved barrier.
So I made section 6 disappear.
Now came the test that really mattered.
If I fired another missile through the resulting hole, would the collision detection understand that there was no longer any shield there?
After a little debugging — including discovering that my first collision calculation was treating the shield more like a circle than the ellipse I’d actually drawn — it worked.
A missile hitting an intact section stops.
That section can be destroyed.
And a subsequent missile can travel through the hole.
That’s a game mechanic
There are plenty of things still to do.
At the moment the amount of damage is based on shield sections rather than the actual width of the projectile. The broken edges need to look damaged rather than perfectly clean. I’d like them to flicker or spit energy, and the whole thing needs integrating properly into the game’s existing update loop.
But those aren’t really experiments any more.
They’re implementation and polish.
The experiment was:
Can Visual FoxPro generate a curved energy shield, detect where a missile hits it, damage that particular area and subsequently allow missiles through the hole?
Apparently it can.
Which is slightly ridiculous.
And exactly why I’m enjoying building this game.
