# Settling Mud Script

2 replies to this topic

### #1 wiiowner

wiiowner

Absolute Zero Team

• New Member
• 685 posts

Posted 04 April 2009 - 08:53 PM

Hey everyone I'm back with another script, this one is for mud (it was originally going to be water but it didn't look good). What this script does is it just takes the average of 2 points on the mud to either side of the current one. It is easily changeable so that it takes more points into account but I am going to leave it like it is. Here is the script:
`//Mud Settling Script//Usage: scr_draw_mud(length,accuaracy,x1,y1)for(i=0; i<argument1; i+=1){if i>1 and i<argument1-2 {water_array[i] = mean(water_array[i-2],water_array[i-1],water_array[i],water_array[i+1],water_array[i+2])} if i>0 and i<argument1-1 {water_array[i] = mean(water_array[i-1],water_array[i],water_array[i+1])} if i = 0 {water_array[i] = mean(water_array[i],water_array[i+1],0)} if i = argument1 {water_array[i] = mean(water_array[i-1],water_array[i],0)}}for(j=0; j<argument1; j+=1){if j<argument1-1 {draw_line((argument2+j)*((argument0+argument1)/argument1),argument3+water_array[j],(argument2+(j+1))*((argument0+argument1)/argument1),argument3+water_array[j+1])}}`
The only thing you have to do first is in the create event you have to initialize water_array[] this is quite simple and here is an example:
`for(i=0; i<64; i+=1){water_array[i] = 0}`
The 64 in there has to be the same as the quality in the real script. I count all this as 1 script because initializing it doesn't really count. I have created an example of it right here:
I also have a screenshot of it in action:
There is one bug I am aware of where sometimes the right edge gets changed and the whole thing screws up but that doesn't happen very often. Thanks you for you time and please post with feedback.
• 0
Completed Projects: Eco-Chrome || Conway's Game of Life - Update that triples framerate!
Scripts: Grid Based Lighting (With Dynamic Soft Shadows) || Mud Physics

### #2 Dark Mario

Dark Mario

GMC Member

• New Member
• 125 posts

Posted 20 April 2009 - 08:57 PM

Cool.

For what can it be used for?

btw

How did you draw a curve?
I can't fully understand your code.
• 0
Hello fellow people of Earth.
I am in the making of a game called In Dig Nation.

### #3 wiiowner

wiiowner

Absolute Zero Team

• New Member
• 685 posts

Posted 20 April 2009 - 09:37 PM

Well it draws lines between each point and the points are fairly close together which gives the illusion of a curve. Try setting the accuracy to something low and you'll see. I'm really sure what it can be used for, maybe like quicksand in a platform game or something, or you might be able to modify it for use in GM Physics so that stuff can roll on it. It's up to you . Thanks though.
• 0
Completed Projects: Eco-Chrome || Conway's Game of Life - Update that triples framerate!
Scripts: Grid Based Lighting (With Dynamic Soft Shadows) || Mud Physics