-
Notifications
You must be signed in to change notification settings - Fork 0
/
test01.monkey
208 lines (158 loc) · 5.47 KB
/
test01.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
Strict
'#REFLECTION_FILTER="*" 'reflect everything!
#REFLECTION_FILTER="test01"
'Import reflection
Import mojo
Import ingamedebugtool
Function Main:Int()
New Game()
Return 0
End
Class Color
Field r:Int, g:Int, b:Int
Method New(r:Int, g:Int, b:Int)
Self.r = r
Self.g = g
Self.b = b
End Method
End Class
Class TestObject Implements IDebuggable
Field x:Int, y:Int, width:Int, height:Int
Field xVel:Int, yVel:Int
Field color:= New Int[3]
Function TestFunction:String(input:String)
Return "I am a function! Input was: " + input
End Function
Global testGlobal:Bool
Method New()
x = Rnd() * DeviceWidth()
y = Rnd() * DeviceHeight()
width = Rnd() * 100
height = Rnd() * 100
xVel = 1
yVel = 1
'color = New Color(Rnd() * 255, Rnd() * 255, Rnd() * 255)
color[0] = Rnd() * 255
color[1] = Rnd() * 255
color[2] = Rnd() * 255
End Method
' These properties are needed by the debugging tool system for drag&drop.
Method X:Int() Property Return x End
Method Y:Int() Property Return y End
Method X:Void(val:Int) Property x = val End
Method Y:Void(val:Int) Property y = val End
Method TestMethod:String(input:String)
Return "I am a Method! Input was: " + input
End Method
Method TestArray:String[] ()
Return["Hello", "World!"]
End Method
Method TestStringArray:String(arrStr:String[])
Local rtn:String = "Elements in array: "
If arrStr.Length() > 0 Then
rtn += arrStr.Length()
Else
rtn += "0 :("
End If
DevConsole.Log("DEBUG::Elements:", txtRed)
For Local i:= 0 Until arrStr.Length()
DevConsole.Log(" - " + arrStr[i], txtRed)
End For
Return "~q" + rtn + "~q"
End Method
Method TestMethod2:String(i:Int, f:Float, b:Bool, s:String)
Local _bool:String
If b Then _bool = "True" Else _bool = "False"
Return "I am a Method2! Input was: " + i + ", " + f + ", " + _bool + ", " + s
End Method
Method OnRender:Void()
SetColor(color[0], color[1], color[2])
DrawRect(x, y, width, height)
End Method
Method OnUpdate:Void()
' Apply velocities
x += xVel
y += yVel
' Don't let the boxes escape!
If x < - width x = DeviceWidth()
If y < - height y = DeviceHeight()
If x > DeviceWidth() x = -width
If y > DeviceHeight() y = -height
End Method
' Very basic implementation. Returns TRUE if mouse hits the object
Method MouseOverMe:Bool()
If MouseX() > x And MouseX() < x + width And MouseY() > y And MouseY() < y + height
Return True
End If
Return False
End Method
' Very basic implementation. Returns TRUE if object "hits" the selection area
Method AreaOverMe:Bool(x:Int, y:Int, w:Int, h:Int)
If (x + w >= Self.x) And
(y + h >= Self.y) And
(x < Self.x + width) And
(y < Self.y + height) Then
Return True
EndIf
Return False
End Method
' Here you could draw your object's hitbox etc
Method DebugOverlay:Void()
SetColor(255, 255, 255)
DrawLine(x, y, x + width, y) 'top
DrawLine(x, y + height, x + width, y + height) 'bot
DrawLine(x, y, x, y + height) 'left
DrawLine(x + width, y, x + width, y + height) 'right
End Method
End Class
' Just a test class to show-off the custom mouse system
Class CustomMouseClass
Global mx:Int, my:Int
Function Update:Void()
mx = MouseX() +32
my = MouseY() +32
End Function
End Class
Class Game Extends App
Field objectList:List<Object>
Method OnCreate:Int()
SetUpdateRate(60)
objectList = New List<Object>
For Local i:= 0 To 9
objectList.AddLast(New TestObject())
End For
DevConsole.Init()
DevConsole.AddObjects(objectList)
DevConsole.Watch(["xVel", "yVel"])
DevConsole.GlobalWatch("TestObject",["testGlobal"])
DevConsole.GlobalWatch("CustomMouseClass",["mx", "my"])
' Un-comment the line below to set up custom mouse. This mouse will be +32,+32px off ;)
'DevConsole.SetupCustomMouseSingleton("CustomMouseClass",["mx", "my"])
Return 0
End
Method OnUpdate:Int()
'Update custom mouse
CustomMouseClass.Update()
For Local obj:= EachIn objectList
TestObject(obj).OnUpdate()
End For
DevConsole.Update()
Local k:Int = GetChar()
If KeyHit(KEY_TAB) Then DevConsole.SetEnabled( Not DevConsole.Enabled())
If KeyHit(KEY_TILDE) or k = 167 Then DevConsole.SetConsoleOpen( Not DevConsole.ConsoleOpen())
If KeyDown(KEY_SPACE) Then
TestObject.testGlobal = True
Else
TestObject.testGlobal = False
End If
Return 0
End
Method OnRender:Int()
Cls()
For Local obj:= EachIn objectList
TestObject(obj).OnRender()
End For
DevConsole.Render()
Return 0
End
End