New Version 2 out. Click here

I made a very simple fluid simulation in Game Maker:


Here's the source: http://anova.57o9.org/junk/fluid.gm81

The controls are: click to place a wall block, right click to release water, Shift to erase whatever is currently under the mouse, Delete to erase everything, and Enter to make a water pump that continually releases water.

The cellular automata rules are very simple:
1. If space to left empty: move left
2. If space to right empty: move right
3. If both left and right spaces are empty: randomly move either left or right
4. If space below empty: move down

Here's the code I used to simulate the water physics:

Code:
if position_empty(x,y+6)
{
y = y + 6;
exit
}
if position_empty(x+6,y) and position_empty(x-6,y)
{
randrange = irandom_range(1,2);
if randrange = 1 {x += 6};
if randrange = 2 {x -= 6};
exit
}
if position_empty(x+6,y)
{
x += 6
exit
}
if position_empty(x-6,y)
{
x -= 6
exit
}


I know I need to add a toolbar or a little box that shows the commands you can use in the next release. Besides this, any other suggestions or comments?
ooh, not bad spyro, it reminds me a lot of the powder game, in some aspects. Good work Smile
Thanks! It wouldn't be too hard to add other elements. I should do that now!
UPDATE!!! (v2)
Awesome updates!!!

    Particles are now 1 pixel big instead of 6*6 pixels
    Different control scheme
    New particle addition: Sand

Here's the new controls:

    Left click draws walls
    Right click erases whatever is under the mouse
    "W" button creates water
    "S" button creates sand
    Enter creates a water pump
    Delete erases entire board


Here's a video for your enjoyment:


Source file: http://anova.57o9.org/junk/fluid.gm81
If anyone with GM 8.1 Pro could compile this, that would be great!
Spyro: that seems extremely straightforward; congrats on an efficient and correct solution. Do you have any further plans to play with it in GameMaker? If not, may I recommend that you might want to start exploring some of the more "serious" languages, and perhaps consider implementing that in those as a fun example project to motivate your learning? I might recommend, among others, C++, Python, Java, z80 ASM, (even TI-BASIC!), and perhaps C#.
Kerm, do note that with C#, you will probably need the XNA game studio for creating certain types of games, especially ones with sprites. Plain C# is fine for text games though.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement