Unterwassereffekt für 2D Spiel

Übersicht BlitzBasic Blitz3D

Neue Antwort erstellen

WEBLink

Betreff: Unterwassereffekt für 2D Spiel

BeitragDo, Sep 18, 2008 19:40
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi,

wüsstet ihr einen guten Unterwassereffekt für 2D Spiele. Eine Art verzerren eines Bildschirmbereichs eventuell?

MfG

SYSThern

BeitragDo, Sep 18, 2008 19:55
Antworten mit Zitat
Benutzer-Profile anzeigen
hallo

soll das wasser transparent sein??

wenn ja und du hast b3d nimm Draw3D

https://www.blitzforum.de/foru...hp?t=21659

von hectic

zu deiner frage ich glaub man kann das mit der draw3d auch machen verzerren

sry wenn ich mich ihre
mfg SYSThern
Tools and Programms
--------------------
www.systhern.de

Rone

BeitragFr, Sep 19, 2008 20:03
Antworten mit Zitat
Benutzer-Profile anzeigen
Zitat:
soll das wasser transparent sein??

Also ich wüsste spontan nicht, wie man sowas ohne 3d machen könnte...unabhängig von transparenz.

hab das mal ausprobiert: hier
Edit: Bild
Code: [AUSKLAPPEN]

Strict

Framework brl.basic
Import brl.max2d
Import brl.GLmax2d
Import brl.pngloader


