
Show HN: Lunar lander-type game with computational fluid dynamics - s-macke
https://github.com/s-macke/Interplanetary-Postal-Service/
======
s-macke
Author here. It started as a technical demonstration for fluid dynamics in the
web browser. Then I saw the js13kgames competition and the decision was made
to make a game out of it. A game in which the fluid mechanic counts. The
decision for the Lunar Lander genre then was quiet easy.

Does someone know more games then the two I mentioned in the README (Plasma
Pong and Pixeljunk Shooter) with more or less realistic fluid dynamics?

~~~
Impossible
Vessel
([https://store.steampowered.com/app/108500/Vessel/](https://store.steampowered.com/app/108500/Vessel/))
and more recently Claybook
([https://www.claybookgame.com](https://www.claybookgame.com)) come to mind.
They both use SPH fluids afaik. The upcoming Noita
([https://store.steampowered.com/app/881100/Noita/](https://store.steampowered.com/app/881100/Noita/))
has some particle based fluids. Tommy Referenes (Super Meatboy programmer) was
working on an unreleased game called Goo
([https://vimeo.com/1793371](https://vimeo.com/1793371)). Also Riders on a
Storm
([http://www.the2bears.com/?page_id=652](http://www.the2bears.com/?page_id=652))
a fluid dynamics shmup inspired by Plasma Pong.

~~~
s-macke
This is great list. Thank you very much. I added most of the games. It is
precisely through this post that I have a strong desire to follow your
postings,blogs,.... Unfortunately there is no button for that.

How did you find these games?

------
AndrewStephens
This is great - especially the pixel-perfect collision detection. But
honestly, these colonists don't really deserve mail service if they insist on
building their cities in such difficult environments.

~~~
schiffern
Don't knock it, that volcano mine pays the bills.

------
nabla9
Very nice.

Has anyone made fluid dynamics sailing game yet?

You would need only two controls, trim and rudder (direction instead rudder
might be easier to comprehend). Wrong trim and point of sail could broache or
even capsize the boat. Oh, and you could add not just the winds but the sea
currents and waves also.

Now I'm salivating.

~~~
vanderZwan
I suspect 3D fluid dynamics gets a lot slower a lot more quickly

~~~
nabla9
You don't need 3D fluid dynamics for 2d sailing game.

You would have 3 separate 2d layers for wind, sea currents and then wave
layer. The waves don't have to follow the wind, but they they could have
specular reflection from the land. It would make sailing in complex
archipelago or narrow choke points more realistic.

~~~
8note
but how will it know if my sailing by the Lee is faster than the waves?

and I'll lose out of surfing!

------
stared
Awesome!

I encourage you to add it to the science-based games list
[https://github.com/stared/science-based-games-
list](https://github.com/stared/science-based-games-list)

~~~
s-macke
Thanks stared. I forked the repository and will make a pull request. Also I
have seen your quantum game project.

~~~
stared
Added!

Nice to hear that, BTW.

For this game - any idea to expand it? I finished 8 levels in one go, and it
seems that there is a lot of potential for even more challenging currents,
whirlpools, floating pieces, etc.

(Side note: mechanic-wise this game reminds me of UGH!:
[https://classicreload.com/ugh.html](https://classicreload.com/ugh.html))

~~~
s-macke
I definitely have too many projects to tell you for sure. Just look at the two
sites [1] [2] and you know what I mean. I have as many projects in the backlog
as you can see on these 2 pages. And actually I don't want to concentrate on
one. The motivation changes about every month, because I do this in my spare
time. And from time to time a project has a status where I can publish it.

So at the moment my motivation for this game is to add more realistic physics
for the ship (turns instead of right and left) and a level editor to learn
Vue. Then just look at the other comments. You see a lot of great ideas.

But building a 13k game next year based on the Voxel Space Engine is also in
my head :-)

[1] [https://simulationcorner.net/](https://simulationcorner.net/)

[2] [https://github.com/s-macke/](https://github.com/s-macke/)

~~~
stared
I see (and emphatize with!) too many projects and ideas.

As a side note, I am learning Vue.js right now (my motivation: brining deep
learning to the browser, with nice, modular interfaces:
[https://inbrowser.ai/](https://inbrowser.ai/)).

------
funkaster
> the result varies depending on the FPS and your actions.

you should try to decouple physics simulation from your rendering code. (i.e.
pass a constant/fixed dt to your simulation step). simulation should not
depend on framerate.

~~~
codeulike
But with a chaotic system like fluid dynamics, you wont get the same behaviour
each time even if you do stuff like pass delta-t to the simulation. Sensitive
dependence on initial conditions, and all that chaos theory stuff comes in to
play.

That is, two run-throughs with very slightly different delta-t's will give
different outcomes.

~~~
saulrh
There's a difference between "numerical stability issues introduce small
chaotic perturbations" and "the game is literally unbeatable if you play on
platform X because the physics step doesn't properly scale Y to framerate and
a trivial conservation-of-energy analysis yields an impossibility result for
level 3".

------
gus_massa
It would be nice to have a vertical speed indication in the ship or nearby.
Perhaps some semaphore like lights in the bottom of the ship. It's difficult
to look simultaneously at the ship position and the speed indicator.

Also, sometimes adding an official name for each map somehow make the game
look better. Nice game, I must try again because I lost all my ships in the
"volcano" level.

Edit:

Putting the light to show the vertical speed in the landing pad may make more
sense in universe.

Also, the buildings look very similar to the old gorilla.bas game :).

It would be nice to be able to disable the simulation in the introduction and
final screen, so I can keep the page open to play later, without using too
much battery.

~~~
s-macke
Thanks for the tips. There are always ways to improve the gameplay. I had
still 2-3kB left at the end.

When I designed the buildings I thought actually about "Save New York" on the
C64.

[https://www.youtube.com/watch?v=ZMUvi6UIV3w](https://www.youtube.com/watch?v=ZMUvi6UIV3w)

~~~
mgkimsal
I was reminded of 'space taxi' (which I guess was just a lunar-lander
variation, come to think of it).

"pad 5 please"

~~~
mar77i
"Up please!" \- Yup. What a blast!
[https://www.newgrounds.com/audio/listen/277378](https://www.newgrounds.com/audio/listen/277378)

"Space Taxi" added a bit more depth to the lunar lander concept by adding
multiple pads and various vector fields for gravity to act in. Some game modes
would accelerate you not downwards but instead towards the center of the map,
away from it or around the center in a circle some way. Quite the brain-teaser
for my kid brain back then that hadn't previously been exposed to
physics/maths like that.

------
aasasd
Genuinely interesting as a game, there's potential for interesting level
designs.

A hardcore mode would be rotating the ship instead of it always staying
upright—like in Atari's version:
[http://moonlander.seb.ly/](http://moonlander.seb.ly/)

~~~
s-macke
Exactly. This is at the moment nothing more than a nice technical
demonstration. Actually my initial code implemented already mechanics for
rotations. But then I skipped this feature for this entry. I was afraid the
game gets too hard for landing.

~~~
sokoloff
It's definitely fun as-is, maybe slightly too easy for long-term playability.
I suspect rotation would make it brutally hard and less fun. Nice work!

------
arnarbi
This is great! I would love love a boat maneuver game with the same engine. A
killer simulator would be one that takes into account wind and current, single
vs multi-engine, bow thrusters, prop walk, etc.

Note that this is different from the sailing suggestion below, which has all
kinds of three dimensional aspects to. Purely thinking about e.g. docking
where all the controls you have is thrust and rudder.

------
codeulike
This is brilliant.

One of my favourite games growing up was Thrust on the BBC Model B. Had
directional velocity and towing mechanics, which was pretty good for the time.

[https://www.youtube.com/watch?v=Dt44PEIWBRg](https://www.youtube.com/watch?v=Dt44PEIWBRg)

~~~
s-macke
I played this game too. And I was close trying to implement such a game. But
then my fluid grid would be much much larger and the game much slower. I
thought about adaptive grids. Fine on the viewing screen and coarse outside.
But to implement this would have taken me too long for this game entry.

------
blunte
Am I the only one experiencing a game-breaking bug/behavior?

The D thrust gets stuck on if you press it once, and randomly the W comes on
and gets stuck too.

Also, after the first ship, every additional ship starts with W and D thrusts
on, permanently.

~~~
s-macke
This happens to me when I use the Internet Explorer. My best guess is, that
the problem is, that the game tries to use all the computing power available.
The game does use the "setTimeout(Loop, 0)" trick to accomplish this. Usually
there is no problem if the event queue is a queue. Then the setTimeout
function is the last one in the queue and keypresses are handled first. If the
events are handled differently, for example by using a stack, such games are
in big trouble.

------
miltondts
Fantastic game! Can anyone recommend any books/courses on how to make
simulations/games like this?

~~~
slavik81
"Fluid Simulation for Computer Graphics" by Robert Bridson would be my
suggestion for getting started with grid-based methods. The SIGGRAPH course
notes on his website are very similar to the 1st edition. [1] It's no longer
the state of the art (which is probably APIC), but the new methods are all
based on the same fundamentals.

Particle-based methods like Smoothed Particle Hydrodynamics (SPH) are simpler
to implement and are more intuitive than grid-based methods, but they're also
harder to analyze mathematically. SPH is the method used by PixelJunk Shooter.
"Fluid Simulation for Video Games" by Michael Gourlay is mostly about a
different fluid technique (vortons), but does include SPH. [2]

[1]:
[https://www.cs.ubc.ca/~rbridson/fluidsimulation/](https://www.cs.ubc.ca/~rbridson/fluidsimulation/)

[2]: [https://software.intel.com/en-us/articles/fluid-
simulation-f...](https://software.intel.com/en-us/articles/fluid-simulation-
for-video-games-part-1)

------
bmillare
This game was brilliant fun, just got over 12k after playing it over and over
again. It really reminds me of white water rafting, you really can move very
efficiently, quickly and with little thrust if you properly read the course.
Simple game, but great depth.

------
hazz99
This is great! I made it all the way to 8, but couldn't win :)

I like the idea of having to examine wind streams to plot your way through the
map. This is an awesome tech demo, would be keen to see something more
polished & fleshed-out.

~~~
s-macke
There is a trick in level 7. You have to do something counterintuitive.

~~~
sliken
Ok, I'll bite, what? I just do the obvious, drop fast from left to right. That
way you can cross without being forced off the top of the screen.

~~~
s-macke
Ok, then the obvious solution is my counterintuitive one. You have to cross
where the wind is the strongest at the bottom. As fast as possible of course.

------
davidovitch
Very cool :-)

Regarding usability: I keep getting confused by the controls: indicating where
you want to go vs which thruster to use. Back in yonder days I used to play
Lunar Lander on Windows
([https://en.wikipedia.org/wiki/Lunar_Lander_(video_game_genre...](https://en.wikipedia.org/wiki/Lunar_Lander_\(video_game_genre\)))
but there the controls indicate which rocket you're firing: down for going up,
left for going right, etc.

------
aravindet
Can you explain the expf_fast function?

~~~
striking
Looks like it's from here
[https://github.com/ekmett/approximate/blob/master/cbits/fast...](https://github.com/ekmett/approximate/blob/master/cbits/fast.c#L103-L109),
there's an explanation here
[https://nic.schraudolph.org/pubs/Schraudolph99.pdf](https://nic.schraudolph.org/pubs/Schraudolph99.pdf)

------
eatitraw
Really cool and fun game. I really wish there were more levels!

Also, like some people suggested, it'd be nice to have an option for running
the game at a higher speed.

------
xte
Oh, despite it's not a "real" modern game a big prize! Games can be nice
teaching solution, if well done and still being fun.

------
anotheryou
Cool!

Can it run faster? This might need more roomy levels and stronger thrust, but
faster speed would mean more feedback for a better feel of the physics.

~~~
s-macke
On my computer the game runs at 40 FPS. So there is still room and I can
increase the timestep if you want. This game simulates the Navier-Stokes
equation on a grid of the size 256x128. Four times the size would already
reduce the game to 10FPS or even more. Of course you can try to rewrite it to
run on the GPU. An alternative would be to use so called Smoothed Particle
Hydrodynamics. This is particle and not grid based. But this technique has
other drawbacks.

~~~
s-macke
I increased the timestep by a factor of two. Have fun

[https://simulationcorner.net/js13kgame/](https://simulationcorner.net/js13kgame/)

~~~
wumms
I love the faster one. Grabs much more attention. Great game! A satisfying
thud on touchdown would be nice. (OT: this was the very first lunar lander I
played on my father's ZX81:
[https://www.youtube.com/watch?v=jlS3fr3t4Fg](https://www.youtube.com/watch?v=jlS3fr3t4Fg))

------
ibarrac
Beautiful! Great job.

Lander used to be the first game I would program when I got a new computer as
a kid. I remember writing it for the TI-99/4A, Commodore 64, and the Amiga 500
(in Modula 2). Your game brings fond memories of those simpler times.

Amazing what you can do these days with the tremendous speed of computation
available on modern hardware, even with the js13k constraints.

------
artursapek
Very cool and great use of webassembly. Bug report: if you get low enough in
the last level and thrust upwards, the black smoke somehow mixes with the
purple smoke outputs and they start instead covering the screen in black
smoke.

[https://i.imgur.com/vHOrBWm.png](https://i.imgur.com/vHOrBWm.png)

~~~
misnome
I also had problem with the last level - on the several attempts I had left,
after about 10 seconds the sim would seem to bug out and it looked like there
was a very, very strong wind along the bottom, which looked like it was
friction-pulling the rest of the play area so that everything was blowing fast
to the left, leaving it (apparently) unplayable.

Good fun, otherwise.

~~~
s-macke
Damn. I thought I have solved this issue. But why does it work for most other
players?

~~~
cellularmitosis
I ran into this as well. Here's a video:
[https://youtu.be/SomX22VGHHc](https://youtu.be/SomX22VGHHc)

It doesn't always happen for me. Here, I had to play through the game several
times before I could get the bug to trigger.

------
ronlobo
Really cool!

Similar but to be solved programmatically is the codingame.com marslander.

[https://www.codingame.com/training/expert/mars-lander-
episod...](https://www.codingame.com/training/expert/mars-lander-episode-3)

Good luck on the 2018 js13kgames competition!

------
sgt
After playing for < 10 minutes it started getting noticeably slower and my MBP
Retina was spinning up its fans. I am using latest Chrome. Is this a sign that
web games are not yet ready - or simply that either the game isn't optimized
enough or perhaps even that Chrome is a poor choice for browser games?

~~~
MrStonedOne
Very likely started thermal throttling because apple is notorious for not
putting adequate cooling on their mac books.

This game uses fluid dynamics calculated in real time, i don't think its
designed to be super optimized but rather super true to physics. Most of the
time game optimization involves cheaping some of the complex calculations to
be less accurate but still "good enough" see
[https://en.wikipedia.org/wiki/Fast_inverse_square_root](https://en.wikipedia.org/wiki/Fast_inverse_square_root)
for an example.

In other words you'll run into this issue any time you do anything taxing for
more than 10 minutes on a mac book.

------
elwell
Ah, this brings back memories of a space landing remake game I made back when
I was learning Java applets (c. 2007).

[https://github.com/celwell/space-landing](https://github.com/celwell/space-
landing)

------
zaq_xsw
[https://i.imgur.com/EksA6Rw.png](https://i.imgur.com/EksA6Rw.png) Woo! +1 to
the comment about larger levels. Though I'm only getting about 20fps on my
laptop as is. Multi-core? GPU? Awesome little game, in any case!

~~~
ObsoleteNerd
Finished with 6128 points here with only 1 ship left. That was a close one.

Great demo. I'd love to see this fleshed out. I think a lot of the older games
had seriously good playability and deserve to be revisited.

------
bArray
7867 points. Great game!

I would recommend that in a future version the craft is actually rotated by
the "air" too for extra challenge, perhaps having rockets that rotate left and
right and make the downward facing rocket more powerful to compensate.

------
teddyh
Does not work in Firefox 60.2.0esr. Worked fine in Chromium (10004 Points,
died once).

~~~
JepZ
Works for me (tm) in Firefox 61.0.1 (64 Bit, Linux)

~~~
Applejinx
Not working in Firefox 60.0.1 (64 Bit, MacOSX). The game runs, but the lunar
lander blows up instantly when the game starts. The audio is only in the left
channel, but works, as does the space bar toggle for sound on/off, and the
explosion uses fluid dynamics which are working.

------
gusmd
Awesome! Couldn't win yet, but I'll keep trying :)

On a more technical note, I wonder if you could use a Lattice-Boltzman-based
flow simulation instead of classical CFD. Could be faster depending on "grid"
size.

Great, great job!

~~~
s-macke
Not sure. Can you point me to a basic implementation in Javascript, C or
Fortran?

~~~
gusmd
From a quick search, there are quite a few on Github. Can't point to a
specific one, though. I implemented a very basic 2D version on one of my MSc
classes, and although we used MATLAB, it was quite fast depending on grid
size/fluid properties.

------
G4BB3R
I died in the last level, in the last life on the platform but with high speed
:(

------
emilga
More levels please! ;-)

~~~
s-macke
I want to learn Vue or React. So you might get a level editor at some time.

------
accrual
About 30 FPS on a 13" 2015 MacBook Pro, 3.1 GHz i7, Chrome 69, and full screen
1200p.

I had a blast and really enjoyed the game. :)

------
soneca
I just keep exploding no matter how slowly I reach the landing pad :(

Any tips of what am I doing wrong?

~~~
s-macke
Do you see the green bar on the speed indicator on the right side?

~~~
soneca
Yes, every time I land with the white bar inside the green area, it explodes.

~~~
soneca
I opened it on Firefox and everything worked out fine.

I realized that on Chrome all the graphics were weird. No colors on the home
page, I couldn't see the windows at the buildings. Maybe there is something
not rendering right in Chrome.

I use Chrome Version 60.0.3112.113 (Official Build) (64-bit) on Fedora 25

~~~
Zitrax
I also had it work better in Firefox for some reason. I tried it in Vivaldi
and it ran at ~6 FPS while in Firefox ~60 FPS.

------
foota
How the heck are you supposed to beat the last level?

~~~
s-macke
You have to fly to the top left. Then fall down. But immediately after you
have started falling you need all your thrusters to stay on the line and land
safely.

------
kreetx
Wonderful game!

------
gioscarab
8962 points :)

------
mito88
thanks for sharing!

