Lightening?

BlitzPlus Forums/BlitzPlus Programming/Lightening?

elseano(Posted 2004) [#1]
I need some lightening effects in my game. I don't want to spend hours making a lightening animation for every time I need to use some special FX, so I tried making a lightening algorythm.
I have no idea how to do this, though. It needs to be something like:

Function DrawLightening(x1#,y1#,x2#,y2#,r%,g%,b%)

;...drawing lightening code goes here

End Function


Can anyone help me with this? Or at least just give me some pointers as to how to go about doing this...?


Valgar(Posted 2004) [#2]
If you want something simple you could try to use "simple lines" with the same command as blitz,but there's a problem:the lightning is instantly show.
So you must write a code that after a line (or a bunch of...)start a timer and after the timer as expired anothe part of the lightning is shown.
Something like this:

line x1,y1,x2,y2
line x2,y2,x3,y3
start timer
if start timer is more than 100 and
previously_drawn_lines=true
line x3,y3,x4,y4
line x4,y4,x5,y5
start timer2
if start timer2 is more than 100 and previously_drawn_lines=true
line........

Something similar.
Or if you want something more graphical,you could replace the "lines"with line that you have draw!


RiK(Posted 2004) [#3]
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



Andy_A(Posted 2004) [#4]
That looks identical to the code that Rob Cummings posted here:

http://www.blitzbasic.com/codearcs/codearcs.php?code=158