This repository has been archived by the owner on Jan 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
flxpath.monkey
218 lines (162 loc) · 4.73 KB
/
flxpath.monkey
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
Strict
Import reflection
Import flxextern
Import flxpoint
Import flxg
Import flixel.system.flxcolor
Import flixel.plugin.debugpathdisplay
Class FlxPath
Field nodes:Stack<FlxPoint>
Field debugColor:Int
Field debugScrollFactor:FlxPoint
Field ignoreDrawDebug:Bool
Private
Field _point:FlxPoint
Field _debugNodeColor:FlxColor
Public
Method New(nodes:Stack<FlxPoint> = Null)
If (nodes = Null) Then
Self.nodes = New Stack<FlxPoint>()
Else
Self.nodes = nodes
End if
_point = New FlxPoint()
debugScrollFactor = New FlxPoint(1.0, 1.0)
debugColor = FlxG.WHITE
ignoreDrawDebug = False
#If FLX_DEBUG_ENABLED
Local debugPathDisplay:DebugPathDisplay = Manager()
If (debugPathDisplay <> Null) debugPathDisplay.Add(Self)
#End
End Method
Method Destroy:Void()
#If FLX_DEBUG_ENABLED
Local debugPathDisplay:DebugPathDisplay = Manager()
If (debugPathDisplay <> Null) debugPathDisplay.Remove(Self)
#End
debugScrollFactor = Null
_point = Null
nodes = Null
_debugNodeColor = Null
End Method
Method Add:Void(x:Float, y:Float)
nodes.Push(New FlxPoint(x, y))
End Method
Method AddAt:Void(x:Float, y:Float, index:Int)
If (index > nodes.Length()) index = nodes.Length()
nodes.Insert(index, New FlxPoint(x, y))
End Method
Method AddPoint:Void(node:FlxPoint, asReference:Bool = False)
If (asReference) Then
nodes.Push(node)
Else
nodes.Push(New FlxPoint(node.x, node.y))
End If
End Method
Method AddPointAt:Void(node:FlxPoint, index:Int, asReference:Bool = False)
If (index > nodes.Length()) index = nodes.Length()
If (asReference) Then
nodes.Insert(index, node)
Else
nodes.Insert(index, New FlxPoint(node.x, node.y))
End If
End Method
Method Remove:FlxPoint(node:FlxPoint)
Local i:Int = 0
Local l:Int = nodes.Length()
Local point:FlxPoint
While (i < l)
point = nodes.Get(i)
If (point = node) Exit
i += 1
Wend
nodes.Remove(i)
Return point
End Method
Method RemoveAt:FlxPoint(index:Int)
If (nodes.Length() <= 0) Return Null
If (index >= nodes.Length()) index = nodes.Length() - 1
Local point:FlxPoint = nodes.Get(index)
nodes.Remove(index)
Return point
End Method
Method Head:FlxPoint()
If (nodes.Length() > 0) Return nodes.Get(0)
Return Null
End Method
Method Tail:FlxPoint()
If (nodes.Length() > 0) Return nodes.Top()
Return Null
End Method
Method DrawDebug:Void(camera:FlxCamera = Null)
If (nodes.Length() <= 0) Return
If (camera = Null) camera = FlxG.Camera
Local node:FlxPoint
Local nextNode:FlxPoint
Local i:Int = 0
Local l:Int = nodes.Length()
Local fromX:Float
Local fromY:Float
While(i < l)
node = nodes.Get(i)
_point.x = node.x - Int(camera.scroll.x * debugScrollFactor.x)
_point.y = node.y - Int(camera.scroll.y * debugScrollFactor.y)
If (_point.x > 0) Then
_point.x = Int(_point.x + 0.0000001)
Else
_point.x = Int(_point.x - 0.0000001)
End If
If (_point.y > 0) Then
_point.y = Int(_point.y + 0.0000001)
Else
_point.y = Int(_point.y - 0.0000001)
End If
Local nodeSize:Int = 2
If (i = 0 Or i = l - 1) nodeSize *= 2
If (_debugNodeColor = Null) _debugNodeColor = New FlxColor()
_debugNodeColor.SetARGB(FlxG.WHITE)
If (l > 1) Then
If (i = 0) Then
_debugNodeColor.SetARGB(FlxG.GREEN)
ElseIf (i = l -1) Then
_debugNodeColor.SetARGB(FlxG.RED)
End If
End If
SetAlpha(.5)
If (FlxG._LastDrawingColor <> _debugNodeColor.argb) Then
SetColor(_debugNodeColor.r, _debugNodeColor.g, _debugNodeColor.b)
FlxG._LastDrawingColor = _debugNodeColor.argb
End If
DrawRect(_point.x - nodeSize * 0.5, _point.y - nodeSize * 0.5, nodeSize, nodeSize)
If (i = l - 1) Exit
Local linealpha:Float = .3
nextNode = nodes.Get(i + 1)
_debugNodeColor.SetARGB(debugColor)
SetAlpha(linealpha)
If (FlxG._LastDrawingColor <> _debugNodeColor.argb) Then
SetColor(_debugNodeColor.r, _debugNodeColor.g, _debugNodeColor.b)
FlxG._LastDrawingColor = _debugNodeColor.argb
End If
fromX = _point.x
fromY = _point.y
_point.x = nextNode.x - Int(camera.scroll.x * debugScrollFactor.x)
_point.y = nextNode.y - Int(camera.scroll.y * debugScrollFactor.y)
If (_point.x > 0) Then
_point.x = Int(_point.x + 0.0000001)
Else
_point.x = Int(_point.x - 0.0000001)
End If
If (_point.y > 0) Then
_point.y = Int(_point.y + 0.0000001)
Else
_point.y = Int(_point.y - 0.0000001)
End If
DrawLine(fromX, fromY, _point.x, _point.y)
i += 1
Wend
SetAlpha(1)
End Method
Function Manager:DebugPathDisplay()
Return DebugPathDisplay(FlxG.GetPlugin(DebugPathDisplay.__CLASS__))
End Function
End Class