' Particle Pinch ' ' Copyright 2005 Ian Cowburn ' ' $Id$ ' Strict Import noddybox.vector Import noddybox.bitmapfont Const MASSSIZE:Int=6 Const MASSRAD:Int=3 Type GameGFX Global font:TBitmapFont Global guifont:TBitmapFont Global star:TImage Global mass:TImage Global collector:TImage Global point:TImage Global particle:Timage Global pointer:TImage End Type Type TMass Field x:Float Field y:Float Field v:TVector 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()) mass=25 friend=True inverse=False swallow=0 End Method Method Attract(o:TMass) If o=Self Return EndIf Local d:TVector=TVector.Create(o.x-x,o.y-y) Local l:Float=d.Length() If l>0.1 l:*l d.Normalise() d.Scale((1/l)*o.mass) If o.inverse d.Minus() EndIf v.Add(d) If d.Length()>MASSSIZE d.SetLength(MASSSIZE) EndIf EndIf End Method Method Move() x:+v.x y:+v.y End Method Method Draw() 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 Field b:Int Field dead:Int Field lost:Int Method New() 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) dead=False lost=False End Method Method Attract:Int(o:TMass) If dead Or lost Return EndIf Local d:TVector=TVector.Create(o.x-x,o.y-y) Local l:Float=d.Length() If lMASSRAD d.SetLength(MASSRAD) EndIf EndIf Return dead End Method Method Move() If (Not dead) And (Not lost) lx=x ly=y x:+v.x y:+v.y If x<0 Or y<0 Or x>GraphicsWidth() Or y>GraphicsHeight() lost=True TParticleMachine.AddLost(Self) EndIf EndIf End Method Method Draw() If (Not dead) And (Not lost) SetColor(r,g,b) DrawImage(img,x,y,0) 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