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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
|
' Particle Pinch
'
' Copyright 2005 Ian Cowburn
'
' $Id$
'
Strict
Import noddybox.vector
Import noddybox.bitmapfont
Import noddybox.simplegui
Import noddybox.algorithm
Import "types.bmx"
Import "level.bmx"
Import "game.bmx"
Function LevelDesigner()
DoDesigner()
End Function
Private
' **** Types
'
Type TDesObj Abstract
Const SELSIZE:Int=3
Function Create:TDesObj(x:Int, y:Int) Abstract
Function CreateFromLevel:TDesObj(o:Object) Abstract
Method Draw() Abstract
Method DrawSelect() Abstract
Method MouseOver:Int(x:Int, y:Int) Abstract
Method Drag(x:Int, y:Int) Abstract
Method Edit() Abstract
Method Save(l:TLevel) Abstract
Method DrawSelBox(x:Int, y:Int)
Local x1:Int=x-SELSIZE
Local y1:Int=y-SELSIZE
Local x2:Int=x+SELSIZE
Local y2:Int=y+SELSIZE
SetColor(255,255,255)
DrawLine(x1,y1,x2,y1)
DrawLine(x2,y1,x2,y2)
DrawLine(x2,y2,x1,y2)
DrawLine(x1,y2,x1,y1)
End Method
Method InSelBox(px:Int, py:Int, x:Int, y:Int)
Local x1:Int=x-SELSIZE
Local y1:Int=y-SELSIZE
Local x2:Int=x+SELSIZE
Local y2:Int=y+SELSIZE
Return px>=x1 And px<=x2 And py>=y1 And py<=y2
End Method
End Type
Type TDesGrav Extends TDesObj
Field g:TGravPoint
Function Create:TDesObj(x:Int, y:Int)
Local o:TDesGrav=New TDesGrav
o.g=New TGravPoint
o.g.x=x
o.g.y=y
o.g.friendly=False
o.g.mass=25
o.g.repel=False
Return o
End Function
Function CreateFromLevel:TDesObj(o:Object)
Local lp:TGravPoint=TGravPoint(o)
Local no:TDesGrav=New TDesGrav
no.g=New TGravPoint
no.g.x=lp.x
no.g.y=lp.y
no.g.friendly=lp.friendly
no.g.mass=lp.mass
no.g.repel=lp.repel
Return no
End Function
Method Draw()
If g.friendly
SetColor(0,255,0)
Else
SetColor(255,0,0)
EndIf
DrawOval(g.x-MASSRAD,g.y-MASSRAD,MASSSIZE,MASSSIZE)
End Method
Method DrawSelect()
DrawSelBox(g.x,g.y)
End Method
Method MouseOver:Int(x:Int, y:Int)
Return InSelBox(x,y,g.x,g.y)
End Method
Method Drag(x:Int, y:Int)
g.x=x
g.y=y
End Method
Method Edit()
Designer.md_friendly.checked = g.friendly
Designer.md_invert.checked = g.repel
Designer.md_mass.text = g.mass
If GUIDialog(Designer.mdialog,Designer.md_ok,Designer.md_cancel,GameGFX.pointer)
g.friendly = Designer.md_friendly.checked
g.repel = Designer.md_invert.checked
g.mass = Designer.md_mass.text.ToFloat()
EndIf
End Method
Method Save(l:TLevel)
l.grav.AddLast(g)
End Method
End Type
Type TDesPoint Extends TDesObj
Field l:TPointLine
Field over_p1:Int
Function Create:TDesObj(x:Int, y:Int)
Local o:TDesPoint=New TDesPoint
o.over_p1=False
o.l=New TPointLine
o.l.x1=x
o.l.y1=y
o.l.y2=y
If x<GraphicsWidth()/2
o.l.x2=x+50
Else
o.l.x2=x-50
EndIf
o.l.gap=1
o.l.v.x=0
o.l.v.y=0
Return o
End Function
Function CreateFromLevel:TDesObj(o:Object)
Local lp:TPointLine=TPointLine(o)
Local no:TDesPoint=New TDesPoint
no.l=New TPointLine
no.l.x1=lp.x1
no.l.y1=lp.y1
no.l.x2=lp.x2
no.l.y2=lp.y2
no.l.gap=lp.gap
no.l.v.x=lp.v.x
no.l.v.y=lp.v.y
Return no
End Function
Method Draw()
Local lp:TList=DoLine(l.x1,l.y1,l.x2,l.y2)
Local i:Int=0
SetColor(0,255,0)
DrawLine(l.x1,l.y1,l.x1+l.v.x*10,l.y1+l.v.y*10)
DrawLine(l.x2,l.y2,l.x2+l.v.x*10,l.y2+l.v.y*10)
For Local p:TAlgoPoint=EachIn lp
If (i Mod l.gap)=0
SetColor(255,255,255)
Else
SetColor(200,0,0)
EndIf
Plot(p.x,p.y)
i:+1
Next
End Method
Method DrawSelect()
If over_p1
DrawSelBox(l.x1,l.y1)
Else
DrawSelBox(l.x2,l.y2)
EndIf
End Method
Method MouseOver:Int(x:Int, y:Int)
If InSelBox(x,y,l.x1,l.y1)
over_p1=True
Return True
EndIf
If InSelBox(x,y,l.x2,l.y2)
over_p1=False
Return True
EndIf
Return False
End Method
Method Drag(x:Int, y:Int)
If over_p1
l.x1=x
l.y1=y
Else
l.x2=x
l.y2=y
EndIf
End Method
Method Edit()
Designer.pd_gap.text = l.gap
Designer.pd_vx.text = l.v.x
Designer.pd_vy.text = l.v.y
If GUIDialog(Designer.pdialog,Designer.pd_ok,Designer.pd_cancel,GameGFX.pointer)
l.gap = Designer.pd_gap.text.ToInt()
l.v.x = Designer.pd_vx.text.ToFloat()
l.v.y = Designer.pd_vy.text.ToFloat()
EndIf
End Method
Method Save(l:TLevel)
l.point.AddLast(l)
End Method
End Type
' **** Globals
'
' This type acts as a namespace for global variables
'
Type Designer
Const TEXTX:Int=100
Global init:Int=False
Global obj:TList
Global levelset:TLevelSet
Global level:TLevel
Global levelsetfname:String
Global done:Int
Global levelindex:Int
Global gui:TGUIHandler
Global fname_txt:TText
Global fname_load:TButton
Global fname_save:TButton
Global setname_txt:TText
Global levname_txt:TText
Global levadd_but:TButton
Global levins_but:TButton
Global levdel_but:TButton
Global levinv_check:TCheckbox
Global levnum:TNumberInt
Global hide_check:TCheckbox
Global validbut:TButton
Global helpbut:TButton
Global quitbut:TButton
Global mdialog:TGUIHandler
Global md_friendly:TCheckbox
Global md_invert:TCheckbox
Global md_mass:TText
Global md_ok:TButton
Global md_cancel:TButton
Global pdialog:TGUIHandler
Global pd_gap:TText
Global pd_vx:TText
Global pd_vy:TText
Global pd_ok:TButton
Global pd_cancel:TButton
Function Initialise()
If Not init
Local l:TLabel
Local p:TPanel
obj = CreateList()
TGUIFont.font = GameGFX.guifont
levelset = New TLevelSet
level = New TLevel
levelsetfname = "Default.ppinch"
levelindex = 0
gui = TGUIHandler.Create()
TLabel.Create(gui,0,0,"File")
fname_txt = TText.Create(gui,TEXTX,0,"",32)
fname_load = TButton.Create(gui,fname_txt.x+fname_txt.w+10,0,50,12,"Load",LoadCallback)
fname_save = TButton.Create(gui,fname_load.x+fname_load.w+10,0,50,fname_load.h,"Save",SaveCallback)
TLabel.Create(gui,0,10,"Levelset name")
setname_txt = TText.Create(gui,TEXTX,10,"",32)
TLabel.Create(gui,0,20,"Level name")
levname_txt = TText.Create(gui,TEXTX,20,"",32)
levadd_but = TButton.Create(gui,levname_txt.x+levname_txt.w+10,levname_txt.y,50,12,"Add",AddLevelCallback)
levins_but = TButton.Create(gui,levadd_but.x+levadd_but.w+10,levname_txt.y,50,12,"Insert",InsertLevelCallback)
levdel_but = TButton.Create(gui,levins_but.x+levins_but.w+10,levname_txt.y,50,12,"Delete",DeleteLevelCallback)
levinv_check = TCheckbox.Create(gui,0,35,"Invert placed masses",InvertPlacedCallback)
l = TLabel.Create(gui,levinv_check.w+50,35,"Level:")
levnum = TNumberInt.Create(gui,l.x+l.w+10,35,LevelNumberCallback)
levnum.value = 0
levnum.minval = 0
levnum.maxval = 0
hide_check = TCheckbox.Create(gui,750,0,"Hide",HideCallback)
validbut = TButton.Create(gui,650,570,49,29,"Check",CheckCallback)
helpbut = TButton.Create(gui,700,570,49,29,"Test",TestCallback)
quitbut = TButton.Create(gui,750,570,49,29,"Quit",QuitCallback)
mdialog = TGUIHandler.Create()
p = TPanel.Create(mdialog,-1,-1,400,100)
md_friendly = TCheckbox.Create(mdialog,p.x+5,p.y+10,"Friendly (scores for player)?")
md_invert = TCheckbox.Create(mdialog,p.x+5,p.y+30,"Inverse gravity?")
l = TLabel.Create(mdialog,p.x+5,p.y+50,"Mass:")
md_mass = TText.Create(mdialog,p.x+l.w+10,p.y+50,"",30,TText.NUMERIC|TText.POSITIVE)
md_ok = TButton.Create(mdialog,p.x+5,p.y+p.h-25,p.w/2-10,20,"OK",Null)
md_cancel = TButton.Create(mdialog,p.x+p.w/2+5,p.y+p.h-25,p.w/2-10,20,"Cancel",Null)
pdialog = TGUIHandler.Create()
p = TPanel.Create(pdialog,-1,-1,400,100)
l = TLabel.Create(pdialog,p.x+5,p.y+10,"Gap per point:")
pd_gap = TText.Create(pdialog,p.x+90,p.y+10,"",30,TText.NUMERIC|TText.INTEGER|TText.POSITIVE)
l = TLabel.Create(pdialog,p.x+5,p.y+30,"Initial dx:")
l = TLabel.Create(pdialog,p.x+5,p.y+50,"Initial dy:")
pd_vx = TText.Create(pdialog,p.x+90,p.y+30,"",30,TText.NUMERIC)
pd_vy = TText.Create(pdialog,p.x+90,p.y+50,"",30,TText.NUMERIC)
pd_ok = TButton.Create(pdialog,p.x+5,p.y+p.h-25,p.w/2-10,20,"OK",Null)
pd_cancel = TButton.Create(pdialog,p.x+p.w/2+5,p.y+p.h-25,p.w/2-10,20,"Cancel",Null)
levelset.level.AddLast(level)
init=True
EndIf
done = False
fname_txt.text = levelsetfname
setname_txt.text = levelset.name
levname_txt.text = level.name
End Function
End Type
' **** Main Loop
'
Function DoDesigner()
Designer.Initialise()
Designer.done=False
Local sel:TDesObj=Null
Local drag:Int=False
While Not Designer.done
Cls
If Not drag
Designer.gui.EventLoop()
EndIf
Local x:Int=MouseX()
Local y:Int=MouseY()
If Not drag
sel=Null
EndIf
For Local o:TDesObj=EachIn Designer.obj
o.Draw()
If sel=Null And o.MouseOver(x,y)
sel=o
EndIf
Next
If sel<>Null
sel.DrawSelect()
EndIf
If drag
sel.Drag(x,y)
EndIf
If KeyHit(KEY_MOUSERIGHT)
If sel<>Null
Select GUIMenu("Object Menu",["Edit","Delete"],x,y,GameGFX.pointer)
Case 0
sel.Edit()
Case 1
Designer.obj.Remove(sel)
End Select
Else
Select GUIMenu("Create Menu",["Create Gravity Point","Create Particle Line"],x,y,GameGFX.pointer)
Case 0
Designer.obj.AddLast(TDesGrav.Create(x,y))
Case 1
Designer.obj.AddLast(TDesPoint.Create(x,y))
End Select
EndIf
sel=Null
EndIf
If Not drag
If KeyDown(KEY_MOUSELEFT) And sel<>Null
drag=True
EndIf
Else
If Not KeyDown(KEY_MOUSELEFT)
drag=False
EndIf
EndIf
SetColor(255,255,255)
DrawImage(GameGFX.pointer,MouseX(),MouseY())
Flip
FlushMem
Wend
End Function
' **** Utils
'
Function LoadLevel()
End Function
Function SaveLevel()
End Function
' **** Callbacks
'
Function HideCallback(w:TWidget)
Local c:TCheckbox=TCheckbox(w)
Designer.gui.SetEnable(Not c.checked)
c.enabled=True
End Function
Function QuitCallback(w:TWidget)
Designer.done=GUIYesNo("Quit back to the|main menu of Particle Pinch?",GameGFX.pointer)
End Function
Function TestCallback(w:TWidget)
End Function
Function CheckCallback(w:TWidget)
End Function
Function LoadCallback(w:TWidget)
Try
Local load:TLevelSet=TLevelSet.Load(Designer.fname_txt.text)
Designer.levelset=load
Catch e:TLevelException
GUINotify("Failed to load '" + Designer.fname_txt.text + "'||"+e.message,GameGFX.pointer)
EndTry
End Function
Function SaveCallback(w:TWidget)
If Not Designer.levelset.Save(Designer.fname_txt.text)
GUINotify("Failed to save '" + Designer.fname_txt.text + "'",GameGFX.pointer)
EndIf
End Function
Function InvertPlacedCallback(w:TWidget)
Local c:TCheckbox=TCheckbox(w)
Designer.level.invmass=c.checked
End Function
Function LevelNumberCallback(w:TWidget)
Local c:TNumberInt=TNumberInt(w)
SaveLevel()
Designer.levelindex=c.value
LoadLevel()
End Function
Function AddLevelCallback(w:TWidget)
End Function
Function InsertLevelCallback(w:TWidget)
End Function
Function DeleteLevelCallback(w:TWidget)
If Designer.levelset.level.Count()<2
GUINotify("Must have at least one level!",GameGFX.pointer)
Return
EndIf
If GUIYesNo("Delete this level:|"+Designer.levname_txt.text,GameGFX.pointer)
EndIf
End Function
|