Lightening?

BlitzPlus Forums/BlitzPlus Programming/Lightening?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hope this helps


Graphics 640,480,16,2

SetBuffer BackBuffer()
While Not KeyHit(1)
	Cls
	
	;bolt(x,y,x2,y2,points,multiplier) - this is all you need.
	lightning(x1,y1,x2,y2,32)

	;simple randomiser to see the function working (to demonstrate)
	x1=320
	y1=240
	x2=MouseX()
	y2=MouseY()
	scale=Rnd(2,12)
	Color 255,255,255
	Oval x1,y1,2,2
	Oval x2,y2,2,2
	Flip
Wend
End

Function lightning(bx1,by1,bx2,by2,s)
	Color 255,255,244
	x=bx2
	y=by2
	xstep=(bx1-bx2)/s
	ystep=(by1-by2)/s
	scale=Rnd(2,12)
	
	LockBuffer BackBuffer()
	For i=1 To s-1
		r1=Rnd(-scale,scale)
		r2=Rnd(-scale,scale)
		x2=(x+xstep)+r1
		y2=(y+ystep)+r2
		Line x,y,x2,y2
		x=x2
		y=y2
	Next
	Line x,y,bx1,by1
	UnlockBuffer BackBuffer()
End Function