Author Topic: Fluid simulation in Game Maker  (Read 7737 times)

0 Members and 1 Guest are viewing this topic.

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Fluid simulation in Game Maker
« on: November 01, 2011, 04:49:01 pm »
New Version 2 out. Click here

I made a very simple fluid simulation in Game Maker:

Link to video

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: [Select]
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?
« Last Edit: November 07, 2011, 06:11:21 pm by Spyro543 »

Offline DJ Omnimaga

  • Former TI programmer
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55847
  • Rating: +3151/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • DJ Omnimaga Music
Re: Fluid simulation in Game Maker
« Reply #1 on: November 01, 2011, 08:40:21 pm »
Looks pretty interesting.  I wonder how the speed compares with a calc equivalent? I unfortunately forgot where was located Builderboy's Axe version on the forums. XD Also to run the gm81 file do I need Game Maker installed? I wonder if you could make an exe file if that's the case?
In case you are wondering where I went, I left Omni back in 2015 to form CodeWalrus due to various reasons explained back then, but I stopped calc dev in 2016 and am now mostly active on the CW Discord server at https://discord.gg/cuZcfcF



Official Website |T-Shirt store | Reverbnation | Facebook | Youtube | Twitter | Spotify

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Fluid simulation in Game Maker
« Reply #2 on: November 01, 2011, 08:48:01 pm »
Here it is DJ http://ourl.ca/4279/169816 :D It's part of the physics lessons tutorials.  And nice implementation!  It seems you stumbled upon the same set of rules that I used! ^^

Offline DJ Omnimaga

  • Former TI programmer
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55847
  • Rating: +3151/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • DJ Omnimaga Music
Re: Fluid simulation in Game Maker
« Reply #3 on: November 01, 2011, 08:55:20 pm »
Ah thanks :D. I like that kind of demo.
In case you are wondering where I went, I left Omni back in 2015 to form CodeWalrus due to various reasons explained back then, but I stopped calc dev in 2016 and am now mostly active on the CW Discord server at https://discord.gg/cuZcfcF



Official Website |T-Shirt store | Reverbnation | Facebook | Youtube | Twitter | Spotify

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: Fluid simulation in Game Maker
« Reply #4 on: November 02, 2011, 06:21:42 am »
Here it is DJ http://ourl.ca/4279/169816 :D It's part of the physics lessons tutorials.  And nice implementation!  It seems you stumbled upon the same set of rules that I used! ^^
Yeah I actually used your cellular automata tutorials to make this ^_^

Offline C0deH4cker

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 258
  • Rating: +11/-1
    • View Profile
    • iNinjas Forum/Repo
Re: Fluid simulation in Game Maker
« Reply #5 on: November 02, 2011, 10:13:30 am »
I could compile it into an exe for ya. i have the full 8.1 version.

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: Fluid simulation in Game Maker
« Reply #6 on: November 03, 2011, 03:09:20 pm »
I could compile it into an exe for ya. i have the full 8.1 version.
Thanks! For some reason, GM 8.1 won't accept my license I paid for...

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: Fluid simulation in Game Maker
« Reply #7 on: November 07, 2011, 06:10:07 pm »
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!
« Last Edit: November 07, 2011, 06:28:51 pm by Spyro543 »

Offline DJ Omnimaga

  • Former TI programmer
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55847
  • Rating: +3151/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • DJ Omnimaga Music
Re: Fluid simulation in Game Maker
« Reply #8 on: November 07, 2011, 06:38:54 pm »
Isn't GM supposed to be free including for compiling? I saw many GM games being compiled using free versions before, the only difference being that no 3D was possible and there was a GM advertisement at the beginning when it was loading.

Btw this looks really nice. :D
« Last Edit: November 07, 2011, 06:40:40 pm by DJ_O »
In case you are wondering where I went, I left Omni back in 2015 to form CodeWalrus due to various reasons explained back then, but I stopped calc dev in 2016 and am now mostly active on the CW Discord server at https://discord.gg/cuZcfcF



Official Website |T-Shirt store | Reverbnation | Facebook | Youtube | Twitter | Spotify

Offline collechess

  • LV3 Member (Next: 100)
  • ***
  • Posts: 93
  • Rating: +22/-2
    • View Profile
Re: Fluid simulation in Game Maker
« Reply #9 on: November 07, 2011, 08:51:22 pm »
Do you have plans for adding other particles?  And does the sand and water interact? e.g. Does the sand sink?  Also, you might find that making the particles larger might be better, as GM gets really slow when you add a lot of objects.  This does look really cool though.  ;)

Offline imo_inx

  • Manman, SaviourOfTheMultiverse!
  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 473
  • Rating: +27/-8
  • imo_inx
    • View Profile
Re: Fluid simulation in Game Maker
« Reply #10 on: December 06, 2011, 04:43:55 pm »
Update: I guess I can help with it now. :P I added some new elements.

Changes:
Fazer added (allows particles to pass through for 1 second every 2 seconds)
Lava added
Bouncers added

I need help on the Lava+Water=Stone problem though, as "change object" and "create instance" don't seem to work.


Offline JL235

  • LV3 Member (Next: 100)
  • ***
  • Posts: 57
  • Rating: +13/-0
    • View Profile
    • Play My Code
Re: Fluid simulation in Game Maker
« Reply #11 on: December 10, 2011, 09:34:40 am »
I always love these, and as inspiration I cooked up my own version (much smaller) a week ago online here.
« Last Edit: December 10, 2011, 09:34:52 am by JL235 »
Build games in the browser at PlayMyCode.com, @playmycode