diff options
Diffstat (limited to 'types.bmx')
-rw-r--r-- | types.bmx | 132 |
1 files changed, 121 insertions, 11 deletions
@@ -1,29 +1,26 @@ ' It's all a bit rolly ' -Global MASSSIZE:Int=4 -Global MASSRAD:Int=MASSSIZE/2 +Global MASSSIZE:Int=6 +Global MASSRAD:Int=3 Type TMass Field x:Float Field y:Float Field v:TVector - Field r:Int - Field g:Int - Field b:Int Field mass:Float Field friend:Int Field inverse:Int + Field img:TImage + Field swallow:Int Method New() v=TVector.Create() x=Rnd(0,GraphicsWidth()) y=Rnd(0,GraphicsWidth()) - r=255 - g=255 - b=255 mass=25 friend=True inverse=False + swallow=False End Method Method Attract(o:TMass) @@ -54,15 +51,20 @@ Type TMass Method MoveAndDraw() x:+v.x y:+v.y - SetColor(r,g,b) - DrawOval(x-MASSRAD,y-MASSRAD,MASSSIZE,MASSSIZE) + SetColor(255,255,255) + DrawImage(img,x,y,swallow) + swallow=0 End Method End Type Type TPoint + Global img:TImage + Field x:Float Field y:Float + Field lx:Float + Field ly:Float Field v:TVector Field r:Int Field g:Int @@ -74,6 +76,8 @@ Type TPoint v=TVector.Create() x=Rnd(0,GraphicsWidth()) y=Rnd(0,GraphicsWidth()) + lx=x + ly=y r=Rand(100,200) g=Rand(100,200) b=Rand(100,200) @@ -95,6 +99,8 @@ Type TPoint Else lost=True EndIf + TParticleMachine.AddCaptured(Self) + o.swallow=1 Else l:*l d.Normalise() @@ -116,14 +122,118 @@ Type TPoint Method MoveAndDraw() If (Not dead) And (Not lost) + lx=x + ly=y x:+v.x y:+v.y + SetColor(r,g,b) - Plot(x,y) + DrawImage(img,x,y,0) If x<0 Or y<0 Or x>GraphicsWidth() Or y>GraphicsHeight() lost=True + TParticleMachine.AddLost(Self) EndIf EndIf End Method End Type + + +Type TParticle + Global img:TImage + Field x:Float + Field y:Float + Field a:Float + Field r:Int + Field g:Int + Field b:Int + Field dx:Float + Field dy:Float + Field ai:Float + + Function FromLostPoint:TParticle(p:TPoint, d:Int) + Local o:TParticle=New TParticle + o.x=p.lx'-p.v.x*d + o.y=p.ly'-p.v.y*d + o.dx=-p.v.x*d + o.dy=-p.v.y*d + o.r=p.r + o.g=p.g + o.b=p.b + o.a=1 + o.ai=-0.05 + Return o + End Function + + Function FromCapturedPoint:TParticle(p:TPoint, d:Int) + Local o:TParticle=New TParticle + o.x=p.x + o.y=p.y + o.dx=Rnd(-1,1) + o.dy=Rnd(-1,1) + o.r=p.r + o.g=p.g + o.b=p.b + o.a=1 + o.ai=-0.05 + Return o + End Function + + Method Update() + x:+dx + y:+dy + a:+ai + + If a>0 + SetAlpha(a) + SetColor(r,g,b) + DrawImage(img,x,y) + EndIf + End Method +End Type + + +Type TParticleMachine + Global list:TList + + Function Init() + list=CreateList() + End Function + + Function Clear() + list.Clear() + End Function + + Function AddLost(p:TPoint) + For Local f:Int=0 To 5 + list.AddLast(TParticle.FromLostPoint(p,f)) + Next + End Function + + Function AddCaptured(p:TPoint) + For Local f:Int=0 To 5 + list.AddLast(TParticle.FromCapturedPoint(p,f)) + Next + End Function + + Function Process() + Local l:TLink=list.FirstLink() + Local t:TLink + + While l<>Null + Local p:TParticle=TParticle(l.Value()) + p.Update() + + If p.a<0.01 + t=l.NextLink() + l.Remove() + l=t + Else + l=l.NextLink() + EndIf + Wend + + SetAlpha(1) + SetColor(255,255,255) + End Function +End Type |