A Shocktopus History – Part 3
(The Electric Shocktopus is coming to Steam on November 30th, so I figured it was a good time for a history lesson. To learn about the first inspirations for this electromagnetic game, see the first or second parts of this series.)
The Physics Strikes Back. (Wait… I guess… Revenge of the Griffiths?)
Right from the get-go, I knew I wanted The Electric Shocktopus to have both electricity and magnetism. And they both seemed so easy to simulate. That’s why I picked this branch of physics, after all. Let’s start with the second one first…
In that first, blocky prototype from January 2013, the game already included magnetic fields – though, unlike with electricity, I defined the fields directly (instead of calculating them). Certain tiles were field arrows pointing *into* your screen, and other tiles that were field arrows pointing *out of* your screen. Simple as that. As you moved through those fields, you’d feel a force from them, turning you the appropriate direction.
But by May 2013, I’d bumped that up a notch, by including current tiles. And as you recall from elementary school, playing around with electromagnets, electric currents can create magnetic fields – which I calculate using the Biot-Savart Law. It’s a bit mathy, but pretty straightforward to calculate.
Phew! Not bad – we can check magnetism off the list. And we all know that electricity is even simpler…
No. No, no, no, no, no, no.
Simulating electric fields started off so easily. So easily. There were electric charges, and I calculated the fields using Coulomb’s Law. An easy equation, and simple to calculate, even with a bunch of charges on the screen.
But. I got greedy. I wanted to add conductors. And that’s where the wheels came off a bit.
Conductors are materials where electrons are free to flow, the charges can move and rearrange themselves. And they do so in complicated ways that depend on what’s around them. There’s no equation you can use to determine how they affect the electric field.
But there is an algorithm you can use. A set of steps ironically called the Relaxation Method. (Aaahhhh….) You break up the space into squares – which, nicely, my tile-based game already does – and then you guess the voltage for each spot. Pick zero, say. You then cycle through all the tiles, changing the voltage depending on what’s around them (charges, conductors, voltage, etc)… repeating this process for all the squares. This gets you a slightly better guess for the voltage. Then you repeat, cycling through all the squares, slowly but surely getting closer and closer to the true answer – converging on the array of voltages for all the squares in the space. And from that, you can get the electric field.
But there are problems with this. For one thing, you need a boundary – an edge all the way around the screen with a well-defined voltage. Which is something I didn’t have… and couldn’t easily add. For by adding in a ring of grounded conductors around the whole level, I’d be changing the result. It’d warp the very fields I was trying to calculate. And losing accuracy, you may know, is something I don’t take lightly! (I don’t have the space here to describe how I *solved* this problem, but if you’re interesting in getting into the weeds with the calculations, let me know, another blog post may be in my future.)
Another problem I had with the Relaxation Method was dimensions. I figured that, since my game was 2D – I could do the calculations in 2D. The screen is 30×24 tiles – so rounding up to allow for some off-screen border, that’s around 1000 tiles that I’d need to run through the calculations. Turns out, that’s fairly manageable, if you write the code well.
And after I added the conductors into the game in May 2013, I went along for some time, not realizing there was a problem. But there was a big one, that had to do with the third dimension – which it turns out I could not ignore. It took me until August 2013 to discover that one, and I summed up the problem and solution here. By having to do the calculations in 3D (with about 30x as many tiles, or cubes, to consider), it slowed the calculations down a lot. Gone was the hope to have the levels calculate the fields in real-time. Charges and conductors would have to be set in place.
By this point, I had the theme in place, the title and place, the physics in place – though hadn’t entirely solved that conductors problem, as it turns out. And I had a bunch of levels in the game. Surely I must almost be at a finished game. Right?
(Tune in next week for a look at the stumbling blocks TES hit coming to market…)