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
/
Copy pathflxg.monkey
908 lines (672 loc) · 20 KB
/
flxg.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
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
Strict
Import mojo
Import reflection
Import flxextern
Import flxbasic
Import flxgame
Import flxcamera
Import flxobject
Import flxsignals
Import flxsound
Import flxmusic
Import flxu
Import system.input.accel
Import system.input.joystick
Import system.input.keyboard
Import system.input.mouse
Import system.input.touch
Import system.tweens.flxtween
Import system.tweens.util.ease
Import system.tweens.misc.multivartween
Import system.resolutionpolicy.flxresolutionpolicy
Import system.resolutionpolicy.fill
Import system.flxresourcesmanager
Import system.flxquadtree
Import system.flxreplay
Import system.flximagedata
Import plugin.timermanager
Import plugin.debugpathdisplay
Alias AccelInput = accel.Accel
Alias MouseInput = mouse.Mouse
Alias TouchInput = touch.Touch
Alias JoystickInput = joystick.Joystick
Alias MojoDeviceWidth = mojo.app.DeviceWidth
Alias MojoDeviceHeight = mojo.app.DeviceHeight
Class FlxG
Const LIBRARY_NAME:String = "Flixel for Monkey"
Const LIBRARY_MAJOR_VERSION:Int = 1
Const LIBRARY_MINOR_VERSION:Int = 0
Const DATA_SUFFIX:String = "_flx"
Const RED:Int = $FFFF0012
Const GREEN:Int = $FF00F225
Const BLUE:Int = $FF0090E9
Const PINK:Int = $FFF01EFF
Const WHITE:Int = $FFFFFFFF
Const BLACK:Int = $FF000000
Global Paused:Bool
#If FLX_DEBUG_ENABLED
Global Debug:Bool = True
#Else
Global Debug:Bool = False
#End
Global Elapsed:Float
Global TimeScale:Float
Global DeviceWidth:Int
Global DeviceHeight:Int
Global Width:Int
Global Height:Int
Global WorldBounds:FlxRect
Global WorldDivisions:Int
Global VisualDebug:Bool
Global Mobile:Bool
Global GlobalSeed:Int
Global Scores:Stack<Int>
Global Score:Int
Global Levels:Stack<Int>
Global Level:Int
Global Accel:AccelInput
Global Keys:Keyboard
Global Mouse:MouseInput
Global Music:FlxMusic
Global Sounds:FlxGroup
Global Mute:Bool
Global Cameras:Stack<FlxCamera>
Global Camera:FlxCamera
Global Plugins:Stack<FlxBasic>
Global VolumeHandler:FlxVolumeChangeListener
Global Updaterate:Int
Global Tweener:FlxBasic
Global Signals:FlxSignals
Global _DeviceScaleFactorX:Float = 1
Global _DeviceScaleFactorY:Float = 1
Global _DeviceOffsetX:Int
Global _DeviceOffsetY:Int
Global _BgColor:FlxColor = FlxColor.ARGB(FlxG.BLACK)
Global _Game:FlxGame
Global _Volume:Float
Global _BitmapCache:FlxResourcesManager<Image>
Global _SoundCache:FlxResourcesManager<Sound>
Global _LastDrawingColor:Int
Global _LastDrawingAlpha:Float
Global _LastDrawingBlend:Int
Global _CurrentCamera:FlxCamera
Private
#If TARGET = "psm"
Const _JOY_UNITS_COUNT:Int = 1
#Else
Const _JOY_UNITS_COUNT:Int = 4
#End
Const _TOUCH_COUNT:Int = 32
Global _Joystick:JoystickInput[_JOY_UNITS_COUNT]
Global _Touch:TouchInput[_TOUCH_COUNT]
Global _CollideListener:FlxCollideProcessListener = New FlxCollideProcessListener()
Global _ResolutionPolicy:FlxResolutionPolicy = New FillResolutionPolicy()
Global _Point:FlxPoint = New FlxPoint()
Public
Function GetLibraryName:String()
Return FlxG.LIBRARY_NAME + " v" + FlxG.LIBRARY_MAJOR_VERSION + "." + FlxG.LIBRARY_MINOR_VERSION
End Function
Function Log:Void(data:String)
#If FLX_DEBUG_ENABLED
'note: TODO: to add log objects
Print data
#End
End Function
Function Random:Float()
FlxG.GlobalSeed = (FlxG.GlobalSeed * 1664525 + 1013904223) | 0
Return FlxU.Srand(FlxG.GlobalSeed)
End Function
Function Random:Float(range:Float)
Return FlxG.Random() * range
End Function
Function Random:Float(low:Float, high:Float)
Return FlxG.Random(high - low) + low
End Function
Function Random:Int(range:Int)
Return Int(FlxG.Random() * (1 + range))
End Function
Function Random:Int(low:Int, high:Int)
Return FlxG.Random(high - low) + low
End Function
#Rem
Function GetRandom:Object(objects:Object[], startIndex:Int = 0, length:Int = 0)
GetRandom is not currently supported in Monkey. Use FlxArray.GetSafeRandom method
End Function
#End
Function LoadReplay:Void(data:String, state:FlxState = Null, cancelKeys:Int[] = [], timeout:Float = 0, callback:FlxReplayListener = Null)
_Game._replay.Load(data)
If (state = Null) Then
FlxG.ResetGame()
Else
FlxG.SwitchState(state)
End If
_Game._replayCancelKeys = cancelKeys
_Game._replayTimer = timeout * 1000
_Game._replayCallback = callback
_Game._replayRequested = True
End Function
Function ReloadReplay:Void(standardMode:Bool = True)
If (standardMode) Then
FlxG.ResetGame()
Else
FlxG.ResetState()
End If
If (_Game._replay.frameCount > 0) _Game._replayRequested = True
End Function
Function StopReplay:Void()
_Game._replaying = False
#If FLX_DEBUG_ENABLED
If (_Game._debugger <> Null) Then
'note: TODO:
End If
#End
ResetInput()
End Function
Function RecordReplay:Void(standardMode:Bool = True)
If (standardMode) Then
FlxG.ResetGame()
Else
FlxG.ResetState()
End If
_Game._recordingRequested = True
End Function
Function StopRecording:String()
_Game._recording = False
#If FLX_DEBUG_ENABLED
If (_Game._debugger <> Null) Then
'note: TODO:
End If
#End
Return _Game._replay.Save()
End Function
Function ResetState:Void()
_Game._requestedState = FlxState(_Game._state.GetClassInfo().NewInstance())
End Function
Function ResetGame:Void()
_Game._requestedReset = True
End Function
Function ResetInput:Void()
For Local i:Int = 0 Until _JOY_UNITS_COUNT
_Joystick[i].Reset()
Next
For Local i:Int = 0 Until _TOUCH_COUNT
_Touch[i].Reset()
Next
Accel.Reset()
Mouse.Reset()
Keys.Reset()
End Function
Function PlayMusic:Void(music:String, volume:Float = 1.0)
If (FlxG.Music = Null) Then
FlxG.Music = New FlxMusic()
ElseIf (FlxG.Music.active) Then
FlxG.Music.Stop()
End If
FlxG.Music.Load(music, True)
FlxG.Music.Volume = volume
FlxG.Music.survive = True
FlxG.Music.Play()
End Function
Function LoadSound:FlxSound(sound:String, volume:Float = 1.0, looped:Bool = False, autoDestroy:Bool = False, autoPlay:Bool = False, stopPrevious:Bool = True)
Local s:FlxSound = FlxSound(Sounds.Recycle(FlxSound.__CLASS__))
s.Load(sound, looped, autoDestroy, stopPrevious)
s.Volume = volume
If (autoPlay) s.Play()
Return s
End Function
Function Play:FlxSound(sound:String, volume:Float = 1.0, looped:Bool = False, autoDestroy:Bool = True)
Return FlxG.LoadSound(sound, volume, looped, autoDestroy, True, False)
End Function
Function Volume:Float()
Return _Volume
End Function
Function Volume:Void(volume:Float)
_Volume = volume
If (_Volume < 0) Then
_Volume = 0
ElseIf (_Volume > 1) Then
_Volume = 1
End If
If (VolumeHandler <> Null) Then
If (FlxG.Mute) Then
VolumeHandler.OnVolumeChange(0)
Else
VolumeHandler.OnVolumeChange(_Volume)
End If
End If
If (Music <> Null And Music.active) Then
Music._UpdateTransform()
End If
For Local basic:FlxBasic = EachIn Sounds
FlxSound(basic)._UpdateTransform()
Next
End Function
Function DestroySounds:Void(forceDestroy:Bool = False)
If (Music <> Null And (forceDestroy Or Not Music.survive)) Then
Music.Destroy()
Music = Null
End If
Local sound:FlxSound
For Local basic:FlxBasic = EachIn Sounds
sound = FlxSound(basic)
If (sound <> Null And (forceDestroy Or Not sound.survive)) Then
sound.Destroy()
End If
Next
End Function
Function UpdateSounds:Void()
If (Music <> Null And Music.active) Then
Music.Update()
End If
If (Sounds <> Null And Sounds.active) Then
Sounds.Update()
End If
End Function
Function PauseSounds:Void()
If (Music <> Null And Music.exists And Music.active) Then
Music.Pause()
End If
Local sound:FlxSound
For Local basic:FlxBasic = EachIn Sounds
sound = FlxSound(basic)
If (sound <> Null And sound.exists And sound.active) Then
sound.Pause()
End If
Next
End Function
Function ResumeSounds:Void()
If (Music <> Null And Music.exists) Then
Music.Resume()
End If
Local sound:FlxSound
For Local basic:FlxBasic = EachIn Sounds
sound = FlxSound(basic)
If (sound <> Null And sound.exists) Then
sound.Resume()
End If
Next
End Function
Function CheckBitmapCache:Bool(key:String)
Return _BitmapCache.CheckResource(key)
End Function
Function CreateBitmap:Image(width:Int, height:Int, color:Int, unigue:Bool, key:String = "")
If (key.Length() = 0) Then
key = width + "x" + height + ":" + color
If (unigue And CheckBitmapCache(key)) Then
Local inc:Int = 0
Local ukey:String
Repeat
ukey = key + inc
inc += 1
Until (CheckBitmapCache(ukey))
key = ukey
End If
End If
Return _BitmapCache.GetResource(key, New CreateImageResource(key, width, height, color))
End Function
Function AddBitmap:Image(resource:FlxResource<Image>, unique:Bool = False, key:String = "")
If (key.Length() = 0) Then
key = resource.name
If (unique And CheckBitmapCache(key)) Then
Local inc:Int = 0
Local ukey:String
Repeat
ukey = key + inc
inc += 1
Until(CheckBitmapCache(ukey))
key = ukey
End If
End If
Return _BitmapCache.GetResource(key, resource)
End Function
Function RemoveBitmap:Void(graphic:String)
If (_BitmapCache <> Null) Then
_BitmapCache.RemoveResource(graphic)
End If
End Function
Function ClearBitmapCache:Void()
If (_BitmapCache = Null) _BitmapCache = New FlxResourcesManager<Image>()
_BitmapCache.Clear()
End Function
Function AddSound:Sound(resource:FlxResource<Sound>)
Return _SoundCache.GetResource(resource.name, resource)
End Function
Function ClearSoundCache:Void()
If (_SoundCache = Null) _SoundCache = New FlxResourcesManager<Sound>()
_SoundCache.Clear()
End Function
Function State:FlxState()
Return _Game._state
End Function
Function SwitchState:Void(state:FlxState)
FlxG._Game._requestedState = state
End Function
Function SetSwitchStateListener:Void(listener:FlxSwitchStateListener)
FlxG._Game.SetSwitchStateListener(listener)
End Function
Function AddCamera:FlxCamera(newCamera:FlxCamera)
FlxG.Cameras.Push(newCamera)
Return newCamera
End Function
Function RemoveCamera:Void(camera:FlxCamera, destroy:Bool = True)
FlxG.Cameras.RemoveEach(camera)
If (destroy) camera.Destroy()
End Function
Function ResetCameras:Void(newCamera:FlxCamera = Null)
Local cam:FlxCamera
Local i:Int = 0
Local l:Int = FlxG.Cameras.Length()
While(i < l)
cam = FlxG.Cameras.Get(i)
cam.Destroy()
i+=1
Wend
FlxG.Cameras.Clear()
FlxG.Camera = Null
If (newCamera = Null) newCamera = New FlxCamera(0, 0, FlxG.Width, FlxG.Height)
FlxG.Camera = FlxG.AddCamera(newCamera)
End Function
Function Flash:Void(color:Int = FlxG.WHITE, duration:Float = 1, onComplete:FlxCameraFlashListener = Null, force:Bool = False)
Local i:Int = 0
Local l:Int = FlxG.Cameras.Length()
While(i < l)
FlxG.Cameras.Get(i).Flash(color, duration, onComplete, force)
i+=1
Wend
End Function
Function Fade:Void(color:Int = FlxG.BLACK, duration:Float = 1, onComplete:FlxCameraFadeListener = Null, force:Bool = False)
Local i:Int = 0
Local l:Int = FlxG.Cameras.Length()
While(i < l)
FlxG.Cameras.Get(i).Fade(color, duration, onComplete, force)
i+=1
Wend
End Function
Function Shake:Void(intensity:Float = 0.05, duration:Float = 0.5, onComplete:FlxCameraShakeListener = Null, force:Bool = True, direction:Int = FlxCamera.SHAKE_BOTH_AXES)
Local i:Int = 0
Local l:Int = FlxG.Cameras.Length()
While(i < l)
FlxG.Cameras.Get(i).Shake(intensity, duration, onComplete, force, direction)
i+=1
Wend
End Function
Function BgColor:Int()
If (FlxG.Camera = Null Or Not FlxG.Camera.alive) Return FlxG._BgColor.argb
Return FlxG.Camera.BgColor
End Function
Function SetBgColor:Void(color:Int)
Local i:Int = 0
Local l:Int = FlxG.Cameras.Length()
While(i < l)
FlxG.Cameras.Get(i).BgColor = color
i+=1
Wend
FlxG._BgColor.SetARGB(color)
End Function
Function Overlap:Bool(objectOrGroup1:FlxBasic = Null, objectOrGroup2:FlxBasic, notifyCallback:FlxOverlapNotifyListener = Null, processCallback:FlxOverlapProcessListener = Null)
If (objectOrGroup1 = Null) objectOrGroup1 = FlxG.State()
If (objectOrGroup2 = objectOrGroup1) objectOrGroup2 = Null
FlxQuadTree.Divisions = FlxG.WorldDivisions
Local quadTree:FlxQuadTree = FlxQuadTree.Recycle(FlxG.WorldBounds.x, FlxG.WorldBounds.y, FlxG.WorldBounds.width, FlxG.WorldBounds.height)
quadTree.Load(objectOrGroup1, objectOrGroup2, notifyCallback, processCallback)
Local result:Bool = quadTree.Execute()
quadTree.Destroy()
Return result
End Function
Function Collide:Bool(objectOrGroup1:FlxBasic = Null, objectOrGroup2:FlxBasic = Null, notifyCallback:FlxOverlapNotifyListener = Null)
Return Overlap(objectOrGroup1, objectOrGroup2, notifyCallback, _CollideListener)
End Function
Function AddPlugin:FlxBasic(plugin:FlxBasic)
Local pluginList:Stack<FlxBasic> = FlxG.Plugins
Local i:Int = 0
Local l:Int = pluginList.Length()
While(i < l)
If (pluginList.Get(i).ToString() = plugin.ToString()) Then
Return plugin
End If
i+=1
Wend
pluginList.Push(plugin)
Return plugin
End Function
Function GetPlugin:FlxBasic(objectClass:ClassInfo)
Local pluginList:Stack<FlxBasic> = FlxG.Plugins
Local plugin:FlxBasic
Local i:Int = 0
Local l:Int = pluginList.Length()
While(i < l)
plugin = pluginList.Get(i)
If (plugin.GetClassInfo().ExtendsClass(objectClass)) Return plugin
i+=1
Wend
Return Null
End Function
Function GetPlugin:FlxBasic(objectOrClass:Object)
If (ClassInfo(objectOrClass) <> Null) Then
Return GetPlugin(ClassInfo(objectOrClass))
Else
Return GetPlugin(GetClass(objectOrClass))
End If
End Function
Function RemovePlugin:FlxBasic(plugin:FlxBasic)
Plugins.RemoveEach(plugin)
Return plugin
End Function
Function RemovePluginType:Bool(objectClass:ClassInfo)
Local results:Bool = False
Local pluginList:Stack<FlxBasic> = FlxG.Plugins
Local i:Int = pluginList.Length() - 1
While(i >= 0)
If (pluginList.Get(i).GetClassInfo().ExtendsClass(objectClass)) Then
pluginList.Remove(i)
results = True
End If
i-=1
Wend
Return results
End Function
Function Init:Void(game:FlxGame, width:Int, height:Int, zoom:Float)
FlxG._Game = game
FlxG.Width = width
FlxG.Height = height
FlxG.Tweener = New FlxBasic()
FlxG.Signals = New FlxSignals()
FlxG.Mute = False
FlxG._Volume = .5
FlxG.Sounds = New FlxGroup()
FlxG.VolumeHandler = Null
FlxG.ClearBitmapCache()
FlxCamera.DefaultZoom = zoom
FlxG.Cameras = New Stack<FlxCamera>()
Plugins = New Stack<FlxBasic>
#If FLX_DEBUG_ENABLED
AddPlugin(New DebugPathDisplay())
#End
AddPlugin(New TimerManager())
FlxG.Accel = New AccelInput()
FlxG.Keys = New Keyboard()
FlxG.Mouse = New MouseInput()
For Local i:Int = 0 Until _JOY_UNITS_COUNT
_Joystick[i] = New JoystickInput(i)
Next
For Local i:Int = 0 Until _TOUCH_COUNT
_Touch[i] = New TouchInput(i)
Next
FlxG.Mobile = FlxIsMobile()
FlxG.Scores = New Stack<Int>()
FlxG.Levels = New Stack<Int>()
FlxG.VisualDebug = False
End Function
Function Reset:Void()
FlxG.ClearBitmapCache()
FlxG.DestroySounds(True)
FlxG.ClearSoundCache()
FlxG.ResetInput()
FlxG.Signals.Destroy()
FlxG.Levels.Clear()
FlxG.Scores.Clear()
FlxG.Level = 0
FlxG.Score = 0
FlxG.TimeScale = 1
FlxG.Elapsed = 0
FlxG.GlobalSeed = Seed
FlxG.WorldBounds = New FlxRect(-10, -10, FlxG.Width + 20, FlxG.Height + 20)
FlxG.WorldDivisions = 6
#If FLX_DEBUG_ENABLED
Local debugPathDisplay:DebugPathDisplay = DebugPathDisplay(FlxG.GetPlugin(DebugPathDisplay.__CLASS__))
If (debugPathDisplay <> Null) debugPathDisplay.Clear()
#End
End Function
Function UpdateInput:Void()
#If FLX_MOUSE_ENABLED
#If FLX_DEBUG_ENABLED
If (Not _Game._debuggerUp Or Not _Game._debugger.hasMouse) Then
Mouse.Update(MouseX(), MouseY())
End If
#Else
Mouse.Update(MouseX(), MouseY())
#End
_Touch[0].Update(TouchX(), TouchY())
#End
#If FLX_KEYBOARD_ENABLED
Keys.Update()
#End
#If FLX_JOYSTICK_ENABLED
For Local i:Int = 0 Until _JOY_UNITS_COUNT
_Joystick[i].Update()
Next
#End
#If FLX_MULTITOUCH_ENABLED
For Local i:Int = 1 Until _TOUCH_COUNT
_Touch[i].Update(TouchX(i), TouchY(i))
If ( Not _Touch[i].Used) Exit
Next
#End
#If FLX_ACCEL_ENABLED
Accel.Update(AccelX(), AccelY(), AccelZ())
#End
End Function
Function UpdateCameras:Void()
Local cam:FlxCamera
Local cams:Stack<FlxCamera> = FlxG.Cameras
Local i:Int = 0
Local l:Int = cams.Length()
While(i < l)
cam = cams.Get(i)
If (cam <> Null And cam.exists And cam.active) cam.Update()
i+=1
Wend
End Function
Function UpdatePlugins:Void()
Local plugin:FlxBasic
Local pluginList:Stack<FlxBasic> = FlxG.Plugins
Local i:Int = 0
Local l:Int = pluginList.Length()
While(i < l)
plugin = pluginList.Get(i)
If (plugin.exists And plugin.active) plugin.Update()
i+=1
Wend
End Function
Function DrawPlugins:Void()
Local plugin:FlxBasic
Local pluginList:Stack<FlxBasic> = FlxG.Plugins
Local i:Int = 0
Local l:Int = pluginList.Length()
While(i < l)
plugin = pluginList.Get(i)
If (plugin.exists And plugin.visible) plugin.Draw()
i+=1
Wend
End Function
Function Joystick:JoystickInput(unit:Int = 0)
Return _Joystick[unit]
End Function
Function Touch:TouchInput(index:Int = 0)
Return _Touch[index]
End Function
Function JoystickCount:Int()
Return _JOY_UNITS_COUNT
End Function
Function TouchCount:Int()
Return _TOUCH_COUNT
End Function
Function SetResolutionPolicy:Void(resolutionPolicy:FlxResolutionPolicy)
_ResolutionPolicy = resolutionPolicy
_Measure()
End Function
Function UpdateDevice:Void()
If(FlxG.DeviceWidth <> MojoDeviceWidth() Or FlxG.DeviceHeight <> MojoDeviceHeight()) Then
_Measure()
End If
End Function
Function Tween:MultiVarTween(object:Object, values:StringMap<Float>, duration:Float, type:Int = FlxTween.ONESHOT, complete:FlxTweenListener = Null, ease:FlxEaseFunction = Null, tweener:FlxBasic = Null)
If (tweener = Null) Then
If (FlxBasic(object) <> Null) Then
tweener = FlxBasic(object)
Else
tweener = FlxG.Tweener
End If
End If
Local tween:MultiVarTween = New MultiVarTween(complete, type)
tween.Tween(object, values, duration, ease)
tweener.AddTween(tween)
Return tween
End Function
Private
Function _Measure:Void()
FlxG.DeviceWidth = MojoDeviceWidth()
FlxG.DeviceHeight = MojoDeviceHeight()
_ResolutionPolicy.OnMeasure(FlxG.DeviceWidth, FlxG.DeviceHeight, _Point)
FlxG._DeviceScaleFactorX = _Point.x / Float(FlxG.Width)
FlxG._DeviceScaleFactorY = _Point.y / Float(FlxG.Height)
Local zoom:Float = FlxCamera.DefaultZoom
If(FlxG.Camera <> Null) zoom = FlxG.Camera.Zoom
FlxG._DeviceOffsetX = Ceil( (FlxG.DeviceWidth - _Point.x * zoom) * 0.5)
FlxG._DeviceOffsetY = Ceil( (FlxG.DeviceHeight - _Point.y * zoom) * 0.5)
Local i:Int = 0
Local l:Int = FlxG.Cameras.Length()
Local cam:FlxCamera
While(i < l)
cam = FlxG.Cameras.Get(i)
'recalc values
cam.X = cam.X
cam.Y = cam.Y
cam.Width = cam.Width
cam.Height = cam.Height
i += 1
Wend
End Function
End Class
Interface FlxVolumeChangeListener
Method OnVolumeChange:Void(volume:Float)
End Interface
Private
Class FlxCollideProcessListener Implements FlxOverlapProcessListener
Method OnOverlapProcess:Bool(object1:FlxObject, object2:FlxObject)
Return FlxObject.Separate(object1, object2)
End Method
End Class
Class CreateImageResource Extends FlxResource<Image>
Field width:Float
Field height:Float
Field color:Int
Field image:Image
Method New(name:String, width:Float, height:Float, color:Int)
Super.New(name)
Self.width = width
Self.height = height
Self.color = color
End Method
Method Load:Image()
image = (New FlxImageData(width, height, False, color)).Image
Return image
End Method
Method Use:Image()
Return image
End Method
Method Discard:Void()
image.Discard()
image = Null
End Method
End Class