Type TileMap
   
   Field TileMap:TImage
   Field frame:TGLImageFrame
   Field uStep:Float
   Field vStep:Float
   
   Field _width:Int
   Field _height:Int
   Field _tilesize:Int
   
   Field _vertexCoords:Float[]
   Field _vertcol:Float[]
   Field _texCoords:Float[]
   Field _tris:Short[]
   

   Method SetTileSet(image:timage, tilesize:Int)
      tilemap = image
      frame = TGLImageFrame( image.Frame( 0 ) )
   End Method
   
   Method Create:TileMap(width:Int , height:Int , tilesize:Int )
      
      _width = width
      _height = height
      
      _vertexCoords = _vertexCoords [..width * height * 4 *3]
      _texCoords= _texCoords[..width * height * 4 * 2]
      _vertcol = _vertcol[..width * height * 4 * 4]
      _tris = _tris[..width*height*2*3]
      
      uStep = 1.0 / Float(width)
      vStep = 1.0 / Float(height)

      Local xpos:Int = -100
      Local ypos:Int = -256
      
      For Local iy:Int = 0 Until height
         For Local ix:Int = 0 Until width
            Local vertIndex:Int = (iy * width + ix) *3 *4
            
            _vertexCoords[vertIndex] = xpos + ix * 32
            _vertexCoords[vertIndex + 1] = ypos + iy * 32
            _vertexCoords[vertIndex+ 2] = 0 ' z
            
            _vertexCoords[vertIndex + 3] = xpos + (ix + 1) * 32
            _vertexCoords[vertIndex + 4] = ypos + (iy * 32)
            _vertexCoords[vertIndex+ 5] = 0 ' z
            
            _vertexCoords[vertIndex + 6] = xpos + (ix + 1) * 32
            _vertexCoords[vertIndex + 7] = ypos + (iy + 1) * 32
            _vertexCoords[vertIndex+ 8] = 0 ' z
            
            _vertexCoords[vertIndex + 9] = xpos + (ix) * 32
            _vertexCoords[vertIndex + 10] = ypos + (iy + 1) * 32
            _vertexCoords[vertIndex + 11] = 0 ' z
            
            Local vertexTexIndex:Int = (iy * width + ix) * 2 * 4
            
            _texCoords[vertexTexIndex] = Float(ix) * uStep'0.0
            _texCoords[vertexTexIndex + 1] = Float(iy) * vStep'0.0
            
            _texCoords[vertexTexIndex + 2] = Float(ix + 1) * uStep'uStep
            _texCoords[vertexTexIndex + 3] = Float(iy) * vStep'0.0

            _texCoords[vertexTexIndex + 4] = Float(ix + 1) * uStep'uStep
            _texCoords[vertexTexIndex + 5] = Float(iy + 1) * vStep'vStep

            _texCoords[vertexTexIndex + 6] = Float(ix) * uStep'0.0
            _texCoords[vertexTexIndex + 7] = Float(iy + 1) * vStep'vStep

            
            Local colorIndex:Int = (iy * width + ix) * 4 * 4
            
            Local alpha:Float = 1.0'Float( Rand(50,255) / 255.0 )
            _vertcol[colorIndex] = 1.0
            _vertcol[colorIndex + 1] = 1.0
            _vertcol[colorIndex + 2] = 1.0
            _vertcol[colorIndex + 3] = alpha
                        
            _vertcol[colorIndex + 4] = 1.0
            _vertcol[colorIndex+5] = 1.0
            _vertcol[colorIndex + 6] = 1.0
            _vertcol[colorIndex+7] = alpha


            _vertcol[colorIndex + 8] = 1.0
            _vertcol[colorIndex + 9] = 1.0

            _vertcol[colorIndex+10] = 1.0
            _vertcol[colorIndex+11] = alpha

            _vertcol[colorIndex+12] = 1.0
            _vertcol[colorIndex+13] = 1.0
            _vertcol[colorIndex + 14] = 1.0
            _vertcol[colorIndex+ 15] = alpha

         
            Local triIndex:Int = (iy * width + ix ) * 2 * 3
            Local triVertIndex:Int = (iy * width + ix ) * 4

            _tris[triIndex] = triVertIndex
            _tris[triIndex+1] = triVertIndex+ 1
            _tris[triIndex + 2] = triVertIndex+ 2
            
            _tris[triIndex+3] = triVertIndex+ 2
            _tris[triIndex+4] = triVertIndex+ 3
            _tris[triIndex+5] = triVertIndex+ 0

         Next
      Next
      
      Return Self
      
   End Method
   
   
   Method Update(time:Int)
   
      Local xpos:Int = -100
      Local ypos:Int = -256
      
      For Local iy:Int = 0 Until _height
         For Local ix:Int = 0 Until _width
            
            
            Local vertIndex:Int = (iy * _width + ix) *3 *4
            
            _vertexCoords[vertIndex] = xpos + ix * 32 + Sin(time + iy * 50) * 7
            _vertexCoords[vertIndex + 1] = ypos + iy * 32 + Sin(time + ix * 50) * 7
            _vertexCoords[vertIndex+ 2] = 0 ' z
            
            _vertexCoords[vertIndex + 3] = xpos + (ix + 1) * 32 + Sin(time + (iy) * 50) * 7
            _vertexCoords[vertIndex + 4] = ypos + (iy * 32) + Sin(time + (ix + 1) * 50) * 7
            _vertexCoords[vertIndex+ 5] = 0 ' z
            
            _vertexCoords[vertIndex + 6] = xpos + (ix + 1) * 32 + Sin(time + (iy + 1) * 50) * 7
            _vertexCoords[vertIndex + 7] = ypos + (iy + 1) * 32 + Sin(time + (ix + 1) * 50) * 7
            _vertexCoords[vertIndex+ 8] = 0 ' z
            
            _vertexCoords[vertIndex + 9] = xpos + (ix) * 32 + Sin(time + (iy + 1) * 50) * 7
            _vertexCoords[vertIndex + 10] = ypos + (iy + 1) * 32 + Sin(time + (ix) * 50) * 7
            _vertexCoords[vertIndex + 11] = 0 ' z

            
            
         Next
      Next      
         
   End Method
   
   
   Method Render()

      
      ' Blending
      glEnable GL_BLEND
      glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
      glAlphaFunc(GL_GREATER, 0.0) ;
      glEnable(GL_ALPHA_TEST)

      ' Enable texture      
      glEnable GL_TEXTURE_2D
      glBindTexture GL_TEXTURE_2D , frame.name


      ' Rendering
      glEnableClientState(GL_COLOR_ARRAY);
      glEnableClientState(GL_VERTEX_ARRAY) ; '
      glEnableClientState(GL_TEXTURE_COORD_ARRAY )
      '
      glTexCoordPointer(2,GL_FLOAT,0,_texCoords)
      glVertexPointer(3 , GL_FLOAT , 0 , _vertexCoords)   
      glColorPointer(4 , GL_FLOAT , 0 , _vertcol)   
      
      glDrawElements(GL_TRIANGLES , _width*_height*2*3, GL_UNSIGNED_SHORT , _tris)

      glDisableClientState(GL_COLOR_ARRAY);
      glDisableClientState(GL_VERTEX_ARRAY) ;
      glDisableClientState(GL_TEXTURE_COORD_ARRAY)
      
      
   End Method
   
End Type

