summaryrefslogtreecommitdiff
path: root/types.bmx
blob: 322d8632655e2d581e605ff3066619e43a6f07dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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