diff options
Diffstat (limited to 'types.bmx')
-rw-r--r-- | types.bmx | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/types.bmx b/types.bmx new file mode 100644 index 0000000..322d863 --- /dev/null +++ b/types.bmx @@ -0,0 +1,129 @@ +' It's all a bit rolly +' +Global MASSSIZE:Int=4 +Global MASSRAD:Int=MASSSIZE/2 + +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 + + 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 + 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 MoveAndDraw() + x:+v.x + y:+v.y + SetColor(r,g,b) + DrawOval(x-MASSRAD,y-MASSRAD,MASSSIZE,MASSSIZE) + End Method +End Type + + +Type TPoint + Field x:Float + Field y: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()) + 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 l<MASSRAD + If o.friend + dead=True + Else + lost=True + EndIf + Else + 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 + + Return dead + End Method + + Method MoveAndDraw() + If (Not dead) And (Not lost) + x:+v.x + y:+v.y + SetColor(r,g,b) + Plot(x,y) + + If x<0 Or y<0 Or x>GraphicsWidth() Or y>GraphicsHeight() + lost=True + EndIf + EndIf + End Method +End Type |