yes, but implementing this here is difficult, I tried several things in different parts of the code but nothing seems to work
I tried everything to this point.
this is the code without modifications
// set window properties
SetWindowTitle( "Water" )
SetWindowSize( 1080, 720, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1080, 720 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
//SetSyncRate(0, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetVSync(1)
SetClearColor(43, 178, 233)
global gTension as float = 0.05
global gDampening as float = 0.02
global gSpread as float = 0.25
type tColumn
targetHeight as float
height as float
speed as float
id as integer
x as float
endtype
columns as tColumn[]
//Actot
CreateSprite(1, 0)
SetSpriteSize(1, 70, 125)
SetSpriteOffset(1 , GetSpriteWidth(1)/2, GetSpriteHeight(1)/2)
setspritephysicsOn(1, 2)
SetSpritePhysicsCanRotate(1, 0)
#constant KEY_1 49
#constant KEY_2 50
//Water
InitializeColumns(columns)
//Ground
CreateSprite(2, 0)
SetSpriteSize(2, 800, 180)
SetSpritePosition(2, columns[columns.length].x, 580)
setspritephysicsOn(2, 1)
SetSpriteColor(2, 0, 181, 0, 255)
do
x = GetSpriteXByOffset(1)
y = GetSpriteYByOffset(1) + (GetSpriteHeight(1)/2)
if GetSpriteHit(x, y) > 0 and GetSpriteHit(x, y) <> 1 and (y < 660 and y > 620)
Splash(columns, x, y)
endif
Print ( "Frame rate = " + str ( screenFPS ( ) ) )
// A W D
if GetRawKeyState(68)
if not GetSpritePhysicsVelocityX(1) > 260
SetSpritePhysicsVelocity(1, 250, GetSpritePhysicsVelocityY(1))
endif
elseif GetRawKeyState(65)
if not GetSpritePhysicsVelocityX(1) < -260
SetSpritePhysicsVelocity(1, -250, GetSpritePhysicsVelocityY(1))
endif
endif
if GetRawKeyPressed(87)
SetSpritePhysicsImpulse(1, 0, 0, 0, -650)
endif
// Change FPSs
if GetRawKeyPressed(KEY_1)
SetVSync(1)
endif
if GetRawKeyPressed(KEY_2)
SetSyncRate(0, 1)
endif
SetSpritePosition(1, GetPointerX(), GetPointerY())
CreateRipple(columns)
Sync()
loop
function Splash(columns ref as tColumn[], x as integer, y as integer)
i as integer
id as integer
for i = 0 to columns.length - 1
if GetSpriteXByOffset(columns[i].id) > x
exit
endif
next
columns[i-1].Speed = (y - columns[i].targetHeight)
columns[i].Speed = (y - columns[i].targetHeight)
columns[i+1].Speed = (y - columns[i].targetHeight)
endfunction
function CreateRipple(columns ref as tColumn[])
i as integer : j as integer
for i=0 to columns.length
UpdateColumn(columns[i])
next
lDeltas as float[] : lDeltas.length = columns.length
rDeltas as float[] : rDeltas.length = columns.length
// do some passes where columns pull on their neighbours
for j = 0 to 7
for i=0 to columns.length
if i > 0
lDeltas[i] = gSpread * (columns[i].height - columns[i - 1].height)
inc columns[i - 1].Speed, lDeltas[i]
endif
if i < columns.Length
rDeltas[i] = gSpread * (columns[i].Height - columns[i + 1].Height)
inc columns[i + 1].Speed, rDeltas[i]
endif
next
for i = 0 to columns.length
if i > 0 then inc columns[i - 1].Height, lDeltas[i]
if i < columns.Length then inc columns[i + 1].Height, rDeltas[i]
next
next
endfunction
function UpdateColumn(column ref as tColumn)
x as float
x = column.targetHeight - column.height
inc column.speed, gTension * x - column.speed * gDampening
inc column.height, column.speed
SetSpritePositionByOffset(column.id, GetSpriteXByOffset(column.id), column.height)
endfunction
function InitializeColumns(columns ref as tColumn[])
i as integer
c as tColumn
s as float
LoadImage(50, "waterTexture.png")
s = GetVirtualWidth() / (GetVirtualWidth()/5 + 0.0)
for i=0 to 150 //columns.length
c.height = 620
c.targetHeight = 620
c.speed = 0
c.x = (s * i)
c.id = CreateSprite(0)
SetSpriteSize(c.id, 5, 400)
SetSpriteOffset(c.id,5,0)
SetSpriteImage(c.id, 50)
SetSpritePositionByOffset(c.id, c.x, 240)
columns.insert(c)
next
endfunction
I tried to reduce the deltas according to the frame rate, but it didn't make any difference either
if i > 0
lDeltas[i] = gSpread * (columns[i].height - columns[i - 1].height)
inc columns[i - 1].Speed, lDeltas[i]
endif
if i < columns.Length
rDeltas[i] = gSpread * (columns[i].Height - columns[i + 1].Height)
inc columns[i + 1].Speed, rDeltas[i]
endif