-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Core.agc
235 lines (197 loc) · 6.63 KB
/
Core.agc
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// File: core.agc
type Core_Vec3Data
X# as float
Y# as float
Z# as float
endtype
type Core_Vec2Data
X# as float
Y# as float
endtype
type Core_ColorData
Red as integer
Green as integer
Blue as integer
Alpha as integer
endtype
type Core_Int3Data
X as integer
Y as integer
Z as integer
endtype
type Core_Int2Data
X as integer
Y as integer
endtype
function Core_Vector3DTo2D(Vector3D as Core_Vec3Data)
local Vector2D as Core_Vec2Data
Vector2D.X#=Vector3D.X#
Vector2D.Y#=Vector3D.Z#
endfunction Vector2D
function Core_GetPointer3D(Pointer as Core_Vec2Data)
Pointer3D as Core_Vec3Data
Pointer3D.X#=Get3DVectorXFromScreen(Pointer.X#,Pointer.Y#)
Pointer3D.Y#=Get3DVectorYFromScreen(Pointer.X#,Pointer.Y#)
Pointer3D.Z#=Get3DVectorZFromScreen(Pointer.X#,Pointer.Y#)
endfunction Pointer3D
function Core_GetAngleBetween(Start as Core_Vec2Data, Stop as Core_Vec2Data)
Dist as Core_Vec2Data
Dist.X#=Stop.X#-Start.X#
Dist.Y#=Stop.Y#-Start.Y#
Angle#=atanfull(Dist.X#,-Dist.Y#)
endfunction Angle#
function Core_StringInsertAtDelemiter(String$,Insert$,Delemiter$)
Left$=GetStringToken(String$,Delemiter$,1)
Right$=GetStringToken(String$,Delemiter$,2)
NewString$=Left$+Insert$+Right$
endfunction NewString$
function Core_GetMask(Mask,Check)
local Result as integer
Result=Mask&&Check > 0
endfunction Result
function Core_AddMask(Mask,Add)
local Result as integer
Result=Mask||Add
endfunction Result
function Core_RemoveMask(Mask,Remove)
local Result as integer
Result=Mask&&!Remove
endfunction Result
function Core_SwitchMask(Mask,Switch)
if Core_GetMask(Mask,Switch)=1
dec Mask,Switch
else
inc Mask,Switch
endif
endfunction Mask
function Core_CurveValue(current# as float, destination# as float, speed# as float)
local diff# as float
if speed# < 1.0 then speed# = 1.0
diff# = destination# - current#
current# = current# + ( diff# / speed# )
endfunction current#
function Core_CurveValueOnFrame(current# as float, destination# as float, speed# as float, frametime# as float)
local diff# as float
diff# = destination# - current#
current# = current# + ( diff# / speed# ) * frametime#
endfunction current#
function Core_CurveAngle(current# as float, destination# as float, speed# as float)
local diff# as float
if speed# < 1.0 then speed# = 1.0
destination# = Core_WrapAngle( destination# )
current# = Core_WrapAngle( current# )
diff# = destination# - current#
if diff# <- 180.0 then diff# = ( destination# + 360.0 ) - current#
if diff# > 180.0 then diff# = destination# - ( current# + 360.0 )
current# = current# + ( diff# / speed# )
current# = Core_WrapAngle( current# )
endfunction current#
function Core_CurveAngleOnFrame(current# as float, destination# as float, speed# as float, frametime# as float)
local diff# as float
destination# = Core_WrapAngle( destination# )
current# = Core_WrapAngle( current# )
diff# = destination# - current#
if diff# <- 180.0 then diff# = ( destination# + 360.0 ) - current#
if diff# > 180.0 then diff# = destination# - ( current# + 360.0 )
current# = current# + ( diff# / speed# ) * frametime#
current# = Core_WrapAngle( current# )
endfunction current#
function Core_WrapAngle( angle# as float)
if angle#=>0
angle#=fmod(angle#,360.0)
else
angle#=360.0 + fmod(angle#,-360.0)
endif
endfunction angle#
function Core_ManhattanDistance2D(StartX,StartY,EndX,EndY)
DistX=abs(EndX-StartX)
DistY=abs(EndY-StartY)
Dist=DistX+DistY
endfunction Dist
function Core_Distance2D(StartX#,StartY#,EndX#,EndY#)
DistX#=EndX#-StartX#
DistY#=EndY#-StartY#
Dist#=sqrt(DistX#*DistX#+DistY#*DistY#)
endfunction Dist#
function Core_Distance3D(StartX#,StartY#,StartZ#,EndX#,EndY#,EndZ#)
DistX#=EndX#-StartX#
DistY#=EndY#-StartY#
DistZ#=EndZ#-StartZ#
Dist#=sqrt(DistX#*DistX#+DistY#*DistY#+DistZ#*DistZ#)
endfunction Dist#
function Core_Lerp(Time#,Start#,End#)
endfunction Start#+Time#*(End#-Start#)
function Core_InverseLerp(Value#,Start#,End#)
endfunction (Value#-Start#)/(End#-Start#)
function Core_Map(Value#,InMin#,InMax#,OutMin#,OutMax#)
Time#=Core_InverseLerp(Value#,InMin#,InMax#)
Result#=Core_Lerp(Time#,OutMin#,OutMax#)
endfunction Result#
function Core_Clamp(Value#,Min#,Max#)
if Value#>Max# then Value#=Max#
if Value#<Min# then Value#=Min#
endfunction Value#
function Core_Max(ValueA#,ValueB#)
if ValueB#>ValueA# then exitfunction ValueB#
endfunction ValueA#
function Core_Min(ValueA#,ValueB#)
if ValueB#<ValueA# then exitfunction ValueB#
endfunction ValueA#
function Core_Sign(Value#)
Result = ((Value#>0)*2)-1
endfunction Result
function Core_TriangleCCW(x1,y1,x2,y2,x3,y3)
endfunction ((x1-x2)*(y3-y2))-((y1-y2)*(x3-x2))>0
function Core_PointInTriangle(PointX,PointY,x1,y1,x2,y2,x3,y3)
AB#=((PointY-y1)*(x2-x1))-((PointX-x1)*(y2-y1))
BC#=((PointY-y2)*(x3-x2))-((PointX-x2)*(y3-y2))
if AB#*BC#<=0 then exitfunction 0
CA#=((PointY-y3)*(x1-x3))-((PointX-x3)*(y1-y3))
if BC#*CA#<=0 then exitfunction 0
endfunction 1
function Core_FillTextEndWithSpaces(String$,MaxWidth#,Size#,Spacing#)
StringTextID=CreateText(String$)
SetTextSize(StringTextID,Size#)
SetTextSpacing(StringTextID,Spacing#)
StringWidth#=GetTextTotalWidth(StringTextID)
SpaceTextID=CreateText(" ")
SetTextSize(SpaceTextID,Size#)
SetTextSpacing(SpaceTextID,Spacing#)
SpaceWidth#=GetTextTotalWidth(SpaceTextID)
RemainingWidth#=MaxWidth#-StringWidth#
SpaceCount=round(RemainingWidth#/SpaceWidth#)
String$=String$+Spaces(SpaceCount)
DeleteText(StringTextID)
DeleteText(SpaceTextID)
endfunction String$
function Core_FillEndWithSpaces(String$,MaxLength)
Length=len(String$)
SpaceLength=MaxLength-Length
String$=String$+Spaces(SpaceLength)
endfunction String$
function Core_RequestString(String$)
EditBoxID=CreateEditBox()
SetEditBoxPosition(EditBoxID,25,50)
SetEditBoxSize(EditBoxID,50,15)
FixEditBoxToScreen(EditBoxID,1)
SetEditBoxDepth(EditBoxID,1)
SetEditBoxFocus(EditBoxID,1)
SetEditBoxText(EditBoxID,String$)
while GetEditBoxHasFocus(EditBoxID)
sync()
endwhile
String$=GetEditBoxText(EditBoxID)
DeleteEditBox(EditBoxID)
endfunction String$
function Core_FileLoad(Filename$)
if GetFileExists(Filename$)
MemblockID=CreateMemblockFromFile(Filename$)
String$=GetMemblockString(MemblockID,0,GetMemblockSize(MemblockID))
DeleteMemblock(MemblockID)
endif
endfunction String$
function Core_FileSave(String$,Filename$)
FileID=OpenToWrite(Filename$)
WriteString(FileID,String$)
CloseFile(FileID)
endfunction