2D particles engine

BlitzMax Forums/BlitzMax Programming/2D particles engine

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.

Nice idea, ftbass
I have made a quick change to the Demo and your Tutorial.
Try this and add it if you think it looks better, too
Edited I was not shure what would be the better solution: Globals or Typefields
If BotShips (random / not steered by user) are on screen maybe Typefields would be better.

Some Lines added in DemoPartEngine05.bmx
' Type TJoueur hérité du type TVaisseau
Type TJoueur Extends TVaisseau

	Method Update()
		RelativeFlag=1	'This Line for Demo usage - could be made a Functionparameter
		RelativeX=0		'To place the particles relative to the ship movement
		RelativeY=0
		If KeyDown(KEY_LEFT) And X >= -10 Then
			X = X - 3 * Vitesse
			If RelativeFlag<>0 RelativeX = -3*Vitesse
		EndIf
		If KeyDown(KEY_RIGHT) And X <= (LARGEUR - 112) Then
			X = X + 3 * Vitesse
			If RelativeFlag<>0 RelativeX = 3*Vitesse
		EndIf
		If KeyHit(KEY_UP) And Not(KeyDown(KEY_DOWN))
			DirV = "haut"
			NumImage = 11
			Timer = MilliSecs()
		End If
		If KeyDown(KEY_UP)
			If Y >= -40 Then
				Y = Y - 3 * Vitesse
				If RelativeFlag<>0 RelativeY= -3 * Vitesse
			End If
			If (Timer + Tempo < MilliSecs()) And (NumImage < 21) Then
				NumImage = NumImage + 1
				Timer = MilliSecs()
			End If
		EndIf
		If KeyHit(KEY_DOWN) And Not(KeyDown(KEY_UP))
			DirV = "bas"
			NumImage = 0
			Timer = MilliSecs()
		End If
		If KeyDown(KEY_DOWN)
			If Y <= 680 Then
				Y = Y + 3 * Vitesse
				If RelativeFlag<>0 RelativeY = 3*Vitesse
			End If
			If (Timer + Tempo < MilliSecs()) And (NumImage < 10) Then
				NumImage = NumImage + 1
				Timer = MilliSecs()
			End If
		EndIf
		If Not(KeyDown(KEY_DOWN) Or KeyDown(KEY_UP))
			Select DirV
				Case "haut"
					If (Timer + Tempo < MilliSecs()) And (NumImage > 11) Then
						NumImage = NumImage - 1
						Timer = MilliSecs()
					ElseIf NumImage = 11 Then
						DirV = "null"
					End If
				Case "bas"
					If (Timer + Tempo < MilliSecs()) And (NumImage > 0) Then
						NumImage = NumImage - 1
						Timer = MilliSecs()
					ElseIf NumImage = 0 Then
						DirV = "null"
					End If
			End Select
		End If
	End Method
	
End Type

This at top of "former Module" now an IncludeFile "ftbass_ParticleEngine.bmx" (makes quicker changes possible)
Global RelativeFlag, RelativeX , RelativeY

And change the 2 Lines in
Type TParticule

	'-----------------------------------------------------------
	' Mise à jour des particules
	'-----------------------------------------------------------
	Method Update()
	
		dx = dx + accX
		dy = dy + accY
		x = x + dx + RelativeX		'Line changed
		y = y + dy + RelativeY		'Line changed
		echelleX :+ dEchelleX
		echelleY :+ dEchelleY


In the Tutorial instead of too many Ifs
Function NumImage:Int(Char:String)
	If ( Char >= "a" And Char <= "z" ) Or ( Char >= "A" And Char <= "Z" ) Return (Asc(char) & 95)-65
	If ( Char >= "0" And Char <= "9" ) Return Asc(Char)-16
	Local Posit=Instr("'.,-!?",Char)
	If Posit>0 Return Posit+25
	If char=" " Return 42
End Function

Hope you can use it :-)