Main Menu

Water Line Effect

Started by kevin, January 20, 2006, 11:41:01 PM

Previous topic - Next topic

kevin

This example requires PlayBASIC V1.11 or above

(original version of code)
PlayBASIC Code: [Select]
  Makebitmapfont 1,$ffffff


; ================================
; Create Water Shape ( WAVE :))
; ================================
WaterLineShape=GetFreeshape()

Createshape WaterLineShape, 100,100

WaveHeight=20
Xpos=0
FirstVertex=10
Vertex=FirstVertex
For angle=0 to (360*4) step 5
ypos=cos(Baseangle#+angle)*WaveHeight
SetShapeVertex Waterlineshape,Vertex,xpos,ypos
xpos=xpos+20
inc vertex
next
lastVertex=Vertex-1

x=GetShapeVertexX(Waterlineshape,FirstVertex)
y=GetShapeVertexy(Waterlineshape,FirstVertex)
SetShapeVertex Waterlineshape,1,x,y
SetShapeVertex Waterlineshape,2,x,1000

SetShapeVertex Waterlineshape,3,xpos,y
SetShapeVertex Waterlineshape,4,xpos,1000

EdgeINdex=1
SetShapeedge WaterlineShape,EdgeINdex,1,2
inc edgeindex
SetShapeedge WaterlineShape,EdgeINdex,3,4

for Vertex=FirstVertex to lastVertex-1
inc Edgeindex
SetShapeedge WaterlineShape,EdgeINdex,Vertex,Vertex+1
next







;=========================================================================
`CReate a Series of Tiles To make the blob Animation blocks.
;=========================================================================

Frames=10
BlockSize=64
; Create the Animated blocks
Block_Image=CreateBlocks(BlockSize,frames)


; Create a Map with provision For 2 level maps To be created using it's Blocks
Thismap=NewMap(2)

; Import the above Image created into our Map as BLocks
MakeMapGFX ThisMap,Block_image,BlockSize,BlockSize,frames+1,RGB(0,0,0)


; Prepare the Block graphics for FX rendering. This Allows Maps to be
; drawn to the images converted to FX format.
PrepareFXMap ThisMap


; =========================
; Create 3 Animations
; =========================
MaxAnims=6
Create_Map_Anims(ThisMap,MAxAnims,Frames)


; CREATE A LEVEL filled with ranomd blocks
Constant z=$80000000
Width=100
height=100
CreateLevel ThisMap,1,Width,height
For ylp=0 To Width
For xlp=0 To height
PokeLevelTile ThisMap,1,xlp,ylp,z Or RndRange(1,MaxAnims)
Next xlp
Next ylp

; SET THIS LEVEL As Transparent + animated..
LevelAnimated ThisMap,1




;=========================================================================
; Create an FX Image the size of the screen.
;=========================================================================

; This image is used as render target. So we render all our games
; elements to this image, then copy it to the real screen.

sw=getscreenwidth()
sh=getscreenheight()

FXScreen=NEwImage(sw,sh)
PrepareFXIMage FXscreen
Rendertoimage FXscreen

createcamera 1


ShowControls=timer()+10000


;=========================================================================
; MAIN LOOp
;=========================================================================

; Start of Main Loop
rendertoscreen
Do

; Tell pPB to capture the following drawn items to the scene buffer
capturetoscene
; clear the buffer
clsscene
; draw our map to the scene buffer
DrawMap thisMap,1,0,0

; draw the camera. This will process the items in the scene buffer
; to the cameras position and render what it can see to the image
; it's attached to. In this case it's attached to the FXscreen
; image
DrawCamera 1


; Redirect drawing to the FX screen image
RendertoIMage FXScreen

; set the INK mode to Alpha 50%
inkmode 1+32

; set the ink colour to a bluey colour
ink rgb(35,75,125)

; draw the wave shape over the map
drawshape WaterLineShape,0,sh/2,2

; restore the ink mode to normal
Login required to view complete source code




  Updated version of code for PlayBASIC V1.64 editions.  You can also find this in the project packs (see PlayBASIC.com)

PlayBASIC Code: [Select]
  Makebitmapfont 1,$ffffff,8


; ================================
; Create Water Shape ( WAVE :))
; ================================
WaterLineShape=Newshape(150,150)

WaveHeight=20
Xpos=0
FirstVertex=10
Vertex=FirstVertex
For angle=0 to (360*4) step 5
if Vertex <150
ypos=cos(Baseangle#+angle)*WaveHeight
SetShapeVertex Waterlineshape,Vertex,xpos,ypos
xpos=xpos+20
inc vertex
endif

next
lastVertex=Vertex-1

x=GetShapeVertexX(Waterlineshape,FirstVertex)
y=GetShapeVertexy(Waterlineshape,FirstVertex)
SetShapeVertex Waterlineshape,1,x,y
SetShapeVertex Waterlineshape,2,x,1000

SetShapeVertex Waterlineshape,3,xpos,y
SetShapeVertex Waterlineshape,4,xpos,1000

EdgeINdex=1
SetShapeedge WaterlineShape,EdgeINdex,1,2
inc edgeindex
SetShapeedge WaterlineShape,EdgeINdex,3,4

for Vertex=FirstVertex to lastVertex-1
inc Edgeindex
SetShapeedge WaterlineShape,EdgeINdex,Vertex,Vertex+1
next







;=========================================================================
`CReate a Series of Tiles To make the blob Animation blocks.
;=========================================================================

Frames=10
BlockSize=64
; Create the Animated blocks
Block_Image=CreateBlocks(BlockSize,frames)


; Create a Map with provision For 2 level maps To be created using it's Blocks
Thismap=NewMap(2)

; Import the above Image created into our Map as BLocks
MakeMapGFX ThisMap,Block_image,BlockSize,BlockSize,frames+1,RGB(0,0,0),2


; =========================
; Create 3 Animations
; =========================
MaxAnims=6
Create_Map_Anims(ThisMap,MAxAnims,Frames)


; CREATE A LEVEL filled with ranomd blocks
Width=100
height=100
CreateLevel ThisMap,1,Width,height
For ylp=0 To Width
For xlp=0 To height
PokeLevelTile ThisMap,1,xlp,ylp,PBMapAnim_Mask Or RndRange(1,MaxAnims)
Next xlp
Next ylp

; SET THIS LEVEL As Transparent + animated..
LevelAnimated ThisMap,1



;=========================================================================
; Create an FX Image the size of the screen.
;=========================================================================

; This image is used as render target. So we render all our games
; elements to this image, then copy it to the real screen.

sw=getscreenwidth()
sh=getscreenheight()

FXScreen=NEwImage(sw,sh,2)
Rendertoimage FXscreen

createcamera 1


ShowControls=timer()+10000


;=========================================================================
; MAIN LOOp
;=========================================================================

; Start of Main Loop
rendertoscreen
Do

; Tell pPB to capture the following drawn items to the scene buffer
capturetoscene
; clear the buffer
clsscene
; draw our map to the scene buffer
DrawMap thisMap,1,0,0

; draw the camera. This will process the items in the scene buffer
; to the cameras position and render what it can see to the image
; it's attached to. In this case it's attached to the FXscreen
; image
DrawCamera 1


; Redirect drawing to the FX screen image
RendertoIMage FXScreen

; set the INK mode to Alpha 50%
inkmode 1+32

; set the ink colour to a bluey colour
ink rgb(35,75,125)

; draw the wave shape over the map
drawshape WaterLineShape,0,sh/2,2

; restore the ink mode to normal
inkmode 1
; restore rendering to the screen
rendertoscreen



;
drawimage FXscreen,0,0,0
Login required to view complete source code



Related Articles

    * Applying a Classic Sine wave effect to an image