How can I create moving water (2D) in BlitzMax?
I'm thinking of simple waves that move from left-to-right (or right-to-left). More specifically, remember the water at the bottom of a Worms level? That's what I'm trying to recreate :)
I'm found some code in the archives but they are only for BlitzPlus AND they really aren't exactly what I'm looking for (although they aren't that bad...)
Make an image of a /\ triangle, move it from left to right while scaling it up and down on the Y axis. Also need to reposition it as you do so, the effect is nice and the code simple.
Repeat for as many waves as you need
or you could just have tiled animated sprites.
Like this?
Graphics 640,480
Local image:TImage = LoadImage(MakeWavePix(64,64,16))
Local a:Float = 0
Local offx:Int = 0
Local offy:Int = 0
While Not KeyHit(KEY_ESCAPE)
Cls
a:+5
offx = (offx + 1) Mod 64
offy = 8+Sin(a)*8
For Local x:Int = -64 To GraphicsWidth() Step 64
DrawImage image,x+offx,GraphicsHeight()-64+offy
Next
Flip
Wend
Function MakeWavePix:TPixmap(w:Int,h:Int,wh:Int,red:Int=100,grn:Int=120,blu:Int=200)
Local p:TPixmap = CreatePixmap(w,h,PF_RGBA8888)
Local argb0:Int = $FF000000 | (red Shl 16) | (grn Shl 8) | blu
Local argb1:Int = $00000000 | (red Shl 16) | (grn Shl 8) | blu
For Local x:Int = 0 Until p.width
Local a:Float = (x/Float(p.width)) * 360.0
Local c:Int = (Cos(a)*0.5*wh) + wh
For Local y:Int = 0 Until p.height
If y<c
p.WritePixel(x,y,argb1)
Else
p.WritePixel(x,y,argb0)
EndIf
Next
Next
Return p
EndFunction
Fredborg, I agree with Lars. Elegant and simple!
I think worms just had an animated sprite, or set of them in parallax, pasted down there.