I wanted to create a simple game for a granddaughter to play on the Kitronik Arcade which involved hiding a sprite behind various objects using the direction keys. However, I had no idea how to get one sprite to go behind another!!
The Kitronik Arcade is a pretty neat piece of kit which runs the downloaded code from Arcade, and includes a "proper" set of GameBoy-like control buttons with a very neat colour screen, a piezo speaker and a vibrator motor for haptic effects. It's great to run your own code on a real handheld device instead of an emulator.
It turns out 3D is pretty simple. Here's my code, stolen largely from an excellent post in the MakeCode Forum, with the addition of jumping on button B, and "mooing" on button A! The main thing is to set the "z" parameter on all the sprites, using a suitable algorithm or choice of values. So the example sets the z value of the two physical object sprites to their "bottom" value, and the moving sprite z value to its "bottom". Then the moving sprite "disappears" behind the object when it overlaps it, because its lowest point is either greater than (in front of) or less than (behind) the object. There's some more code for making sure it walks around the object by removing ambiguous values.
This was so much fun I decided to make a spaceship orbiting a planet... Here's the code. This uses the formula for an ellipse to move the moving sprite around the planet sprite. The spaceship Z is set to its current Y location, and that of the planet to its horizontal centreline. The cunning bit is using A and B buttons to accelerate/decelerate the ship and change the orbit - faster is lower, slower is higher. The really hard bit was getting an image of the Earth into the Arcade environment - I followed the instructions in the manual, which results in a .ts file that you copy into your JavaScript in Arcade. Yeah, JavaScript, sadly Blocks/PXT doesn't seem to support imported images. The video is of the emulator on my computer, not the Kitronik Arcade.
