Alright here's an example i knocked up, just paste 'n compile.
click to create a partical explosion with 50 particals and a max distance of 100.
But as you can see it doesnt work correctly, what am i doing wrong?
click to create a partical explosion with 50 particals and a max distance of 100.
But as you can see it doesnt work correctly, what am i doing wrong?
SeedRnd MilliSecs() Global ParticalList:TList = CreateList() Type TPartical Field x:Int,y:Int,a:Float,r:Int Field ox:Int,oy:Int Field img:TImage Field dx:Int,dy:Int Field maxdistance:Float Field fade:Int Method Create:TPartical(_x:Int, _y:Int, _img:TImage, _dx:Int = 0, _dy:Int = 0, mxdist:Float = 0, _fade:Int = False) ListAddLast(ParticalList,Self) x = _x y = _y ox = _x oy = _y img = _img dx = _dx dy = _dy If mxdist maxdistance = mxdist End If If _fade fade = True End If End Method Method Update:TPartical() x:+dx y:+dy SetRotation(r) SetAlpha(a) DrawImage img,x,y SetRotation(0) SetAlpha(1) If maxdistance If DistanceTraveled() >= maxdistance Destroy() End If End If If fade a = DistanceTraveled()/maxdistance End If End Method Method SetPAlpha(alpha:Float) a = alpha End Method Method SetPRotation(rot:Int) r = rot End Method Method Destroy() ParticalList.Remove(Self) End Method Method SetX(_x:Int) x = _x End Method Method SetY(_y:Int) y = _y End Method Method DistanceTraveled:Float() Local returnx:Float=Abs(ox-y) Local returny:Float=Abs(oy-y) Return returnx+returny End Method End Type 'Partical explosion function; creates a explosion of particals Function ParticalExplosion(_x:Int, _y:Int, image:TImage, n:Int, dist:Float) Local dx:Int = Rand(-3,3) Local dy:Int = Rand(-3,3) For Local i:Int = 1 To n Local part:TPartical = New TPartical.Create(_x, _y, image, dx, dy, dist, True) Next End Function AppTitle = "Partical test - click to fire" Graphics 800,600 'Create a dot image (our partical) Global dot:TImage = CreateImage(5, 5) DrawOval 0, 0, 5, 5 GrabImage(dot,0,0) While Not KeyHit(KEY_ESCAPE) Cls For Local UpdateParticals:TPartical = EachIn ParticalList UpdateParticals.Update() Next If MouseHit(1) ParticalExplosion(MouseX(), MouseY(), dot, 50, 100) Flip Wend End