Creating Scanlines

BlitzPlus Forums/BlitzPlus Programming/Creating Scanlines

woiks!

Here you are :)
; scanlines

window=CreateWindow("5c4nl1n35 - CS_TBL",0,0,640,480)

Global canvas=CreateCanvas(8,8,512,256,window)

; tilesets

Global tilesmain=CreateImage(64,64)

; create the light tiles
SetBuffer ImageBuffer(tilesmain)
	For t=0 To 99 ; random puke
		r=Rnd(255):g=Rnd(255):b=Rnd(255)
		x=Rnd(32):y=Rnd(32)
		f=Rnd(2)
		Color r,g,b
		Rect x,y,32,32,f>1
	Next
SetBuffer DesktopBuffer()

; create the dark tiles
Global tilesdark=CopyImage(tilesmain)
DarkenImage(tilesdark,50) ; 50% dark


; make 2 gamebuffers
Global gamebuffer1=CreateImage(512,256)
Global gamebuffer2=CreateImage(512,256)
MaskImage gamebuffer2,255,0,255



Repeat
	WaitEvent()
	If EventID()=$803 quit=True
	Main()
Until quit
End

Function Main()

	SetBuffer ImageBuffer(gamebuffer1)
		Cls
		; draw your game here
		DrawImage tilesmain,EventX(),EventY()

	SetBuffer ImageBuffer(gamebuffer2)
		Cls
		; and here too, but now the dark tiles
		DrawImage tilesdark,EventX(),EventY()

		; add purple scanlines
		For t=0 To ImageHeight(gamebuffer2)-1 Step 2
			Color 255,0,255
			Line 0,t,ImageWidth(gamebuffer2)-1,t
		Next
		
	SetBuffer CanvasBuffer(canvas)
		; and add the whole lot together..!
		DrawBlock gamebuffer1,0,0
		DrawImage gamebuffer2,0,0
	FlipCanvas canvas
	
End Function

Function DarkenImage(img,percent)
	If percent<0 percent=0
	If img
		SetBuffer ImageBuffer(img)
			For y=0 To ImageHeight(img)-1
				For x=0 To ImageWidth(img)-1
					GetColor x,y
					r=ColorRed()*percent/100
					g=ColorGreen()*percent/100
					b=ColorBlue()*percent/100
					If r>255 r=255
					If g>255 g=255
					If b>255 b=255
					Color r,g,b
					Plot x,y
				Next
			Next
		SetBuffer DesktopBuffer()
	EndIf
End Function