'#################################################################

SetGraphicsDriver(GLMax2DDriver())
Graphics 800, 600
SetClsColor 255, 255, 255

Incbin "bla.png"
Local img:TImage = LoadImage("incbin::bla.png")

Local map:TileMap = New TileMap
map.SetTileSet(img, 32)
map.Create(32 , 32 , 32)

'#################################################################

Repeat
   
   Cls
   map.Update(MilliSecs() / 6)
   map.Render()
   Flip

Until KeyHit(KEY_ESCAPE)

End

SYSThern

BeitragSo, Sep 21, 2008 16:23
Antworten mit Zitat
Benutzer-Profile anzeigen
hat er bmax??

er posted ja in b3d forum...
Tools and Programms
--------------------
www.systhern.de

WEBLink

BeitragMo, Sep 29, 2008 6:12
Antworten mit Zitat
Benutzer-Profile anzeigen
@ Rone

Du hast die Sache schon sehr gut getroffen. Ich habe zwar BMax das Spiel ist aber in Blitz3D.

Draw3D hab ich natürlich auch Very Happy, also müsste ich es mit DrawQuad machen. Ist es denn dann möglich z. B. an der Maus ein Rechteck zu zeichnen und alles was unter dem rechteck ist verschimmt so wie es in deinem BMax Beispiel ist.


MfG

Rone

