-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmariolike.mrc
2856 lines (2241 loc) · 61.6 KB
/
mariolike.mrc
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Mario-like game ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
menu menubar {
mario
.new map { mariolikegame -f }
.-
.lots of anim { mariolikegame -f lotsofanim.obj }
.fucking huge map (but empty) { mariolikegame -f fhugemap.obj }
.test big map { mariolikegame -f testbigmap.obj }
}
alias f2 { mariolikegame -f }
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; desc: launch the game
; param:
alias mariolikegame {
var %file = $1
if ($1 == -f) {
game_Unload
%file = $2
}
if (!$game_IsRunning()) {
if (!$game_Launch(%file,22,16)) {
game_Unload
}
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; desc: unload the game
; param:
alias -l game_Unload {
.timered off
window -c @edc
window -c @edb0
window -c @edt
window -c @edts
if ($hget(edig)) {
var %id = $obj_readFirst(spritesheet)
while (%id) {
window -c $+(@edbss,$obj_get(spritesheet,%id).name)
%id = $obj_readNext(spritesheet)
}
}
engine_ClearData
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_ClearData {
if ($hget(edig)) hfree edig
unset %tile.*
unset %map.*
unset %win.*
unset %cam.*
unset %buffer.*
unset %fps.*
unset %game.*
unset %phys.*
unset %keydown[*]
unset %keypress[*]
unset %collision.*
unset %edit.*
unset %player.*
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l game_IsRunning {
return $hget(edig)
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l game_Launch {
var %w = $2
var %h = $3
window -hpf @edt 0 0 992 418
window -hp @edts 0 0 600 800
if ($engine_Init($1, %w, %h)) {
window -Bdfkop +fnt @edc 0 0 %win.w %win.h
; +128 to w and h is a buffer size to fit 2 tiles max (used for scrolling)
window -hpf @edb0 0 0 $calc(%win.w + 128) $calc(%win.h + 128)
var %id = $obj_readFirst(spritesheet)
while (%id) {
game_InitSpritesSheet $obj_get(spritesheet,%id).name $obj_get(spritesheet,%id).file
%id = $obj_readNext(spritesheet)
}
if ($engine_JumpToMap($obj_get(game,1).starting_map)) {
.timered -om 0 0 engine_GameLoop
engine_SetFont $font.default
return 1
}
else {
engine_showError Can't find $qt($obj_get(game,1).starting_map) map
}
}
else {
return 0
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l game_InitSpritesSheet {
var %path = $+($scriptdir,$2-)
if ($isfile(%path)) {
var %w = $pic(%path).width
var %h = $pic(%path).height
window -hpf $+(@edbss,$1) 0 0 %w %h
drawpic $+(@edbss,$1) 0 0 $shortfn(%path)
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_Init {
engine_ClearData
hmake edig 1000
var %file = $game_Path($1)
if ($isfile(%file)) {
if (!$engine_LoadMap(%file)) {
engine_ShowError Can't load map file %file
return 0
}
set %game.file %file
}
else {
if (!$engine_LoadObjectsFile(objects.txt)) {
engine_ShowError Can't load objects.txt
return 0
}
unset %game.file
}
obj_clear cp
set %tile.w $obj_get(game,1).tile_w
set %tile.h $obj_get(game,1).tile_h
; window size
set %win.w $calc(%tile.w * $2)
set %win.h $calc(%tile.h * $3)
set %game.bx $calc(%tile.w * 9)
set %game.bw $calc(%win.w - %game.bx - %tile.w)
set %game.by $calc(%tile.h * 7)
set %game.bh $calc(%win.h - %game.by)
engine_createPlayer mario 10 300
%game.cp.x = 10
%game.cp.y = 300
var %id = $obj_ReadFirst(tileset)
if (%id) {
drawpic -n @edt 0 0 $game_path($obj_get(tileset,%id).filename)
}
; start the game by controlling the first player
set %game.cp $obj_readFirst(cp)
;
engine_SetFont $rgb(255,255,255) arial 10
phys_InitConst
set %fps.val 65
set %fps.lc $ticks
set %fps.fc 0
set %game.animFrame 0
return 1
}
alias -l creep_spawn {
var %id = $obj_getNextId(mon)
obj_new mon %id
obj_set mon %id x $1
obj_set mon %id y $2
obj_set mon %id w 32
obj_set mon %id h 32
obj_set mon %id maxvel 6
obj_set mon %id jump 10
obj_set mon %id rgb $rgb(255,0,0)
obj_set mon %id face R
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias engine_createPlayer {
var %pid = $obj_findByName(player,$1)
var %id = $obj_getNextId(cp)
obj_new cp %id
obj_set cp %id x $2
obj_set cp %id y $3
obj_set cp %id maxvel $obj_get(player,%pid).velocity
obj_set cp %id jump $obj_get(player,%pid).jump
obj_set cp %id detectBorder $obj_get(player,%pid).detectBorder
obj_set cp %id face R
obj_set cp %id vx 0
obj_set cp %id vy 0
player_setSprite %id $obj_get(player,%pid).sprite
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_InitObjPhys {
obj_set $1 $2 vx 0
obj_set $1 $2 vy 0
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l phys_InitConst {
; terminal velocity
set %phys.tv 9
; check collision or not
set %phys.checkColl 1
; x&y acceleration
set %phys.ax .18
set %phys.ay .3
; x deceleration
set %phys.dx .08
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param: type, id
; desc:
alias -l phys_InitObj {
obj_set $1 $2 vx 0
obj_set $1 $2 vy 0
obj_set $1 $2 xoff 0
obj_set $1 $2 yoff 0
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias engine_JumpToMap {
var %mapid = $obj_findByProp(map,name,$1)
if (%mapid) {
set %map.id %mapid
set %cam.x 0
set %cam.y 0
set %buffer.x 0
set %buffer.y 0
set %map.w $obj_get(map,%map.id).map_w
set %map.h $obj_get(map,%map.id).map_h
set %buffer.w $calc(%win.w + %tile.w * 2)
set %buffer.h $calc(%win.h + %tile.h * 2)
set %cam.maxw $calc(%map.w * %tile.w - %win.w)
set %cam.maxh $calc(%map.h * %tile.h - %win.h)
; number of tiles that fits on screen
set %win.xtile $calc(%win.w / %tile.w)
set %win.ytile $calc(%win.h / %tile.h)
drawrect -r @edc 0 1 0 400 %win.w 20
drawtext -r @edc 0 arial 16 20 380 loading map ... %map.w tiles by %map.h tiles
; creates a row of tiles at bottom of the map to handle collision detection
var %n = 0, %t = $calc(%map.w + %map.h)
var %x = 0, %m = $obj_findByName(tile,blocker)
while (%x < %map.w) {
hadd edig $+(%map.id,%x,.,%map.h,.m) %m
if ($calc(%n % 30) == 0) {
drawrect -rf @edc 255 1 2 401 $calc((%n / %t) * %win.w - 1) 18
}
inc %n
inc %x
}
drawrect -rf @edc 255 1 2 401 $calc((%win.w / 2) - 1) 18
; creates a row of tiles at both sides of the map to handle collision detection
var %y = 0
while (%y < %map.h) {
if ($calc(%n % 30) == 0) {
drawrect -rf @edc 255 1 2 401 $calc((%n / %t) * %win.w - 2) 18
}
inc %n
hadd edig $+(%map.id,-1,.,%y,.m) %m
hadd edig $+(%map.id,%map.w,.,%y,.m) %m
inc %y
}
drawrect -rf @edc 255 1 $calc(%win.w / 2) 401 $calc(1 * (%win.w / 1)) 18
buffer_Redraw
return 1
}
else {
return 0
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_GameLoop {
%player.killFrame = 0
if (!%game.paused) {
%game.ticks = $calc($ticks - %game.deltaticks)
}
; update animation frame number
if ($calc(%game.ticks - %game.anim_sync) >= 100) {
%game.af = $calc((%game.af + 1) % 4)
%game.anim_sync = %game.ticks
}
engine_HandleKeypress
if (%game.paused) {
engine_RenderPauseScreen
}
else {
engine_UpdateAndRender
}
engine_UpdateFps
drawdot @edc
; clear the keypresses if needed
if (%game.clearkeypress) {
unset %keypress[*]
%game.clearkeypress = 0
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_renderPauseScreen {
drawtext -nr @edc $rgb(255,255,255) arial 16 400 300 PAUSE
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_HandleKeypress {
if (%keypress[67]) {
%game.camera = $abs($calc(%game.camera - 1))
engine_SetFont $rgb(255,255,255) Arial 26
msg_Show -1 10 1500 camera is now $iif(%game.camera,centered,loose)
engine_SetFont $font.default
}
if (%keypress[66]) {
if (%player.state != bigmario) {
engine_SetFont $rgb(255,255,255) Arial 26
msg_Show -1 10 2000 cheat : big mario
engine_SetFont $font.default
player_changeState bigmario
}
}
if (%keypress[32]) {
%game.paused = $abs($calc(%game.paused - 1))
if (!%game.paused) {
%game.deltaticks = $calc($ticks - %game.ticks)
}
}
if (%game.paused) {
return
}
if (!$obj_get(cp,%game.cp).crouch) {
if (%keydown[37]) {
player_WalkLeft %game.cp
}
elseif (%keydown[39]) {
player_WalkRight %game.cp
}
}
if (%keypress[38]) {
player_Jump %game.cp 100
}
if (!%keydown[40]) {
if ($obj_get(cp,%game.cp).crouch) {
player_crouch %game.cp 0
}
}
if (%keypress[40]) {
player_crouch %game.cp 1
}
if (%game.cp && !%game.edit) {
if (%keypress[71]) {
engine_SetEditMode 1
}
}
else {
if (%keypress[33]) {
if ($editor_prevTile()) {
%edit.selm = $v1
}
else %edit.selm = 0
}
if (%keypress[34]) {
if ($editor_nextTile()) {
%edit.selm = $v1
}
}
if (%keypress[83]) {
var %name
if (%game.file) %name = %game.file
else %name = $sfile($game_Path())
if (%name) {
if ($engine_SaveMap(%name)) {
engine_SetFont $rgb(255,255,255) Arial 20
msg_Show -1 10 2000 Map saved
engine_SetFont $font.default
}
}
}
if (%keypress[76]) {
var %name = $sfile($game_Path())
if (%name) {
if ($engine_LoadMap(%name)) {
engine_setEditMode 0
}
}
}
if (%keypress[49]) {
engine_createplayer goomba %edit.selx %edit.sely
}
if (%keypress[50]) {
engine_createplayer koopa %edit.selx %edit.sely
}
if (%keypress[51]) {
engine_createplayer goombafly %edit.selx %edit.sely
}
if (%keypress[52]) {
engine_createplayer shell %edit.selx %edit.sely
}
if (%keypress[71]) { engine_SetEditMode 0 }
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l editor_prevTile {
var %id = 0
if (%edit.selm) {
%id = $obj_findPrev(tile,%edit.selm)
while (%id) {
if ($obj_get(tile,%id).editor) {
break
}
else {
%id = $obj_findPrev(tile,%id)
}
}
}
return %id
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l editor_nextTile {
var %id = %edit.selm
if (%id) %id = $obj_findNext(tile,%id)
else %id = $obj_readFirst(tile)
while (%id) {
if ($obj_get(tile,%id).editor) {
break
}
else {
%id = $obj_findNext(tile,%id)
}
}
return %id
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_UpdateCamera {
if (%game.cp && !%game.edit) {
; follow the player
if (%game.camera == 1) {
cam_ScrollToPlayer %game.cp
}
else {
var %x = $calc($obj_get(cp,%game.cp).x - %cam.x)
var %y = $calc($obj_get(cp,%game.cp).y - %cam.y)
if (%x < %game.bx) {
cam_Pan $calc(-1 * (%game.bx - %x)) 0
}
elseif (%x > %game.bw) {
cam_Pan $calc(-1 * (%game.bw - %x)) 0
}
if (%y < %game.by) {
cam_Pan 0 $calc(-1 * (%game.by - %y))
}
elseif (%y > %game.bh) {
cam_Pan 0 $calc(-1 * (%game.bh - %y))
}
}
}
else {
if (!%game.mousedown) {
if (!$editor_isMouseInEditor) {
if ($mouse.x > $calc(%win.w - 48)) {
cam_pan 4 0
}
if ($mouse.x < 48) {
cam_pan -4 0
}
if ($mouse.y < 48) {
cam_pan 0 -4
}
if ($mouse.y > $calc(%win.h - 48)) {
cam_pan 0 4
}
}
}
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_SetEditMode {
%game.edit = $1
if ($1) {
engine_SetFont $rgb(255,255,255) Arial 20
msg_Show -1 50 2000 Entering map editor
engine_SetFont $font.default
; center the selector
%edit.selx = $calc(%cam.x + %win.w / 2)
%edit.sely = $calc(%cam.y + %win.h / 2)
if (!%edit.selm) {
%edit.selm = $editor_nextTile()
}
%edit.tool.w = 30
%edit.tool.h = 2
%edit.tool.x = 80
%edit.tool.y = 30
engine_createEditorTileSet
buffer_Redraw
}
else {
engine_SetFont $rgb(255,255,255) Arial 20
msg_Show -1 50 2000 Leaving map editor
engine_SetFont $font.default
cam_MoveToPlayer %game.cp
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param: x y duration text
; desc:
alias -l msg_Show {
; use -1 for x-y to center message
; use -1 for duration for unknown duration (use msg_Kill <id> to del msg)
var %id = $obj_getNextId(msg)
if (%id) {
var %start = %game.ticks
if ($3 == -1) var %end = $calc(%game.ticks + $math_HugeInt())
else var %end = $calc(%start + $3)
obj_new msg %id
obj_set msg %id start %start
obj_set msg %id end %end
obj_set msg %id font $engine_GetFont
var %font = %game.fontname
var %size = %game.fontsize
var %color = %game.fontcolor
var %x = $1
var %y = $2
var %msg = $4-
if (%x == -1) {
var %w = $width(%msg,%font,%size)
%x = $calc((%win.w - %w) / 2)
}
if (%y == -1) {
var %h = $height(%msg,%font,%size)
%y = $calc((%win.h - %h) / 2)
}
obj_set msg %id x %x
obj_set msg %id y %y
obj_set msg %id msg %msg
return %id
}
else {
engine_ShowError Cannot show message > $4-
return -1
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l msg_Kill {
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l buffer_Redraw {
obj_clear ab
var %x = $calc(%buffer.x / %tile.w)
var %w = $calc(%x + %win.xtile + 2)
while (%x < %w) {
buffer_RedrawCol %x
inc %x
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l buffer_RedrawCol {
var %y = $calc(%buffer.y / %tile.h)
var %h = $calc(%y + %win.ytile + 2)
while (%y < %h) {
buffer_RedrawTile $1 %y
inc %y
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l buffer_RedrawRow {
var %x = $calc(%buffer.x / %tile.w)
var %w = $calc(%x + %win.xtile + 2)
while (%x < %w) {
buffer_RedrawTile %x $1
inc %x
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l buffer_RedrawTile {
var %bufx = $calc(($1 - %buffer.x / %tile.w) * %tile.w)
var %bufy = $calc(($2 - %buffer.y / %tile.h) * %tile.h)
var %m = $hget(edig,$+(%map.id,$1,.,$2,.m))
var %r = $calc($abs($cos($calc($1 / 10))) * 200)
var %g = $calc($abs($sin($calc($2 / 10))) * 200)
var %b = 255
drawrect -rnf @edb0 $rgb(%r,%g,%b) 1 %bufx %bufy %tile.w %tile.h
if (%m) {
var %imgcache = $hget(edig,$+(%map.id,$1,.,$2,.imgcache0))
if (%imgcache) {
var %anim = $obj_get(tile,%m).anim
if (%anim) {
var %id = $obj_getnextid(ab)
obj_new ab %id
obj_set ab %id x $1
obj_set ab %id y $2
hadd edig $+(%map.id,$1,.,$2,.animid) %id
}
else {
drawcopy -tn @edt $rgb(255,0,255) %imgcache @edb0 %bufx $calc(%bufy - $3) %tile.w %tile.h
}
}
}
if (%game.edit) {
drawrect -ntr @edb0 $rgb(128,128,128) 1 %bufx %bufy $calc(%tile.w + 1) $calc(%tile.h + 1)
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_UpdateAndRender {
engine_UpdateCamera
drawcopy -n @edb0 $calc(%cam.x % %tile.w) $calc(%cam.y % %tile.h) %win.w %win.h @edc 0 0
engine_renderAllAnimBlocks
obj_ForEach cp engine_RenderPlayers
obj_ForEach msg engine_RenderMsg
if (%collision.bl) {
engine_RenderBl2
}
if (%game.edit) {
engine_RenderEditor
}
drawtext -nr @edc 16777215 arial 12 1 -2 %fps.val (press G for map editor)
}
alias -l engine_RenderBl2 {
var %e = $calc($ticks - %collision.t)
var %x = %collision.blx
var %y = %collision.bly
var %bufx = $calc((%x - %buffer.x / %tile.w) * %tile.w)
var %bufy = $calc((%y - %buffer.y / %tile.h) * %tile.h)
if (%e > 200) %e = 200
var %d = $calc($sin($calc(%e / 200 * $pi)) * 14)
var %rx = $calc(%x * %tile.w - $floor(%cam.x))
var %ry = $calc(%y * %tile.h - %cam.y)
drawrect -nrf @edc 0 1 %rx %ry %tile.w %tile.h
drawcopy -nr @edb0 %bufx %bufy %tile.w %tile.h @edc %rx $calc(%ry - %d) %tile.w %tile.h
if (%e >= 200) {
%collision.t = 0
%collision.bl = 0
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_renderAllAnimBlocksSlow {
var %n = $floor($calc($obj_count(ab) / 4))
while (%n) {
var %id = $obj_readNext(ab)
if (!%id) %id = $obj_readFirst(ab)
engine_renderAnimBlocks %id
dec %n
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_renderAllAnimBlocks {
var %nb = $obj_count(ab)
if (%nb > 0) {
; this method is only worth using if we have more than 16 animated objects
if (%nb > 16) {
var %n = $ceil($calc(%nb / 4))
%game.n = $calc((%game.n + 1) % 4)
var %n1 = $calc(%game.n * %n + 1)
var %n2 = $calc((%game.n + 1) * %n)
obj_ForEach ab engine_renderAnimBlocks %n1 %n2
}
else {
obj_ForEach ab engine_renderAnimBlocks
}
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_RenderExplosions {
var %id = $obj_ReadFirst(exp)
while (%id) {
var %d = $calc(%game.ticks - $obj_get(exp, %id).t)
if (%d < 300) {
var %x = $calc($obj_get(exp, %id).x * %tile.w + %tile.w / 2 - %cam.x)
var %y = $calc($obj_get(exp, %id).y * %tile.h + %tile.h / 2 - %cam.y)
drawdot -nri @edc $rgb($r(0,255),$r(0,255),$r(0,255)) $r(14,27) %x %y
}
else {
obj_delete exp %id
}
%id = $obj_ReadNext(exp)
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_RenderAnimBlocks {
var %x = $obj_get(ab,$1).x
var %y = $obj_get(ab,$1).y
drawcopy -tn @edt 16711935 $hget(edig,$+(%map.id,%x,.,%y,.imgcache,%game.af)) @edb0 $calc((%x - %buffer.x / %tile.w) * %tile.w) $calc((%y - %buffer.y / %tile.h) * %tile.h) %tile.w %tile.h
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_RenderBombs {
var %id = $obj_ReadFirst(bomb)
while (%id) {
var %explode_at = $obj_get(bomb,%id).explode_at
if (%game.ticks >= %explode_at) {
; do_explosion $obj_get(bomb,%id).x $obj_get(bomb,%id).y $obj_get(bomb,%id).expl_w $obj_get(bomb,%id).expl_h
obj_delete bomb %id
}
else {
var %x = $calc($obj_get(bomb,%id).x - %cam.x)
var %y = $calc($obj_get(bomb,%id).y - %cam.y)
var %w = $obj_get(bomb,%id).w
var %h = $obj_get(bomb,%id).h
var %time_left = $round($calc((%explode_at - %game.ticks) / 1000),0)
; Ajust vertical velocity
var %vy = $obj_get(bomb,%id).vy + %phys.ay
if (%vy > %phys.tv) %vy = %phys.tv
obj_set bomb %id vy %vy
inc %y %vy
; if ($phys_CheckCollisionBott(%x,%y,%w,%h,0)) {
; %y = %collision.y
; }
drawrect -nfr @edc $rgb(0,0,0) 1 $calc(%x - %cam.x) $calc(%y - %cam.y) %w %h
drawtext -nr @edc $ed.getFont $calc(%x + 1) %y %time_left
obj_set bomb %id y %y
}
%id = $obj_readNext(bomb)
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_RenderMsg {
var %id = $1
if ($obj_get(msg,%id).end > %game.ticks) {
var %msg = $obj_get(msg,%id).msg
if (%msg) {
engine_SetFont $obj_get(msg,%id).font
drawtext -nr @edc $engine_GetFont $calc($obj_get(msg,%id).x) $calc($obj_get(msg,%id).y) %msg
engine_SetFont $font.default
}
}
else {
obj_delete msg %id
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; param:
; desc:
alias -l engine_LoadMap {
hload -b edig $1-
return 1