Good Fire?

Blitz3D Forums/Blitz3D Beginners Area/Good Fire?

Ked(Posted 2007) [#1]
I was wondering if this was a good fire effect. It didn't take me long to do, but I would like some feedback from the community.

IMG


You are allowed to use the code and image if you like it but please put me in the credits or in any source code released.

Graphics3D 640,480,32,2
SetBuffer BackBuffer()
SeedRnd MilliSecs()

Global halfwidth=640/2
Global halfheight=480/2

Type flame
	Field x,y
	Field size
	Field alpha#
	Field src
	Field rot
	Field angle
	Field speed
	Field fadespeed#
	Field rotright
End Type

Global f.flame

Global camera=CreateCamera(),light=CreateLight()

Global flamesprite=LoadSprite("flame.bmp",1):HideEntity flamesprite

Global fps=CreateTimer(60)

For i=1 To 10
	CreateFlame(halfwidth,halfheight+50)
Next

While Not KeyHit(1)
	Flip:RenderWorld
	
	WaitTimer(fps)
	
	UpdateFlame()
	
Wend
End

Function CreateFlame(x,y)
	f.flame=New flame
	f\x=x
	f\y=y
	f\size=Rand(50,100)/2
	f\alpha=1
	f\src=CopyEntity(flamesprite)
	f\rot=Rand(360)
	f\speed=Rand(1,3)
	f\angle=Rand(-40,40)
	f\fadespeed=Rnd(0.01,0.04)
	f\rotright=Rand(1,2)
	ScaleSprite f\src,f\size,f\size
End Function

Function UpdateFlame()
	For f.flame=Each flame
		If f\alpha > 0
			f\alpha=f\alpha-f\fadespeed
			If f\rotright=1
				f\rot=f\rot+6
			ElseIf f\rotright=2
				f\rot=f\rot-6
			EndIf
			f\y=f\y-f\speed
			;f\x=f\x+Sin(f\angle)*f\speed
			RotateSprite f\src,f\rot
			PositionEntity f\src,f\x-halfwidth,halfheight-f\y,halfwidth*1
			EntityAlpha f\src,f\alpha
		Else
			FreeEntity f\src
			Delete f
			CreateFlame(halfwidth,halfheight+50)
		EndIf
	Next
End Function



chwaga(Posted 2007) [#2]
nice. I like it!


Ked(Posted 2007) [#3]
Could a mod move this to Graphics Showcase, please?

Thanks


jfk EO-11110(Posted 2007) [#4]
canīt move forum things to the archives. Please copy paste. Thanks for sharing, will try this asap.


jfk EO-11110(Posted 2007) [#5]
Nice tho mostly "torch-only" fire. FOr the rotation: how about an additional random flag for left vs right rotation?


Ked(Posted 2007) [#6]
I modified the code so that it has the random flag for rotating left or right.

Hey, jfk EO-11110! Did you notice what piece of code I used to get the 2D screen co-ords? I must say that I use that all the time now. It's very useful. Now I can make 2D games with alpha and transparency effects!


jfk EO-11110(Posted 2007) [#7]
3D emulated 2D rules. Not only alpha, but also add-blendmode for shiny magic fx, as well as smooth "antialiased" contours are possible this way.