133. Landing on the moon in 3D – and what goes into finishing a game
This post is partly about the little game above, and partly about the time and skills needed to produce quality software. And the fun of exploring new things.
Landing on the moon in 3D
Some months ago I managed to draw bumpy terrain (hills and valleys) in 3D, and walk around on it, and after seeing someone recreate the old lunar landing game, I wondered if it was possible to create a 3D lunar landing game.
In the end, it took me nearly a month. Why?
Because when I drew my terrain with a pale dusty colour, I couldn’t tell where anything was. If there were trees or houses or anything, that would help the eye to figure out the bumps, but when it’s all one colour, it looks featureless. (Don’t suggest craters – have you ever tried drawing craters in 3D?).
I knew the answer was to put in some lighting. I’d seen quite a lot of lighting code on the forum, and not understood any of it, but I wanted to learn it. So I began learning about ambient, diffuse and specular light, and that journey is documented in earlier blog posts. It was really difficult (for me, anyway), and I was stuck for days at a time on small things. But eventually I got it working, and when I put it together with my lunar terrain, the results were amazing. The shadows are really beautiful, especially the way they fade into sunlight, very realistically.
My next (much smaller) problem was how to decide where you could land, when the surface is bumpy. So I got Codea to find places where the surface height is much the same, and mark them with a yellow rectangle, to show the player where to land.
Then it was simply a matter of designing some controls to go up, left and right (no need for a down control, gravity does that). I didn’t use real gravity, but just fiddled until it felt right.
And the result is above, and the code is here.
You’ll find it takes a little time to start (the first time, it also has to download the moon texture image). It’s not too easy to land without crashing, but when you do land, you’ll find you can walk all over the surface, and it feels very realistic. I’d like to make some of the hills a little less pointy (that comes from the way the terrain is created), but otherwise, I think it’s beautiful and very real.
I could also have drawn a spaceship sitting on the moon. This only requires a 2D image, because you can keep turning it so it always faces the viewer (this is called billboarding, and I’ve used it a lot in earlier 3D work). The problem is the terrain isn’t quite flat, so bits of the spaceship keep disappearing into the ground. So I just put a yellow marker for the ship and let players use their imaginations.
If you find it too hard to land, you can hack it so that even if you crash, you get to walk around on the surface, which is the really cool part. Change line 322 in the Main tab, from setup2(), to SetupWalking(), and when you touch the screen after crashing, you’ll be on the surface. You can also change the size of the map, in the Map4 tab, at line 29.
I find it amazing to be able to create something so realistic…
The skills required
To build this game requires the following skills (with blog links)
- creating realistic terrain and walking around on it
- tiling a large area with a small image
- lighting (diffuse light)
- creating controls
- managing different game states
- reasonably good Lua and Codea programming skills
You’ll see it’s taken me over six months to reach this point.
The point I’m trying to make is that you can’t simply download Codea and expect to make something brilliant straight away, as some new users seem to expect. It takes time and effort, you need to be patient, and you can’t always predict what is going to be useful. My attitude is to keep exploring what interests me and is fun, otherwise I’ll just get bored and stop.
And the more skills you have, the more ideas that will give you for games. All you need to do is start playing with something simple, and it’s surprising how quickly you’ll start to think of ways to make it more interesting. The more you know, the more ideas and choices you will have.