I recently had some time off and built this game that I think turned out well (enough):
I suspect some folks in this community might get a kick out of it. Feel free to provide any feedback!
I recently had some time off and built this game that I think turned out well (enough):
I suspect some folks in this community might get a kick out of it. Feel free to provide any feedback!
Love it
I like this. However, it seems each level is generated randomly, right? Some levels seem not to have solutions, within the allowed velocity and angle ranges.
That’s correct. Sometimes, there is no solution and you just have to start over. I started thinking about ways to ensure a solution exists, but I didn’t get around to it. I’m open to suggestions!
If the velocity and the angle are the only two parameters determining the trajectory, a stupid method is checking all possible trajectories for a given gravitational field.
But I do not how to deal with the possible collisions with planets.
It was fun! An optional challenge could be to limit the length of the trajectory trace
Neat.
On my mobile I cannot get past level 1 though.
If I fail, I can retry, but if I succeed the UFO simply stays at the planet and nothing happens.
Hmmm…I’m not sure what’s going on there but the game is definitely not mobile-friendly right now. It’s using a fixed canvas size (800 x 600) because that made everything easier. It likely only works as intended on large screens
It also works on Android phones, but requires some fiddly unzooming to fit the canvas to the screen. Pin the top and pan the canvas to reach the bottom, then zoom out with two fingers.
PS:
By the way, can you tell us more about what goes on under the hood?
On your PC (doesn’t work on my Android device) you can hover over the information icon (🛈) and it will tell you more about the game. The same info is also on the GitHub repo:
All of the action takes place in src/game/scenes/MainScene.js
In a nutshell:
The code calculates how strongly each planet would pull on the spacecraft using Newton’s law of gravitation F = \frac{G m_1 m_2}{r^2}. The masses of the planets are assigned somewhat arbitrarily (it’s their size in pixels multiplied by 100). Then, the code uses the Runge-Kutta 4th order method (RK4) to calculate the spacecraft’s motion under these gravitational forces. It does this at each time step in the game (I have the time step set to 0.2 seconds) to predict the path and speed of the spacecraft.
EDIT: After looking at the code, it seems that the planet size used is its diameter ~ 2r
while for a constant planet density the mass is proportional to ~ r³
. Shouldn’t the masses be scaled with ~ r³
?
I tried that, as well as many variations, but many of them caused strange behaviors. I found that simply doing size * 100
resulted in the best game play experience, so I went with it.
That is what we call: massaging the physics
I encounter this too, but it was after a good time Love it!
Only if the density is constant.
Linear scaling is actually the correct one for black holes.
I wrote the obvious already.
Ahh, totally missed that!