From 8dbb5e4ab32cc2e0d105f51fde19dedb5b2bb2bc Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 22 Nov 2005 00:46:56 +0000 Subject: Initial import --- particle.bmx | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 particle.bmx (limited to 'particle.bmx') diff --git a/particle.bmx b/particle.bmx new file mode 100644 index 0000000..6269381 --- /dev/null +++ b/particle.bmx @@ -0,0 +1,100 @@ +' Hardwire +' +' Copyright 2005 Ian Cowburn +' +' $Id$ +' +Strict +Import "types.bmx" + +Type TParticle + Field life:Int + Field i:TImage + Field x:Double + Field y:Double + Field a:Double + Field dx:Double + Field dy:Double + Field ai:Double + Field s:Double + Field si:double + + Function Dust:TParticle(x:Int, y:Int) + Local o:TParticle=New TParticle + o.life=50 + o.x=x + o.y=y + o.a=1 + o.ai=-0.05 + o.dx=0 + o.dy=0 + o.s=1 + o.si=0.1 + o.i=GameGFX.dust + Return o + End Function + + Function Image:TParticle(i:TImage, x:Int, y:Int) + Local o:TParticle=New TParticle + o.life=120 + o.x=x + o.y=y + o.a=1 + o.ai=-0.01 + o.dx=0 + o.dy=-0.1 + o.s=1 + o.si=0 + o.i=i + Return o + End Function + + Method Update:Int() + SetAlpha(a) + SetScale(s,s) + DrawImage(i,x,y) + x:+dx + y:+dy + life:-1 + a:+ai + s:+si + Return life>0 + End Method +End Type + +Type Particles + Global plist:TList + + Function Init() + plist=CreateList() + End Function + + Function Clear() + plist.Clear() + End Function + + Function AddDust(x:Int, y:Int) + plist.AddLast(TParticle.Dust(x,y)) + End Function + + Function AddImage(i:TImage, x:Int, y:Int) + plist.AddLast(TParticle.Image(i,x,y)) + End Function + + Function Draw() + SetColor(255,255,255) + Local l:TEasyLink=TEasyLink.Create(plist) + + While l.Value() + Local p:TParticle=TParticle(l.Value()) + + If (p.Update()) + l.MoveNext() + Else + l.Remove() + EndIf + Wend + SetAlpha(1) + SetScale(1,1) + End Function +End Type -- cgit v1.2.3