-
Notifications
You must be signed in to change notification settings - Fork 6
/
mycraft_0_001.bas
1433 lines (1022 loc) · 30.1 KB
/
mycraft_0_001.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
CONST MaxVis& = 15 'how many squares away you can see (warning: massive performance implications at this stage)
CONST HardwareOnly& = 1 'set to 1 to disable the software "SCREEN" (you will lose PRINTed debugging output but will get performance gains)
IF _DIREXISTS("mycraft") THEN CHDIR "mycraft"
IF _DIREXISTS("blocks") = 0 OR _DIREXISTS("items") = 0 THEN
PRINT "Could not locate resource files"
END
END IF
DEFLNG A-Z
$RESIZE:ON
'$DYNAMIC
SCREEN _NEWIMAGE(1024, 600, 32)
'Generate Perlin Noise
'Modified from http://forum.qbasicnews.com/index.php?action=printpage;topic=3459.0
'-generates noise from 0 to 255
'-doesn't use x=0,y=0
'-noise tiles
DEFSNG A-Z
Iter = 8
BumpFactor = 1.2
CloudWidth% = 2 ^ Iter + 1
CloudHeight% = 2 ^ Iter + 1
DIM Cloud%(CloudWidth%, CloudHeight%)
DIM CloudBumpFactor(CloudWidth%, CloudHeight%) AS SINGLE
'1.5=undulating hills (mostly walkable, quite bumpy)
'2.0=ultra-flat
DIM CloudDirectionBias(CloudWidth%, CloudHeight%) AS SINGLE '-0.3 to 0.3
FOR x = 0 TO CloudWidth%
FOR y = 0 TO CloudHeight%
'1.3=perfect mountains
'1.5=plains
CloudBumpFactor(x, y) = 1.3 '1.4 '+ x * 0.002 '1.2 + x
NEXT
NEXT
FOR x = 0 TO CloudWidth%
FOR y = 0 TO CloudHeight%
CloudDirectionBias(x, y) = 0 '0.3 'x * 0.0008 '1.1 + x * 0.004 '1.2 + x
NEXT
NEXT
RANDOMIZE TIMER
T0 = TIMER
' Init the corners
Cloud%(1, 1) = 128
Cloud%(1, CloudHeight%) = 128
Cloud%(CloudWidth%, 1) = 128
Cloud%(CloudWidth%, CloudHeight%) = 128
' Init the edges
FOR Rank% = 1 TO Iter
dx = 2 ^ (Iter - Rank% + 1)
dy = 2 ^ (Iter - Rank% + 1)
Nx% = 2 ^ (Rank% - 1) + 1
Ny% = 2 ^ (Rank% - 1) + 1
FOR kx = 1 TO Nx% - 1
x% = (kx - 1) * dx + 1: y% = 1
Alt% = (Cloud%(x%, y%) + Cloud%(x% + dx, y%)) / 2
' zNew% = Bump%(Alt%, Rank%, BumpFactor)
zNew% = Bump%(Alt%, Rank%, CloudBumpFactor(x% + dx / 2, 1), CloudDirectionBias(x% + dx / 2, 1))
Cloud%(x% + dx / 2, 1) = zNew%
Cloud%(x% + dx / 2, CloudHeight%) = zNew%
NEXT kx
FOR ky = 1 TO Ny% - 1
x% = 1: y% = (ky - 1) * dy + 1
Alt% = (Cloud%(x%, y%) + Cloud%(x%, y% + dy)) / 2
' zNew% = Bump%(Alt%, Rank%, BumpFactor)
zNew% = Bump%(Alt%, Rank%, CloudBumpFactor(1, y% + dy / 2), CloudDirectionBias(1, y% + dy / 2))
Cloud%(1, y% + dy / 2) = zNew%
Cloud%(CloudWidth%, y% + dy / 2) = zNew%
NEXT ky
NEXT Rank%
' Fill the clouds
FOR Rank% = 1 TO Iter
dx = 2 ^ (Iter - Rank% + 1): dy = dx
Nx% = 2 ^ (Rank% - 1) + 1: Ny% = Nx%
FOR kx = 1 TO Nx% - 1
FOR ky = 1 TO Ny% - 1
x% = (kx - 1) * dx + 1
y% = (ky - 1) * dy + 1
Alt% = (Cloud%(x%, y%) + Cloud%(x% + dx, y%) + Cloud%(x%, y% + dy) + Cloud%(x% + dx, y% + dy)) / 4
Cloud%(x% + dx / 2, y% + dy / 2) = Bump%(Alt%, Rank%, CloudBumpFactor(x% + dx / 2, y% + dy / 2), CloudDirectionBias(x% + dx / 2, y% + dy / 2))
Alt% = (Cloud%(x%, y%) + Cloud%(x% + dx, y%)) / 2
IF y% <> 1 THEN Cloud%(x% + dx / 2, y%) = Bump%(Alt%, Rank%, CloudBumpFactor(x% + dx / 2, y%), CloudDirectionBias(x% + dx / 2, y%))
Alt% = (Cloud%(x%, y%) + Cloud%(x%, y% + dy)) / 2
IF x% <> 1 THEN Cloud%(x%, y% + dy / 2) = Bump%(Alt%, Rank%, CloudBumpFactor(x%, y% + dy / 2), CloudDirectionBias(x%, y% + dy / 2))
Alt% = (Cloud%(x% + dx, y%) + Cloud%(x% + dx, y% + dy)) / 2
IF (x% + dx) <> CloudWidth% THEN Cloud%(x% + dx, y% + dy / 2) = Bump%(Alt%, Rank%, CloudBumpFactor(x% + dx, y% + dy / 2), CloudDirectionBias(x% + dx, y% + dy / 2))
Alt% = (Cloud%(x%, y% + dy) + Cloud%(x% + dx, y% + dy)) / 2
IF (y% + dy) <> CloudHeight% THEN Cloud%(x% + dx / 2, y% + dy) = Bump%(Alt%, Rank%, CloudBumpFactor(x% + dx / 2, y% + dy), CloudDirectionBias(x% + dx / 2, y% + dy))
NEXT ky
NEXT kx
NEXT Rank%
dt = TIMER - T0
FOR x = 0 TO CloudWidth%
FOR y = 0 TO CloudHeight%
PSET (x, y), _RGB(Cloud%(x, y), 0, 0)
NEXT
NEXT
DEFLNG A-Z
DIM SHARED MapLimitX AS LONG, MapLimitY AS LONG, MapLimitZ AS LONG
MapLimitX = CloudWidth% - 1: MapLimitY = CloudHeight% - 1: MapLimitZ = 100
DIM SHARED TexLast
TexLast = 0
DIM SHARED Tex(1000, 15, 3) AS LONG 'handle, brightness, hue-specific to time of day
DIM SHARED darken
darken = _NEWIMAGE(1, 1)
_DEST darken
_DONTBLEND
PSET (0, 0), _RGBA(0, 0, 0, 50)
_BLEND
_DEST 0
_MOUSEHIDE
DIM PX AS SINGLE
DIM PY AS SINGLE
DIM PZ AS SINGLE
DIM oPX AS SINGLE
DIM oPY AS SINGLE
DIM oPZ AS SINGLE
PZ = 70
'TYPE BoxType
' left AS LONG
' right AS LONG
' top AS LONG
' bottom AS LONG
' front AS LONG
' back AS LONG
'END TYPE
'DIM SHARED Box(1000) AS BoxType
'load textures
grass = LoadTexture("grass")
water = LoadTexture("water")
'I = 0
'I = I + 1
'h = grass
'Box(I).left = h
'Box(I).right = h
'Box(I).top = h
'Box(I).bottom = h
'Box(I).front = h
'Box(I).back = h
TYPE MapBlockType
Typ AS LONG '0=air, 1=...
Vis AS LONG
Lit AS LONG 'light offset
END TYPE
DIM Blk(-1 TO MapLimitX + 1, -1 TO MapLimitY + 1, -1 TO MapLimitZ + 1) AS MapBlockType
'place bottom layer (a single layer of "rock" which cannot be crossed)
z = 0
FOR x = 0 TO MapLimitX
FOR y = 0 TO MapLimitY
Blk(x, y, z).Typ = 1: boxcount = boxcount + 1
NEXT
NEXT
DIM GM(-1 TO MapLimitX + 1, -1 TO MapLimitY + 1)
'get GM
FOR x = 0 TO MapLimitX
FOR y = 0 TO MapLimitY
h = Cloud%(x + 1, y + 1) \ 4 + 30
GM(x, y) = h
NEXT
NEXT
FOR f = 5 TO 8
'despeckle "pinacles"
FOR x = 0 TO MapLimitX
FOR y = 0 TO MapLimitY
h = GM(x, y)
c = 0
c2 = 0
FOR x2 = x - 1 TO x + 1
FOR y2 = y - 1 TO y + 1
IF x2 <> x OR y2 <> y THEN
h2 = GM(x2, y2)
IF h2 < h THEN c = c + 1
IF h2 > h THEN c2 = c2 + 1
END IF
NEXT
NEXT
IF c >= 5 THEN
GM(x, y) = GM(x, y) - 1
'END
'GM(x, y) = 2
END IF
IF c2 >= 5 THEN
GM(x, y) = GM(x, y) + 1
END IF
NEXT
NEXT
NEXT
wl = 128 \ 4 + 30 - 3
'place "dirt"
FOR x = 0 TO MapLimitX
FOR y = 0 TO MapLimitY
zz = GM(x, y)
FOR z = zz TO 1 STEP -1
Blk(x, y, z).Typ = 1
NEXT
NEXT
NEXT
'place water
FOR x = 0 TO MapLimitX
FOR y = 0 TO MapLimitY
zz = GM(x, y)
IF zz < wl THEN
Blk(x, y, wl).Typ = 2
END IF
NEXT
NEXT
IF 1 = 0 THEN
zrange = 10
FOR basez = 1 TO MapLimitZ - zrange - 50
FOR I = 1 TO (MapLimitX * MapLimitY) * 10
x = INT(RND * (MapLimitX + 1))
y = INT(RND * (MapLimitY + 1))
z = basez + INT(RND * (10)) 'cannot replace lowest layer
''' IF Blk(x, y, z).Typ = 0 AND Blk(x, y, z - 1).Typ <> 0 THEN
n = 0
FOR z2 = z - 1 TO z + 1
FOR y2 = y - 1 TO y + 1
FOR x2 = x - 1 TO x + 1
dist = ABS(x2 - x) + ABS(y2 - y) + ABS(z2 - z)
IF dist <= 2 THEN
x3 = x2: y3 = y2: z3 = z2
MapOffset x3, y3, z3
IF Blk(x3, y3, z3).Typ > 0 THEN
n = n + 1
END IF
END IF
NEXT
NEXT
NEXT
IF n >= 3 THEN
Blk(x, y, z).Typ = 1: boxcount = boxcount + 1
IF z > highestz THEN highestz = z
END IF
'''END IF
NEXT
NEXT 'basez
'fill map till top reached
END IF
'assess visibility
FOR z = 0 TO MapLimitZ
FOR x = 0 TO MapLimitX
FOR y = 0 TO MapLimitY
IF Blk(x, y, z).Typ THEN
visible = 0
FOR x2 = x - 1 TO x + 1
IF Blk(x2, y, z).Typ <> 1 THEN visible = 1
NEXT
FOR y2 = y - 1 TO y + 1
IF Blk(x, y2, z).Typ <> 1 THEN visible = 1
NEXT
FOR z2 = z - 1 TO z + 1
IF Blk(x, y, z2).Typ <> 1 THEN visible = 1
NEXT
IF visible = 1 THEN
Blk(x, y, z).Vis = 1: viscount = viscount + 1
END IF
END IF
NEXT
NEXT
NEXT
'assess lighting offsets
FOR z = 0 TO MapLimitZ
FOR x = 0 TO MapLimitX
FOR y = 0 TO MapLimitY
IF Blk(x, y, z).Vis THEN 'it is visible
count = 0
FOR z2 = z + 1 TO z + 5
FOR y2 = y - 1 TO y + 1
FOR x2 = x - 1 TO x + 1
IF Blk(x2, y2, z2).Typ <> 0 THEN count = count + 1
NEXT
NEXT
NEXT
IF count > 30 THEN count = 30
Blk(x, y, z).Lit = -count / 2
END IF
NEXT
NEXT
NEXT
DIM SHARED ax AS SINGLE, ay AS SINGLE
DIM SHARED SINax AS SINGLE
DIM SHARED COSax AS SINGLE
DIM SHARED SINay AS SINGLE
DIM SHARED COSay AS SINGLE
TYPE Point3D
x AS SINGLE
y AS SINGLE
z AS SINGLE
END TYPE
TYPE TexturePoint3D
p AS Point3D
tx AS SINGLE
ty AS SINGLE
END TYPE
TYPE Triangle3D
p1 AS TexturePoint3D
p2 AS TexturePoint3D
p3 AS TexturePoint3D
textureHandle AS LONG
END TYPE
TYPE Rect3D
p1 AS TexturePoint3D
p2 AS TexturePoint3D
p3 AS TexturePoint3D
p4 AS TexturePoint3D
textureHandle AS LONG
END TYPE
DIM SHARED vert(1 TO 8) AS Point3D
DIM SHARED side(1 TO 6) AS Rect3D
zz = -10
IF HardwareOnly THEN
_DISPLAYORDER _HARDWARE
bgImage = _NEWIMAGE(1, 1, 32)
_DEST bgImage
PSET (0, 0), _RGB(180, 220, 255)
_DEST 0
bgImage = _COPYIMAGE(bgImage, 33)
END IF
DIM SHARED ETT AS DOUBLE
ETT = TIMER(0.001)
DIM SHARED ET AS SINGLE
DIM SHARED TOD AS SINGLE
TOD = 0
'gun32 = _LOADIMAGE("items\gun1.png", 32)
gun32 = _LOADIMAGE("items\sworddiamond.png", 32)
gun = _COPYIMAGE(gun32, 33)
'sets of vertexes for scaling/rotation/etc
DIM SHARED VertexSource AS LONG
DIM SHARED VertexCount AS LONG 'the number of vertices to apply an operation to
DIM SHARED VertexLast AS LONG
VertexLast = 0
DIM SHARED VertexX(1 TO 10000) AS SINGLE
DIM SHARED VertexY(1 TO 10000) AS SINGLE
DIM SHARED VertexZ(1 TO 10000) AS SINGLE
DIM SHARED VertexTX(1 TO 10000) AS SINGLE
DIM SHARED VertexTY(1 TO 10000) AS SINGLE
DIM SHARED TriangleSource AS LONG 'the base index of the first triangle's vertex
DIM SHARED TriangleLast AS LONG
TriangleLast = 0
DIM SHARED TriangleCount AS LONG 'the number of triangles to apply an operation to
DIM SHARED TriangleVertex(1 TO 10000) AS LONG
TYPE MODEL
VertexCount AS LONG
FirstVertex AS LONG
FirstTriangle AS LONG
TriangleCount AS LONG
END TYPE
DIM SHARED Model(1 TO 10000) AS MODEL
'add object
tex = gun
tx = _WIDTH(tex)
ty = _HEIGHT(tex)
p = VertexLast
t = TriangleLast
d = 1
'convert 2D image into a 3D object by giving it depth
'place image onto a canvas which has an extra unit on each size
tex = gun32
w = _WIDTH(tex)
h = _HEIGHT(tex)
I = _NEWIMAGE(w + 2, h + 2, 32)
_DONTBLEND I
_PUTIMAGE (1, 1), tex, I
_SOURCE I
_DEST I
DIM col AS LONG
FOR y = 1 TO h
FOR x = 1 TO w
col = POINT(x, y)
alpha = _ALPHA(col)
col2 = POINT(x, y - 1)
alpha2 = _ALPHA(col2)
IF alpha2 = 0 AND alpha <> 0 THEN
x1 = x - 1
y1 = y - 1
bp = p
t = t + 1: TriangleVertex(t) = bp + 1
t = t + 1: TriangleVertex(t) = bp + 2
t = t + 1: TriangleVertex(t) = bp + 3
t = t + 1: TriangleVertex(t) = bp + 1
t = t + 1: TriangleVertex(t) = bp + 3
t = t + 1: TriangleVertex(t) = bp + 4
p = p + 1: VertexX(p) = x1: VertexY(p) = -y1: VertexZ(p) = 0
VertexTX(p) = x1: VertexTY(p) = y1
p = p + 1: VertexX(p) = x1 + 1: VertexY(p) = -y1: VertexZ(p) = 0
VertexTX(p) = x1: VertexTY(p) = y1
p = p + 1: VertexX(p) = x1 + 1: VertexY(p) = -y1: VertexZ(p) = d
VertexTX(p) = x1: VertexTY(p) = y1
p = p + 1: VertexX(p) = x1: VertexY(p) = -y1: VertexZ(p) = d
VertexTX(p) = x1: VertexTY(p) = y1
END IF
col2 = POINT(x - 1, y)
alpha2 = _ALPHA(col2)
IF alpha2 = 0 AND alpha <> 0 THEN
x1 = x - 1
y1 = y - 1
bp = p
t = t + 1: TriangleVertex(t) = bp + 1
t = t + 1: TriangleVertex(t) = bp + 2
t = t + 1: TriangleVertex(t) = bp + 3
t = t + 1: TriangleVertex(t) = bp + 1
t = t + 1: TriangleVertex(t) = bp + 3
t = t + 1: TriangleVertex(t) = bp + 4
p = p + 1: VertexX(p) = x1: VertexY(p) = -y1: VertexZ(p) = 0
VertexTX(p) = x1: VertexTY(p) = y1
p = p + 1: VertexX(p) = x1: VertexY(p) = -y1: VertexZ(p) = d
VertexTX(p) = x1: VertexTY(p) = y1
p = p + 1: VertexX(p) = x1: VertexY(p) = -y1 - 1: VertexZ(p) = d
VertexTX(p) = x1: VertexTY(p) = y1
p = p + 1: VertexX(p) = x1: VertexY(p) = -y1 - 1: VertexZ(p) = 0
VertexTX(p) = x1: VertexTY(p) = y1
END IF
NEXT
NEXT
_SOURCE 0
_DEST 0
itemPicture = I
FOR oz = 0 TO d STEP d
bp = p
t = t + 1: TriangleVertex(t) = bp + 1
t = t + 1: TriangleVertex(t) = bp + 2
t = t + 1: TriangleVertex(t) = bp + 3
t = t + 1: TriangleVertex(t) = bp + 1
t = t + 1: TriangleVertex(t) = bp + 3
t = t + 1: TriangleVertex(t) = bp + 4
p = p + 1: VertexX(p) = 0: VertexY(p) = 0: VertexZ(p) = oz
VertexTX(p) = -0.49: VertexTY(p) = -0.49
p = p + 1: VertexX(p) = tx: VertexY(p) = 0: VertexZ(p) = oz
VertexTX(p) = tx - 1 + 0.49: VertexTY(p) = -0.49
p = p + 1: VertexX(p) = tx: VertexY(p) = -ty: VertexZ(p) = oz
VertexTX(p) = tx - 1 + 0.49: VertexTY(p) = ty - 1 + 0.49
p = p + 1: VertexX(p) = 0: VertexY(p) = -ty: VertexZ(p) = oz
VertexTX(p) = -0.49: VertexTY(p) = ty - 1 + 0.49
NEXT
VertexCount = p - VertexLast
TriangleCount = (t - TriangleLast) \ 3
m = 1
Model(m).VertexCount = VertexCount
Model(m).FirstVertex = VertexLast + 1
Model(m).TriangleCount = TriangleCount
Model(m).FirstTriangle = TriangleLast + 1
VertexLast = p
TriangleLast = t
DO
T# = TIMER(0.001)
ET = T# - ETT
ETT = T#
TOD = TOD + ET
IF TOD >= 24 THEN TOD = TOD - 24
SINax = SIN(ax)
COSax = COS(ax)
SINay = SIN(ay)
COSay = COS(ay)
IF HardwareOnly THEN
_PUTIMAGE (0, 0)-(_WIDTH - 1, _HEIGHT - 1), bgImage
ELSE
CLS , _RGB(180, 220, 255)
END IF
LOCATE 1, 1
PRINT TOD
PRINT boxcount, viscount
PRINT zz
RANDOMIZE TIMER 'USING 1
OX = INT(PX)
OY = INT(PY)
oz = INT(PZ)
PRINT PX, PY, PZ
PRINT OX, OY, oz
x = OX
y = OY
z = oz
MapOffset x, y, z
PRINT x, y, z, "!"
_PUTIMAGE (0, 0), itemPicture
nn = 0
'opaque pass
FOR mapz = oz + MaxVis TO oz - MaxVis STEP -1
FOR mapx = OX - MaxVis TO OX + MaxVis
FOR mapy = OY - MaxVis TO OY + MaxVis
x = mapx
y = mapy
z = mapz
MapOffset x, y, z
IF Blk(x, y, z).Vis THEN
typ = Blk(x, y, z).Typ
IF typ = 1 THEN
DrawCube mapx - PX, mapz - PZ, mapy - PY, typ, Blk(x, y, z).Lit
END IF
END IF
NEXT
NEXT
NEXT
'semi-tranparent pass
'_DEPTHBUFFER LOCK
FOR mapz = oz - MaxVis TO oz + MaxVis
FOR mapx = OX - MaxVis TO OX + MaxVis
FOR mapy = OY - MaxVis TO OY + MaxVis
x = mapx
y = mapy
z = mapz
MapOffset x, y, z
IF Blk(x, y, z).Vis THEN
typ = Blk(x, y, z).Typ
IF typ = 2 THEN
DrawCube mapx - PX, mapz - PZ, mapy - PY, typ, Blk(x, y, z).Lit
END IF
END IF
NEXT
NEXT
NEXT
'draw object(s)
'preserve offsets of permanent content
oldVertexLast = VertexLast
oldTriangleLast = TriangleLast
VertexSource = Model(1).FirstVertex
TriangleSource = Model(1).FirstTriangle
TriangleCount = Model(1).TriangleCount
VertexCount = Model(1).VertexCount
TriangleSource = TriangleLast + 1
VertexSource = VertexLast + 1
CopyModel (1)
tex = gun
'orient pointing forwards
VertexRotateXZ_YZ -90, 0
'scale
VertexScale 0.1 * 0.7 * 2
'move to right hand
VertexTranslate 1, 0, -2 - 0.5
'render the objects
_DEPTHBUFFER _CLEAR
_DEPTHBUFFER ON
FOR t = TriangleSource TO TriangleSource + TriangleCount * 3 - 3 STEP 3
p1 = TriangleVertex(t)
p2 = TriangleVertex(t + 1)
p3 = TriangleVertex(t + 2)
_maptriangle( VertexTX(p1), VertexTY(p1))-( VertexTX(p2), VertexTY(p2))-( VertexTX(p3), VertexTY(p3)), _
tex to _
(VertexX(p1),Vertexy(p1),Vertexz(p1))-(VertexX(p2),Vertexy(p2),Vertexz(p2))-(VertexX(p3),Vertexy(p3),Vertexz(p3))
NEXT
'move vertically
ms! = .1
IF _KEYDOWN(ASC("q")) THEN PZ = PZ + ms! * 4
IF _KEYDOWN(ASC("z")) THEN PZ = PZ - ms! * 4
oPX = PX: oPY = PY: oPZ = PZ
DO
k$ = INKEY$
IF k$ = " " THEN 'jump (teleport up 2 squares)
PZ = PZ + 2
END IF
LOOP UNTIL k$ = ""
IF _KEYDOWN(ASC("w")) THEN 'walk forwards
PX = PX + SIN(ax) * ms!
PY = PY - COS(ax) * ms!
'PZ = PZ + SIN(ay) * ms!
END IF
IF _KEYDOWN(ASC("s")) THEN 'walk backwards
PX = PX - SIN(ax) * ms!
PY = PY + COS(ax) * ms!
'PZ = PZ - SIN(ay) * ms!
END IF
PZ = PZ - 1 * ms!
x = INT(PX)
y = INT(PY)
z = INT(PZ)
MapOffset x, y, z
t = Blk(x, y, z).Typ
IF t = 1 THEN
' PX = oPX
' PY = oPY
' PZ = oPZ
END IF
'calculate x/y/z dist to adjacent blocks
'check z movement
newpx! = PX
newpy! = PY
newpz! = PZ
PX = oPX
PY = oPY
PZ = newpz!
x = INT(PX)
y = INT(PY)
z = INT(PZ)
ox! = PX - INT(PX)
oy! = PY - INT(PY)
oz! = PZ - INT(PZ)
' IF PX >= 0 THEN
dx1! = ox!
dx2! = 1 - ox!
' ELSE
' dx2! = ox!
' dx1! = 1 - ox!
' END IF
' IF PY >= 0 THEN
dy1! = oy!
dy2! = 1 - oy!
' ELSE
' dy2! = oy!
' dy1! = 1 - oy!
'END IF
' IF PZ >= 0 THEN
dz1! = oz!
dz2! = 1 - oz!
' ELSE
' dz2! = oz!
' dz1! = 1 - oz!
'END IF
'PRINT
'PRINT PX; PY; PZ
'PRINT dx1!; dx2!; dy1!; dy2!; dz1!; dz2!;
'PRINT
FOR z2 = z - 1 TO z + 1
relevant = 0
IF z2 = z THEN relevant = 0 'if we are already in the square--too bad!
'IF z2 <> z THEN
'check z relevance
' relvant = 0
IF z2 < z AND dz1! < 0.4 THEN relevant = 1
IF z2 > z AND dz2! < 0.4 THEN relevant = 1
IF relevant THEN PRINT z2
IF relevant THEN
FOR y2 = y - 1 TO y + 1
FOR x2 = x - 1 TO x + 1
dx = ABS(x2 - x)
dy = ABS(y2 - y)
relevant = 0
IF dx + dy THEN
'check if location should be checked
dx! = 0
IF x2 > x THEN dx! = dx2!
IF x2 < x THEN dx! = dx1!
dy! = 0
IF y2 > y THEN dy! = dy2!
IF y2 < y THEN dy! = dy1!
IF dx! < 0.4 AND dy! < 0.4 THEN
relevant = 1
PRINT "["; x2 - x; ","; y2 - y; "]";
END IF
ELSE
relevant = 1
END IF
'END IF
IF relevant THEN
x3 = x2: y3 = y2: z3 = z2
MapOffset x3, y3, z3
t2 = Blk(x3, y3, z3).Typ
IF t2 = 1 THEN
'PZ = oPZ
newpz! = oPZ
END IF
END IF
NEXT
NEXT
END IF
NEXT
PX = newpx!
PY = oPY
PZ = newpz!
x = INT(PX)
y = INT(PY)
z = INT(PZ)
ox! = PX - INT(PX)
oy! = PY - INT(PY)
oz! = PZ - INT(PZ)
' IF PX >= 0 THEN
dx1! = ox!
dx2! = 1 - ox!
' ELSE
' dx2! = ox!
' dx1! = 1 - ox!
' END IF
' IF PY >= 0 THEN
dy1! = oy!
dy2! = 1 - oy!
' ELSE
' dy2! = oy!
' dy1! = 1 - oy!
'END IF
' IF PZ >= 0 THEN
dz1! = oz!
dz2! = 1 - oz!
' ELSE
' dz2! = oz!
' dz1! = 1 - oz!
'END IF
z2 = z
FOR x2 = x - 1 TO x + 1
relevant = 0
IF x2 < x AND dx1! < 0.4 THEN relevant = 1
IF x2 > x AND dx2! < 0.4 THEN relevant = 1
IF relevant THEN
FOR y2 = y - 1 TO y + 1
FOR z2 = z - 1 TO z + 1
dy = ABS(y2 - y)
dz = ABS(z2 - z)
relevant = 0