-
Notifications
You must be signed in to change notification settings - Fork 2
/
cftObject.monkey
executable file
·3847 lines (3467 loc) · 126 KB
/
cftObject.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
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#rem
Title: fantomEngine
Description: A 2D game framework for the Monkey programming language
Author: Michael Hartlef
Contact: [email protected]
Website: http://www.fantomgl.com
License: MIT
#End
Import fantomEngine
'Global dbXXX:Int = 0
'nav:<blockquote><nav><b>fantomEngine documentation</b> | <a href="index.html">Home</a> | <a href="classes.html">Classes</a> | <a href="3rdpartytools.html">3rd party tools</a> | <a href="examples.html">Examples</a> | <a href="changes.html">Changes</a></nav></blockquote>
'#DOCON#
#Rem
'header:The class [b]ftObject[/b] offers you a huge set of methods to deal with its object. And object can either be an (animated) image, a bitmap font text, a tile map, a primitive (circle, rectangle) or a zone (circle, rectangle).
#End
'***************************************
Class ftObject
'#DOCOFF#
Field xPos:Float = 0.0
Field yPos:Float = 0.0
Field zPos:Float = 0.0
Field w:Float = 0.0
Field h:Float = 0.0
'**---------------------------------------------------------------------------------------------------------------------------------------**
Field x2:Float = 0.0 'Render -- case ftEngine.otLine
Field y2:Float = 0.0 'Render -- case ftEngine.otLine
'Field verts:Float[] = [0.0,0.0, 0.0,0.0, 0.0,0.0] 'Render -- case ftEngine.otPoly (Polygon requires minimum of 3 x,y pairs)
Field verts:Float[]
'**---------------------------------------------------------------------------------------------------------------------------------------**
Field rw:Float = 0.0
Field rh:Float = 0.0
Field rox:Float = 0.0
Field roy:Float = 0.0
Field angle:Float = 0.0
Field scaleX:Float = 1.0
Field scaleY:Float = 1.0
Field radius:Float = 1.0
Field friction:Float = 0.0
Field speed:Float = 0.0
Field speedX:Float = 0.0
Field speedY:Float = 0.0
Field speedSpin:Float = 0.0
Field speedAngle:Float = 0.0
Field speedMax:Float = 9999.0
Field speedMin:Float = -9999.0
Field engine:ftEngine = Null
Field red:Float = 255.0
Field blue:Float = 255.0
Field green:Float = 255.0
Field alpha:Float = 1.0
Field blendMode:Int = 0
Field objImg:ftImage[1]
'Field animTime:Float = 0.0
Field frameCount:Float = 1
Field frameStart:Float = 0
Field frameEnd:Float = 0
'Field frameTime:Float = 10
Field frameLength:Float = 0
Field layer:ftLayer = Null
Field layerNode:list.Node<ftObject> = Null 'Version 1.21
Field parentObj:ftObject = Null
Field parentNode:list.Node<ftObject> = Null 'Version 1.21
Field timerList := New List<ftTimer>
Field childObjList := New List<ftObject>
Field transitionList := New List<ftTrans>
Field marker:ftMarker = Null
Field markerNode:list.Node<ftObject> = Null
Field objFont:ftFont = Null
Field id:Int = 0
Field textMode:Int = 0
Field name:String = ""
Field text:String = ""
Field tag:Int = 0
Field type:Int = ftEngine.otImage
Field groupID:Int = 0
Field collType:Int = 0
Field collScale:Float = 1.0
Field collGroup:Int = 0
Field collWith:Int[] = [0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0]
Field colCheck:Bool = False
Field isVisible:Bool = True
Field isAnimated:Bool = False
Field isActive:Bool = True
Field isWrappingX:Bool = False
Field isWrappingY:Bool = False
Field touchMode:Int = 0
Field isFlipH:Bool = False 'Up/Down =Y
Field isFlipV:Bool = False 'Left/Right =X
Field onDeleteEvent:Bool = False
Field onRenderEvent:Bool = False
Field onUpdateEvent:Bool = True
Field x1c:Float = 0.0
Field y1c:Float = 0.0
Field x2c:Float = 0.0
Field y2c:Float = 0.0
Field x3c:Float = 0.0
Field y3c:Float = 0.0
Field x4c:Float = 0.0
Field y4c:Float = 0.0
Field deleted:Bool = False
#rem
Field tileMap:ftMapTile[]
Field tileCount:Int = 0
Field tileCountX:Int = 0
Field tileCountY:Int = 0
Field tileSizeX:Int = 0
Field tileSizeY:Int = 0
Field tileModSX:Float = 0.0
Field tileModSY:Float = 0.0
Field tileSpacing:Int = 0
Field mapObjList := New List<ftMapObj>
#End
Field tileMap:ftTileMap = Null
Field dataObj:Object = Null
Field box2DBody:Object = Null
Field objPathUpdAngle:Bool = False
Field offAngle:Float = 0.0
Field handleX:Float = 0.5
Field handleY:Float = 0.5
Field hOffX:Float = 0.0
Field hOffY:Float = 0.0
Field animMng:ftObjAnimMng = Null
Field currImageIndex:Int = 1
Field currImageFrame:Int = 1
Field minX:Float
Field minY:Float
Field maxX:Float
Field maxY:Float
'#DOCON#
'-----------------------------------------------------------------------------
#Rem
'summery:Activates the ftEngine.OnObjectDelete method to be called for an object when it will be removed through the Remove method with the direct flag.
'By default this flag is set OFF.
#End
Method ActivateDeleteEvent:Void (onOff:Bool = True )
Self.onDeleteEvent = onOff
End
'-----------------------------------------------------------------------------
#Rem
'summery:Activates the ftEngine.OnObjectRender method to be called for a visible object during the execution of the ftEngine.Render() method.
'By default this flag is set OFF.
#End
Method ActivateRenderEvent:Void (onOff:Bool = True )
Self.onRenderEvent = onOff
End
'-----------------------------------------------------------------------------
#Rem
'summery:Activates the ftEngine.OnObjectUpdate? method to be called for an active object during ftEngine.Update.
'By default this flag is set ON.
#End
Method ActivateUpdateEvent:Void (onOff:Bool = True )
Self.onUpdateEvent = onOff
End
'----------------------------------------------------------
'summery:Add to an existing animation. Image and frame indexes start at 1.
Method AddAnim:Void(animName:String, imgIndex:Int, _frameStart:Int = 1, _frameEnd:Int = 1)
Local cc:Int = Self.objImg.Length()
#If CONFIG="debug"
If cc < imgIndex Or imgIndex < 1 Then Error("~n~nError in file fantomEngine.cftObject, Method ftObject.AddAnim:Void(animName:String, imgIndex:Int, _frameStart:Int = 1, _frameEnd:Int = 1):~n~nimgIndex ("+imgIndex+") is out of bounds (1-"+cc+")")
#End
Local ifc:Int = Self.objImg[imgIndex-1].img.Frames()
#If CONFIG="debug"
If ifc < _frameEnd Or _frameStart < 1 Then Error("~n~nError in file fantomEngine.cftObject, Method ftObject.AddAnim:Void(animName:String, imgIndex:Int, _frameStart:Int = 1, _frameEnd:Int = 1):~n~nThe frame range ("+_frameStart+"-"+_frameEnd+") is out of bounds (1-"+ifc+")")
#End
Self.animMng.AddAnim(animName, imgIndex, _frameStart, _frameEnd)
End
'----------------------------------------------------------
'summery:Add to an existing animation. Image and frame indexes start at 1.
Method AddAnim:Void(animName:String, imgName:String, _frameStart:Int = 1, _frameEnd:Int = 1)
Local imgIndex:Int = Self.GetImageIndex(imgName)
#If CONFIG="debug"
If imgIndex < 1 Then Error("~n~nError in file fantomEngine.cftObject, Method ftObject.AddAnim:Void(animName:String, imgName:String, _frameStart:Int = 1, _frameEnd:Int = 1):~n~nThe image "+imgName+" was not loaded for this object.")
#End
Local ifc:Int = Self.objImg[imgIndex-1].img.Frames()
#If CONFIG="debug"
If ifc < _frameEnd Or _frameStart < 1 Then Error("~n~nError in file fantomEngine.cftObject, Method ftObject.AddAnim:Void(animName:String, imgName:String, _frameStart:Int = 1, _frameEnd:Int = 1):~n~nThe frame range ("+_frameStart+"-"+_frameEnd+") is out of bounds (1-"+ifc+")")
#end
Self.animMng.AddAnim(animName, imgIndex, _frameStart, _frameEnd)
End
'----------------------------------------------------------
'summery:Adds a single image (frame) to an object.
Method AddImage:Void(filename:String)
Local currSize:Int = Self.objImg.Length()
Self.objImg = Self.objImg.Resize(currSize + 1)
currSize += 1
Self.objImg[currSize-1] = Self.engine.imgMng.LoadImage(filename, 1, Image.MidHandle)
#If CONFIG="debug"
If Self.objImg[currSize-1] = Null Then Error("~n~nError in file fantomEngine.cftObject, Method AddImage:Void(filename:String)~n~nImage "+filename+" not found!")
#End
End
'----------------------------------------------------------
'summery:Adds a single image (frame) to an object.
Method AddImage:Void(image:Image)
Local currSize:Int = Self.objImg.Length()
Self.objImg = Self.objImg.Resize(currSize + 1)
currSize += 1
Self.objImg[currSize-1] = Self.engine.imgMng.LoadImage(image)
#If CONFIG="debug"
If Self.objImg[currSize-1] = Null Then Error("~n~nError in file fantomEngine.cftObject, Method AddImage:Void(image:Image)~n~nCould not assign Image!")
#End
End
'----------------------------------------------------------
'summery:Adds a single image object (frame) to an object.
Method AddImageObj:Void(imageObj:ftImage)
Local currSize:Int = Self.objImg.Length()
Self.objImg = Self.objImg.Resize(currSize + 1)
currSize += 1
Self.objImg[currSize-1] = imageObj
#If CONFIG="debug"
If Self.objImg[currSize-1] = Null Then Error("~n~nError in file fantomEngine.cftObject, Method AddImageObj:Void(imageObj:ftImage)~n~nCould not assign Image!")
#End
End
'-----------------------------------------------------------------------------
'summery:Adds speed to the object. If an angle is given, the speed will be added in that direction. If not, then in the objects angle.
'seeAlso:SetSpeed,GetSpeed,SetMaxSpeed,SetMinSpeed
Method AddSpeed:Void (sp:Float, ang:Float=9876.5)
Local a:Float
If ang = 9876.5 Then
a = angle
Else
a = ang
Endif
speedX = speedX + Sin(a) * sp
speedY = speedY - Cos(a) * sp
a= ATan2( speedY, speedX )+90.0
If a < 0.0 Then
a = a + 360.0
Else
If a > 360.0 Then
a = a - 360.0
Endif
Endif
speedAngle = a
speed = Sqrt(speedX * speedX + speedY * speedY)
If speed > speedMax Then speed = speedMax
End
'-----------------------------------------------------------------------------
'summery:Add an alpha transition to an existing transition.
'seeAlso:CreateTransAlpha
Method AddTransAlpha:Void(trans:ftTrans, alpha:Float, relative:Int)
trans.AddAlpha(alpha,Self,trans.duration, relative)
End
'-----------------------------------------------------------------------------
'summery:Add a position transition to an existing transition.
'seeAlso:CreateTransPos
Method AddTransPos:Void(trans:ftTrans, xt:Float, yt:Float, relative:Int)
trans.AddPos(xt, yt, Self, trans.duration, relative)
End
'-----------------------------------------------------------------------------
'summery:Add a rotation transition to an existing transition.
'seeAlso:CreateTransot
Method AddTransRot:Void(trans:ftTrans, rot:Float, relative:Int)
trans.AddRot(rot, Self, trans.duration, relative)
End
'-----------------------------------------------------------------------------
'summery:Add a scaling transition to an existing transition.
'seeAlso:CreateTransScale
Method AddTransScale:Void(trans:ftTrans, sca:Float, relative:Int)
trans.AddScale(sca, Self, trans.duration, relative)
End
'-----------------------------------------------------------------------------
'summery:Cancels all timers attached to an object.
'seeAlso:CreateTimer,PauseTimerAll,ResumeTimerAll
Method CancelTimerAll:Void()
For Local timer := Eachin timerList
timer.RemoveTimer()
Next
End
'-----------------------------------------------------------------------------
'summery:Cancels all transitions attached to an object.
'seeAlso:PauseTransAll,ResumeTransAll
Method CancelTransAll:Void()
For Local trans := Eachin transitionList
trans.Cancel()
Next
End
'-----------------------------------------------------------------------------
#Rem
'summery:Check if a collision has happened for this object.
The following collision types are valid at the moment:
[list]ftEngine.ctCircle (Value = 0)
ftEngine.ctBox% (Value = 1 -> rotated bounding box)
ftEngine.ctBound (Value = 2 -> non-rotated bounding box)
ftEngine.ctLine (Value = 3)[/list]
#End
'seeAlso:SetColWith,SetColType,SetColGroup,SetColScale
Method CheckCollision:Bool(sp2:ftObject)
If sp2.deleted = False And Self.deleted = False Then
If sp2.collGroup > 0 And sp2.isActive Then
If (Self.collWith[(sp2.collGroup-1)]>0) Then
Select Self.collType
Case ftEngine.ctCircle
Select sp2.collType
Case ftEngine.ctLine
Return internal_Circle2LineObj(self, sp2)
Case ftEngine.ctBox, ftEngine.ctBound
Return internal_Circle2Box(Self, sp2)
Default
Return internal_Circle2Circle(Self, sp2)
End
Case ftEngine.ctBox
Select sp2.collType
Case ftEngine.ctCircle
Return internal_Box2Circle(Self, sp2)
'Return internal_Circle2Box(sp2,Self)
Default
Return internal_Box2Box(Self, sp2)
End
Case ftEngine.ctBound
Select sp2.collType
Case ftEngine.ctCircle
Return internal_Box2Circle(Self, sp2)
Case ftEngine.ctBox, ftEngine.ctLine
Return internal_Box2Box(Self, sp2)
Default
Return internal_Bound2Bound(Self, sp2)
End
Case ftEngine.ctLine
Select sp2.collType
Case ftEngine.ctCircle
Return internal_Circle2LineObj(sp2, self)
Default
Return internal_Box2Box(Self, sp2)
End
Default
Return internal_Circle2Circle(Self, sp2)
End
Endif
Endif
Endif
Return False
End
'-----------------------------------------------------------------------------
#Rem
'summery:Check if a touch has happened.
The following touch types are valid at the moment:
[list]ftEngine.tmCircle (Value = 1)
ftEngine.tmBound (Value = 2)
ftEngine.tmBox (Value = 3)[/list]
#End
'seeAlso:GetTouchMode,SetTouchMode
Method CheckTouchHit:Bool(px:Float, py:Float)
Local txOff:Float = 0.0
Local tyOff:Float = 0.0
Local ret:Bool = False
If deleted = False Then
Select type
Case ftEngine.otText
Select textMode
Case 0 'taTopLeft
txOff = -(Float(Self.objFont.Length(Self.text))/2.0)*Self.scaleX
tyOff = (Self.objFont.lineHeight/2.0*Self.scaleY)
Case 1 'taTopCenter
txOff = 0.0
tyOff = (Self.objFont.lineHeight/2.0*Self.scaleY)
Case 2 'taTopRight
txOff = (Float(Self.objFont.Length(Self.text))/2.0)*Self.scaleX
tyOff = (Self.objFont.lineHeight/2.0*Self.scaleY)
Case 7 'taCenterLeft
txOff = -(Float(Self.objFont.Length(Self.text))/2.0)*Self.scaleX
tyOff = 0.0
Case 3 'taCenterCenter
txOff = 0.0
tyOff = 0.0
Case 4 'taCenterRight
txOff = (Float(Self.objFont.Length(Self.text))/2.0)*Self.scaleX
tyOff = 0.0
Case 8 'taBottomLeft
txOff = -(Float(Self.objFont.Length(Self.text))/2.0)*Self.scaleX
tyOff = -(Self.objFont.lineHeight/2.0*Self.scaleY)
Case 5 'taBottomCenter
txOff = 0.0
tyOff = -(Self.objFont.lineHeight/2.0*Self.scaleY)
Case 6 'taBottomRight
txOff = (Float(Self.objFont.Length(Self.text))/2.0)*Self.scaleX
tyOff = -(Self.objFont.lineHeight/2.0*Self.scaleY)
End
Select Self.touchMode
Case ftEngine.tmCircle
ret = internal_PointInsideCircle(Self, px+txOff, py-tyOff)
Case ftEngine.tmBound
ret = internal_PointInsideBound(Self, px+txOff, py-tyOff)
Case ftEngine.tmBox
ret = internal_PointInsidePolygon(Self, px+txOff, py-tyOff)
End
Default
Select Self.touchMode
Case ftEngine.tmCircle
ret = internal_PointInsideCircle(Self, px, py)
Case ftEngine.tmBound
ret = internal_PointInsideBound(Self, px, py)
Case ftEngine.tmBox
ret = internal_PointInsidePolygon(Self, px+txOff, py-tyOff)
End
End
Endif
Return ret
End
'#DOCOFF#
'-----------------------------------------------------------------------------
Method CleanupLists:Void()
Local a:String
For Local trans:ftTrans = Eachin Self.transitionList
If trans.deleted Then trans.Cancel()
Next
For Local timer:ftTimer = Eachin Self.timerList
'Bug fix to prevent Error:1023 Stack overflow
#If TARGET = "flash" Then
XWA(0)
#End
If timer.deleted Then timer.RemoveTimer()
Next
End
'#DOCON#
'----------------------------------------------------------
'summery:Add a animation sequence to an object. This way an object becomes animated.
'seeAlso:AddAnim
Method CreateAnim:Void(animName:String, imgIndex:Int, _frameStart:Int = 1, _frameEnd:Int = 1, _repeatCount:Int = -1)
Local cc:Int = Self.objImg.Length()
#If CONFIG="debug"
If cc < imgIndex Or imgIndex < 1 Then Error("~n~nError in file fantomEngine.cftObject, Method ftObject.CreateAnim:Void(animName:String, imgIndex:Int, _frameStart:Int = 1, _frameEnd:Int = 1):~n~nimgIndex ("+imgIndex+") is out of bounds (1-"+cc+")")
#End
Local ifc:Int = Self.objImg[imgIndex-1].img.Frames()
#If CONFIG="debug"
If ifc < _frameEnd Or _frameStart < 1 Then Error("~n~nError in file fantomEngine.cftObject, Method CreateAnim:Void(animName:String, imgIndex:Int, _frameStart:Int = 1, _frameEnd:Int = 1):~n~nThe frame range ("+_frameStart+"-"+_frameEnd+") is out of bounds (1-"+ifc+")")
#End
If Self.animMng = Null Then
Self.animMng = New ftObjAnimMng
Self.animMng.animObj = Self
Self.SetAnimated(True)
Endif
Self.animMng.CreateAnim(animName, imgIndex, _frameStart, _frameEnd)
Self.SetAnimRepeatCount(_repeatCount)
End
'----------------------------------------------------------
'summery:Add a animation sequence to an object. This way an object becomes animated.
'seeAlso:AddAnim
Method CreateAnim:Void(animName:String, imgName:String, _frameStart:Int = 1, _frameEnd:Int = 1, _repeatCount:Int = -1)
Local imgIndex:Int = Self.GetImageIndex(imgName)
#If CONFIG="debug"
If imgIndex < 1 Then Error("~n~nError in file fantomEngine.cftObject, Method ftObject.CreateAnim:Void(animName:String, imgName:String, _frameStart:Int = 1, _frameEnd:Int = 1):~n~nThe image "+imgName+" was not loaded for this object.")
#End
Local ifc:Int = Self.objImg[imgIndex-1].img.Frames()
#If CONFIG="debug"
If ifc < _frameEnd Or _frameStart < 1 Then Error("~n~nError in file fantomEngine.cftObject, Method CreateAnim:Void(animName:String, imgName:String, _frameStart:Int = 1, _frameEnd:Int = 1):~n~nThe frame range ("+_frameStart+"-"+_frameEnd+") is out of bounds (1-"+ifc+")")
#End
If Self.animMng = Null Then
Self.animMng = New ftObjAnimMng
Self.animMng.animObj = Self
Self.SetAnimated(True)
Endif
Self.animMng.CreateAnim(animName, imgIndex, _frameStart, _frameEnd)
Self.SetAnimRepeatCount(_repeatCount)
End
'-----------------------------------------------------------------------------
#Rem
'summery:Create a timer for this object.
'A repeatCount of -1 will let the timer run forever. The duration is the time in milliseconds, after which the [b]ftEngine.OnObjectTimer[/b] method is called.
#End
'seeAlso:
Method CreateTimer:ftTimer(timerID:Int, duration:Int, repeatCount:Int = 0 )
Local timer:ftTimer = New ftTimer
timer.engine = Self.engine
timer.currTime = Self.engine.time
timer.duration = duration
timer.id = timerID
timer.intervall = duration
timer.loop = repeatCount
timer.obj = Self
timer.timerNode = Self.timerList.AddLast(timer)
Return timer
End
'-----------------------------------------------------------------------------
#Rem
'summery:Create an alpha transition.
'The duration is the time in milliseconds, the transition takes to complete. Only a transID > 0 will fire the [b]ftEngine.OnObjectTrans[/b] method.
#End
'seeAlso:AddTransAlpha
Method CreateTransAlpha:ftTrans(transAlpha:Float, duration:Float, relative:Int, transId:Int=0 )
Local trans:ftTrans = New ftTrans
trans.engine = Self.engine
trans.obj = Self
trans.layer = Null
trans.currTime = Self.engine.time
trans.finishID = transId
trans.duration = duration
trans.AddAlpha(transAlpha,Self,duration, relative)
trans.transNode = Self.transitionList.AddLast(trans)
Return trans
End
'-----------------------------------------------------------------------------
#Rem
'summery:Create a position transition.
'The duration is the time in milliseconds, the transition takes to complete. Only a transID > 0 will fire the [b]ftEngine.OnObjectTrans[/b] method.
#End
'seeAlso:AddTransPos
Method CreateTransPos:ftTrans(xt:Float, yt:Float, duration:Float, relative:Int, transId:Int=0 )
Local trans:ftTrans = New ftTrans
trans.engine = Self.engine
trans.obj = Self
trans.layer = Null
trans.currTime = Self.engine.time
trans.finishID = transId
trans.duration = duration
trans.AddPos(xt, yt, Self, duration, relative)
trans.transNode = Self.transitionList.AddLast(trans)
Return trans
End
'-----------------------------------------------------------------------------
#Rem
'summery:Create a rotation transition.
'The duration is the time in milliseconds, the transition takes to complete. Only a transID > 0 will fire the [b]ftEngine.OnObjectTrans[/b] method.
#End
'seeAlso:AddTransRot
Method CreateTransRot:ftTrans(transRotation:Float, duration:Float, relative:Int, transId:Int=0 )
Local trans:ftTrans = New ftTrans
trans.engine = Self.engine
trans.obj = Self
trans.layer = Null
trans.currTime = Self.engine.time
trans.finishID = transId
trans.duration = duration
trans.AddRot(transRotation, Self, duration, relative )
trans.transNode = Self.transitionList.AddLast(trans)
Return trans
End
'-----------------------------------------------------------------------------
#Rem
'summery:Create a scaling transition.
'The duration is the time in milliseconds, the transition takes to complete. Only a transID > 0 will fire the [b]ftEngine.OnObjectTrans[/b] method.
#End
'seeAlso:AddTransScale
Method CreateTransScale:ftTrans(transScale:Float, duration:Float, relative:Int, transId:Int=0 )
Local trans:ftTrans = New ftTrans
trans.engine = Self.engine
trans.obj = Self
trans.layer = Null
trans.currTime = Self.engine.time
trans.finishID = transId
trans.duration = duration
trans.AddScale(transScale, Self, duration, relative )
trans.transNode = Self.transitionList.AddLast(trans)
Return trans
End
'-----------------------------------------------------------------------------
'summery:Returns the active flag.
'seeAlso:SetActive
Method GetActive:Bool()
Return isActive
End
'-----------------------------------------------------------------------------
'summery:Get the alpha value.
'seeAlso:SetAlpha
Method GetAlpha:Float()
Return alpha
End
'-----------------------------------------------------------------------------
'summery:Get the angle the object is heading.
'seeAlso:SetAngle
Method GetAngle:Float()
Return angle
End
'-----------------------------------------------------------------------------
'summery:Return the isAnimated flag.
'seeAlso:SetAnimated
Method GetAnimated:Bool ()
Return isAnimated
End
'-----------------------------------------------------------------------------
'summery:Get the number of frame from the active animation.
Method GetAnimCount:Int ()
Return Self.animMng.GetCurrAnimCount()
End
'-----------------------------------------------------------------------------
'summery:Get the current frame(time) of the active animation. It starts with 1.
'seeAlso:SetAnimFrame
Method GetAnimFrame:Float ()
Return Self.animMng.GetCurrAnimFrame()
End
'-----------------------------------------------------------------------------
'summery:Return the name from the active animation.
Method GetAnimName:String ()
Return Self.animMng.GetCurrAnimName()
End
'-----------------------------------------------------------------------------
'summery:Return the pause flag for the active animation of an animated object.
'seeAlso:SetAnimPaused
Method GetAnimPaused:Bool ()
Return Self.animMng.isAnimPaused
End
'-----------------------------------------------------------------------------
'summery:Get the frame time of the current animation.
'seeAlso:SetAnimTime
Method GetAnimTime:Float ()
Return Self.animMng.GetCurrAnimTime()
End
'-----------------------------------------------------------------------------
#rem
'summery:Get the blend mode of an object.
'Used are the regular mojo blend modes.
#end
'seeAlso:SetBlendMode
Method GetBlendMode:Int ()
Return Self.blendMode
End
'-----------------------------------------------------------------------------
'summery:Get the child object with the given index (Index starts with 1).
'seeAlso:GetParent,SetParent
Method GetChild:ftObject (index:Int)
Local c:Int
Local cc:Int = childObjList.Count()
#If CONFIG="debug"
If index < 1 Or index > cc Then Error ("~n~nError in file fantomEngine.cftObject, Method ftObject.GetChild():~n~nUsed index ("+index+") is out of bounds (1-"+cc+")")
#End
For Local child := Eachin childObjList
c += 1
If c = index Then Return child
Next
Return Null
End
'-----------------------------------------------------------------------------
'summery:Returns the child count of an object.
Method GetChildCount:Int ()
Return childObjList.Count()
End
'-----------------------------------------------------------------------------
#rem
'summery:Returns the closest active object.
'If useRadius is set to FALSE, the distance between each object will be calculated from its position,
'without taking its radius into the calculation.
#end
Method GetClosestObj:ftObject (useRadius:Bool = True)
Local dist:Float = 0.0
Local tmpDist:Float = 0.0
Local co:ftObject = Null
Local obj:ftObject = Null
For obj = Eachin Self.layer.objList
If obj.isActive = True Then
If obj <> Self Then
tmpDist = Self.GetTargetDist(obj, useRadius)
If co = Null Then
dist = tmpDist
co = obj
Else
If tmpDist < dist Then
dist = tmpDist
co = obj
Endif
Endif
Endif
Endif
Next
Return co
End
'-----------------------------------------------------------------------------
#rem
'summery:Returns the collision group of an object.
'A value of 0 means that collisions for this object are disabled.
#End
'seeAlso:SetColGroup,SetColWith,CheckCollision
Method GetColGroup:Int ()
Return collGroup
End
'-----------------------------------------------------------------------------
'summery:Returns the color of an object in an array.
'seeAlso:SetColor
Method GetColor:Float[]()
Local c:Float[3]
c[0] = Self.red
c[1] = Self.green
c[2] = Self.blue
Return c
End
'-----------------------------------------------------------------------------
#rem
'summery:Returns the collision type of an object.
'Collision types can be:
[list][*]Const ctCircle% = 0
[*]Const ctBox% = 1 (this will check against the rotated box of the Object)
[*]Const ctBound% = 2 (This will check against the bounding box of the Object)
[*]Const ctLine% = 3[/list]
#End
'seeAlso:SetColType,SetColWith,CheckCollision
Method GetColType:Int ()
Return collType
End
'-----------------------------------------------------------------------------
'summery:Returns the data object of this object.
'seeAlso:SetDataObj
Method GetDataObj:Object ()
Return dataObj
End
'-----------------------------------------------------------------------------
#Rem
'summery:Returns an edge position (bottom,top,left,right) of the object.
'The edge parameter can have the following values:
'[list][*]1 = Bottom edge
[*]2 = Top edge
[*]3 = Left edge
[*]4 = Right edge[/list]
'
'If the relative flag is set, then you only get the distance in pixel towards that edge
#End
Method GetEdge:Float(edge:Int=1, relative:Int = False )
Local ret:Float = 0.0
Local xp:Float = 0.0
Local yp:Float = 0.0
If relative = False Then
xp = Self.xPos
yp = Self.yPos
Endif
Select edge
Case 1 'Bottom
ret = yp + ((h*Self.scaleY)/2.0)+Self.hOffY
Case 2 'Top
ret = yp - ((h*Self.scaleY)/2.0)+Self.hOffY
Case 3 'Left
ret = xp - ((w*Self.scaleX)/2.0)+Self.hOffX
Case 4 'Right
ret = xp + ((w*Self.scaleX)/2.0)+Self.hOffX
#If CONFIG="debug"
Default 'Error
Error ("~n~nError in file fantomEngine.cftObject, Method ftObject.GetEdge():~n~nUsed edge value ("+edge+") is out of bounds (1-4)")
#End
End
Return ret
End
'-----------------------------------------------------------------------------
#Rem
'summery:Returns the horizontal and vertical FLIP flags in a Bool array.
'Index 0 contains the horizontal flag and index 1 of the returned array contains the vertical flag.
#End
'seeAlso:SetFlip,GetFlipH,GetFlipV
Method GetFlip:Bool[]()
Local f:Bool[2]
f[0] = Self.isFlipH
f[1] = Self.isFlipV
Return f
End
'-----------------------------------------------------------------------------
'summery:Returns the horizontal FLIP flag.
'seeAlso:SetFlipH,GetFlip,GetFlipV
Method GetFlipH:Bool()
Return Self.isFlipH
End
'-----------------------------------------------------------------------------
'summery:Returns the vetical FLIP flag.
'seeAlso:SetFlipV,GetFlip,GetFlipH
Method GetFlipV:Bool()
Return Self.isFlipV
End
'-----------------------------------------------------------------------------
'summery:Get the friction value.
'seeAlso:SetFriction
Method GetFriction:Float()
Return friction
End
'-----------------------------------------------------------------------------
'summery:Returns the group ID of an object.
'seeAlso:SetGroupID
Method GetGroupID:Int ()
Return groupID
End
'-----------------------------------------------------------------------------
#Rem
'summery:Get the height of an object.
The returned value is the stored height multiplied by the Y scale factor.
#End
'seeAlso:,SetHeight,GetWidth
Method GetHeight:Float()
Return h*scaleY
End
'-----------------------------------------------------------------------------
'summery:Returns the ID of an object.
'seeAlso:SetID
Method GetID:Int ()
Return id
End
'-----------------------------------------------------------------------------
'summery:Returns the Image of an object. The index starts with 1.
Method GetImage:Image(index:Int = 1)
Local cc:Int = Self.objImg.Length()
#If CONFIG="debug"
If cc < index Or index < 1 Then Error("~n~nError in file fantomEngine.cftObject, Method ftObject.GetImage:Image(index:Int = 1):~n~nIndex ("+index+") is out of bounds (1-"+cc+")")
#End
Return Self.objImg[index-1].GetImage()
End
'-----------------------------------------------------------------------------
'summery:Returns the number of images of an object.
Method GetImageCount:Int()
Return Self.objImg.Length()
End
'-----------------------------------------------------------------------------
'summery:Returns the number of subframe from an image of an object. Index starts with 1.
Method GetImageFrameCount:Int(index:Int = 1)
Local cc:Int = Self.objImg.Length()
#If CONFIG="debug"
If cc < index Or index < 1 Then Error("~n~nError in file fantomEngine.cftObject, Method ftObject.GetImageFrameCount:Int(index:Int = 1):~n~nIndex ("+index+") is out of bounds (1-"+cc+")")
#End
Return Self.objImg[index-1].img.Frames()
End
'-----------------------------------------------------------------------------
'summery:Returns the name from an image of an object. Index starts with 1.
Method GetImagePath:String(index:Int = 1)
Local cc:Int = Self.objImg.Length()
#If CONFIG="debug"
If cc < index Or index < 1 Then Error("~n~nError in file fantomEngine.cftObject, Method ftObject.GetImageName:String(index:Int = 1):~n~nIndex ("+index+") is out of bounds (1-"+cc+")")
#End
Return Self.objImg[index-1].GetPath()
End
'-----------------------------------------------------------------------------
'summery:Returns the index of an image with a given name. Index starts with 1.
Method GetImageIndex:Int(imgPath:String)
Local ic:Int = Self.objImg.Length()
Local idx:Int = 0
For Local index:Int = 1 To ic
If Self.objImg[index-1].GetPath()=imgPath Then
idx = index
Exit
Endif
Next
Return idx
End
'-----------------------------------------------------------------------------
'summery:Returns the ftImage of an object. The index starts with 1.
'seeAlso:SetImageObj
Method GetImageObj:ftImage(index:Int = 1)
Local cc:Int = Self.objImg.Length()
#If CONFIG="debug"
If cc < index Or index < 1 Then Error("~n~nError in file fantomEngine.cftObject, Method ftObject.GetImageObj:Image(index:Int = 1):~n~nIndex ("+index+") is out of bounds (1-"+cc+")")
#End
Return Self.objImg[index-1]
End
'------------------------------------------
'summery:Get the objects layer.
'seeAlso:SetLayer
Method GetLayer:ftLayer()
Return Self.layer
End
'-----------------------------------------------------------------------------
#Rem
'summery:Returns the tile map object with the given index. Index starts with 1.
#End
'seeAlso:GetMapObjCount
Method GetMapObj:ftMapObj (index:Int)
Local c:Int
Local cc:Int = tileMap.mapObjList.Count()
#If CONFIG="debug"
If index < 1 Or index > cc Then Error ("~n~nError in file fantomEngine.cftObject, Method ftObject.GetMapObj():~n~nUsed index ("+index+") is out of bounds (1-"+cc+")")
#End
For Local mapObj := Eachin tileMap.mapObjList
c += 1
If c = index Then Return mapObj
Next
Return Null
End
'-----------------------------------------------------------------------------
#Rem
'summery:Returns the number of tile map objects.
'The objects were stored when a Tiled compatible map was loaded.
#End
'seeAlso:GetMapObj
Method GetMapObjCount:Int ()
Return tileMap.mapObjList.Count()
End
'-----------------------------------------------------------------------------
'summery:Get the name of an object.
'seeAlso:SetName
Method GetName:String ()
Return name
End
'------------------------------------------
'summery:Get the parent object.
'seeAlso:SetParent
Method GetParent:ftObject()
Return Self.parentObj
End
'-----------------------------------------------------------------------------
'summery:Returns the objects X and Y position in a 2D Float array.
'seeAlso:SetPos,GetPosX,GetPosY,GetPosZ
Method GetPos:Float[]()
Local p:Float[2]
p[0] = xPos
p[1] = yPos
Return p
End
'-----------------------------------------------------------------------------
'summery:Get the X position.
'seeAlso:SetPosX,GetPos,GetPosY,GetPosZ
Method GetPosX:Float()
Return xPos
End
'-----------------------------------------------------------------------------
'summery:Get the Y position.
'seeAlso:SetPosY,GetPosX,GetPos,GetPosZ
Method GetPosY:Float()
Return yPos
End
'-----------------------------------------------------------------------------
'summery:Get the Z position.
'seeAlso:SetPosZ,GetPosX,GetPosY,GetPos
Method GetPosZ:Float()
Return zPos
End
'-----------------------------------------------------------------------------
'summery:Returns the radius of an object.
'seeAlso:SetRadius
Method GetRadius:Float()
Return radius*scaleX
End
'-----------------------------------------------------------------------------
'summery:Get current scale factor of an object.
'seeAlso:SetScale,GetScaleX,GetScaleY
Method GetScale:Float()
Return scaleX
End
'-----------------------------------------------------------------------------
'summery:Returns the X scale factor (width) of the object.
'seeAlso:SetScaleX,GetScale,GetScaleY
Method GetScaleX:Float()
Return scaleX
End
'-----------------------------------------------------------------------------
'summery:Returns the Y scale factor (height) of the object.
'seeAlso:SetScaleY,GetScaleX,GetScale
Method GetScaleY:Float()
Return scaleY
End
'-----------------------------------------------------------------------------
'summery:Get current linear speed of an object.
'seeAlso:SetSpeed,GetSpeedAngle
Method GetSpeed:Float()
Return speed
End
'-----------------------------------------------------------------------------
'summery:Get the current speed angle.
'seeAlso:SetSpeedangle,GetSpeed
Method GetSpeedAngle:Float()
Return Self.speedAngle
End
'-----------------------------------------------------------------------------
'summery:Get the max speed of an object.