-
Notifications
You must be signed in to change notification settings - Fork 1
/
engine.bas
3508 lines (2961 loc) · 111 KB
/
engine.bas
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
Include once
Include "strings.bas"
Include "math_util.bas"
Include "joystick.bas"
Include "simple_touch.bas"
ENGINE_VERSION = 1
ENGINE_EDITOR_USE = False
Dim STAGE_SCREEN_POS_X
Dim STAGE_SCREEN_POS_Y
Dim STAGE_SCREEN_WIDTH
Dim STAGE_SCREEN_HEIGHT
Dim ACTOR_PATH$
Dim FONT_PATH$
Dim BKG_PATH$
Dim GUI_PATH$
Dim STAGE_PATH$
Dim MUSIC_PATH$
Dim SFX_PATH$
Dim SPRITE_PATH$
Dim TILE_PATH$
Dim VIDEO_PATH$
Dim ENGINE_DIR$
If Trim$(Env("ENGINE_DIR")) <> "" Then
ENGINE_DIR$ = Env("ENGINE_DIR")
Print "ENG DIR: "; ENGINE_DIR$
Else
ENGINE_DIR$ = Dir$
End If
Print ENGINE_DIR$
If OS = "WINDOWS" Then
ACTOR_PATH$ = ENGINE_DIR$ + "\\actor\\"
BKG_PATH$ = ENGINE_DIR$ + "\\bkg\\"
FONT_PATH$ = ENGINE_DIR$ + "\\font\\"
GUI_PATH$ = ENGINE_DIR$ + "\\gui_gfx\\"
STAGE_PATH$ = ENGINE_DIR$ + "\\stage\\"
MUSIC_PATH$ = ENGINE_DIR$ + "\\music\\"
SFX_PATH$ = ENGINE_DIR$ + "\\sfx\\"
SPRITE_PATH$ = ENGINE_DIR$ + "\\sprite\\"
TILE_PATH$ = ENGINE_DIR$ + "\\tile\\"
VIDEO_PATH$ = ENGINE_DIR$ + "\\video\\"
Else
ACTOR_PATH$ = ENGINE_DIR$ + "/actor/"
BKG_PATH$ = ENGINE_DIR$ + "/bkg/"
FONT_PATH$ = ENGINE_DIR$ + "/font/"
GUI_PATH$ = ENGINE_DIR$ + "/gui_gfx/"
STAGE_PATH$ = ENGINE_DIR$ + "/stage/"
MUSIC_PATH$ = ENGINE_DIR$ + "/music/"
SFX_PATH$ = ENGINE_DIR$ + "/sfx/"
SPRITE_PATH$ = ENGINE_DIR$ + "/sprite/"
TILE_PATH$ = ENGINE_DIR$ + "/tile/"
VIDEO_PATH$ = ENGINE_DIR$ + "/video/"
End If
MAX_IMAGES = 1024
MAX_TILESETS = 4
MAX_TILES = 2048
MAX_SHAPES_PER_LAYER = 512
MAX_STAGE_IMAGES = 12
MAX_LAYERS = 5
MAX_TILE_FRAMES = 4
MAX_SPRITES = 50
MAX_SPRITE_FRAMES = 2048
MAX_SPRITE_ANIMATIONS = 512
MAX_SPRITE_ANIMATION_FRAMES = 8
MAX_ACTORS = 512
'Stage Structure
'Stage Name
Dim Stage_Name$
Dim Stage_Version
'Dimensions
Dim Stage_Tile_Width 'In tiles
Dim Stage_Tile_Height 'In tiles
Dim Stage_Pixel_Width
Dim Stage_Pixel_Height
'Layer Info
Dim STAGE_LAYER_TYPE_NONE
Dim STAGE_LAYER_TYPE_TILE
Dim STAGE_LAYER_TYPE_BKG
STAGE_LAYER_TYPE_NONE = 0
STAGE_LAYER_TYPE_TILE = 1
STAGE_LAYER_TYPE_BKG = 2
Dim Stage_Layer_Type[MAX_LAYERS] 'Type can be tile or image
Dim Stage_Layer_Active[MAX_LAYERS]
Dim Stage_Layer_ColDet[MAX_LAYERS]
Dim Stage_Layer_Physics[MAX_LAYERS]
Dim Stage_Physics_Gravity
'Tileset
Dim Stage_Tileset_Tile_Width
Dim Stage_Tileset_Tile_Height
Dim Stage_Tileset_Tile_FPS
Dim Stage_Tileset_Tile_Delay '1000 / FPS
Dim Stage_Tileset_CurrentTime
Dim Stage_Tileset_ImageIsLoaded[MAX_TILESETS]
Dim Stage_Tileset_File$[MAX_TILESETS]
Dim Stage_Tileset_Version[MAX_TILESETS]
Dim Stage_Tileset_NumTiles[MAX_TILESETS]
Dim Stage_Tileset_Image[MAX_TILESETS]
Dim Stage_Tileset_Image_Width[MAX_TILESETS]
Dim Stage_Tileset_Image_Height[MAX_TILESETS]
Dim Stage_Tileset_Image_WidthInTiles[MAX_TILESETS]
Dim Stage_Tileset_Image_HeightInTiles[MAX_TILESETS]
Dim Stage_Tileset_Tile_NumFrames[MAX_TILESETS, MAX_TILES]
Dim Stage_Tileset_Tile_Frame[MAX_TILESETS, MAX_TILES, MAX_TILE_FRAMES]
Dim Stage_Tileset_Tile_CurrentFrame[MAX_TILESETS, MAX_TILES]
Dim Stage_Tileset_Tile_CurrentTime[MAX_TILESETS, MAX_TILES]
'Background Layer
Dim STAGE_LAYER_BKG_TYPE_IMAGE
Dim STAGE_LAYER_BKG_TYPE_SURFACE
Dim STAGE_LAYER_BKG_FLAG_NONE
Dim STAGE_LAYER_BKG_FLAG_TILED
Dim STAGE_LAYER_BKG_FLAG_STRETCHED
Dim STAGE_LAYER_BKG_FLAG_BLIT
Dim STAGE_LAYER_BKG_FLAG_SCROLL
STAGE_LAYER_BKG_TYPE_IMAGE = 0
STAGE_LAYER_BKG_TYPE_SURFACE = 1
Stage_LAYER_BKG_FLAG_NONE = 0
Stage_LAYER_BKG_FLAG_TILED = 1
Stage_LAYER_BKG_FLAG_STRETCHED = 2
Stage_LAYER_BKG_FLAG_BLIT = 3
STAGE_LAYER_BKG_FLAG_SCROLL = 4
Dim Stage_Layer_Bkg_ImageIsLoaded[MAX_LAYERS]
Dim Stage_Layer_Bkg_Image_W[MAX_LAYERS]
Dim Stage_Layer_Bkg_Image_H[MAX_LAYERS]
Dim Stage_Layer_Bkg_File$[MAX_LAYERS]
Dim Stage_Layer_Bkg_Image[MAX_LAYERS]
Dim Stage_Layer_Bkg_Flag[MAX_LAYERS]
Dim Stage_Layer_Bkg_Type[MAX_LAYERS]
Dim Stage_Layer_Bkg_ZoomX[MAX_LAYERS]
Dim Stage_Layer_Bkg_ZoomY[MAX_LAYERS]
Dim Stage_Layer_Bkg_Angle[MAX_LAYERS]
Dim Stage_Layer_Bkg_BlitX[MAX_LAYERS]
Dim Stage_Layer_Bkg_BlitY[MAX_LAYERS]
Dim Stage_Layer_Bkg_BlitW[MAX_LAYERS]
Dim Stage_Layer_Bkg_BlitH[MAX_LAYERS]
Dim Stage_Layer_Bkg_Color[MAX_LAYERS, 3]
Dim Stage_Layer_Bkg_Alpha[MAX_LAYERS]
Dim Stage_Layer_Bkg_Scroll_HSpeed[MAX_LAYERS]
Dim Stage_Layer_Bkg_Scroll_VSpeed[MAX_LAYERS]
'Stage Tile Data
MAX_STAGE_WIDTH = 512
MAX_STAGE_HEIGHT = 512
Dim Stage_Layer_Tile_Tileset[MAX_LAYERS, MAX_STAGE_HEIGHT, MAX_STAGE_WIDTH]
Dim Stage_Layer_Tile_Data[MAX_LAYERS, MAX_STAGE_HEIGHT, MAX_STAGE_WIDTH]
'Stage Shape Data
MAX_SECTORS_ACROSS = 30
MAX_SECTORS_DOWN = 30
MAX_SHAPES_PER_SECTOR = 50
Dim SHAPE_TYPE_RECT
Dim SHAPE_TYPE_LINE
Dim SHAPE_TYPE_NULL
Dim SHAPE_TYPE_CIRCLE
Dim SHAPE_TYPE_DYNARECT
SHAPE_TYPE_NULL = 0
SHAPE_TYPE_RECT = 1
SHAPE_TYPE_LINE = 2
SHAPE_TYPE_CIRCLE = 3
SHAPE_TYPE_DYNARECT = 4
Dim Stage_Layer_Shape_Count[MAX_LAYERS]
Dim Stage_Layer_Shape_Type[MAX_LAYERS, MAX_SHAPES_PER_LAYER]
Dim Stage_Layer_Shape_X[MAX_LAYERS, MAX_SHAPES_PER_LAYER]
Dim Stage_Layer_Shape_Y[MAX_LAYERS, MAX_SHAPES_PER_LAYER]
Dim Stage_Layer_Shape_Param[MAX_LAYERS, MAX_SHAPES_PER_LAYER, 2]
Dim Stage_Layer_Shape_Attribute[MAX_LAYERS, MAX_SHAPES_PER_LAYER, 2]
Dim Stage_Layer_Shape_AddValue[MAX_LAYERS]
Dim Stage_Layer_Shape_Actor[MAX_LAYERS, MAX_SHAPES_PER_LAYER]
'Dim Stage_Layer_Shape_Sector[MAX_LAYERS, MAX_SHAPES_PER_LAYER, (MAX_SECTORS_ACROSS*MAX_SECTORS_DOWN)]
'Sectors
Dim Stage_Sector_Shape_Index[MAX_SECTORS_ACROSS, MAX_SECTORS_DOWN, MAX_SHAPES_PER_SECTOR]
Dim Stage_Sector_Shape_Layer[MAX_SECTORS_ACROSS, MAX_SECTORS_DOWN, MAX_SHAPES_PER_SECTOR]
Dim Stage_Sector_X[MAX_SECTORS_ACROSS, MAX_SECTORS_DOWN]
Dim Stage_Sector_Y[MAX_SECTORS_ACROSS, MAX_SECTORS_DOWN]
Dim Stage_Sector_Width
Dim Stage_Sector_Height
Dim Stage_Sector_NumShapes[MAX_SECTORS_ACROSS, MAX_SECTORS_DOWN]
'Stage Actors
Dim Stage_Layer_NumActors[MAX_LAYERS]
Dim Stage_Layer_Actor[MAX_LAYERS, MAX_ACTORS]
'Actors
Dim Actor_Visible[MAX_ACTORS]
Dim Actor_Active[MAX_ACTORS]
Dim Actor_Name$[MAX_ACTORS]
Dim Actor_inUse[MAX_ACTORS]
Dim Actor_Layer[MAX_ACTORS]
Dim Actor_LayerPosition[MAX_ACTORS]
Dim Actor_Sprite[MAX_ACTORS]
Dim Actor_X[MAX_ACTORS]
Dim Actor_Y[MAX_ACTORS]
Dim Actor_NewX[MAX_ACTORS]
Dim Actor_NewY[MAX_ACTORS]
Dim Actor_ZX[MAX_ACTORS]
Dim Actor_ZY[MAX_ACTORS]
Dim Actor_Angle[MAX_ACTORS]
Dim Actor_Physics[MAX_ACTORS]
Dim Actor_Speed[MAX_ACTORS]
Dim Actor_Momentum[MAX_ACTORS]
Dim Actor_Physics_State[MAX_ACTORS]
Dim Actor_Solid_State[MAX_ACTORS]
Dim Actor_Solid_Priority[MAX_ACTORS]
Dim Actor_Jump[MAX_ACTORS]
Dim Actor_Weight[MAX_ACTORS]
Dim Actor_DynaRect_SpeedAdjust[MAX_ACTORS,2]
Dim Actor_Contact_Shape[MAX_ACTORS]
Dim EFFECT_NONE
Dim EFFECT_FLASH
EFFECT_NONE = 0
EFFECT_FLASH = 1
Dim Actor_Effect_Active[MAX_ACTORS]
Dim Actor_Effect_Type[MAX_ACTORS]
Dim Actor_Effect_Timer[MAX_ACTORS]
Dim Actor_Effect_Time[MAX_ACTORS] 'Total time for one iteration of the effect
Dim Actor_Effect_Value[MAX_ACTORS]
Dim Actor_Effect_Increment[MAX_ACTORS]
Dim PHYSICS_STATE_GROUND
Dim PHYSICS_STATE_RISE
Dim PHYSICS_STATE_FALL
PHYSICS_STATE_GROUND = 2
PHYSICS_STATE_RISE = 1
PHYSICS_STATE_FALL = 0
Dim Actor_Force_X[MAX_ACTORS]
Dim Actor_Force_Y[MAX_ACTORS]
Dim Actor_Force_Acceleration[MAX_ACTORS]
Dim Actor_Force_Speed[MAX_ACTORS]
Dim Actor_CurrentAnimation[MAX_ACTORS]
Dim Actor_CurrentFrame[MAX_ACTORS]
Dim Actor_CurrentFrameTime[MAX_ACTORS]
Dim Actor_CurrentFrameDelay[MAX_ACTORS]
Dim Actor_AnimationSync[MAX_ACTORS]
Dim Actor_AnimationParent[MAX_ACTORS]
Dim Actor_AnimationEnded[MAX_ACTORS]
'Dynamic Rect
Dim Actor_Shape[MAX_ACTORS]
Dim Actor_Shape_Layer[MAX_ACTORS]
Dim Actor_Move_Flag[MAX_ACTORS]
'Actor Offset From another actor
Dim Actor_OffsetActor[MAX_ACTORS, 3]
'Actor Collision and Physics
MAX_STAGE_COLLISIONS = 20
Dim Actor_NumStageCollisions[MAX_ACTORS]
Dim Actor_Stage_Collision_X[MAX_ACTORS, MAX_STAGE_COLLISIONS]
Dim Actor_Stage_Collision_Y[MAX_ACTORS, MAX_STAGE_COLLISIONS]
Dim Actor_Stage_Collision_From_Direction[MAX_ACTORS, MAX_STAGE_COLLISIONS]
Dim Actor_Collision_Inside_Shape[MAX_ACTORS]
Dim MAX_ACTOR_COLLISIONS
MAX_ACTOR_COLLISIONS = 5
Dim Actor_Collision[MAX_ACTORS]
Dim Actor_CollisionActor[MAX_ACTORS, MAX_ACTOR_COLLISIONS]
Dim Actor_ParentActor[MAX_ACTORS]
Dim Actor_ChildActor[MAX_ACTORS]
Dim Actor_NumActorCollisions[MAX_ACTORS]
Dim Actor_Persistent[MAX_ACTORS]
Dim Stage_SolidActors[MAX_ACTORS]
Dim Stage_NumSolidActors
'Sprites
Dim Sprite_Version[MAX_SPRITES]
Dim Sprite_Name$[MAX_SPRITES]
Dim Sprite_Image[MAX_SPRITES]
Dim Sprite_Image_W[MAX_SPRITES]
Dim Sprite_Image_H[MAX_SPRITES]
Dim Sprite_Image_WidthInFrames[MAX_SPRITES]
Dim Sprite_Image_HeightInFrames[MAX_SPRITES]
Dim Sprite_inUse[MAX_SPRITES]
Dim Sprite_Visible[MAX_SPRITES]
Dim Sprite_Frame_Width[MAX_SPRITES]
Dim Sprite_Frame_Height[MAX_SPRITES]
Dim Sprite_NumFrames[MAX_SPRITES]
Dim Sprite_NumAnimations[MAX_SPRITES]
Dim Sprite_Frame_Bound_Shape[MAX_SPRITES]
Dim Sprite_Frame_Bound_X[MAX_SPRITES, MAX_SPRITE_FRAMES]
Dim Sprite_Frame_Bound_Y[MAX_SPRITES, MAX_SPRITE_FRAMES]
Dim Sprite_Frame_Bound_Param[MAX_SPRITES, MAX_SPRITE_FRAMES, 2]
Dim Sprite_Animation_Name$[MAX_SPRITES, MAX_SPRITE_ANIMATIONS]
Dim Sprite_Animation_NumFrames[MAX_SPRITES, MAX_SPRITE_ANIMATIONS]
Dim Sprite_Animation_FPS[MAX_SPRITES, MAX_SPRITE_ANIMATIONS]
Dim Sprite_Animation_Delay[MAX_SPRITES] 'Recalc everytime animation is changed
Dim Sprite_Animation_Frame[MAX_SPRITES, MAX_SPRITE_ANIMATIONS, MAX_SPRITE_ANIMATION_FRAMES]
'Engine Rendering Stuff
Dim Stage_offset_x
Dim Stage_offset_y
Dim Stage_Viewport_w
Dim Stage_Viewport_h
Sub Engine_Init()
For i = 0 to MAX_LAYERS-1
Stage_Layer_NumActors[i] = 0
Next
Stage_Sector_Width = 640
Stage_Sector_Height = 480
End Sub
Sub Num32_To_ByteArray(num32, byref byte_array)
byte_array[0] = AndBit( (num32 shr 24), 255)
byte_array[1] = AndBit( (num32 shr 16), 255)
byte_array[2] = AndBit( (num32 shr 8), 255)
byte_array[3] = AndBit( num32, 255)
End Sub
Function ByteArray_To_Num32(byref byte_array)
num32 = (byte_array[0] shl 24) + (byte_array[1] shl 16) + (byte_array[2] shl 8) + byte_array[3]
Return num32
End Function
Sub Write32(stream, num32)
Dim byte_array[4]
Num32_To_ByteArray(num32, byte_array)
WriteByte(stream, byte_array[0])
WriteByte(stream, byte_array[1])
WriteByte(stream, byte_array[2])
WriteByte(stream, byte_array[3])
End Sub
Function Read32(stream)
Dim byte_array[4]
byte_array[0] = ReadByte(stream)
byte_array[1] = ReadByte(stream)
byte_array[2] = ReadByte(stream)
byte_array[3] = ReadByte(stream)
Return ByteArray_To_Num32(byte_array)
End Function
'Manage Image Slots
Function GetFreeImage()
For i = 0 to MAX_IMAGES-1
If Not ImageExists(i) Then
Return i
End If
Next
Return -1
End Function
'Manage Fonts
Function GetFreeFont()
For i = 0 to 31
If Not FontIsLoaded(i) Then
Return i
End If
Next
Return -1
End Function
'ACTOR FUNCTIONS
Function NewActor(a_name$, spr)
a_index = -1
For i = 0 To MAX_ACTORS-1
If Not Actor_inUse[i] Then
a_index = i
Actor_inUse[a_index] = True
Exit For
End If
Next
If a_index = -1 Then
Return -1
End If
Actor_Name$[a_index] = a_name$
Actor_Sprite[a_index] = spr
Actor_Layer[a_index] = -1
Actor_LayerPosition[a_index] = -1
Actor_ZX[a_index] = 1
Actor_ZY[a_index] = 1
Actor_Angle[a_index] = 0
Actor_CurrentAnimation[a_index] = 0
Actor_CurrentFrame[a_index] = 0
Actor_Visible[a_index] = true
Actor_Active[a_index] = true
Actor_AnimationSync[a_index] = false
Actor_ParentActor[a_index] = -1
Actor_Shape[a_index] = -1
Actor_OffsetActor[a_index, 0] = -1
Actor_Collision[a_index] = true
Actor_Effect_Type[a_index] = 0
Actor_Physics[a_index] = 0
Actor_AnimationEnded[a_index] = 0
Actor_Angle[a_index] = 0
Actor_AnimationSync[a_index] = 0
Actor_ChildActor[a_index] = -1
Actor_NumActorCollisions[a_index] = 0
Actor_NumStageCollisions[a_index] = 0
Actor_Weight[a_index] = 0
Actor_ParentActor[a_index] = -1
Actor_Persistent[a_index] = 0
Actor_CurrentFrameDelay[a_index] = 0
Actor_CurrentFrameTime[a_index] = 0
Return a_index
End Function
Function SaveActor(actor)
If actor < 0 Or actor >= MAX_ACTORS Or (Not Actor_inUse[actor]) Then
Return 0
End If
a_file$ = Actor_Name$[actor] + ".actor"
If FileExists(ACTOR_PATH$ + a_file$) Then
RemoveFile(ACTOR_PATH$ + a_file$)
End If
f = FreeFile
spr = Actor_Sprite[actor]
FileOpen(f, ACTOR_PATH$ + a_file$, TEXT_OUTPUT)
WriteLine(f, Sprite_Name$[spr])
WriteLine(f, Str$(Actor_CurrentAnimation[spr]))
FileClose(f)
End Function
Function GetActorID(a_name$)
For i = 0 to MAX_ACTORS-1
If Actor_Name$[i] = a_name$ Then
Return i
End If
Next
Return -1
End Function
Function GetSpriteID(s_name$)
For i = 0 to MAX_SPRITES-1
If Sprite_Name$[i] = s_name$ Then
Return i
End If
Next
Return -1
End Function
Function LoadActor(a_name$)
actor = -1
For i = 0 to MAX_ACTORS-1
If Not Actor_inUse[i] Then
actor = i
Exit For
End If
Next
If actor = -1 Then
Return -1
End If
a_file$ = Actor_Name$[actor] + ".actor"
If FileExists(ACTOR_PATH$ + a_file$) Then
RemoveFile(ACTOR_PATH$ + a_file$)
End If
f = FreeFile
FileOpen(f, ACTOR_PATH$ + a_file$, TEXT_INPUT)
s_name$ = ReadLine(f)
s_anim = Val(ReadLine(f))
FileClose(f)
Actor_Sprite[actor] = GetSpriteID(s_name$)
Actor_CurrentAnimation[actor] = s_anim
Actor_inUse[actor] = True
Actor_Layer[actor] = -1
Actor_LayerPosition[actor] = -1
Actor_Active[actor] = true
Actor_Visible[actor] = true
Actor_AnimationSync[actor] = false
Actor_Collision[actor] = true
Return actor
End Function
Sub RemoveActor(actor)
a_layer = Actor_Layer[actor]
a_pos = Actor_LayerPosition[actor]
If a_layer >= 0 Then
If Stage_Layer_NumActors[a_layer] > 0 Then
num_to_sort = Stage_Layer_NumActors[a_layer] - a_pos - 1
'Print "apos = ";a_pos
'Print "num to sort = ";num_to_sort
'Print Stage_Layer_Actor[a_layer, a_pos];" should be ";actor
For i = a_pos to a_pos + num_to_sort
Stage_Layer_Actor[a_layer, i] = Stage_Layer_Actor[a_layer, i+1]
Actor_LayerPosition[ Stage_Layer_Actor[a_layer, i] ] = i
Next
Stage_Layer_NumActors[a_layer] = Stage_Layer_NumActors[a_layer] - 1
Actor_Layer[actor] = -1
Actor_LayerPosition[actor] = -1
Actor_AnimationSync[actor] = false
End If
End If
End Sub
Sub DestroyActor(actor)
RemoveActor(actor)
Actor_inUse[actor] = False
Actor_AnimationSync[actor] = false
End Sub
Function Actor_SetLayer(actor, layer)
If layer < 0 Then
Return False
End If
If Stage_Layer_NumActors[layer] >= MAX_ACTORS Then
Return False
End If
If Actor_Layer[actor] <> layer Then
RemoveActor(actor)
pos = Stage_Layer_NumActors[layer]
Stage_Layer_NumActors[layer] = pos + 1
Stage_Layer_Actor[layer, pos] = actor
Actor_Layer[actor] = layer
Actor_LayerPosition[actor] = pos
End If
Return True
End Function
Function Actor_SetAnimation(actor, anim)
If anim >= Sprite_NumAnimations[Actor_Sprite[actor]] Then
Return False
End If
If anim = Actor_CurrentAnimation[actor] Then
Return True
End If
Actor_CurrentAnimation[actor] = anim
sprite = Actor_Sprite[actor]
Actor_CurrentFrameDelay[actor] = 1000 / Max(1, Sprite_Animation_FPS[sprite, anim])
Actor_CurrentFrameTime[actor] = Timer
Return True
End Function
Function Actor_SetAnimationByName(actor, a_name$)
s = Actor_Sprite[actor]
If Sprite_NumAnimations[s] <= 0 Then
Return False
End If
anim = -1
For i = 0 to Sprite_NumAnimations[s]-1
If Sprite_Animation_Name$[s, i] = a_name$ Then
anim = i
Exit For
End If
Next
If anim = -1 Then
Return False
End If
If anim = Actor_CurrentAnimation[actor] Then
Return True
End If
Actor_CurrentAnimation[actor] = anim
sprite = Actor_Sprite[actor]
Actor_CurrentFrameDelay[actor] = 1000 / Max(1, Sprite_Animation_FPS[sprite, anim])
Actor_CurrentFrameTime[actor] = Timer
Actor_AnimationEnded[actor]
Return True
End Function
Function Actor_GetAnimationName$(actor, n)
Return Sprite_Animation_Name$[ Actor_Sprite[actor], n]
End Function
Sub Actor_SetAnimationFrame(actor, frame)
Actor_CurrentFrame[actor] = frame
Actor_CurrentFrameDelay[actor] = 1000 / Max(1, Sprite_Animation_FPS[Actor_Sprite[actor], Actor_CurrentAnimation[actor]])
Actor_CurrentFrameTime[actor] = Timer
End Sub
Sub Actor_SetVisible(actor, flag)
Actor_Visible[actor] = flag
End Sub
Function Actor_isVisible(actor)
Return Actor_Visible[actor]
End Function
Sub Actor_SetActive(actor, flag)
Actor_Active[actor] = flag
End Sub
Function Actor_isActive(actor)
Return Actor_Active[actor]
End Function
Function Actor_GetDistance(actor1, actor2)
Return getDistance(Actor_X[actor1], Actor_Y[actor1], Actor_X[actor2], Actor_Y[actor2])
End Function
Sub DrawActor(actor)
sprite = Actor_Sprite[actor]
anim = Actor_CurrentAnimation[actor]
frame = Actor_CurrentFrame[actor]
src_x = Int(Sprite_Animation_Frame[sprite, anim, frame] Mod Sprite_Image_WidthInFrames[sprite]) * Sprite_Frame_Width[sprite]
src_y = Int(Sprite_Animation_Frame[sprite, anim, frame] / Sprite_Image_WidthInFrames[sprite]) * Sprite_Frame_Height[sprite]
src_w = Sprite_Frame_Width[sprite]
src_h = Sprite_Frame_Height[sprite]
img = Sprite_Image[sprite]
x = Actor_X[actor]
y = Actor_Y[actor]
w = Sprite_Frame_Width[sprite] * Actor_ZX[actor]
h = Sprite_Frame_Height[sprite] * Actor_ZY[actor]
DrawImage_Blit_Ex(img, x, y, w, h, src_x, src_y, src_w, src_h)
End Sub
Dim COLLISION_DIR_RIGHT
Dim COLLISION_DIR_LEFT
Dim COLLISION_DIR_TOP
Dim COLLISION_DIR_BOTTOM
Dim COLLISION_DIR_LINE
Dim COLLISION_LINE_P1[MAX_STAGE_COLLISIONS]
Dim COLLISION_LINE_P2[MAX_STAGE_COLLISIONS]
Dim COLLISION_LINE_P3[MAX_STAGE_COLLISIONS]
Dim COLLISION_LINE_P4[MAX_STAGE_COLLISIONS]
Dim COLLISION_LINE_LEFT
Dim COLLISION_LINE_RIGHT
Dim COLLISION_LINE_TOP
Dim COLLISION_LINE_BOTTOM
COLLISION_DIR_LEFT = 1
COLLISION_DIR_RIGHT = 2
COLLISION_DIR_TOP = 3
COLLISION_DIR_BOTTOM = 4
COLLISION_DIR_LINE = 5
COLLISION_LINE_LEFT = 6
COLLISION_LINE_RIGHT = 7
COLLISION_LINE_TOP = 8
COLLISION_LINE_BOTTOM = 9
Include "lines.bas"
Function Actor_isOnScreen(actor)
x = Actor_X[actor] + Sprite_Frame_Bound_X[ Actor_Sprite[actor], 0 ]
y = Actor_Y[actor] + Sprite_Frame_Bound_Y[ Actor_Sprite[actor], 0 ]
w = Sprite_Frame_Bound_Param[ Actor_Sprite[actor], 0, 0]
h = Sprite_Frame_Bound_Param[ Actor_Sprite[actor], 0, 1]
'If Actor_Name[actor] = "graizor_blaster" Then
' Print "BLASTER: ";x;", ";y;", ";w;", ";h
' Print "Stage: ";Stage_offset_x;", ";Stage_offset_y;", ";STAGE_SCREEN_WIDTH;", ";STAGE_SCREEN_HEIGHT
'End If
If (x+w) >= Stage_offset_x And x < (Stage_offset_x + STAGE_SCREEN_WIDTH) And (y+h) >= Stage_offset_y And y < (Stage_offset_y + STAGE_SCREEN_HEIGHT) Then
Return True
End If
x = Actor_NewX[actor] + Sprite_Frame_Bound_X[ Actor_Sprite[actor], 0 ]
y = Actor_NewY[actor] + Sprite_Frame_Bound_Y[ Actor_Sprite[actor], 0 ]
If (x+w) >= Stage_offset_x And x < (Stage_offset_x + STAGE_SCREEN_WIDTH) And (y+h) >= Stage_offset_y And y < (Stage_offset_y + STAGE_SCREEN_HEIGHT) Then
Return True
End If
Return False
End Function
Function World_Actor_Collision(actor, old_frame, old_x, old_y, new_frame, new_x, new_y)
'ax = Actor_X[actor]
'ay = Actor_Y[actor]
s = Actor_Sprite[actor]
'frame = Actor_CurrentFrame[actor]
layer = Actor_Layer[actor]
layer_index = Actor_LayerPosition[actor]
'diff_x = new_x - ax
'diff_y = new_y - ay
Dim sect_x[9]
Dim sect_y[9]
Dim collide_x
Dim collide_y
Actor_DynaRect_SpeedAdjust[actor, 0] = 0
Actor_DynaRect_SpeedAdjust[actor, 1] = 0
Actor_Collision_Inside_Shape[actor] = -1
Select Case Sprite_Frame_Bound_Shape[s]
Case SHAPE_TYPE_RECT 'Sprite Bound is a Rect
a_lx1 = old_x + Sprite_Frame_Bound_X[s, old_frame]
a_ly1 = old_y + Sprite_Frame_Bound_Y[s, old_frame]
a_lx2 = old_x + Sprite_Frame_Bound_Param[s, old_frame, 0]
a_ly2 = a_ly1
a_lx3 = a_lx2
a_ly3 = old_y + Sprite_Frame_Bound_Param[s, old_frame, 1]
a_lx4 = a_lx1
a_ly4 = a_ly3
n_lx1 = new_x + Sprite_Frame_Bound_X[s, new_frame]
n_ly1 = new_y + Sprite_Frame_Bound_Y[s, new_frame]
n_lx2 = new_x + Sprite_Frame_Bound_Param[s, new_frame, 0]
n_ly2 = n_ly1
n_lx3 = n_lx2
n_ly3 = new_y + Sprite_Frame_Bound_Param[s, new_frame, 1]
n_lx4 = n_lx1
n_ly4 = n_ly3
''''''''''''
sect_x[0] = Int(old_x / Stage_Sector_Width)
sect_y[0] = Int(old_y / Stage_Sector_Height)
sector_x = sect_x[0]
sector_y = sect_y[0]
sect_x[1] = sector_x - 1
sect_y[1] = sector_y - 1
sect_x[2] = sector_x
sect_y[2] = sector_y - 1
sect_x[3] = sector_x + 1
sect_y[3] = sector_y - 1
sect_x[4] = sector_x - 1
sect_y[4] = sector_y
sect_x[5] = sector_x + 1
sect_y[5] = sector_y
sect_x[6] = sector_x - 1
sect_y[6] = sector_y + 1
sect_x[7] = sector_x
sect_y[7] = sector_y + 1
sect_x[8] = sector_x + 1
sect_y[8] = sector_y + 1
num_collisions = 0
'a_dn_shape = Actor_Shape[actor]
For i = 0 to 8
sector_x = sect_x[i]
sector_y = sect_y[i]
If sector_x >= 0 And sector_y >= 0 Then
If Stage_Sector_NumShapes[sector_x, sector_y] > 0 Then
For shape_num = 0 to Stage_Sector_NumShapes[sector_x, sector_y]-1
If Stage_Sector_Shape_Layer[sector_x, sector_y, shape_num] = layer Then
shape_index = Stage_Sector_Shape_Index[sector_x, sector_y, shape_num]
shape_x = Stage_Layer_Shape_X[layer, shape_index]
shape_y = Stage_Layer_Shape_Y[layer, shape_index]
shape_p1 = Stage_Layer_Shape_Param[layer, shape_index, 0]
shape_p2 = Stage_Layer_Shape_Param[layer, shape_index, 1]
Select Case Stage_Layer_Shape_Type[layer, shape_index]
Case SHAPE_TYPE_LINE
'need to do line collision
lx1 = shape_x
ly1 = shape_y
lx2 = shape_p1
ly2 = shape_p2
If lx1 = lx2 Then
lx2 = lx2 + 2
End If
If ly1 = ly2 Then
ly2 = ly2 + 2
End If
If lx1 < lx2 Then
lx1 = lx1 - 1
lx2 = lx2 + 1
Else
lx1 = lx1 + 1
lx2 = lx2 + 1
End If
in_vt_left_mv_right = (lx1 > a_lx1) And (lx1 < n_lx1) And (lx2 > a_lx1) And (lx2 < n_lx1)
in_ht_top_mv_down = (ly1 > a_ly1) And (ly1 < n_ly1) And (ly2 > a_ly1) And (ly2 < n_ly1)
in_vt_left_mv_left = (lx1 > n_lx1) And (lx1 < a_lx1) And (lx2 > n_lx1) And (lx2 < a_lx1)
in_ht_top_mv_up = (ly1 > n_ly1) And (ly1 < a_ly1) And (ly2 > n_ly1) And (ly2 < a_ly1)
in_vt_right_mv_right = (lx1 > a_lx2) And (lx1 < n_lx2) And (lx2 > a_lx2) And (lx2 < n_lx2)
in_ht_bottom_mv_down = (ly1 > a_ly4) And (ly1 < n_ly4) And (ly2 > a_ly4) And (ly2 < n_ly4)
in_vt_right_mv_left = (lx1 > n_lx2) And (lx1 < a_lx2) And (lx2 > n_lx2) And (lx2 < a_lx2)
in_ht_bottom_mv_up = (ly1 > n_ly4) And (ly1 < a_ly4) And (ly2 > n_ly4) And (ly2 < a_ly4)
h_collide = false
v_collide = false
If in_vt_left_mv_right Or in_vt_left_mv_left Then
adj_x = lx1 + ((lx2-lx1)/2)
If GetLineCollision(lx1, ly1, lx2, ly2, adj_x, n_ly1, adj_x, n_ly4, collide_x, collide_y) Then
Actor_Stage_Collision_X[actor, num_collisions] = collide_x
Actor_Stage_Collision_Y[actor, num_collisions] = collide_y
Actor_Stage_Collision_From_Direction[actor, num_collisions] = COLLISION_LINE_RIGHT
num_collisions = num_collisions+1
h_collide = true
End If
ElseIf in_vt_right_mv_right Or in_vt_right_mv_left Then
adj_x = lx1 + ((lx2-lx1)/2)
If GetLineCollision(lx1, ly1, lx2, ly2, adj_x, n_ly2, adj_x, n_ly3, collide_x, collide_y) Then
Actor_Stage_Collision_X[actor, num_collisions] = collide_x
Actor_Stage_Collision_Y[actor, num_collisions] = collide_y
Actor_Stage_Collision_From_Direction[actor, num_collisions] = COLLISION_LINE_LEFT
num_collisions = num_collisions+1
h_collide = true
End If
End If
If in_ht_top_mv_up Or in_ht_top_mv_down Then
adj_y = ly1 + ((ly2-ly1)/2)
If GetLineCollision(lx1, ly1, lx2, ly2, n_lx1, adj_y, n_lx2, adj_y, collide_x, collide_y) Then
Actor_Stage_Collision_X[actor, num_collisions] = collide_x
Actor_Stage_Collision_Y[actor, num_collisions] = collide_y
Actor_Stage_Collision_From_Direction[actor, num_collisions] = COLLISION_LINE_BOTTOM
num_collisions = num_collisions+1
v_collide = true
End If
ElseIf in_ht_bottom_mv_up Or in_ht_bottom_mv_down Then
adj_y = ly1 + ((ly2-ly1)/2)
If GetLineCollision(lx1, ly1, lx2, ly2, n_lx4, adj_y, n_lx3, adj_y, collide_x, collide_y) Then
Actor_Stage_Collision_X[actor, num_collisions] = collide_x
Actor_Stage_Collision_Y[actor, num_collisions] = collide_y
Actor_Stage_Collision_From_Direction[actor, num_collisions] = COLLISION_LINE_TOP
num_collisions = num_collisions+1
v_collide = true
End If
End If
'Regular collision
If Not h_collide Then
py1 = a_ly1
py4 = a_ly4
ny1 = n_ly1
ny4 = n_ly4
If (shape_y > py1) And (shape_y < py4) And (shape_p2 > py1) And (shape_p2 < py4) Then
py1 = shape_y
py4 = shape_p2
ny1 = py1 + (n_ly1 - a_ly1)
ny4 = py4 + (n_ly4 - a_ly4)
End If
py2 = py1
py3 = py4
ny2 = ny1
ny3 = ny4
'left of actor bounds against right of shape
If GetLineCollision(a_lx1, py1, n_lx1, ny1, lx1, ly1, lx2, ly2, collide_x, collide_y) Then
Actor_Stage_Collision_X[actor, num_collisions] = collide_x
Actor_Stage_Collision_Y[actor, num_collisions] = collide_y
Actor_Stage_Collision_From_Direction[actor, num_collisions] = COLLISION_LINE_RIGHT
num_collisions = num_collisions+1
'print "condition 1 = ";collide_x;", ";collide_y
ElseIf GetLineCollision(a_lx4, py4, n_lx4, ny4, lx1, ly1, lx2, ly2, collide_x, collide_y) Then
Actor_Stage_Collision_X[actor, num_collisions] = collide_x
Actor_Stage_Collision_Y[actor, num_collisions] = collide_y
Actor_Stage_Collision_From_Direction[actor, num_collisions] = COLLISION_LINE_RIGHT
num_collisions = num_collisions+1
'print "condition 2 = ";collide_x;", ";collide_y
'right of actor bounds against left of shape
ElseIf GetLineCollision(a_lx2, py2, n_lx2, ny2, lx1, ly1, lx2, ly2, collide_x, collide_y) Then
Actor_Stage_Collision_X[actor, num_collisions] = collide_x
Actor_Stage_Collision_Y[actor, num_collisions] = collide_y
Actor_Stage_Collision_From_Direction[actor, num_collisions] = COLLISION_LINE_LEFT
num_collisions = num_collisions+1
ElseIf GetLineCollision(a_lx3, py3, n_lx3, ny3, lx1, ly1, lx2, ly2, collide_x, collide_y) Then
Actor_Stage_Collision_X[actor, num_collisions] = collide_x
Actor_Stage_Collision_Y[actor, num_collisions] = collide_y
Actor_Stage_Collision_From_Direction[actor, num_collisions] = COLLISION_LINE_LEFT
num_collisions = num_collisions+1
End If
End If
If Not v_collide Then
px1 = a_lx1
px2 = a_lx2
nx1 = n_lx1
nx2 = n_lx2
If (shape_x > px1) And (shape_x < px2) And (shape_p1 > px1) And (shape_p1 < px2) Then
px1 = shape_x
px2 = shape_p1
nx1 = px1 + (n_lx1 - a_lx1)
nx2 = px2 + (n_lx2 - a_lx2)
End If
px4 = px1
px3 = px2
nx4 = nx1
nx3 = nx2
'top of actor bounds against bottom of shape
If GetLineCollision(px1, a_ly1, nx1, n_ly1, lx1, ly1, lx2, ly2, collide_x, collide_y) Then
Actor_Stage_Collision_X[actor, num_collisions] = collide_x
Actor_Stage_Collision_Y[actor, num_collisions] = collide_y
Actor_Stage_Collision_From_Direction[actor, num_collisions] = COLLISION_LINE_BOTTOM
num_collisions = num_collisions+1
ElseIf GetLineCollision(px2, a_ly2, nx2, n_ly2, lx1, ly1, lx2, ly2, collide_x, collide_y) Then
Actor_Stage_Collision_X[actor, num_collisions] = collide_x
Actor_Stage_Collision_Y[actor, num_collisions] = collide_y
Actor_Stage_Collision_From_Direction[actor, num_collisions] = COLLISION_LINE_BOTTOM
num_collisions = num_collisions+1
'bottom of actor bounds against top of shape
ElseIf GetLineCollision(px4, a_ly4, nx4, n_ly4, lx1, ly1, lx2, ly2, collide_x, collide_y) Then
Actor_Stage_Collision_X[actor, num_collisions] = collide_x
Actor_Stage_Collision_Y[actor, num_collisions] = collide_y
Actor_Stage_Collision_From_Direction[actor, num_collisions] = COLLISION_LINE_TOP
num_collisions = num_collisions+1
ElseIf GetLineCollision(px3, a_ly3, nx3, n_ly3, lx1, ly1, lx2, ly2, collide_x, collide_y) Then
Actor_Stage_Collision_X[actor, num_collisions] = collide_x
Actor_Stage_Collision_Y[actor, num_collisions] = collide_y
Actor_Stage_Collision_From_Direction[actor, num_collisions] = COLLISION_LINE_TOP
num_collisions = num_collisions+1
End If
End If
Case SHAPE_TYPE_RECT
py1 = a_ly1
py4 = a_ly4
ny1 = n_ly1
ny4 = n_ly4
If (shape_y > py1) And (shape_y < py4) And (shape_p2 > py1) And (shape_p2 < py4) Then
py1 = shape_y
py4 = shape_p2
ny1 = py1 + (n_ly1 - a_ly1)
ny4 = py4 + (n_ly4 - a_ly4)
End If
py2 = py1
py3 = py4
ny2 = ny1
ny3 = ny4
'left of actor bounds against right of shape
If num_collisions < MAX_STAGE_COLLISIONS Then
If GetLineCollision(a_lx1, py1, n_lx1, ny1, shape_p1, shape_y, shape_p1, shape_p2, collide_x, collide_y) Then
Actor_Stage_Collision_X[actor, num_collisions] = collide_x
Actor_Stage_Collision_Y[actor, num_collisions] = collide_y
Actor_Stage_Collision_From_Direction[actor, num_collisions] = COLLISION_DIR_RIGHT
num_collisions = num_collisions+1
'print "condition 1 = ";collide_x;", ";collide_y
ElseIf GetLineCollision(a_lx4, py4, n_lx4, ny4, shape_p1, shape_y, shape_p1, shape_p2, collide_x, collide_y) Then
Actor_Stage_Collision_X[actor, num_collisions] = collide_x