BeitragMo, Sep 29, 2008 11:13
Antworten mit Zitat
Benutzer-Profile anzeigen
Ob BMax oder Blitz3d spielt keine Rolle.
Ist immer das gleiche, einfach X und Y Positionen der Eckpunkte der Tiles mit Sinus/Cosinus verschieben...
Code: [AUSKLAPPEN]
Function UpdateMap(time#)

   For iy= 0 to _height -1
           For ix= 0 Until _width -1
   
         anim# = Sin(time + iy * 50) * 7
   
         x1# = xpos + ix * tilesize + anim#
         y1# = ypos + iy * tilesize + anim#
   
         x2# = xpos + (ix + 1) * tilesize + anim#
         y2# = ypos + iy * tilesize + anim#

         x3# = xpos + (ix + 1) * tilesize + anim#
         y3# = ypos + (iy + 1) * tilesize + anim#

         x4# = xpos + ix * tilesize + anim#
         y4# = ypos + (iy + 1) * tilesize + anim#
   
         DrawQuad3D handle, x1#, y1#, x2#, y2#, x3#, y3#, x4#, y4#
      next
   next

end function

hectic

Sieger des IS Talentwettbewerb 2006

BeitragMo, Sep 29, 2008 12:08
Antworten mit Zitat
Benutzer-Profile anzeigen
Mit der Draw3D wird es nur beding richtig funktionieren. Es liegt zwar so ein ähnliches Programmbeispiel dem Paket bei, aber dieses verschwimmt nicht den Hintergrund, sondern zeichnet die Quads direkt so ein. Wenn der Hintergrund verschwimmen soll, dann müßte man den Screen in eine Textur rendern und dann entsprechend die Stellen (zum Beispiel mit DrawQuad3D) nachzeichnen. Leider kann Blitz3D von Haus aus kein render-to-texture was die Sache sehr langsam macht. Bei einer Tileengine könnte man allerdings ohne große Recourcenverschwendung die entsprechende Teile animiert mit DrawQuad3D einzeichnen. Das würde allerdings nicht 100%ig den erwünschten Effekt bringen.
Download der Draw3D2 V.1.1 für schnelle Echtzeiteffekte über Blitz3D

Rone

BeitragMo, Sep 29, 2008 22:13
Antworten mit Zitat
Benutzer-Profile anzeigen
Das geht mit Draw3d genauso wie in dem BMax Beispiel von mir.
Hätte mich auch gewundert, wenn DrawQuad sich anders verhalten würde...

Bild
Exe

Code: [AUSKLAPPEN]
AppTitle "Draw3D - 2d Wasser"
Graphics3D 800,600,0,2
SetBuffer BackBuffer()

Local Timer=CreateTimer(60)
Local Camera=CreateCamera()
CameraClsColor Camera,64,64,64

Include "Includes\Draw3D.bb"
DrawInit3D(Camera)
Origin3D(800,600)

SetFont3D(1,1,-6,0)
Local Main=LoadImage3D("bla.png",2,2,0)

;Local tileset=GrabImage3D(Main,0,128,64,64)


Dim tileset(33,33)


For iy = 0 To 30
   For ix = 0 To 30
      tileset(ix,iy) = GrabImage3D(Main,ix*32,iy*32,32,32)

   Next
Next


Global tilesize  = 32

xpos = -450
ypos = 400
While Not KeyHit(1)
   
   time = MilliSecs() / 6
   
   For iy = 0 To 30
      For ix = 0 To 30
      
       ; horizontal animation
       ;anim# = Sin(time + ix * 65) * 10.0
       ;anim2# = Sin(time + (ix+1) * 65) * 10.0
      
       ; vertical animation
       anim3# = Sin(time + iy * 65) * 10.0
       anim4# = Sin(time + (iy+1) * 65) * 10.0

       ; ------------------------------------------
      
         x1# = xpos + ix * tilesize +anim3#
         y1# = ypos  -iy * tilesize + anim#
   
         x2# = xpos + (ix + 1) * tilesize + anim3#
         y2# = ypos  -iy * tilesize + anim2#


         x3# = xpos + (ix + 1) * tilesize  + anim4#
         y3# = ypos - (iy + 1) * tilesize + anim2#


         x4# = xpos + ix * tilesize + anim4#
         y4# = ypos - (iy + 1) * tilesize + anim#
 

       DrawQuad3D tileset(ix,iy), x1#, y1#, x2#, y2#, x3#, y3#, x4#, y4#
      

      Next
   Next
   
   
   WaitTimer(Timer)
   RenderWorld
   Clear3D()
   Flip 0
Wend
End

Klar bei zu geringer Wellenlänge wirds kantig...

WEBLink

BeitragDi, Sep 30, 2008 20:24
Antworten mit Zitat
Benutzer-Profile anzeigen
JO, ist ja super. Hier greifen wir aber wieder nur auf das eine Bild zu was wellig dargestellt werden soll.


Wie gesagt. Ein bereich egal wie viele verschiedene Objekte sich darauf tummeln diese Wellig dargestellt werden, wenn halt in den Bereich ein neues Objekt läuft dann wird dieses auch wellig dargestellt.
Ich schätze auch mal das man das nur machen kann indem man ein Bild von dem Bereich kopiert als Sprite speichert und mit Quad ausgibt. aber das würde denke ich zu lahm sein.

hectic

Sieger des IS Talentwettbewerb 2006

BeitragDi, Sep 30, 2008 20:41
Antworten mit Zitat
Benutzer-Profile anzeigen
Ja eben, das ist das Problem. Der Draw3D V.3.2 liegt ein Beispiel ''Test, Waves.bb'' bei, wo auch solche Wellenmuster vorhanden sind - mit dem Unterschied zu Rone's Code, dass nur eine Kachel und nicht ein ganzes Hintergrundbild ''gewellt'' wird. In vielen Fällen reicht es aber auch schon aus. Da man auch transparente Texturen zeichnen kann, kann man auch hier bestimmte Effekte noch einbringen.

P.S. In dem Beispiel von Rone, könnte man auf die vertikale Aufteilung der Quads auch verzichten und nur noch horizontale Balken verwellen.

Bei einer Tileengine könnte man auch ab einer bestimmten Tiefe die Kacheln auch verwellen, was nahezu den gleichen Effekt bringen würde.
Download der Draw3D2 V.1.1 für schnelle Echtzeiteffekte über Blitz3D

Rone

BeitragDi, Sep 30, 2008 22:42
Antworten mit Zitat
Benutzer-Profile anzeigen
Zitat:
P.S. In dem Beispiel von Rone, könnte man auf die vertikale Aufteilung der Quads auch verzichten und nur noch horizontale Balken verwellen.

klar, aber dann ginge der TileEngine Ansatz verloren...Wink

Zitat:
Wie gesagt. Ein bereich egal wie viele verschiedene Objekte sich darauf tummeln diese Wellig dargestellt werden, wenn halt in den Bereich ein neues Objekt läuft dann wird dieses auch wellig dargestellt.
Ich schätze auch mal das man das nur machen kann indem man ein Bild von dem Bereich kopiert als Sprite speichert und mit Quad ausgibt. aber das würde denke ich zu lahm sein.


Ich denke das ist nicht so leicht möglich, zumindest in B3d. Mit MiniB3d und Shadern wäre es zumindest leichter und schneller...

Neue Antwort erstellen


Übersicht BlitzBasic Blitz3D

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group