Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do those java sand games keep track of so many particles?

Tags:

java

particles

Can anyone shed any light on how a program like that might be structured?

What java classes would they employ to keep track of so many particles and then check against them for things like collision detection? Particles need to know what particles they are next to, or that they're not next to anything so they can fall etc.

Here's an example, incase you're not sure what a sand game is.

like image 204
Stretch Avatar asked Aug 11 '10 16:08

Stretch


People also ask

How do falling sand games work?

In falling-sand games, the user can interact with (e.g. place and remove) particles on a canvas which can interact with other particles in various ways, which can lead to complex emergent behaviour. As sandbox games, they generally have an emphasis on free-form gameplay, relaxed rules, and minimal goals.

Who made falling sand game?

The basics of falling sand games are simple, and well-explained by one of Noita's three developers, Petri Purho, in this blog post. Before Noita he worked on Crayon Physics Deluxe, which has obvious physics-y parallels. The lineage from falling sand to Noita's "Falling Everything" engine is even clearer.


1 Answers

Arrays, mainly.

  • A one-dimensional array of actively moving grains, represented by two coordinates (and possible a velocity if you want gravitational acceleration).
  • A two-dimensional array of bools (or colours), representing the fixed parts of the world.

The simplest physics model is to remove a grain once it is at rest (e.g. when the world positions below, below to the left and below to the right are filled): instead, the corresponding world coordinate is filled in. This keeps the calculations manageable. Allow a grain to shift down if either the left or right below world coordinate is free. Grain collisions between moving grains can be ignored without loss of much verisimilitude.

(I can't quite get over how much CPU power we've got to spare these days!)

like image 112
Pontus Gagge Avatar answered Sep 28 '22 17:09

Pontus Gagge