OOP Particle Tutorial (Bmax 1.14)

BlitzMax Forums/BlitzMax Tutorials/OOP Particle Tutorial (Bmax 1.14)

Hi everyone,

this is my first post or rather reply here on the forum, so forgive me, if I'm a little clumsy.

Even more wild, this is my first day with BlitzMax and I'm rather thrilled! I've played around with the code above and made some kind of pretty changes. If you like I'll post it, once I find out how to do it properly here...<shame>. If I've managed to write a new breakout and easily play around with code, I should handle the forum codes, too...<LOL>.

So yeah, let's try. I mean, if my posting this is not wanted, don't hesitate to delete the whole reply, but just for fun...

This is based on the latest code using openGL. I've just reintroduced the mouse spark emitting and changed the life behavior. Any life time results in a smooth fading and the color fading is a bit more vivid, too.

SuperStrict

SetGraphicsDriver GLMax2DDriver() 
Graphics 800, 600,,, GRAPHICS_BACKBUFFER

Global SparkList:TList = CreateList()
AutoMidHandle(True)

Global iSpark:TImage = LoadImage("spark.png", MIPMAPPEDIMAGE | FILTEREDIMAGE) 
SetBlend LIGHTBLEND

Type TSpark
	Field x:Float
	Field y:Float
	Field r:Int
	Field g:Int
	Field b:Int
	Field xv:Float
	Field yv:Float
	Field scale:Float
	Field life:Float
	Field lifeset:Int
	
	Function Create(x:Int, y:Int, xv:Float, yv:Float, scale:Float, lifeset:Int) 
		Local Spark:TSpark = New TSpark
		Spark.x = x
		Spark.y = y
		Spark.xv = xv
		Spark.yv = yv
		spark.r = 255
		spark.g = 255
		spark.b = 255
		spark.scale = scale
		spark.life = lifeset
		spark.lifeset= lifeset
		SparkList.AddLast(Spark) 
	End Function
	
	Method Destroy()
		SparkList.Remove(Self) 
	End Method
	
	Function UpdateAll()
		For Local Spark:TSpark = EachIn SparkList
		Local tmp# = (spark.life/spark.lifeset)
		spark.yv:+RndFloat() 
		Spark.x:+Spark.xv
		Spark.y:+Spark.yv
		spark.r= (1.0-(1.0-tmp)*(1.0-tmp))*255
		spark.b= tmp *tmp *255
		spark.g= tmp *255
		SetColor spark.r, spark.g, spark.b
		SetScale spark.scale, spark.scale
		DrawImage(iSpark, spark.x, spark.y) 
		SetColor 255,255,255
		SetScale 1,1
		spark.life:-1
		If spark.life < 1 spark.Destroy() 
		Next
	End Function
End Type

Local t:Int = MilliSecs() 
Local counter:Int
Local FPS:Int

While Not KeyHit(KEY_ESCAPE) 
	Cls
	
	If t < MilliSecs() 
		t = MilliSecs() + 1000
		FPS = counter
		counter = 0
	End If
	counter:+1

	If MouseDown(1) 	
		Local yv# = 1
	        For Local lx# = 0.1 To 5 Step .5
	    	yv#:-RndFloat()*2
	    	TSpark.Create (MouseX(),MouseY()-5,lx#,yv#,0.5,Rand(1,80))
	    	TSpark.Create (MouseX(),MouseY()-5,-lx#,yv#,.2,Rand(1,80))
	    Next
	
	End If
	TSpark.UpdateAll

	DrawText "FPS: " + FPS, 730, 580
	Flip 1
Wend

 


More than anything else, I want to say: THANK YOU! That's a wonder code with a really nice and easy explanation. I hope to find more such snippits around here.

Thanks again,

Taron