-
Notifications
You must be signed in to change notification settings - Fork 36
/
kys_draw.pas
1713 lines (1549 loc) · 50.9 KB
/
kys_draw.pas
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
unit kys_draw;
//{$mode delphi}
interface
uses
SysUtils,
{$IFDEF fpc}
{$ELSE}
Windows,
{$ENDIF}
Math,
SDL2_image,
SDL2,
kys_main,
kys_type;
//画单个图片的子程
procedure DrawTitlePic(imgnum, px, py: integer);
procedure DrawMPic(num, px, py: integer; Framenum: integer = -1); overload;
procedure DrawMPic(num, px, py, shadow, alpha: integer; mixColor: uint32; mixAlpha: integer;
Framenum: integer = -1); overload;
procedure DrawSPic(num, px, py: integer); overload;
procedure DrawSPic(num, px, py, x, y, w, h: integer); overload;
procedure DrawSPic(num, px, py, shadow, alpha, depth: integer; mixColor: uint32; mixAlpha: integer); overload;
procedure InitialSPic(num, px, py, x, y, w, h: integer); overload;
procedure InitialSPic(num, px, py, x, y, w, h, needBlock, depth: integer); overload;
procedure InitialSPic(num, px, py, x, y, w, h, needBlock, depth, temp: integer); overload;
procedure DrawHeadPic(num, px, py: integer); overload;
procedure DrawHeadPic(num, px, py: integer; scr: PSDL_Surface); overload;
procedure DrawHeadPic(num, px, py, shadow, alpha, depth: integer; mixColor: uint32; mixAlpha: integer); overload;
procedure DrawBPic(num, px, py, shadow: integer); overload;
procedure DrawBPic(num, px, py, shadow, alpha, depth: integer; mixColor: uint32; mixAlpha: integer); overload;
procedure DrawBPicInRect(num, px, py, shadow, x, y, w, h: integer);
procedure InitialBPic(num, px, py: integer); overload;
procedure InitialBPic(num, px, py, needBlock, depth: integer); overload;
procedure DrawEPic(num, px, py: integer); overload;
procedure DrawEPic(num, px, py, shadow, alpha, depth: integer; mixColor: uint32; mixAlpha: integer); overload;
procedure DrawFPic(num, px, py, index: integer); overload;
procedure DrawFPic(num, px, py, index, shadow, alpha, depth: integer; mixColor: uint32; mixAlpha: integer); overload;
procedure DrawCPic(num, px, py, shadow, alpha: integer; mixColor: uint32; mixAlpha: integer);
//绘制整个屏幕的子程
procedure Redraw(WriteFresh: integer = 0);
procedure RecordFreshScreen(x, y, w, h: integer);
procedure LoadFreshScreen(x, y, w, h: integer);
procedure DrawMMap;
procedure DrawScence;
procedure DrawScenceWithoutRole(x, y: integer);
procedure DrawRoleOnScence(x, y: integer);
procedure ExpandGroundOnImg();
procedure InitialScence(); overload;
procedure InitialScence(Visible: integer); overload;
function CalBlock(x, y: integer): integer;
procedure CalPosOnImage(i1, i2: integer; var x, y: integer);
procedure CalLTPosOnImageByCenter(i1, i2: integer; var x, y: integer);
procedure InitialScenceOnePosition(i1, i2, x1, y1, w, h, depth, temp: integer);
procedure UpdateScence(xs, ys: integer);
procedure LoadScencePart(x, y: integer);
procedure DrawBField(needProgress: integer = 1);
procedure DrawBfieldWithoutRole(x, y: integer);
procedure DrawRoleOnBfield(x, y: integer; mixColor: uint32 = 0; mixAlpha: integer = 0; Alpha: integer = 75);
procedure InitialBFieldImage;
procedure InitialBFieldPosition(i1, i2, depth: integer);
procedure LoadBfieldPart(x, y: integer; noBuild: integer = 0);
procedure LoadBFieldPart2(x, y, alpha: integer);
procedure DrawBFieldWithCursor(step: integer);
procedure DrawBFieldWithEft(Epicnum: integer); overload;
procedure DrawBFieldWithEft(Epicnum, beginpic, endpic, bnum: integer; mixColor: uint32); overload;
procedure DrawBFieldWithEft(Epicnum, beginpic, endpic, curlevel, bnum, forteam, flash: integer;
mixColor: uint32); overload;
procedure DrawBFieldWithAction(bnum, Apicnum: integer);
procedure DrawClouds;
procedure DrawProgress;
procedure DrawVirtualKey;
implementation
uses
kys_engine;
//显示title.grp的内容(即开始的选单)
procedure DrawTitlePic(imgnum, px, py: integer);
var
len, grp, idx: integer;
BufferIdx: TIntArray;
BufferPic: TByteArray;
begin
if PNG_TILE > 0 then
begin
if imgnum <= high(TitlePNGIndex) then
DrawPNGTile(TitlePNGIndex[imgnum], 0, nil, screen, px, py);
end;
if PNG_TILE = 0 then
begin
len := LoadIdxGrp('resource/title.idx', 'resource/title.grp', BufferIdx, BufferPic);
if imgnum < len then
DrawRLE8Pic(@ACol[0], imgnum, px, py, @BufferIdx[0], @BufferPic[0], nil, nil, 0, 0, 0, 0);
end;
end;
//显示主地图贴图
procedure DrawMPic(num, px, py: integer; Framenum: integer = -1); overload;
begin
DrawMPic(num, px, py, 0, 0, 0, 0, Framenum);
end;
//显示主地图贴图
procedure DrawMPic(num, px, py, shadow, alpha: integer; mixColor: uint32; mixAlpha: integer;
Framenum: integer = -1); overload;
var
NeedGRP: integer;
begin
if (num >= 0) and (num < MPicAmount) then
begin
NeedGRP := 0;
if (PNG_TILE > 0) then
begin
if MPNGIndex[num].UseGRP = 0 then
begin
if Framenum = -1 then
Framenum := SDL_GetTicks div 200 + random(3);
if (num = 1377) or (num = 1388) or (num = 1404) or (num = 1417) then
Framenum := SDL_GetTicks div 200;
//瀑布场景的闪烁需要
//DrawPNGTile(MPNGIndex[num], Framenum, nil, screen, px, py, shadow)
DrawPNGTile(MPNGIndex[num], Framenum, nil, screen, px, py, shadow, alpha, mixColor, mixAlpha,
0, nil, 0, 0, 0, 0, 0);
end
else
NeedGRP := 1;
end;
if (PNG_TILE = 0) or (NeedGRP = 1) then
begin
DrawRLE8Pic(@ACol[0], num, px, py, @Midx[0], @Mpic[0], nil, nil, 0, 0, 0, shadow, alpha,
nil, nil, 0, 0, 0, 4096, mixColor, mixAlpha);
end;
end;
end;
//显示场景图片
procedure DrawSPic(num, px, py: integer); overload;
begin
DrawSPic(num, px, py, 0, 0, 0, 0);
end;
procedure DrawSPic(num, px, py, x, y, w, h: integer); overload;
var
Area: TSDL_Rect;
begin
if (num >= 0) and (num < SPicAmount) then
begin
Area.x := x;
Area.y := y;
Area.w := w;
Area.h := h;
if num = 1941 then
begin
num := 0;
py := py - 50;
end;
if PNG_TILE > 0 then
DrawPNGTile(SPNGIndex[num], 0, @Area, screen, px, py)
else
begin
DrawRLE8Pic(@ACol[0], num, px, py, @SIdx[0], @SPic[0], @Area, nil, 0, 0, 0, 0);
end;
end;
end;
//画考虑遮挡的内场景
procedure DrawSPic(num, px, py, shadow, alpha, depth: integer; mixColor: uint32; mixAlpha: integer); overload;
begin
if (num >= 0) and (num < SPicAmount) then
begin
if num = 1941 then
begin
num := 0;
py := py - 50;
end;
if PNG_TILE > 0 then
DrawPNGTile(SPNGIndex[num], 0, nil, screen, px, py, shadow, alpha, mixColor, mixAlpha,
depth, @BlockImg[0], ImageWidth, ImageHeight, sizeof(BlockImg[0]), BlockScreen.x, BlockScreen.y)
else
begin
DrawRLE8Pic(@ACol[0], num, px, py, @SIdx[0], @SPic[0], nil, nil, 0, 0, 0, shadow, alpha,
@BlockImg[0], @BlockScreen, ImageWidth, ImageHeight, sizeof(BlockImg[0]), depth, mixColor, mixAlpha);
end;
end;
end;
//将场景图片信息画到映像
procedure InitialSPic(num, px, py, x, y, w, h: integer); overload;
begin
InitialSPic(num, px, py, x, y, w, h, 0, 0, 0);
end;
//画到映像并记录深度数据
procedure InitialSPic(num, px, py, x, y, w, h, needBlock, depth: integer); overload;
begin
InitialSPic(num, px, py, x, y, w, h, needBlock, depth, 0);
end;
procedure InitialSPic(num, px, py, x, y, w, h, needBlock, depth, temp: integer); overload;
var
Area: TSDL_Rect;
pImg: PSDL_Surface;
pBlock: PAnsiChar;
begin
if temp = 0 then
begin
pImg := ImgScence;
pBlock := @BlockImg[0];
end
else
begin
pImg := ImgScenceBack;
pBlock := @BlockImg2[0];
end;
if (num >= 0) and (num < SPicAmount) then
begin
if x + w > ImageWidth then
w := ImageWidth - x - 1;
if y + h > ImageHeight then
h := ImageHeight - y - 1;
Area.x := x;
Area.y := y;
Area.w := w;
Area.h := h;
if num = 1941 then
begin
num := 0;
py := py - 50;
end;
if (PNG_TILE > 0) then
begin
if temp <> 1 then
LoadOnePNGTile('resource/smap/', nil, num, SPNGIndex[num], @SPNGTile[0]);
DrawPNGTile(SPNGIndex[num], SDL_GetTicks div 300, @Area, pImg, px, py);
if needBlock <> 0 then
begin
SetPNGTileBlock(SPNGIndex[num], px, py, depth, pBlock, ImageWidth, ImageHeight, sizeof(BlockImg[0]));
end;
end
else
begin
if needBlock <> 0 then
begin
DrawRLE8Pic(@ACol[0], num, px, py, @SIdx[0], @SPic[0], @Area, pImg, ImageWidth, ImageHeight,
sizeof(BlockImg[0]), 0, 0, pBlock, nil, 0, 0, 0, depth, 0, 0);
end
else
DrawRLE8Pic(@ACol[0], num, px, py, @SIdx[0], @SPic[0], @Area, pImg, ImageWidth,
ImageHeight, sizeof(BlockImg[0]), 0);
end;
end;
end;
//显示头像, 优先考虑'.head/'目录下的png图片
procedure DrawHeadPic(num, px, py: integer); overload;
begin
DrawHeadPic(num, px, py, 0, 0, 0, 0, 0);
end;
procedure DrawHeadPic(num, px, py: integer; scr: PSDL_Surface); overload;
var
image: PSDL_Surface;
dest: TSDL_Rect;
str: AnsiString;
Area: TSDL_Rect;
offset: integer;
y: smallint;
begin
str := AppPath + 'head/' + IntToStr(num) + '.png';
if FileExists(str) then
begin
image := IMG_Load(PAnsiChar(str));
dest.x := px;
dest.y := py;
SDL_BlitSurface(image, nil, scr, @dest);
SDL_FreeSurface(image);
end
else
begin
Area.x := 0;
Area.y := 0;
Area.w := scr.w;
Area.h := scr.h;
offset := 0;
if num > 0 then
offset := HIdx[num - 1];
y := Psmallint(@HPic[offset + 6])^;
//showmessage(inttostr(y));
if (num >= 0) and (num < HPicAmount) then
DrawRLE8Pic(@ACol1[0], num, px, py + y, @HIdx[0], @HPic[0], @Area, scr, scr.w, scr.h, 0,
0, 0, nil, nil, 0, 0, 0, 0, 0, 0);
end;
end;
procedure DrawHeadPic(num, px, py, shadow, alpha, depth: integer; mixColor: uint32; mixAlpha: integer); overload;
var
len, grp, idx: integer;
str: AnsiString;
begin
str := AppPath + 'head/' + IntToStr(num) + '.png';
if FileExists(str) { *Converted from FileExists* } then
display_img(@str[1], px, py - 60)
else
begin
if (num >= 0) and (num < HPicAmount) then
DrawRLE8Pic(@ACol1[0], num, px, py, @HIdx[0], @HPic[0], nil, nil, 0, 0, 0, shadow, alpha,
nil, nil, 0, 0, 0, depth, mixColor, mixAlpha);
end;
end;
//显示战场图片
procedure DrawBPic(num, px, py, shadow: integer); overload;
begin
DrawBPic(num, px, py, shadow, 0, 0, 0, 0);
end;
//用于画带透明度和遮挡的战场图
procedure DrawBPic(num, px, py, shadow, alpha, depth: integer; mixColor: uint32; mixAlpha: integer); overload;
begin
if (num > 0) and (num < BPicAmount) then
begin
if PNG_TILE > 0 then
begin
//LoadOnePNGTile('resource/wmap/', num, BPNGIndex[num], @BPNGTile[0]);
DrawPNGTile(BPNGIndex[num], 0, nil, screen, px, py, shadow, alpha, mixColor, mixAlpha,
depth, @BlockImg2[0], ImageWidth, ImageHeight, sizeof(BlockImg2[0]), BlockScreen.x, BlockScreen.y);
end
else
begin
DrawRLE8Pic(@ACol[0], num, px, py, @WIdx[0], @WPic[0], nil, nil, 0, 0, 0, shadow, alpha,
@BlockImg2[0], @BlockScreen, ImageWidth, ImageHeight, sizeof(BlockImg2[0]), depth, mixColor, mixAlpha);
end;
end;
end;
//仅在某区域显示战场图
procedure DrawBPicInRect(num, px, py, shadow, x, y, w, h: integer);
var
Area: TSDL_Rect;
begin
if (num > 0) and (num < BPicAmount) then
begin
Area.x := x;
Area.y := y;
Area.w := w;
Area.h := h;
if PNG_TILE > 0 then
begin
//LoadOnePNGTile('resource/wmap/', num, BPNGIndex[num], @BPNGTile[0]);
DrawPNGTile(BPNGIndex[num], 0, @Area, screen, px, py);
end
else
begin
DrawRLE8Pic(@ACol[0], num, px, py, @WIdx[0], @WPic[0], @Area, nil, 0, 0, 0, shadow);
end;
end;
end;
//将战场图片画到映像
procedure InitialBPic(num, px, py: integer); overload;
begin
InitialBPic(num, px, py, 0, 0);
end;
//画到映像并记录深度
procedure InitialBPic(num, px, py, needBlock, depth: integer); overload;
var
pImg: PSDL_Surface;
begin
if (num > 0) and (num < BPicAmount) then
begin
if PNG_TILE > 0 then
begin
LoadOnePNGTile('resource/wmap/', nil, num, BPNGIndex[num], @BPNGTile[0]);
if needBlock <> 0 then
begin
SetPNGTileBlock(BPNGIndex[num], px, py, depth, @BlockImg[0], ImageWidth, ImageHeight, sizeof(BlockImg[0]));
pImg := ImgBBuild;
end
else
pImg := ImgBfield;
DrawPNGTile(BPNGIndex[num], 0, nil, pImg, px, py);
end
else
begin
if needBlock <> 0 then
DrawRLE8Pic(@ACol[0], num, px, py, @WIdx[0], @WPic[0], nil, ImgBBuild, ImageWidth, ImageHeight,
sizeof(BlockImg2[0]), 0, 0, @BlockImg2[0], nil, 0, 0, 0, depth, 0, 0)
else
DrawRLE8Pic(@ACol[0], num, px, py, @WIdx[0], @WPic[0], nil, ImgBfield, ImageWidth,
ImageHeight, sizeof(BlockImg2[0]), 0);
end;
end;
end;
//显示效果图片
procedure DrawEPic(num, px, py: integer); overload;
begin
DrawEPic(num, px, py, 0, 0, 0, 0, 0);
end;
procedure DrawEPic(num, px, py, shadow, alpha, depth: integer; mixColor: uint32; mixAlpha: integer); overload;
begin
if (num >= 0) and (num < EPicAmount) then
begin
if PNG_TILE > 0 then
begin
DrawPNGTile(EPNGIndex[num], 0, nil, screen, px, py, shadow, alpha, mixColor, mixAlpha,
depth, nil, 0, 0, 0, 0, 0);
end;
if PNG_TILE = 0 then
begin
DrawRLE8Pic(@ACol[0], num, px, py, @EIdx[0], @EPic[0], nil, nil, 0, 0, 0, shadow, alpha,
nil, nil, 0, 0, 0, depth, mixColor, mixAlpha);
end;
end;
end;
//显示人物动作图片
procedure DrawFPic(num, px, py, index: integer); overload;
begin
DrawFPic(num, px, py, 0, 0, 0, 0, 0, index);
end;
//用于画带透明度和遮挡的人物动作图片
procedure DrawFPic(num, px, py, index, shadow, alpha, depth: integer; mixColor: uint32; mixAlpha: integer); overload;
begin
case PNG_TILE of
1, 2:
begin
if (index >= 0) and (index < BRoleAmount) then
if (num >= Low(FPNGIndex[index])) and (num <= High(FPNGIndex[index])) then
DrawPNGTile(FPNGIndex[index][num], 0, nil, screen, px, py, shadow, alpha, mixColor, mixAlpha,
depth, @BlockImg2[0], ImageWidth, ImageHeight, sizeof(BlockImg2[0]), BlockScreen.x, BlockScreen.y);
end;
0:
begin
if num < FPicAmount then
DrawRLE8Pic(@ACol[0], num, px, py, @FIdx[0], @FPic[0], nil, nil, 0, 0, 0, shadow,
alpha, @BlockImg2[0], @BlockScreen, ImageWidth, ImageHeight, sizeof(BlockImg2[0]),
depth, mixColor, mixAlpha);
end;
end;
end;
//主地图上画云
procedure DrawCPic(num, px, py, shadow, alpha: integer; mixColor: uint32; mixAlpha: integer);
begin
if PNG_TILE > 0 then
begin
DrawPNGTile(CPNGIndex[num], 0, nil, screen, px, py, shadow, alpha, mixColor, mixAlpha);
end;
if PNG_TILE = 0 then
begin
DrawRLE8Pic(@ACol1[0], num, px, py, @CIdx[0], @CPic[0], nil, nil, 0, 0, 0, shadow, alpha,
nil, nil, 0, 0, 0, 0, mixColor, mixAlpha);
end;
end;
//重画屏幕
procedure Redraw(WriteFresh: integer = 0);
begin
case where of
0: DrawMMap;
1: DrawScence;
2: DrawBField;
3:
begin
SDL_FillRect(screen, nil, 0);
display_img(PAnsiChar(AppPath + 'resource/open.png'), OpenPicPosition.x, OpenPicPosition.y);
end;
4:
begin
SDL_FillRect(screen, nil, 0);
display_img(PAnsiChar(AppPath + 'resource/dead.png'), OpenPicPosition.x, OpenPicPosition.y);
end;
end;
if WriteFresh = 1 then
SDL_BlitSurface(screen, nil, freshscreen, nil);
end;
//以下两个函数用于需要连续几个相同帧时的快速重绘
procedure RecordFreshScreen(x, y, w, h: integer);
var
dest: TSDL_Rect;
begin
dest.x := x;
dest.y := y;
dest.w := w;
dest.h := h;
SDL_BlitSurface(screen, @dest, freshscreen, @dest);
end;
procedure LoadFreshScreen(x, y, w, h: integer);
var
dest: TSDL_Rect;
begin
dest.x := x;
dest.y := y;
dest.w := w;
dest.h := h;
SDL_BlitSurface(freshscreen, @dest, screen, @dest);
end;
//显示主地图场景于屏幕
{procedure DrawMMap;
var
i1, i2, i, sum, x, y: integer;
temp: array[0..479, 0..479] of smallint;
pos: TPosition;
begin
if (SDL_MustLock(screen)) then
begin
if (SDL_LockSurface(screen) < 0) then
begin
MessageBox(0, PAnsiChar(Format('Can''t lock screen : %s', [SDL_GetError])), 'Error', MB_OK or MB_ICONHAND);
exit;
end;
end;
//由上到下绘制, 先绘制中心点靠上的建筑
for sum := -29 to 40 do
for i := -15 to 15 do
begin
i1 := Mx + i + (sum div 2);
i2 := My - i + (sum - sum div 2);
Pos := GetPositionOnScreen(i1, i2, Mx, My);
if (i1 >= 0) and (i1 < 480) and (i2 >= 0) and (i2 < 480) then
begin
if (sum >= -27) and (sum <= 28) and (i >= -9) and (i <= 9) then
begin
DrawMPic(earth[i1, i2] div 2, pos.x, pos.y);
if surface[i1, i2] > 0 then
DrawMPic(surface[i1, i2] div 2, pos.x, pos.y);
end;
temp[i1, i2] := building[i1, i2];
end
else
DrawMPic(0, pos.x, pos.y);
end;
for sum := -29 to 40 do
for i := -15 to 15 do
begin
i1 := Mx + i + (sum div 2);
i2 := My - i + (sum - sum div 2);
if (i1 >= 0) and (i1 < 480) and (i2 >= 0) and (i2 < 480) then
begin
x := buildy[i1, i2];
y := buildx[i1, i2];
Pos := GetPositionOnScreen(x, y, Mx, My);
if (buildx[i1, i2] > 0) and (((buildx[i1 - 1, i2 - 1] <> buildx[i1, i2]) and (buildx[i1 + 1, i2 + 1] <> buildx[i1, i2]))
or ((buildy[i1 - 1, i2 - 1] <> buildy[i1, i2]) and (buildy[i1 + 1, i2 + 1] <> buildy[i1, i2]))) then
begin
if temp[x, y] > 0 then
begin
DrawMPic(building[x, y] div 2, pos.x, pos.y);
temp[x, y] := 0;
end;
end;
//如在水面上则绘制船的贴图
if (i1 = Mx) and (i2 = My) then
if (InShip = 0) then
if still = 0 then
DrawMPic(2501 + MFace * 7 + MStep, CENTER_X, CENTER_Y)
else
DrawMPic(2528 + Mface * 6 + MStep, CENTER_X, CENTER_Y)
else
DrawMPic(3714 + MFace * 4 + (MStep + 1) div 2, CENTER_X, CENTER_Y);
if (temp[i1, i2] > 0) and (buildx[i1, i2] = i2) then
begin
DrawMPic(building[i1, i2] div 2, pos.x, pos.y);
temp[i1, i2] := 0;
end;
end;
end;
if (SDL_MustLock(screen)) then
begin
SDL_UnlockSurface(screen);
end;
//SDL_UpdateRect2(screen, 0,0,screen.w,screen.h);
end;}
//注意: 按照主地图的定义, 以下排序方式应该是准确的, 但是原版有些地方的引用建筑值设置不正确, 效果并不好
{procedure DrawMMap;
var
i1, i2, i, sum, x, y, k, j1, j2, BAmount, mini1, mini2, swaptemp, a, b, col: integer;
temp, tempindex: array[0..479, 0..479] of smallint;
width, height: smallint;
pos: TPosition;
List, ListIndex, BuildingPic: array[0..10000] of integer;
BuildingPos: array[0..10000] of TPosition;
begin
if (SDL_MustLock(screen)) then
begin
if (SDL_LockSurface(screen) < 0) then
begin
MessageBox(0, PAnsiChar(Format('Can''t lock screen : %s', [SDL_GetError])), 'Error', MB_OK or MB_ICONHAND);
exit;
end;
end;
for i1 := 0 to 479 do
for i2 := 0 to 479 do
begin
temp[i1, i2] := -1;
tempindex[i1, i2] := -1;
end;
mini1 := Mx - 16 - 14;
mini2 := My - 16 - 15;
k := 0;
for sum := -29 to 41 do
for i := -16 to 16 do
begin
i1 := Mx + i + (sum div 2);
i2 := My - i + (sum - sum div 2);
Pos := GetPositionOnScreen(i1, i2, Mx, My);
if (i1 >= 0) and (i1 < 480) and (i2 >= 0) and (i2 < 480) then
begin
if (sum >= -27) and (sum <= 28) and (i >= -9) and (i <= 9) then
begin
DrawMPic(earth[i1, i2] div 2, pos.x, pos.y);
if surface[i1, i2] > 0 then
DrawMPic(surface[i1, i2] div 2, pos.x, pos.y);
end;
end
else
DrawMPic(0, pos.x, pos.y);
if building[i1, i2] > 0 then
begin
List[k] := k;
ListIndex[k] := k;
BuildingPos[k].x := i1;
BuildingPos[k].y := i2;
BuildingPic[k] := building[i1, i2] div 2;
temp[i1, i2] := k;
for j1 := i1 downto mini1 do
begin
for j2 := i2 downto mini2 do
begin
if j1 + j2 < Mx + My - 29 then
continue;
if (BuildX[j1, j2] = i2) and (BuildY[j1, j2] = i1) then
begin
tempindex[j1, j2] := k;
end;
end;
end;
k := k + 1;
end;
if (i1 = Mx) and (i2 = My) then
begin
List[k] := k;
ListIndex[k] := k;
BuildingPos[k].x := i1;
BuildingPos[k].y := i2;
temp[i1, i2] := k;
tempindex[i1, i2] := k;
if InShip = 0 then
if still = 0 then
BuildingPic[k] := 2501 + MFace * 7 + MStep
else
BuildingPic[k] := 2528 + Mface * 6 + MStep
else
BuildingPic[k] := 3714 + MFace * 4 + (MStep + 1) div 2;
k := k + 1;
end;
end;
BAmount := k;
for sum := -29 to 41 do
begin
for i := -16 to 16 do
begin
i1 := Mx + i + (sum div 2);
i2 := My - i + (sum - sum div 2);
if temp[i1, i2] < 0 then
begin
continue;
end;
for j1 := i1 downto mini1 do
begin
for j2 := i2 downto mini2 do
begin
if j1 + j2 < Mx + My - 29 then
continue;
b := temp[i1, i2];
a := tempindex[j1, j2];
if (ListIndex[b] < ListIndex[a]) and (a < BAmount) then
begin
swaptemp := List[ListIndex[a]];
for k := ListIndex[a] downto ListIndex[b] + 1 do
List[k] := List[k - 1];
List[ListIndex[b]] := swaptemp;
for k := 0 to BAmount - 1 do
begin
ListIndex[List[k]] := k;
end;
end;
end;
end;
end;
end;
for i := 0 to BAmount - 1 do
begin
x := BuildingPos[List[i]].x;
y := BuildingPos[List[i]].y;
Pos := GetPositionOnScreen(x, y, Mx, My);
DrawMPic(BuildingPic[List[i]], pos.x, pos.y);
end;
DrawClouds;
if (SDL_MustLock(screen)) then
begin
SDL_UnlockSurface(screen);
end;
//SDL_UpdateRect2(screen, 0,0,screen.w,screen.h);
end;}
procedure DrawMMap;
var
i1, i2, i, sum, x, y, k, c, widthregion, sumregion, num, h: integer;
//temp: array[0..479, 0..479] of smallint;
Width, Height, xoffset, yoffset: smallint;
pos: TPosition;
BuildArray: array[0..2000] of TBuildInfo;
tempb: TBuildInfo;
tempscr, tempscr1: PSDL_Surface;
dest: TSDL_Rect;
begin
{if BIG_PNG_TILE = 1 then
begin
SDL_FillRect(screen, nil, 0);
dest.x := (-Mx * 18 + My * 18 + 8640 - CENTER_X) div 2;
dest.y := (Mx * 9 + My * 9 + 18 - CENTER_Y) div 2;
//dest.x := 8640 div 2;
//dest.y := 4320 div 2;
dest.w := CENTER_X;
dest.h := CENTER_Y;
tempscr := SDL_CreateRGBSurface(screen.flags, CENTER_X, CENTER_Y, 32, 0, 0, 0, 0);
SDL_BlitSurface(MMapSurface, @dest, tempscr, nil);
tempscr1 := sdl_gfx.zoomSurface(tempscr, 2, 2, 0);
SDL_BlitSurface(tempscr1, nil, screen, nil);
SDL_FreeSurface(tempscr);
SDL_FreeSurface(tempscr1);
end;}
//由上到下绘制, 先绘制地面和表面, 同时计算出现的建筑数
k := 0;
h := High(BuildArray);
widthregion := CENTER_X div 36 + 3;
sumregion := CENTER_Y div 9 + 2;
for sum := -sumregion to sumregion + 15 do
for i := -Widthregion to Widthregion do
begin
if k >= h then
break;
i1 := Mx + i + (sum div 2);
i2 := My - i + (sum - sum div 2);
Pos := GetPositionOnScreen(i1, i2, Mx, My);
if (i1 >= 0) and (i1 < 480) and (i2 >= 0) and (i2 < 480) then
begin
if (BIG_PNG_TILE = 0) then
begin
DrawMPic(earth[i1, i2] div 2, pos.x, pos.y);
if surface[i1, i2] > 0 then
DrawMPic(surface[i1, i2] div 2, pos.x, pos.y);
end;
num := building[i1, i2] div 2;
//将主角的位置计入建筑
if (i1 = Mx) and (i2 = My) then
begin
if (InShip = 0) then
if still = 0 then
num := 2501 + MFace * 7 + MStep
else
num := 2528 + Mface * 6 + MStep
else
num := 3715 + MFace * 4 + (MStep + 1) div 2;
end;
if (num > 0) and (num < MPicAmount) then
begin
BuildArray[k].x := i1;
BuildArray[k].y := i2;
BuildArray[k].b := num;
if PNG_TILE > 0 then
begin
if MPNGIndex[num].CurPointer <> nil then
begin
if MPNGIndex[num].CurPointer^ <> nil then
begin
Width := MPNGIndex[num].CurPointer^.w;
Height := MPNGIndex[num].CurPointer^.h;
yoffset := MPNGIndex[num].y;
xoffset := MPNGIndex[num].y;
end;
end;
end
else
begin
Width := SmallInt(Mpic[MIdx[num - 1]]);
Height := SmallInt(Mpic[MIdx[num - 1] + 2]);
yoffset := SmallInt(Mpic[MIdx[num - 1] + 6]);
xoffset := SmallInt(Mpic[MIdx[num - 1] + 4]);
end;
//根据图片的宽度计算图的中点的坐标和作为排序依据
//y坐标为第二依据
//BuildArray[k].c := (i1 + i2) - (Width + 35) div 36 - (yoffset - Height + 1) div 9;
BuildArray[k].c := ((i1 + i2) - (Width + 35) div 36 - (yoffset - Height + 1) div 9) * 1024 + i2;
if (i1 = Mx) and (i2 = My) then
BuildArray[k].c := (i1 + i2) * 1024 + i2;
k := k + 1;
end;
end
else
DrawMPic(0, pos.x, pos.y);
end;
//按照中点坐标排序
//tic;
{for i1 := 0 to k - 2 do
for i2 := i1 + 1 to k - 1 do
begin
if BuildArray[i1].c > BuildArray[i2].c then
begin
tempb := BuildArray[i1];
BuildArray[i1] := BuildArray[i2];
BuildArray[i2] := tempb;
end;
end;}
QuickSortB(BuildArray, 0, k - 1);
//toc;
for i := 0 to k - 1 do
begin
Pos := GetPositionOnScreen(BuildArray[i].x, BuildArray[i].y, Mx, My);
DrawMPic(BuildArray[i].b, pos.x, pos.y);
end;
DrawClouds;
DrawVirtualKey;
end;
//画场景到屏幕
procedure DrawScence;
var
i1, i2, x, y, xpoint, ypoint: integer;
begin
//先画无主角的场景, 再画主角
//如在事件中, 则以Cx, Cy为中心, 否则以主角坐标为中心
if (CurEvent < 0) then
begin
DrawScenceWithoutRole(Sx, Sy);
CurScenceRolePic := BEGIN_WALKPIC + SFace * 7 + SStep;
DrawRoleOnScence(Sx, Sy);
end
else
begin
DrawScenceWithoutRole(Cx, Cy);
if (DData[CurScence, CurEvent, 10] = Sx) and (DData[CurScence, CurEvent, 9] = Sy) then
begin
if DData[CurScence, CurEvent, 5] <= 0 then
begin
DrawRoleOnScence(Cx, Cy);
end;
end
else
DrawRoleOnScence(Cx, Cy);
end;
DrawVirtualKey;
end;
//画不含主角的场景(与DrawScenceByCenter相同)
procedure DrawScenceWithoutRole(x, y: integer);
var
x1, y1: integer;
begin
CalLTPosOnImageByCenter(x, y, x1, y1);
LoadScencePart(x1, y1);
end;
//画主角于场景
procedure DrawRoleOnScence(x, y: integer);
var
depth: integer;
pos: TPosition;
begin
pos := GetPositionOnScreen(Sx, Sy, x, y);
DrawSPic(CurScenceRolePic, pos.x, pos.y - SData[CurScence, 4, Sx, Sy], 0, 100, CalBlock(Sx, Sy), 0, 0);
end;
//将地面扩大并绘图, 避免场景出现黑色边缘, 方法是重复边缘的贴图
//因为有些场景自身的问题, 可能会出现较奇怪的结果
procedure ExpandGroundOnImg();
var
i1, i2, x, y, num: integer;
begin
if EXPAND_GROUND <> 0 then
begin
fillchar(ExGround, sizeof(ExGround), 0);
for i1 := 0 to 63 do
for i2 := 0 to 63 do
begin
case where of
1: ExGround[i1, i2] := SData[CurScence, 0, i1, i2];
2: ExGround[i1, i2] := Bfield[0, i1, i2];
end;
end;
for i1 := 31 downto -64 do
for i2 := 0 to 63 do
begin
if ExGround[i1, i2] <= 0 then
ExGround[i1, i2] := ExGround[i1 + 1, i2];
end;
for i1 := 32 to 127 do
for i2 := 0 to 63 do
begin
if ExGround[i1, i2] <= 0 then
ExGround[i1, i2] := ExGround[i1 - 1, i2];
end;
for i1 := -64 to 127 do
for i2 := 31 downto -64 do
begin
if ExGround[i1, i2] <= 0 then
ExGround[i1, i2] := ExGround[i1, i2 + 1];
end;
for i1 := -64 to 127 do
for i2 := 32 to 127 do
begin
if ExGround[i1, i2] <= 0 then
ExGround[i1, i2] := ExGround[i1, i2 - 1];
end;
for i1 := -64 to 127 do
for i2 := -64 to 127 do
begin
CalPosOnImage(i1, i2, x, y);
num := ExGround[i1, i2] div 2;
case where of
1: InitialSPic(num, x, y, 0, 0, ImageWidth, ImageHeight, 0, 0, 0);
2: InitialBPic(num, x, y, 0, 0);
end;
end;
end;
end;
//Save the image informations of the whole scence.
//生成场景映像