Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Water...?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
amz_best




PostPosted: Sat Jan 03, 2015 6:33 pm   Post subject: Water...?

What is it you are trying to achieve?
I don't have the slightest clue about how to program water with water physics. I did search it up, and it talk about pressure and viscosity and elasticity... which is not wut i was looking for.


What is the problem you are having?
No idea where to begin


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Literally the only thing i could think off...

Turing:

setscreen ("graphics:500, 500, offscreenonly")
var x, y : int := maxx div 2
loop
    cls
    x += Rand.Int (-1, 1)
    y += Rand.Int (-1, 1)
    drawfillbox (x, y, x + 50, y + 10, blue)
    View.Update
end loop



Please specify what version of Turing you are using
Latest
Sponsor
Sponsor
Sponsor
sponsor
Nathan4102




PostPosted: Sat Jan 03, 2015 6:58 pm   Post subject: RE:Water...?

Do you have any experience working with physics and programming together? Are you able to simulate a bouncing ball first? I don't know how to program realistic liquid physics, but I know it isn't simple with no experience.
Zren




PostPosted: Sat Jan 03, 2015 7:04 pm   Post subject: RE:Water...?

By water, what do you mean? Do you mean an area that the player moves through slowly? You can get away with a drawing the area blue. If you want waves, then things get a lot more complicated.

As a stepping stone project, make a particle engine. In other words, a flexible array of points that move independently according to their own velocity.
amz_best




PostPosted: Sat Jan 03, 2015 7:20 pm   Post subject: Re: Water...?

Here is the bouncing ball program you wanted:

Turing:

setscreen ("graphics:500, 500, offscreenonly")
const bRadius : int := 5
var bX, bY : real := maxx / 2
bY := 50
var bouncePower : real := 5
var fallVel : real := 0

loop
    if bouncePower <= 0.01 then
        exit
    else
        if bY >= (bRadius + fallVel) then
            fallVel += 0.1
        else
            bY := (bRadius + fallVel)
            bouncePower -= fallVel / 10
            fallVel := 0
        end if
    end if
    cls
    bY += bouncePower
    bY -= fallVel

    drawoval (round (bX), round (bY), bRadius, bRadius, black)
    delay (10)
    View.Update ()
end loop


I've seen water with waves, and its super complicated. All i want is simple block water. Im making Terraria.
Insectoid




PostPosted: Sat Jan 03, 2015 8:30 pm   Post subject: RE:Water...?

Quote:
I've seen water with waves, and its super complicated.


Water IS super complicated. Even simple block water. I'm not saying you can't do it, but it will take a lot of thought. Take a very close look at Terraria's water system and try to define how it behaves. Here's some things you should think about:

-How can we calculate the proper height & width of the pool?
-How can we check if there is a leak or overflow?
-How can individual blocks of water behave?

You can cheat for now and ignore pressure, etc. I doubt even Terraria uses them.
amz_best




PostPosted: Sun Jan 04, 2015 6:30 pm   Post subject: RE:Water...?

We know that water moves, meaning that is you check a the previous cell of water in a current section of a loop, it might be on the opposite side of the screen. Is there anyway to reorganize an array so that the previous cell becomes the one right beside it?

OR even better,

Somehow get information about the surrounding area of the cell?
Insectoid




PostPosted: Sun Jan 04, 2015 7:38 pm   Post subject: RE:Water...?

Quote:
Is there anyway to reorganize an array so that the previous cell becomes the one right beside it?


There are many ways, most of which are really easy. You can figure that out on your own.


Try making a program that just fills up a rectangular bucket (a U shape, basically) with water. Design it so the height of the water is a variable, so you can change the height by changing the variable. From there, you might add in a feature that automatically adjusts the height if the size of the bucket changes, to preserve volume (this is important). This will only require basic math operations to do, so you should be able to figure it out. From there, you'll notice some problems that are a little more complicated but can be solved with a lot of work.
amz_best




PostPosted: Tue Jan 06, 2015 5:05 pm   Post subject: Re: Water...?

I got water working on my game, using this guide:
http://w-shadow.com/blog/2009/09/01/simple-fluid-simulation/

I added a variable for each block, every block has a fluid mass between 0 and 1 by 0.1.
However, their is a new problem.

All blocks on my screen in loaded by a for loop, from left to right.
When Water flows to the right, it ends up on the end of the screen.

Why is this happening? how do i fix it?
Sponsor
Sponsor
Sponsor
sponsor
Nathan4102




PostPosted: Tue Jan 06, 2015 5:35 pm   Post subject: RE:Water...?

Can you provide a code snippet or a working example?
amz_best




PostPosted: Tue Jan 06, 2015 5:53 pm   Post subject: Re: Water...?

This is the code used for moving the blocks left and right. its litterally the exact same, but im still getting weird results..

i - Vertical Number
s - Horizontal Number

changeInFlow := 0.1

fMass (fluid Mass) is always either, or between 0 and 1.



capture screen.PNG
 Description:
 Filesize:  8.17 KB
 Viewed:  3050 Time(s)

capture screen.PNG


Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: