2007-04-19

Simulating a Decimal Place

As I said in my last post, I needed to change the sprites to use internal co-ordinates 10x what they should be, so that the least-significant digit can be used as a decimal value. If we divide by 10 before displaying the sprite, the last digit gets ignored (we’re dealing with integers), but internally, we can effectively increase a sprite’s x/y position by 0.1 pixels.

Implemented this in all of the sprite classes, but still needed to leave the timer in place for the human class - even moving a tenth of a pixel every loop was still far too fast. For the other sprites, though, it works perfectly.

Added y-axis damping to the landers, too. As they follow the contours of the mountains, and as the mountains are quite jagged, the landers would jitter up and down as they moved over the peaks and troughs. I’ve added a 2 pixel allowance to solve this - if the lander is within 2 pixels either side of the correct y co-ordinate it won’t attempt to rectify its position. I think I borrowed this from the Blitz code (it’s how I interpreted the code, anyway), but it’s tremendously difficult to understand what all of the unhelpful variable names mean. It’s quite a good idea, so I’d hope it was in the original code. Instead of jittering about the place, the landers now glide over the landscape.

Also fixed the jitter that occurred when the landers position themselves over their human.