[6] Lunar Lander WIP [1/9]
- Conlan Walker

- Oct 28, 2021
- 3 min read
Updated: Jan 3, 2022
This week, I start work on Lunar Lander, which is one of the first games I remember trying on MAME, though I scarcely remember its specifics.
The lesson called for a few things, including the usage of the built-in physics behavior.
Put simply, I didn't want to use it. This was for a few reasons; two of which being my recent headache involving said behavior, and the potential accomplishment of creating a simple physics engine. I knew I could do it at least in some capacity, because it doesn't involve anything I haven't been at least partially exposed to already.
In about 15 minutes on Monday, I brainstormed most of the ideas I wanted to try adding:
Have the lander orbit a circular moon, with the player having to de-orbit it to land
Lander should look somewhat stationary on screen, with the moon rotating beneath it
Smoother transition between zooming in/out camera, depending on altitude
Add thrust animation to lander
Maybe have hard-to-reach fuel containers that can be picked up
Have two fuel tanks: one tank you can refuel, and a reserve tank you can't refuel
Use a variable thrust that becomes increasingly less fuel-efficient with throttle power
Add gauges to UI, which includes a visual vector for direction of movement
I knew many of the mechanics involving displays and physics would require some vector math, so I started learning such following the brainstorm.
The lander's velocity is effectively a 2d vector, for vertical and horizontal velocity.
As such, adding to that velocity would require another vector to be added to it.
Apparently, adding two vectors using their components is as easy as:
result_x=a_x+b_X ; result_y=a_y+b_y
The following is a sketch of what happens when applying a force vector to a velocity vector:

The other thing I did that day was create a function that returned an angle based on the components of a vector going from a to b:
In this instance, a and b are treated as the lander and dot's x&y positions.
However, there was a bug that was fixed, but is still present in the video, in which the angle sometimes goes negative, so instead of 0 -> 359, it actually shows something like
0 -> 270 -> -90 -> 0
The video also shows the lander's thrust animation.
The current (fixed) version of the function is shown below:

For Tuesday, I focused on angular displacement between two vectors, as part of a theory on how to solve the problem of translating the lander's position relative to the moon, to the moon being rotated on the screen accurately.
Again, the following is a sketch of that:

Wednesday was spent by learning about gravity, and gravitational force.
I noticed that all of the 2d orbital sims I looked at appeared to be using force vectors, so the only thing then was to think of how the gravity would scale depending on distance. So with the help of my monkey brain, using some math I barely understand, I proved my theory that using gravity is as simple as applying a force vector with strength depending on the object's distance:
Another hassle I'll need to deal with is how I'd ground the lander's real-life measurements to the in-game lander's more arbitrary nature of 8x8 pixels scaled by a just as arbitrary factor:

And that's it for this week.
To end this, here's an example of how the lander actually is supposed to orbit the moon under-the-hood, versus how you'd view the lander on your actual screen:

The weird-looking polygon is just to demonstrate rotation, because a perfect circle wouldn't give any useful information just by looking at it.

![[158] Most Important Brick in the Least Important Wall](https://static.wixstatic.com/media/df100d_f70be6ae4318455fbbc605cd1069c6ee~mv2.jpg/v1/fill/w_980,h_410,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/df100d_f70be6ae4318455fbbc605cd1069c6ee~mv2.jpg)
![[157] Mail Order Sacrifice](https://static.wixstatic.com/media/df100d_e284fa6c51b04524bab9d3cf9f1f6441~mv2.png/v1/fill/w_980,h_382,al_c,q_90,usm_0.66_1.00_0.01,enc_avif,quality_auto/df100d_e284fa6c51b04524bab9d3cf9f1f6441~mv2.png)
![[156] Moat of Babble](https://static.wixstatic.com/media/df100d_091e451794b14aecb494a16c15c966c3~mv2.png/v1/fill/w_980,h_705,al_c,q_90,usm_0.66_1.00_0.01,enc_avif,quality_auto/df100d_091e451794b14aecb494a16c15c966c3~mv2.png)
Comments