PDA

View Full Version : Simple falling sand game in Pascal?



paul_nicholls
22-09-2008, 11:36 PM
Hi all,
I have looked at the falling sand game here http://chir.ag/stuff/sand/ and I was wondering how on earth you would code something like this?

I want to start simple and only make particles fall and be constrained by walls like in this game, but I wouldn't know where to start...

Anyone have any ideas?

EDIT:

I did find these links after some more googling:

http://www.piettes.com/fallingsandgame/index.html - C++ Falling sand game
clone
http://www.piettes.com/fallingsandgame/download.html - sources and binaries for C++ falling sand game clone.

Cheers,
Paul.

czar
23-09-2008, 02:04 AM
No ideas how to make it - but it it is really cool once you work out what is going on

czar
23-09-2008, 02:07 AM
http://phoenix.forest-tm.com/?p=48


So, lets start with the solver itself! I wrote SAB in Delphi, so all of the code here will be in Delphi. Don’t worry, it’s not hard, think of it as of psuedo code

paul_nicholls
23-09-2008, 02:34 AM
http://phoenix.forest-tm.com/?p=48


So, lets start with the solver itself! I wrote SAB in Delphi, so all of the code here will be in Delphi. Don’t worry, it’s not hard, think of it as of psuedo code

Thanks for that link czar!! It will be very useful!! :)

cheers.
Paul

User137
23-09-2008, 12:20 PM
You have a bunch of particles and also solid pixel map to use, or if memory and speed is not an issue it would be easiest if everything is particles. Used graphics engine don't matter much, it could be basic WinAPI, OpenGL etc. they just draw everything little differently but basic code behind is independent of engine.

Each particle follows given laws of physics, gravity and collisions to pixelmap/materialmap, and when they make a complete stop, insert them in pixelmap and remove particle itself. Information about particle type should be later seen as color in pixelmap or a separate materialmap (just a 2 dimensional array of bytes).

There is also a detach behaviour to clear a pixel and make it a particle again, that triggers when neigbour particle (that is up, down, left or right of it) makes a move off, or a hole is made in pixelmap. This makes solid water flow down again once the floor is removed, even if the water itself is stabilized to 0 particles and all pixelmap.

cronodragon
23-09-2008, 01:53 PM
Something is missing there is the electrostatic force that keeps particles together, maybe that could added to the implementation for a more realistic effect. And maybe a game could be made about picking charged particles with a brush... just an idea. :D