I'm making another physics toy, this is the loop which transmits air pressure to the surrounding squares. However The whole screen almost instantly fills up with air as soon as I put 1 bit of air into the simulation and the program crashes, the number is too high for the int64. I cannot see where I am going wrong, maybe one of you can see?
For x As Integer = 1 To 78 For y As Integer = 1 To 58 If terrain(x, y).type = "air" Then Dim possiblemove As Integer = 1 Dim pressuretotal As Decimal If terrain(x + 1, y).type = "air" Then possiblemove += 1 : pressuretotal += terrain(x + 1, y).pressure If terrain(x - 1, y).type = "air" Then possiblemove += 1 : pressuretotal += terrain(x - 1, y).pressure If terrain(x, y + 1).type = "air" Then possiblemove += 1 : pressuretotal += terrain(x, y + 1).pressure If terrain(x, y - 1).type = "air" Then possiblemove += 1 : pressuretotal += terrain(x, y - 1).pressure Dim unitpressure As Decimal = (pressuretotal / possiblemove) terrain(x, y).tpressure += unitpressure If terrain(x + 1, y).type = "air" Then terrain(x + 1, y).tpressure += unitpressure If terrain(x - 1, y).type = "air" Then terrain(x - 1, y).tpressure += unitpressure If terrain(x, y + 1).type = "air" Then terrain(x, y + 1).tpressure += unitpressure If terrain(x, y - 1).type = "air" Then terrain(x, y - 1).tpressure += unitpressure End If Next Next
For x As Integer = 1 To 78 For y As Integer = 1 To 58 terrain(x, y).pressure = terrain(x, y).tpressure terrain(x, y).tpressure = 0 Next Next
If it can move only right, it can still have air in itself. So its 1 + 1 direction. So if you have 100 it will be split between the 2 with 50 each. if there were 3 possible directions it would be 33 each.