-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.ras
2254 lines (2011 loc) · 56 KB
/
game.ras
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
program game;
//@define CRT_VERSION 1
@ifdef CRT_VERSION
@projectsettings "exomize" "1"
@endif
@ifndef CRT_VERSION
@projectsettings "exomize" "0"
@endif
@use "system/str"
@use "screen/screen"
@use "compression/compression"
// @use "input/key"
@startblock $1200 "Variables"
var
//@define DEBUG 1
//@define OVERFLOW_CHECK 1
@define USE_KERNAL 0
// Charsets
@define charsetLoc1 $3800
@define charsetLoc2 $7800
@define tilesetLoc1 $3000
@define tilesetLoc2 $7000
@define spriteLoc1 $2000
@define spriteLoc2 $4800
@define tilesetCol $3a00
@define logoLoc $3e00
@define sfxLoc $e000
// Automatically export charsets
@export "charsets/charset.flf" "charsets/charset.bin" 60
@export "charsets/tileset.flf" "charsets/tileset.bin" 256
@export "charsets/logo.flf" "charsets/logo.bin" 120
@export "sprites/spr.flf" "sprites/spr.bin" 4096
charset1: incbin("charsets/charset.bin", @charsetLoc1);
charset2: incbin("charsets/charset.bin", @charsetLoc2);
tileset1: incbin("charsets/tileset.bin", @tilesetLoc1);
tileset2: incbin("charsets/tileset.bin", @tilesetLoc2);
logo: incbin("charsets/logo.bin", @logoLoc);
// sprite1: incbin("sprites/spr.bin", @spriteLoc1);
sprite2: incbin("sprites/spr.bin", @spriteLoc2);
tilesetColors : incbin("charsets/tileset_color.bin", @tilesetCol);
@ifndef IS_DEMO
musicintro: incsid("music/fizz_intro_2000.sid",2);
// music: incsid("music/fizz_ingame_e000.sid",2);
sfx: incbin("sounds/sounds.prg", @sfxLoc, 2);
@endif
// rands: array[256] of byte;
// Double Buffer
currentBank: byte=0;
time: byte=0;
globaltime: byte=0;
frameStatus: byte;
screen: byte;
countSprite: byte=0;
cycle: byte;
needExtraCycle : boolean;
pos: byte;
statusCol: byte;
maxSingleLevels: byte;
maxMultiLevels: byte;
// Game
@define SCENES_SIZE 1
@define DIMX 20
@define DIMY 12
@define DIMZ 4
@define MAX_OBJECTS 240
@define MAX_CONTROLS 2
@define MAX_LASERS 12
@define MAX_LASER_SIZE 30
@define MAX_ACTORS 32
@define MAX_LEV_STRINGS 8
@define ACTOR_LENGTH 8
@define DIMTILES 240
@define DIMANIMS 14
@define Z_BACK2 3
@define Z_BACK1 2
@define Z_MAIN 1
@define Z_FRONT 0
@define UNKNOWN $FF
@define DOWN 7
@define UP 1
@define LEFT 3
@define RIGHT 5
@define SHIFT_DOWN 4
@define SHIFT_UP 5
@define SHIFT_LEFT 6
@define SHIFT_RIGHT 7
@define DOWN_LEFT 6
@define DOWN_RIGHT 8
@define UP_LEFT 0
@define UP_RIGHT 2
@define STOP 12
@define AREA_OUT $FF
@define AREA_DOWN 0
@define AREA_UP 1
@define AREA_LEFT 2
@define AREA_RIGHT 3
@define AREA_CENTER 4
@define LASER_STEP 4
@define TURN_RIGHT 1
@define TURN_LEFT 2
@define TURN_THROUGH 3
@define ON 1
@define OFF $FF
@define LASER_TYPE_USER 10
@define REND_TYPE_TILE 0
@define REND_TYPE_SPRITE 1
@define REND_TYPE_BYTE 2
@define ANIM_MODE_FIX 0
@define ANIM_MODE_LR 1
@define ANIM_MODE_LR_REPEAT 2
@define ANIM_MODE_MANUAL 3
@define ANIM_WALK_L 0
@define ANIM_WALK_R 1
@define ANIM_STAND 2
@define ANIM_SWIM_L 3
@define ANIM_SWIM_R 4
@define ANIM_CLIMB 5
@define ANIM_ROBE 6
@define ANIM_PORTAL 7
@define ANIM_SWITCH_ON 8
@define ANIM_SWITCH_OFF 9
@define ANIM_DOOR_ON 10
@define ANIM_DOOR_OFF 11
@define ANIM_EXIT_ON 12
@define ANIM_EXIT_OFF 13
@define SOUND_TRANSPORT 18 // ->19
@define SOUND_DAMAGE 7
@define SOUND_LASER 11
@define SOUND_JUMP 3
@define SOUND_STEP 8
@define SOUND_SWIM 9 // ->1
@define SOUND_GRAV_ACTIVATE 10 // ->15
@define SOUND_SWITCH_ON 4 // ->16
@define SOUND_SWITCH_OFF 5
@define SOUND_FALL_CRASH 17
@define SOUND_FALL 2
@define SOUND_SHIFT 13
@define SOUND_LADDER 0
@define SOUND_SCENE_START 6
@define SOUND_END 16
@define SOUND_PLAYER_CHANGE 12
@define SOUND_PORTAL_ACTIVATE 20
@define SOUND_PORTAL 21
@define SOUND_EXIT 22
@define SOUND_EXIT_CLOSE 23
collAreaUp: array[9] of byte = (8,7,6,5,4,3,2,1,0);
collAreaLeft: array[9] of byte = (2,5,8,1,4,7,0,3,6);
collAreaRight: array[9] of byte = (6,3,0,7,4,1,8,5,2);
shiftAreaDownX: array[9] of byte = (-1, 0, 1 , -1, 0, 1, -1, 0, 1);
shiftAreaUpX: array[9] of byte = (1, 0, -1, 1, 0, -1, 1, 0, -1);
shiftAreaLeftX: array[9] of byte = (1, 1, 1, 0, 0, 0, -1, -1, -1);
shiftAreaRightX: array[9] of byte = (-1, -1, -1,0, 0, 0, 1, 1, 1);
shiftAreaDownY: array[9] of byte = (-1, -1, -1, 0, 0, 0, 1, 1, 1);
shiftAreaUpY: array[9] of byte = ( 1, 1, 1 , 0, 0, 0, -1, -1, -1);
shiftAreaLeftY: array[9] of byte = ( -1, 0, 1, -1, 0, 1, -1, 0, 1);
shiftAreaRightY: array[9] of byte = ( 1, 0, -1, 1, 0, -1, 1, 0, -1);
ystart: array[12] of byte = ( 0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220 );
tempPointer: pointer of byte;
@define STATE_MENU 0
@define STATE_INIT 1
@define STATE_OPEN_SCENE 2
@define STATE_PLAY 3
@define STATE_CLOSE_SCENE 5
@define STATE_MENU_INPUT 6
@define STATE_OPEN_SCENE_INPUT 7
@define STATE_OPEN_SCENE_REQUEST 8
@define MODE_SINGLE 0
@define MODE_SINGLE_2CHAR 1
@define MODE_COOP 2
@define COMP_PHYSICS_0 %00000001
@define COMP_COLLIDE_ABLE_0 %00000010
@define COMP_SHIFT_PLATTFORM_0 %00000100
@define COMP_DESTROY_COLLIDE_0 %00001000
@define COMP_ERASE_ABLE_0 %00010000
@define COMP_WATER_0 %00100000
@define COMP_ANIMATION_0 %01000000
@define COMP_CONTROL_0 %10000000
@define COMP_PUSHPULL_1 %00000001
@define COMP_CLIMB_ABLE_1 %00000010
@define COMP_ROBE_ABLE_1 %00000100
@define COMP_FLOATER_1 %00001000
@define COMP_PORTAL_1 %00010000
@define COMP_GRAVPAD_1 %00100000
@define COMP_LASER_1 %01000000
@define COMP_MIRROR_1 %10000000
@define COMP_DESTROY_ABLE_2 %00000001
@define COMP_LASERBEAN_2 %00000010
@define COMP_LASERTRANS_ABLE_2 %00000100
@define COMP_LASERONCE_2 %00001000
@define COMP_PORTAL_ACTIVATE_2 %00010000
@define COMP_FONTAINE_2 %00100000
@define COMP_SWITCH_2 %01000000
@define COMP_DOOR_2 %10000000
@define COMP_EXIT_3 %00000001
@define COMP_WAYPOINT_3 %00000010
@define COMP_BULK_PHYS_3 %00000100
// https://www.aivosto.com/articles/petscii.pdf
@define LEV_CHARACTER $40 //@
@define LEV_CHARACTER2 $25 //%
@define LEV_BRICK $61 // a
@define LEV_STONE $62 // b
@define LEV_SAND $73 // s
@define LEV_WATER $3d // =
@define LEV_WATER_UP $27 // '
@define LEV_WATER_DOWN $26 // &
@define LEV_WATER_LEFT $7b // ?
@define LEV_WATER_RIGHT $7d // ?
@define LEV_SHIFT_DOWN $59 // Y
@define LEV_SHIFT_UP $5E // ^
@define LEV_SHIFT_LEFT $3C // <
@define LEV_SHIFT_RIGHT $3E // >
@define LEV_LADDER $68 // h
@define LEV_ROBE_DOWN $5f // _
@define LEV_ROBE_UP $2d // -
@define LEV_ROBE_LEFT $21 // !
@define LEV_ROBE_RIGHT $7C // |
@define LEV_PORTAL $6F // o
@define LEV_GRAVPAD_DOWN $32 // 2
@define LEV_GRAVPAD_UP $38 // 8
@define LEV_GRAVPAD_LEFT $34 // 4
@define LEV_GRAVPAD_RIGHT $36 // 6
@define LEV_MIRROR_LEFT $6e // n
@define LEV_MIRROR_RIGHT $6d // m
@define LEV_GLASS $67 // g
@define LEV_LASER_TRANSPORT $74 // t
@define LEV_PUSH_BOX $64 // d
@define LEV_PULL_BOX $65 // e
@define LEV_PORTAL_ACTIVATE $63 // c
@define LEV_FONTAINE_DOWN $5b // [
@define LEV_FONTAINE_LEFT $28 // (
@define LEV_FONTAINE_RIGHT $29 // )
@define LEV_FONTAINE_UP $5d // ]
@define LEV_CANNON_DOWN $31 // 1
@define LEV_CANNON_UP $39 // 9
@define LEV_CANNON_LEFT $37 // 7
@define LEV_CANNON_RIGHT $33 // 3
@define LEV_SWITCH_MANUAL $72 // r
@define LEV_DOOR $78 // x
@define LEV_EXIT $58 // X
@define LEV_WAYPOINT $2E // .
@define LEV_BLOCK $66 // f
@define CTRL_STATE_WALK 0
@define CTRL_STATE_CLIMB 1
@define CTRL_STATE_ROBE 2
@define CTRL_STATE_SWIM 3
@define CTRL_STATE_JUMP 4
@define CTRL_STATE_DESTROY 5
@define CTRL_STATE_RETRY 6
@define CTRL_STATE_EXITED 7
@define CTRL_STATE_DIE 8
@define EVENT_INIT_LEVEL 0
@define EVENT_SWITCH_ON 1
@define EVENT_SWITCH_OFF 2
@define EVENT_WAYPOINT_ENTER 3
@define EVENT_WAYPOINT_LEAVE 4
@define ACTION_DOOR_OPEN 1
@define ACTION_DOOR_CLOSE 2
@define ACTION_EXIT_OPEN 3
@define ACTION_EXIT_CLOSE 4
@define ACTION_PRINT_TEXT 5
@define ACTION_CLEAR_TEXT 6
@define ACTION_LASERCANNON_ON 7
@define ACTION_LASERCANNON_OFF 8
@define ACTION_FONTAINE_ON 9
@define ACTION_FONTAINE_OFF 10
@define ACTION_SET_GRAV 11
@define ACTION_SWITCH_ON 12
@define ACTION_SWITCH_OFF 13
@define ACTION_SET_GRAV_BULK 14
@define DO_ACTIVATE_SWITCH_START 17
txtDoActiveSwitch: string=("SWITCH");
@define ACTIVATE_SWITCH_START 12
txtActiveSwitch: string=("SWITCH ACTIVATED");
@define DEACTIVATE_SWITCH_START 11
txtDeactiveSwitch: string=("SWITCH DEACTIVATED");
@define EXIT_CLOSED_START 16
txtExitClosed: string=("EXIT CLOSED");
@define CHAR_SWAP_RED 15
txtCharSwapRed: string=("ACTIVE: RED");
@define CHAR_SWAP_GREEN 12
txtCharSwapGreen: string=("ACTIVE: GREEN");
@define PLAYER_EXIT 12
txtPlayerExit: string=("PLAYER EXITED");
txtSelectGameMode: string=("SELECT GAME MODE:");
txtSinglePlayer: string=("SINGLE PLAYER");
txtSinglePlayer2Chars: string=("SINGLE PLAYER TWO CHARACTERS");
txtCoop: string=("TWO PLAYER CO-OP");
txtSingleStart: string=("SINGLE PLAYER START LEVEL:");
txtCoopStart: string=("CO-OP START LEVEL:");
txtAuthor: string=("CODE: ANDY DAUMANN");
txtMusican: string=("MUSIC: PICRARD");
countObjects: byte;
deletedObjects: Array[@MAX_OBJECTS] of byte;
dynObjectList : Array[@MAX_OBJECTS] of byte;
animObjectList : Array[@MAX_OBJECTS] of byte;
countDyn: byte;
countAnim: byte;
countLasers: byte;
mapback2 : Array[@DIMTILES] of byte;
mapback1 : Array[@DIMTILES] of byte;
mapmain : Array[@DIMTILES] of byte;
mapfront : Array[@DIMTILES] of byte;
portals: Array [2] of byte;
lastPortal: byte;
state: byte;
sp: pointer;
dp: pointer;
textTimer: byte;
levelSingle: byte;
levelCoop: byte;
nextLevel: byte;
gameMode: byte;
activeChar: byte;
retryPressed: byte;
menuItem: byte = 0;
soundId: byte;
soundTimer: byte;
initSound: byte;
freq: byte;
voice: byte;
musicStr: string = ("T1");
@define ANIM_CONSIDER_GRAV_IGNORE 0
@define ANIM_CONSIDER_GRAV_FULL 1
// @define ANIM_CONSIDER_GRAV_HALF 2
animObject = class
animSeq: array[4] of byte;
considerGravity: byte;
size: byte;
speed: byte;
mode: byte;
end;
animList : Array[@DIMANIMS] of animObject;
actorObject = record
event: byte;
senderId: byte;
action: byte;
receiverId: byte;
param0, param1, param2, param3: byte;
end;
controlObject = record
controlJumpStep: byte;
controlState: byte;
controlFollowKeyRight, controlFollowKeyLeft: byte;
b_controlPressLeft, b_controlPressRight, b_controlPressUp, b_controlPressDown, b_controlPressAction: byte;
b_firePressed: byte;
controlLastPortal: byte;
b_waitRelease, b_release: byte;
waypointId: byte;
lastWaypointId: byte;
controlCollideLaserTag: byte;
b_fallDown: byte;
end;
laserObject = record
laserDir: byte;
lastLaserDir: byte;
laserLastTransportAble: byte;
laserType : byte;
currentLaser: byte;
end;
controlList : Array[@MAX_CONTROLS] of controlObject;
actorList : Array[@MAX_ACTORS] of actorObject;
laserList : Array[@MAX_LASERS] of laserObject;
@endblock
/*
@ifdef IS_DEMO
@startblock "$08FD" "Global"
maxSingle, maxMulti: byte;
@endblock
@endif
*/
@startblock $1c00 "level"
lev: string = ("x {aaaaaa a a aaa ^a aa a aa aa6 e aaa aa d aaa a6 [12 ^ ^Yaa % o ^ ^Yaa& ^ ^Yaa& ^ ^Yaa& h a& 4------====hh aa&m n b@ = f aaX x===ss rs8 h o aaaaaaaaaaaaaaa>>aaaa");
//event, action, senderpos, receiverpos, p1, p2, p3, p48
levActor: Array[@MAX_ACTORS * @ACTOR_LENGTH] of byte = (1, 1 ,211 , 204, $FF, $FF, $FF, $FF,
2, 2 ,211 , 204, $FF, $FF, $FF, $FF,
1, 1, 211, 0, $FF, $FF, $FF, $FF,
2, 2, 211, 0, $FF, $FF, $FF, $FF,
1, 3, 211, 201,$FF, $FF, $FF, $FF,
2, 4, 211, 201,$FF, $FF, $FF, $FF,
3, 5, 211, $FF, $00, 17, 10, $FF,
4, 6, 211, $FF, $FF, $FF, $FF, $FF,
0, 5, $FF, $FF, $00, 17, 10, $FF,
3, 5, 70, $FF, $00, 17, 10, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF,
$FF, $FF, $FF, $FF,$FF, $FF, $FF, $FF);
levBothMustComplete: boolean = true;
levStrings: Array[@MAX_LEV_STRINGS] of string = ("WELCOME","aa","bb","cc","dd","ee","ff","gg");
@endblock
@startblock $ea00 "Objects"
gobject = record
component0, component1, component2, component3: byte;
// TransformTile
transX, transY, transZ: byte;
// Render
rendTilePos: byte;
rendType: byte;
// Physics
physGravity: byte;
b_physFallDown: byte;
b_physRollLeftRight: byte;
// ShiftPlattform
shiftDir: byte;
// Control
controlId: byte;
moves: byte;
// Animation
animId: byte;
animPos: byte;
animFinish: byte;
// Portal
portalFireExitDir: byte;
// Laser, Fontaine
laserEmitId: byte;
laserTag: byte;
// Mirror
mirrorTurn: byte;
// PushPull , Door, Exit, Switch
onOff: byte;
end;
objectList : Array[@MAX_OBJECTS] of gobject;
@endblock
@ifdef CRT_VERSION
@startblock $1000 "CodeCrt"
procedure LoadMusicFromCrt();
begin
setmemoryconfig(1,1,1);
Poke(^$DE00,0,$0F);
Compression::Decompress($8000, $2000);
setmemoryconfig(1,0,0);
end;
procedure LoadLevelFromCrt(lev: byte, isSingle: boolean);
var
bank, i : byte;
begin
sp := CreatePointer($80, 00);
if(isSingle = true) then begin
if(lev <= $1f) then
bank := $0B
else begin
bank := $0C;
lev := lev - $20;
end;
if(lev <> 0) then begin
for i := 0 to lev do
begin
sp := sp + $100;
end;
end;
end
else begin
if(lev <= $13) then
bank := $0D
else begin
bank := $0E;
lev := lev - $14;
end;
if(lev <> 0) then begin
for i := 0 to lev do
begin
sp := sp + $80;
sp := sp + $100;
end;
end;
end;
setmemoryconfig(1,1,1);
Poke(^$DE00,0,bank);
Compression::Decompress(sp, $1bfe);
setmemoryconfig(1,0,0);
end;
@endblock
@endif
@startblock $5800 "Code"
procedure InitSprites();
var
i:byte;
begin
// Set all sprites to be multicolor
sprite_multicolor:=$ff;
// Set common sprite multicolor #1
sprite_multicolor_reg1:=dark_grey;
// Set common sprite multicolor #2
sprite_multicolor_reg2:=white;
for i := 0 to 8 do begin
sprite_color[i]:=light_red;
SpritePos(0,0,i);
end;
sprite_color[1]:=green;
// Turn on sprite 0 (or @useSprite)
sprite_bitmask := $FF;
// togglebit(sprite_bitmask,0,1);
end;
procedure PrintText(x: byte);
begin
@IFDEF OVERFLOW_CHECK
if(x >= 40) then SCREEN_BG_COL:=BLUE;
@ENDIF
@IFNDEF DEBUG
moveto(0,24,screen);
fillfast(screenmemory,$20,40);
screenmemory[0]:=$1c;
screenmemory[39]:=$1d;
moveto(x,24,screen);
printstring(sp,0,40);
statusCol := @WHITE;
@ENDIF
end;
procedure ClearText();
begin
@IFNDEF DEBUG
moveto(0,24,screen);
fillfast(screenmemory,$20,40);
screenmemory[0]:=$1c;
screenmemory[39]:=$1d;
statusCol := @DARK_GREY;
@ENDIF
end;
procedure SwapActiveChar();
begin
textTimer := 20;
if(activeChar = 0 and controlList[1].controlState <> @CTRL_STATE_EXITED) then begin
activeChar := 1;
sp := #txtCharSwapGreen;
PrintText(@CHAR_SWAP_GREEN);
end
else if(activeChar = 1 and controlList[0].controlState <> @CTRL_STATE_EXITED) then begin
activeChar := 0;
sp := #txtCharSwapRed;
PrintText(@CHAR_SWAP_RED);
end;
end;
procedure InitLevel();
var
i : integer;
levStr: string = "XFF";
begin
state := @STATE_PLAY;
countObjects := 0;
countDyn := 0;
countAnim := 0;
textTimer := 0;
countSprite := 0;
countLasers := 0;
retryPressed := false;
activeChar := 1;
statusCol := @DARK_GREY;
levStr[2] := 0;
for i:= $EA00 to $FFF0 do begin
sp := int2ptr(i);
sp[0] := $FF;
end;
if(gameMode = @MODE_SINGLE) then begin
AddBreakpoint();
// if(nextLevel <> levelSingle) then begin
levelSingle := nextLevel;
levStr[0] := 'S';
str::itoa(levelSingle, #levStr+1, 16);
@ifdef CRT_VERSION
LoadLevelFromCrt(levelSingle, true);
@endif
@ifdef IS_DEMO
asm(
"
ldx #<localVariable_InitLevel_levStr
ldy #>localVariable_InitLevel_levStr
jsr $200
");
@endif
// end;
end
else begin
if(gameMode = @MODE_SINGLE_2CHAR) then SwapActiveChar();
// if(nextLevel <> levelCoop) then begin
levelCoop := nextLevel;
levStr[0] := 'M';
str::itoa(levelCoop, #levStr+1, 16);
@ifdef CRT_VERSION
LoadLevelFromCrt(levelCoop, false);
@endif
@ifdef IS_DEMO
asm(
"
ldx #<localVariable_InitLevel_levStr
ldy #>localVariable_InitLevel_levStr
jsr $200
");
@endif
// end;
end;
end;
procedure SetNextLevel();
begin
if(gameMode = @MODE_SINGLE) then begin
if(levelSingle + 1 >= maxSingleLevels) then nextLevel := 0
else begin
nextLevel := levelSingle + 1;
end;
end
else begin
if(levelCoop +1 >= maxMultiLevels) then nextLevel := 0
else begin
nextLevel := levelCoop + 1;
end;
end;
end;
procedure IncLevel(mode: byte);
begin
if(mode = @MODE_SINGLE) then begin
if(levelSingle < maxSingleLevels - 1) then inc(levelSingle);
end
else begin
if(levelCoop < maxMultiLevels - 1) then inc(levelCoop);
end;
end;
procedure DecLevel(mode: byte);
begin
if(mode = @MODE_SINGLE) then begin
if(levelSingle > 0) then dec(levelSingle);
end
else begin
if(levelCoop > 0) then dec(levelCoop);
end;
end;
procedure InitGame(levSingle, levCoop: byte, mode: byte);
begin
levelSingle := levSingle;
levelCoop := levCoop;
gameMode := mode;
if(gameMode = @MODE_SINGLE) then nextLevel := levSingle else nextLevel := levCoop;
menuItem := 0;
cycle := 0;
needExtraCycle := false;
// InitRand();
end;
procedure print2x2block(x,y,c: byte);
begin
@IFDEF OVERFLOW_CHECK
if(x = $FF or y = $FF) then SCREEN_BG_COL:=BROWN;
if(x = @DIMX or y = @DIMY) then SCREEN_BG_COL:=YELLOW;
@ENDIF
moveto(x*2,y*2,screen);
screenmemory[0]:=c;
screenmemory[1]:=c+1;
screenmemory[40]:=c+40;
screenmemory[41]:=c+41;
moveto(x*2,y*2,hi(SCREEN_COL_LOC));
screenmemory[0]:=tilesetColors[c]+8;
screenmemory[1]:=tilesetColors[c+1]+8;
screenmemory[40]:=tilesetColors[c+40]+8;;
screenmemory[41]:=tilesetColors[c+41]+8;;
end;
procedure print1x1block(x,y,c: byte);
begin
@IFDEF OVERFLOW_CHECK
if(x = $FF or y = $FF) then SCREEN_BG_COL:=BROWN;
if(x = @DIMX or y = @DIMY) then SCREEN_BG_COL:=YELLOW;
@ENDIF
moveto(x*2,y*2,screen);
screenmemory[0]:=c;
screenmemory[1]:=c;
screenmemory[40]:=c;
screenmemory[41]:=c;
moveto(x*2,y*2,hi(SCREEN_COL_LOC));
screenmemory[0]:=tilesetColors[c]+8;
screenmemory[1]:=tilesetColors[c]+8;
screenmemory[40]:=tilesetColors[c]+8;;
screenmemory[41]:=tilesetColors[c]+8;;
end;
procedure CycleWater();
var
waterStep : byte;
begin
waterStep := mod(globaltime,4);
sp := @tilesetLoc1 + (240 + waterStep) * 8;
dp := @tilesetLoc1 + 22*8;
MemCpyFast(sp, 0, dp,8);
dp := @tilesetLoc2 + 22*8;
MemCpyFast(sp, 0, dp,8);
sp := @tilesetLoc1 + (243 - waterStep) * 8;
dp := @tilesetLoc1 + 23*8;
MemCpyFast(sp, 0, dp,8);
dp := @tilesetLoc2 + 23*8;
MemCpyFast(sp, 0, dp,8);
sp := @tilesetLoc1 + (244 + waterStep) * 8;
dp := @tilesetLoc1 + 62*8;
MemCpyFast(sp, 0, dp,8);
dp := @tilesetLoc2 + 62*8;
MemCpyFast(sp, 0, dp,8);
sp := @tilesetLoc1 + (247 - waterStep) * 8;
dp := @tilesetLoc1 + 63*8;
MemCpyFast(sp, 0, dp,8);
dp := @tilesetLoc2 + 63*8;
MemCpyFast(sp, 0, dp,8);
end;
procedure PrintSprite(x: byte, y: byte, spriteLoc: byte, num: byte);
var
xs: integer;
ys: byte;
ns: byte;
begin
xs := 24 + (x shl 4);
ys := 50 + (y shl 4);
if(currentBank = 0) then begin
ns := spriteLoc + $80;
SetSpriteLoc(num, ns, 0);
end
else begin
ns := spriteLoc + $20;
SetSpriteLoc(num, ns, 1);
end;
SpritePos(xs,ys,num);
end;
procedure print2x2blockEmpty(x,y:byte);
begin
@IFDEF OVERFLOW_CHECK
if(x >= @DIMX or y >= @DIMY) then SCREEN_BG_COL:=GREY;
@ENDIF
moveto(x*2,y*2,screen);
screenmemory[0]:=255;
screenmemory[1]:=255;
screenmemory[40]:=255;
screenmemory[41]:=255;
end;
procedure GetZLayerPointer(z: byte);
begin
case z of
@Z_BACK2: tempPointer := #mapback2;
@Z_BACK1: tempPointer := #mapback1;
@Z_MAIN: tempPointer := #mapmain;
@Z_FRONT: tempPointer := #mapfront;
end;
end;
function PaintPosAnim(t: byte, considerAnimation: boolean) : byte;
var
x,y: byte;
animId: byte;
hideSprite: boolean;
pa: pointer of animObject;
currentTile: byte;
gravity: byte;
shiftAnim: byte;
begin
animId := objectList[t].animId;
pa := #animList[animId];
if(considerAnimation = true and (objectList[t].component0 & @COMP_ANIMATION_0 = @COMP_ANIMATION_0)) then begin
if(pa.considerGravity = @ANIM_CONSIDER_GRAV_IGNORE) then shiftAnim := 0
else if(pa.considerGravity = @ANIM_CONSIDER_GRAV_FULL) then begin
gravity := @DOWN;
if((objectList[t].component0 & @COMP_PHYSICS_0) = @COMP_PHYSICS_0) then gravity := objectList[t].physGravity;
if(gravity = @DOWN) then shiftAnim := 0
else if(gravity = @UP) then shiftAnim := 1
else if(gravity = @RIGHT) then shiftAnim := 2
else if(gravity = @LEFT) then shiftAnim := 3;
end;
/* else if(pa.considerGravity = @ANIM_CONSIDER_GRAV_HALF) then begin
gravity := @DOWN;
if((objectList[t].component0 & @COMP_PHYSICS_0) = @COMP_PHYSICS_0) then gravity := objectList[t].physGravity;
if(gravity = @UP) then shiftAnim := 1
else if(gravity = @RIGHT) then shiftAnim := 0
else if(gravity = @LEFT) then shiftAnim := 1;
end;*/
currentTile := pa.animSeq[objectList[t].animPos];
currentTile := currentTile + shiftAnim;
if(pa.mode = @ANIM_MODE_FIX) then objectList[t].animPos := 0
else if(pa.mode = @ANIM_MODE_LR and objectList[t].animFinish = false) then begin
if(objectList[t].animPos = pa.size - 1) then begin
objectList[t].animPos := pa.size - 1;
objectList[t].animFinish := true;
end
else if(mod(globaltime, pa.speed) = 0) then inc(objectList[t].animPos);
end
else if(pa.mode = @ANIM_MODE_LR_REPEAT) then begin
if(objectList[t].animPos = pa.size - 1) then begin
objectList[t].animPos := 0;
objectList[t].animFinish := false;
end
else if(mod(globaltime, pa.speed) = 0) then inc(objectList[t].animPos);
end;
end
else currentTile := objectList[t].rendTilePos;
PaintPosAnim := currentTile;
end;
procedure PaintPos(pos: byte, considerAnimation: boolean);
var
x,y: byte;
t, tHide: byte;
animId: byte;
hideSprite: boolean;
pa: pointer of animObject;
currentTile: byte;
gravity: byte;
shiftAnim: byte;
begin
@IFDEF OVERFLOW_CHECK
if(pos >= @DIMTILES) then SCREEN_BG_COL:=BROWN;
@ENDIF
x := mod(pos,@DIMX);
y := pos / @DIMX;
t := $FF;
currentTile := $FF;
hideSprite:= false;
if(mapfront[pos] <> 255) then begin
t := mapfront[pos];
currentTile := PaintPosAnim(t, considerAnimation);
hideSprite := true;
end
else if(mapmain[pos] <> 255) then begin
t := mapmain[pos];
currentTile := PaintPosAnim(t, true);
end
else if(mapback1[pos] <> 255) then begin
t := mapback1[pos];
currentTile := PaintPosAnim(t, considerAnimation);
end
else if(mapback2[pos] <> 255) then begin
t := mapback2[pos];
currentTile := PaintPosAnim(t, considerAnimation);
end;
if(t <> $FF) then begin
if(hideSprite = true) then begin
tHide := mapmain[pos];
if(tHide <> $FF and objectList[tHide].rendType = @REND_TYPE_SPRITE) then
PrintSprite(0,@DIMY+1,0,objectList[tHide].controlId)
end;
if(objectList[t].rendType = @REND_TYPE_SPRITE and hideSprite = false) then
PrintSprite(x,y,currentTile,objectList[t].controlId)
else if(objectList[t].rendType = @REND_TYPE_TILE) then
print2x2block(x,y,currentTile)
else
print1x1block(x,y,currentTile);
end
else print2x2blockEmpty(x,y);
end;
procedure HideSprite(controlId : byte);
begin
PrintSprite(0,@DIMY+1,0,controlId)
end;
function ConvertShift(gravity: byte, pos: byte) : integer;
var
ret: integer;
begin
@IFDEF OVERFLOW_CHECK
if(pos >= 9) then SCREEN_BG_COL:=RED;
if(gravity = $FF) then SCREEN_BG_COL:=RED;
@ENDIF
if(gravity = @DOWN) then ret := CreateInteger(shiftAreaDownX[pos],shiftAreaDownY[pos])
else if(gravity = @UP) then ret := CreateInteger(shiftAreaUpX[pos],shiftAreaUpY[pos])
else if(gravity = @LEFT) then ret := CreateInteger(shiftAreaLeftX[pos],shiftAreaLeftY[pos])
else if(gravity = @RIGHT) then ret := CreateInteger(shiftAreaRightX[pos],shiftAreaRightY[pos]);
ConvertShift := ret;
end;
function CalcPosition(startx,starty, pos: byte) : integer;
var
destx, desty: byte;
begin
destx := startx + shiftAreaDownX[pos];
desty := starty + shiftAreaDownY[pos];
if(destx = $FF) then destx := @DIMX - 1
else if(destx = @DIMX) then destx := 0;
if(desty = $FF) then desty := @DIMY - 1
else if(desty = @DIMY) then desty := 0;
CalcPosition := CreateInteger(destx, desty);
end;
function CalcPositionMapPos(startx,starty, pos: byte) : byte;
var
npos: integer;
begin
npos := CalcPosition(startx,starty, pos);
CalcPositionMapPos := hi(npos) + ystart[lo(npos)];
end;
function GetObjectByPosFilterComp(x: byte, y: byte, z: byte, comp: byte, compIdx: byte) : byte;
var
mapPos, colId, ret, val: byte;
begin
GetZLayerPointer(z);