41 keymode
,updx
,updy
:integer;
42 seed
,nextseed
:integer;
45 light
:array [0..15] of image
;
46 bg
:array[0..1] of image
;
47 osad
:array [0..1,0..7] of image
;
48 back
:array [0..8] of image
;
49 gui
:array [0..34] of image
;
50 tue
:array [0..9] of image
;
57 toolus
,toolind
:integer;
64 msg
:array [0..4] of string;
65 msg_time
:array[0..4] of integer;
66 last_sleep_x
,last_sleep_y
:integer;
79 if nextseed
=0 then seed
:=getrelativetimems
; else seed
:=nextseed
;
82 if world_typ
=0 then genworld
;
84 if world_typ
=1 then genflat
;
86 player
.setX(get_spawn_x
*16+4);
87 player
.setY(get_spawn_y
*16);
91 procedure drwrect(x
,y
,w
,h
,t
:integer);
96 drawrect(x
+i
,y
+i
,w
-i
*2,h
-i
*2);
101 dt
:=GetRelativeTimeMs
- time
;
102 time
:=GetRelativeTimeMs
;
108 if fps
<s_max_fps
then if del
>0 then del
:=del
-1;
109 if fps
>s_max_fps
then if del
<200 then del
:=del
+1;
113 procedure ClearTextures
;
116 ix
, iy
, iz
: integer;
123 Vars
.clock
[ix
] := no
;
125 for ix
:= 0 to maxBlockTex
do
130 for ix
:= 0 to maxItemTex
do
153 Particles
.FreeTextures
;
161 for ix
:= 0 to CONST_MAX_CURS
do
164 //resetVirtualKeyboard(-1);
167 procedure create_msg(s
:string);
174 msg_time
[i
]:=msg_time
[i
-1];
177 msg_time
[0]:=getrelativetimems
;
181 procedure loadtexture(path
:string);
187 im
:=ld_tex('background.png',path
,'title/');
189 bg
[ix
]:=rotate_image_from_image(im
,ix
*16,0,16,16,0);
190 float
:=ld_tex('float.png',path
,'gui/');
191 compas
:=ld_tex('compass.png',path
,'gui/');
192 im
:=ld_tex('clock.png',path
,'gui/');
194 Vars
.clock
[ix
]:=rotate_image_from_image(im
,ix
*16,0,16,16,0);
195 if load_back_tex
then
197 im
:=ld_tex('back.png',path
,'');
198 for ix
:=0 to 8 do back
[ix
]:=rotate_image_from_image(im
,ix
*16,0,16,16,0);
201 console
.exec('textures.cfg', 'AUTO');
203 Player
.LoadSkin('char_ani.png', path
);
204 Mobs
.LoadTextures(path
);
206 im
:=ld_tex('gui.png',path
,'gui/');
207 gui
[0]:=rotate_image_from_image(im
,0,0,16,16,0);
208 LoadCurImg(gui
[0], CUR_SELECT1
);
209 gui
[1]:=rotate_image_from_image(im
,0,16,168,21,0);
210 gui
[3]:=rotate_image_from_image(im
,16,0,16,16,0);
211 LoadCurImg(gui
[3], CUR_SELECT2
);
212 gui
[6]:=rotate_image_from_image(im
,0,56,120,12,0);
213 gui
[7]:=rotate_image_from_image(im
,0,68,120,12,0);
214 gui
[8]:=rotate_image_from_image(im
,0,80,120,12,0);
215 gui
[13]:=rotate_image_from_image(im
,1,93,9,9,0);//hp
216 gui
[14]:=rotate_image_from_image(im
,12,93,9,9,0);//hp
217 gui
[15]:=rotate_image_from_image(im
,23,93,9,9,0);//hp
218 gui
[17]:=rotate_image_from_image(im
,120,56,18,18,0);
220 gui
[26]:=rotate_image_from_image(im
,89,93,9,9,0);//hunger
221 gui
[27]:=rotate_image_from_image(im
,100,93,9,9,0);//hunger
222 gui
[28]:=rotate_image_from_image(im
,111,93,9,9,0);//hunger
224 gui
[29]:=rotate_image_from_image(im
,67,93,9,9,0);//air
225 gui
[30]:=rotate_image_from_image(im
,78,93,9,9,0);//air
227 gui
[31]:=rotate_image_from_image(im
,122,93,9,9,0);//hp hardcore
228 gui
[32]:=rotate_image_from_image(im
,133,93,9,9,0);//hp hardcore
229 gui
[33]:=rotate_image_from_image(im
,144,93,9,9,0);//hp hardcore
231 gui
[20]:=rotate_image_from_image(im
,121,75,9,13,0);
232 gui
[21]:=rotate_image_from_image(im
,130,75,9,13,0);
233 gui
[22]:=rotate_image_from_image(im
,0,103,120,12,0);
235 if load_minimap_tex
then gui
[16]:=ld_tex('mapbg.png',path
,'gui/');
237 for ix
:=0 to 9 do tue
[ix
]:=rotate_image_from_image(im
,16*ix
,40,16,16,0);
239 if load_weather_tex
then
241 im
:=ld_tex('rain.png',path
,'terrain/');
242 for ix
:=0 to 7 do osad
[0,ix
]:=rotate_image_from_image(im
,16*ix
,0,16,16,0);
243 im
:=ld_tex('snow.png',path
,'terrain/');
244 for ix
:=0 to 7 do osad
[1,ix
]:=rotate_image_from_image(im
,16*ix
,0,16,16,0);
247 if load_light_tex
then
249 im
:=ld_tex('light.png',path
,'terrain/');
250 for ix
:=0 to 15 do light
[ix
]:=rotate_image_from_image(im
,16*ix
,0,16,16,0);
253 Particles
.LoadTextures(path
);
255 im
:=ld_tex('partition.png',path
,'gui/');
256 gui
[18]:=rotate_image_from_image(im
,0,0,84,42,0);
257 gui
[19]:=rotate_image_from_image(im
,0,42,4,4,0);
259 if load_sky_siz
<=0 then
260 sky
:=ld_tex('sky.png',path
,'terrain/');
262 sky
:=resize_image(ld_tex('sky.png',path
,'terrain/'),load_sky_siz
,2);
266 sun
:=ld_tex('sun.png',path
,'terrain/');
267 moon
:=ld_tex('moon_phase_0.png',path
,'terrain/moon_phases/');
271 sun
:=resize_image(ld_tex('sun.png',path
,'terrain/'),(getWidth
+getHeight
)/5,(getWidth
+getHeight
)/5);
272 moon
:=resize_image(ld_tex('moon_phase_0.png',path
,'terrain/moon_phases/'),(getWidth
+getHeight
)/5,(getWidth
+getHeight
)/5);
275 //load_virt_tex(ld_tex('touch.png',path,'gui/'));
333 setmaplight(0,ix
,iy
);
343 for ix
:=0 to CONST_MAX_LAYERS
do
347 procedure drw_load_line(s
:string;percent
:integer);
351 for ix
:=0 to getWidth
/16 do
352 for iy
:=0 to getHeight
/16 do
353 drawimage(bg
[0],ix
*16,iy
*16);
354 drawfonttext(s
,(getWidth
/2)-(length(s
)*8/2),(getHeight
/2)-8);
355 setcolor(128,128,128);
356 fillrect(getwidth
/2-50,getheight
/2+6,100,3);
357 setcolor(128,255,128);
358 fillrect(getwidth
/2-50,getheight
/2+6,percent
,3);
359 drawfonttext(integertostring(percent
)+'%',getwidth
/2-(length(integertostring(percent
)+'%')*8)/2,getheight
/2+12);
363 function getFlatMap(i
:integer):integer;
369 getFlatMap
:=getmap(ix
,iy
);
372 procedure setFlatMap(n
, i
:integer);
381 function getFlatMapInfo(i
:integer):integer;
387 getFlatMapInfo
:=getmapinfo(ix
,iy
);
390 procedure setFlatMapInfo(n
, i
:integer);
399 procedure SaveMapRLE
;
407 if (id
<>getFlatMap(i
+s
)) or (i
+s
>32767) then
417 procedure SaveMapInfoRLE
;
423 id
:=getFlatMapInfo(i
);
425 if (id
<>getFlatMapInfo(i
+s
)) or (i
+s
>32767) then
435 procedure LoadMapRLE
;
450 procedure LoadMapInfoRLE
;
459 setFlatMapInfo(id
, i
+j
);
465 procedure saveworld(path
:string);
470 if pl_world
=0 then world_name
:='world.sav';
472 if pl_world
=1 then world_name
:='nether.sav';
473 if file_exists(path
)<>1 then if create_folder(path
)=1 then debug('Folder created!');
474 if file_exists(path
+world_name
)>0 then delete_file(path
+world_name
);
475 if file_exists(path
+world_name
)<>1 then file_create(path
+world_name
);
476 if open_file(path
+world_name
)=1 then
478 writeint(player
.getX
);
479 writeint(player
.getY
);
483 drw_load_line('Background',50);
484 //Background and biomes
487 write_byte(getBackMap(ix
));
488 write_byte(getBiomMap(ix
));
491 drw_load_line('Chests', 55);
493 drw_load_line('Furnaces', 60);
495 drw_load_line('Mobs', 70);
497 drw_load_line('Drop', 80);
499 drw_load_line('Particles', 85);
502 drw_load_line('Other', 90);
506 write_byte(osadki_ani
);
507 write_byte(global_light
);
510 write_byte(clock_stage
);
513 writebool(b_sign
[ix
]);
514 writestr(t_sign
[ix
]);
517 drw_load_line('Ready',100);
518 if close_file(path
+world_name
)=1 then debug('World Saved!');
522 procedure savegame(path
:string);
526 drw_load_line('Basic',0);
527 if file_exists(path
+'player.dat')=1 then delete_file(path
+'player.dat');
528 if file_exists(path
)<>1 then if create_folder(path
)=1 then debug('Folder created!');
529 if file_exists(path
+'player.dat')<>1 then file_create(path
+'player.dat');
530 if open_file(path
+'player.dat')=1 then
533 write_byte(version_map
);
534 write_byte(gamemode
);
537 write_byte(pl_world
);
539 writeint(last_sleep_x
);
540 writeint(last_sleep_y
);
547 write_byte(moon_phase
);
550 if close_file(path
+'player.dat')=1 then debug('Saved!');
551 drw_load_line('Matrix',10);
557 function version_err(ver
:integer):boolean;
561 for ix
:=0 to getWidth
/16 do
562 for iy
:=0 to getHeight
/16 do
564 drawimage(bg
[0],ix
*16,iy
*16);
566 if version_map
=ver
then version_err
:=true; else
567 if version_map
>ver
then
569 drawfonttext('Old save format!',(getWidth
/2)-60,(getHeight
/2)-4);
574 if version_map
<ver
then
576 drawfonttext('New save format!',(getWidth
/2)-60,(getHeight
/2)-4);
584 function loadworld(path
:string):boolean;
589 if pl_world
=0 then world_name
:='world.sav';
591 if pl_world
=1 then world_name
:='nether.sav';
592 if file_exists(path
)=1 then
594 if file_exists(path
+world_name
)=1 then
596 if open_file(path
+world_name
)=1 then
598 player
.setX(readint
);
599 player
.setY(readint
);
603 drw_load_line('Background',50);
604 //Background and biomes
607 setBackMap(read_byte
, ix
);
608 setBiomMap(read_byte
, ix
);
610 drw_load_line('Chests', 55);
612 drw_load_line('Furnaces', 60);
615 drw_load_line('Drop', 80);
617 drw_load_line('Particles', 85);
620 drw_load_line('Other',90);
624 osadki_ani
:=read_byte
;
625 global_light
:=read_byte
;
628 clock_stage
:=read_byte
;
631 b_sign
[ix
]:=readbool
;
634 drw_load_line('Ready',100);
635 ///////////////////////
636 if close_file(path
+world_name
)=1 then begin loadworld
:=true; debug('World loaded!'); end;
637 end; else begin loadworld
:=false; debug('File not opened!'); end;
638 end; else begin loadworld
:=false; debug('File not exists!'); end;
639 end; else begin loadworld
:=false; debug('Folder not exists!'); end;
642 function loadgame(path
:string):boolean;
646 drw_load_line('Basic',0);
647 if file_exists(path
)=1 then
649 if file_exists(path
+'player.dat')=1 then
651 if open_file(path
+'player.dat')=1 then
655 if version_err(ver
)=false then
657 if close_file(path
+'player.dat')=1 then loadgame
:=false;
665 last_sleep_x
:=readint
;
666 last_sleep_y
:=readint
;
673 moon_phase
:=read_byte
;
676 drw_load_line('Matrix',10);
677 if close_file(path
+'player.dat')=1 then loadgame
:=loadworld(path
);
678 end; else loadgame
:=false;
679 end; else loadgame
:=false;
680 end; else loadgame
:=false;
683 procedure drawdeadlogo
;
688 fillrect(0,0,getWidth
,getHeight
);
689 dead
:=loadimage('/dl');
690 drawimage(dead
,(getWidth
/2)-(getimagewidth(dead
)/2),(getHeight
/2)-(getimageheight(dead
)/2));
691 drawfonttext(#119+#119+#119+#46+#100+#101+#97+#100+#115+#111+#102+#116+#119+#97+#114+#101+#46+#114+#117,getWidth
/2-80,(getHeight
/2)+(getimageheight(dead
)/2));
692 drawfonttext('Loading...',(getWidth
/2)-(40),getHeight
-8);
701 for ix
:=0 to getWidth
/16 do
702 for iy
:=0 to getHeight
/16 do
704 drawimage(bg
[0],ix
*16,iy
*16);
706 drawfonttext('Generation World...',(getWidth
/2)-(76),(getHeight
/2)-4);
712 //if s_spawn_mob then begin if pl_world=0 then begin megaspawn; end; else begin netherspawn; end; end;
713 if gamemode
=1 then fly
:=true else fly
:=false;
717 function gettext(text,text_f
:string; max
,typ
:integer;):string;
719 textField_id
:integer;
723 exitCmd
:=createCommand('Ok',CM_OK
,1);
726 textField_id
:=formAddTextField(text,text_f
,max
,typ
);
730 cli
:=getClickedCommand
;
732 gettext
:=formGetText(textField_id
);
736 procedure drw_btn(text:string; cur
,ccur
,h
,ty
:integer);
740 m_x
:=(getWidth
/2)-(120/2);
741 m_y
:=h
+((getHeight
/2))-((getimageheight(gui
[7])-2*cur
)/2)+((getimageheight(gui
[7])+2)*cur
);
744 if ccur
=cur
then drawimage(gui
[22],m_x
+i
*4,m_y
); else drawimage(gui
[6],m_x
+i
*8,m_y
);
748 if ccur
=cur
then drawimage(gui
[8],m_x
+i
*8,m_y
); else drawimage(gui
[7],m_x
+i
*8,m_y
);
750 setclip(0,0,getwidth
,getheight
);
751 m_x
:=(getWidth
/2)-(length(text)*8/2);
752 m_y
:=h
+((getHeight
/2))-((getimageheight(gui
[7])-2*cur
)/2)+((getimageheight(gui
[7])+2)*cur
)+((getimageheight(gui
[7])-8)/2);
753 drawfonttext(text,m_x
,m_y
);
756 procedure drw_txt(str
:string; xx
,n
,t
:integer);
760 m_x
:=(getWidth
/2)-(length(str
)*8/2);
762 if t
=0 then drawfonttext(str
,0,m_y
); else
763 if t
=1 then drawfonttext(str
,m_x
,m_y
);
766 function pos_end(s
:string; c
:char):integer;
770 for i
:=length(s
)-1 downto 0 do
772 if getchar(s
,i
)=c
then
781 function getroot(cancel_b
:boolean):string;
783 m_cur
,max_r
,pars
,ix
,iy
:integer;
786 roots
:array [0..15] of string;
788 im
:=rotate_image_from_image(ld_tex('background.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','title/'),16,0,16,16,0);
790 if cancel_b
then roots
[0]:='<CANCEL>';
791 if cancel_b
then max_r
:=1; else max_r
:=0;
792 while pos(rr
,'|')<>-1 do
795 roots
[max_r
]:=copy(rr
,0,pars
-1);
796 rr
:=copy(rr
,pars
+1,length(rr
));
802 if clickedKey(KEY_FM_UP
) then begin m_cur
:=m_cur
-1; if m_cur
<0 then m_cur
:=max_r
; end;
803 if clickedKey(KEY_FM_DOWN
) then begin m_cur
:=m_cur
+1; if m_cur
>max_r
then m_cur
:=0; end;
804 if clickedKey(KEY_FM_SELECT
) then
806 if (m_cur
=0) and (cancel_b
) then
813 getroot
:=roots
[m_cur
];
818 for ix
:=0 to getWidth
/16 do
819 for iy
:=0 to getHeight
/16 do
820 drawimage(im
,ix
*16,iy
*16);
823 fillrect(0,m_cur
*8,getWidth
-1,8);
824 for ix
:=0 to max_r
do
826 drawfonttext(roots
[ix
],0,ix
*8);
828 setcolor(255,255,255);
829 drawrect(0,m_cur
*8,getWidth
-1,8);
836 function filemanager(cancel_b
:boolean):string;
838 m_cur
,ix
,iy
,max_r
,pars
:integer;
840 last
,rr
,root
,path
:string;
841 names
:array [0..255] of string;
843 im
:=rotate_image_from_image(ld_tex('background.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','title/'),16,0,16,16,0);
846 root
:=getroot(cancel_b
);
853 if cancel_b
then names
[2]:='<CANCEL>';
855 if cancel_b
then max_r
:=3; else max_r
:=2;
856 while pos(rr
,'|')<>-1 do
859 names
[max_r
]:=copy(rr
,0,pars
-1);
860 rr
:=copy(rr
,pars
+1,length(rr
));
867 if clickedKey(KEY_FM_UP
) then begin m_cur
:=m_cur
-1; if m_cur
<0 then m_cur
:=max_r
; end;
868 if clickedKey(KEY_FM_DOWN
) then begin m_cur
:=m_cur
+1; if m_cur
>max_r
then m_cur
:=0; end;
869 if clickedKey(KEY_FM_SELECT
) then
874 debug('lol:'+pos_end(path
,'/'));
875 if (path
=root
) or (path
=root
+'/') then
877 root
:=getroot(cancel_b
);
887 path
:=copy(path
,0,pos_end(path
,'/'));
888 if cancel_b
then names
[2]:='<CANCEL>';
890 if cancel_b
then max_r
:=3; else max_r
:=2;
891 while pos(rr
,'|')<>-1 do
894 names
[max_r
]:=copy(rr
,0,pars
-1);
895 rr
:=copy(rr
,pars
+1,length(rr
));
907 if (m_cur
=2) and (cancel_b
) then
914 path
:=path
+'/'+names
[m_cur
];
916 if cancel_b
then names
[2]:='<CANCEL>';
918 if cancel_b
then max_r
:=3; else max_r
:=2;
919 while pos(rr
,'|')<>-1 do
922 names
[max_r
]:=copy(rr
,0,pars
-1);
923 rr
:=copy(rr
,pars
+1,length(rr
));
932 for ix
:=0 to getWidth
/16 do
933 for iy
:=0 to getHeight
/16 do
934 drawimage(im
,ix
*16,iy
*16);
937 fillrect(0,m_cur
*8,getWidth
-1,8);
938 for ix
:=0 to max_r
do
940 drawfonttext(names
[ix
],0,ix
*8);
942 setcolor(255,255,255);
943 drawrect(0,m_cur
*8,getWidth
-1,8);
951 procedure setsd(cancel_b
:boolean);
957 s
:=filemanager(cancel_b
);
961 if file_exists('/'+sd
+'/cavecraft')<>1 then
962 if create_folder('/'+sd
+'/cavecraft')=1 then debug('/cavecraft created!');
964 if file_exists('/'+sd
+'/cavecraft/saves')<>1 then
965 if create_folder('/'+sd
+'/cavecraft/saves')=1 then debug('/saves created!');
967 if file_exists('/'+sd
+'/cavecraft/screenshots')<>1 then
968 if create_folder('/'+sd
+'/cavecraft/screenshots')=1 then debug('/screenshots created!');
970 if file_exists('/'+sd
+'/cavecraft/texturepacks')<>1 then
971 if create_folder('/'+sd
+'/cavecraft/texturepacks')=1 then debug('/texturepacks created!');
973 deleteRecordStore('SD');
974 rs
:=openRecordStore('SD');
975 t
:=addRecordStoreEntry(rs
,sd
);
976 closeRecordStore(rs
);
987 rs
:=openRecordStore('SD');
988 sd
:=readRecordStoreEntry(rs
,1);
989 closeRecordStore(rs
);
990 console
.exec('autoexec.cfg', 'AUTO');
998 //load_virt_tex(loadimage('/gui/touch.png'));
1002 if file_exists('/'+sd
+'/cavecraft')<>1 then
1003 if create_folder('/'+sd
+'/cavecraft')=1 then debug('/cavecraft created!');
1005 if file_exists('/'+sd
+'/cavecraft/saves')<>1 then
1006 if create_folder('/'+sd
+'/cavecraft/saves')=1 then debug('/saves created!');
1008 if file_exists('/'+sd
+'/cavecraft/screenshots')<>1 then
1009 if create_folder('/'+sd
+'/cavecraft/screenshots')=1 then debug('/screenshots created!');
1011 if file_exists('/'+sd
+'/cavecraft/texturepacks')<>1 then
1012 if create_folder('/'+sd
+'/cavecraft/texturepacks')=1 then debug('/texturepacks created!');
1014 rs
:=openRecordStore('TX');
1015 ss
:=readRecordStoreEntry(rs
,1);
1016 closeRecordStore(rs
);
1021 LoadDrawFont('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1022 loadtexture('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1031 function question(text:string):boolean;
1033 ix
,iy
,m_cur
:integer;
1037 if clickedKey(KEY_MENU_UP
) then begin m_cur
:=m_cur
-1; if m_cur
<0 then m_cur
:=1; end;
1038 if clickedKey(KEY_MENU_DOWN
) then begin m_cur
:=m_cur
+1; if m_cur
>1 then m_cur
:=0; end;
1039 if clickedKey(KEY_MENU_SELECT
) then begin if m_cur
=0 then question
:=true; else question
:=false; exit
; end;
1040 for ix
:=0 to getwidth
/16 do for iy
:=0 to getheight
/16 do drawimage(bg
[0],ix
*16,iy
*16);
1041 drawfonttext(text,getwidth
/2-(length(text)*8)/2,getheight
/2-16);
1042 drw_btn('Yes',0,m_cur
,0,1);
1043 drw_btn('No',1,m_cur
,0,1);
1049 function menu_game_new
:boolean;
1051 m_cur
,tmp_gm
,ix
,iy
,lol
:integer;
1052 tmp_cheats
,tmp_bon_chest
:boolean;
1053 newgametxt
:array[0..4] of string;
1057 newgametxt
[0]:='Survival';
1058 newgametxt
[1]:='Creative';
1059 newgametxt
[2]:='Hardcore';
1060 newgametxt
[3]:='Normal';
1061 newgametxt
[4]:='Flat';
1065 if clickedKey(KEY_MENU_UP
) then begin m_cur
:=m_cur
-1; if m_cur
<-2 then m_cur
:=5; end;
1066 if clickedKey(KEY_MENU_DOWN
) then begin m_cur
:=m_cur
+1; if m_cur
>5 then m_cur
:=-2; end;
1067 if clickedKey(KEY_MENU_SELECT
) then
1071 name
:=gettext('Name:',name
,10,TF_ANY
);
1075 tmp_gm
:=tmp_gm
+1; if tmp_gm
>2 then tmp_gm
:=0;
1076 if tmp_gm
=0 then tmp_cheats
:=false;
1077 if tmp_gm
=1 then tmp_cheats
:=true;
1078 if tmp_gm
=2 then begin tmp_cheats
:=false; tmp_bon_chest
:=false; end;
1082 nextseed
:=stringtointeger(gettext('Seed:',''+nextseed
,10,TF_NUMERIC
));
1086 world_typ
:=world_typ
+1;
1087 if world_typ
>1 then world_typ
:=0;
1091 if tmp_gm
<2 then tmp_cheats
:= not tmp_cheats
;
1095 if tmp_gm
<2 then tmp_bon_chest
:= not tmp_bon_chest
;
1101 bon_chest
:=tmp_bon_chest
;
1103 while file_exists('/'+sd
+'/cavecraft/saves/'+name
)=1 do
1110 menu_game_new
:=true;
1118 for ix
:=0 to getWidth
/16 do
1119 for iy
:=0 to getHeight
/16 do
1120 drawimage(bg
[0],ix
*16,iy
*16);
1122 drw_btn('Name:'+name
,-2,m_cur
,0,1);
1123 drw_btn('Mode:'+newgametxt
[tmp_gm
],-1,m_cur
,0,1);
1124 drw_btn('Seed:'+nextseed
,0,m_cur
,0,1);
1125 drw_btn('Type:'+newgametxt
[world_typ
+3],1,m_cur
,0,1);
1127 drw_btn('Cheats:'+tmp_cheats
,2,m_cur
,0,1);
1129 drw_btn('Cheats:'+tmp_cheats
,2,m_cur
,0,0);
1131 drw_btn('Chest:'+tmp_bon_chest
,3,m_cur
,0,1);
1133 drw_btn('Chest:'+tmp_bon_chest
,3,m_cur
,0,0);
1134 drw_btn('Create',4,m_cur
,0,1);
1135 drw_btn('Cancel',5,m_cur
,0,1);
1142 procedure deleteworld(path
:string);
1144 if file_exists(path
+'player.dat')=1 then delete_file(path
+'player.dat');
1145 if file_exists(path
+'world.sav')=1 then delete_file(path
+'world.sav');
1146 if file_exists(path
+'nether.sav')=1 then delete_file(path
+'nether.sav');
1147 if file_exists(path
+'pic.png')=1 then delete_file(path
+'pic.png');
1148 if file_exists(path
)=1 then delete_file(path
);
1149 if file_exists(path
)=0 then debug('World deleted!');
1152 function menu_game
:boolean;
1154 ix
,iy
,pars
,max_r
,cur_name
,m_cur
:integer;
1158 names
:array[0..255] of string;
1160 rr
:=get_dirs('/'+sd
+'/cavecraft/saves/');
1161 while pos(rr
,'|')<>-1 do
1164 names
[max_r
]:=copy(rr
,0,pars
-1);
1165 rr
:=copy(rr
,pars
+1,length(rr
));
1166 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[max_r
]+'/player.dat')=1 then max_r
:=max_r
+1;
1169 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png')=1 then
1170 im_game
:=safely_load_image_fs('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png');
1171 else im_game
:=ld_tex('maps.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','');
1173 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/player.dat')=1 then
1174 mm_t_b
:=true; else mm_t_b
:=false;
1178 if clickedKey(KEY_MENU_UP
) then
1181 if m_cur
<0 then m_cur
:=3;
1183 if clickedKey(KEY_MENU_DOWN
) then
1186 if m_cur
>3 then m_cur
:=0;
1189 if (max_r
>= 0) and clickedKey(KEY_MENU_LEFT
) then
1191 cur_name
:=cur_name
-1;
1192 if cur_name
<0 then cur_name
:=0;
1193 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png')=1 then
1194 im_game
:=safely_load_image_fs('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png');
1195 else im_game
:=ld_tex('maps.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','');
1197 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/player.dat')=1 then
1199 if (max_r
>= 0) and clickedKey(KEY_MENU_RIGHT
) then
1201 cur_name
:=cur_name
+1;
1202 if cur_name
>max_r
then cur_name
:=max_r
;
1203 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png')=1 then
1204 im_game
:=safely_load_image_fs('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png');
1205 else im_game
:=ld_tex('maps.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','');
1207 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/player.dat')=1 then
1209 if clickedKey(KEY_MENU_SELECT
) then
1214 if loadgame('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/') then
1216 sav_fl
:=names
[cur_name
];
1223 if menu_game_new
then begin menu_game
:=true; break
; end;
1227 debug('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/');
1229 if question('Are you sure?')=true then deleteworld('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/');
1232 rr
:=get_dirs('/'+sd
+'/cavecraft/saves/');
1233 while pos(rr
,'|')<>-1 do
1236 names
[max_r
]:=copy(rr
,0,pars
-1);
1237 rr
:=copy(rr
,pars
+1,length(rr
));
1241 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png')=1 then
1242 im_game
:=safely_load_image_fs('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png');
1243 else im_game
:=ld_tex('maps.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','');
1251 for ix
:=0 to getWidth
/16 do
1253 drawimage(bg
[1],ix
*16,iy
*16);
1254 for ix
:=0 to getWidth
/16 do
1255 drawimage(bg
[0],ix
*16,0);
1256 for ix
:=0 to getWidth
/16 do
1257 for iy
:=8 to getHeight
/16 do
1258 drawimage(bg
[0],ix
*16,iy
*16);
1263 fillrect(32,24,getWidth
-64,96);
1264 setclip(32,24,getWidth
-64,96);
1265 drawimage(im_game
,(getWidth
/2)-(32),32);
1266 drawfonttext(names
[cur_name
],(getWidth
/2)-(length(names
[cur_name
])*8/2),104);
1267 setclip(0,0,getWidth
,getHeight
);
1268 setcolor(128,128,128);
1269 drawrect(32,24,getWidth
-64,96);
1270 if cur_name
>0 then drawimage(gui
[20],0,58);
1271 if cur_name
<max_r
then drawimage(gui
[21],getWidth
-9,58);
1276 fillrect(32,24,getWidth
-64,96);
1277 setclip(32,24,getWidth
-64,96);
1278 drawfonttext('No saves!',(getWidth
/2)-(length('No saves!')*8/2),104);
1279 setclip(0,0,getWidth
,getHeight
);
1280 setcolor(128,128,128);
1281 drawrect(32,24,getWidth
-64,96);
1284 if mm_t_b
then drw_btn('Play',0,m_cur
,32,1); else drw_btn('Play',0,m_cur
,32,0);
1285 drw_btn('Create new',1,m_cur
,32,1);
1286 if mm_t_b
then drw_btn('Delete',2,m_cur
,32,1); else drw_btn('Delete',2,m_cur
,32,0);
1287 drw_btn('Back',3,m_cur
,32,1);
1288 if not mm_t_b
then cur_name
:=cur_name
+1;
1297 ix
,iy
,pars
,max_r
,cur_name
,m_cur
,t
:integer;
1300 names
:array[0..255] of string;
1303 rr
:=get_dirs('/'+sd
+'/cavecraft/texturepacks/');
1304 names
[0]:='Default';
1306 while pos(rr
,'|')<>-1 do
1309 names
[max_r
]:=copy(rr
,0,pars
-1);
1310 rr
:=copy(rr
,pars
+1,length(rr
));
1314 im_game
:=loadimage('/pack.png');
1318 if clickedKey(KEY_MENU_UP
) then
1321 if m_cur
<0 then m_cur
:=1;
1323 if clickedKey(KEY_MENU_DOWN
) then
1326 if m_cur
>1 then m_cur
:=0;
1329 if clickedKey(KEY_MENU_LEFT
) then
1331 cur_name
:=cur_name
-1;
1332 if cur_name
<0 then cur_name
:=0;
1333 im_game
:=ld_tex('pack.png','/'+sd
+'/cavecraft/texturepacks/'+names
[cur_name
]+'/','');
1335 if clickedKey(KEY_MENU_RIGHT
) then
1337 cur_name
:=cur_name
+1;
1338 if cur_name
>max_r
then cur_name
:=max_r
;
1339 im_game
:=ld_tex('pack.png','/'+sd
+'/cavecraft/texturepacks/'+names
[cur_name
]+'/','');
1341 if clickedKey(KEY_MENU_SELECT
) then
1343 if m_cur
=0 then begin
1346 debug("Select TexturePack @ /" + sd
+ "/cavecraft/texturepacks/" + names
[cur_name
]);
1347 tex_pack
:=names
[cur_name
];
1348 LoadDrawFont('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1349 loadtexture('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1350 deleteRecordStore('TX');
1351 rs
:=openRecordStore('TX');
1352 t
:=addRecordStoreEntry(rs
,tex_pack
);
1353 closeRecordStore(rs
);
1355 LoadDrawFont('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1356 loadtexture('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1360 debug("Cancel Select TecturePack");
1363 deleteRecordStore('TX');
1364 rs
:=openRecordStore('TX');
1365 t
:=addRecordStoreEntry(rs
,'');
1366 closeRecordStore(rs
);
1369 if m_cur
=1 then break
;
1373 for ix
:=0 to getWidth
/16 do
1375 drawimage(bg
[1],ix
*16,iy
*16);
1376 for ix
:=0 to getWidth
/16 do
1377 drawimage(bg
[0],ix
*16,0);
1378 for ix
:=0 to getWidth
/16 do
1379 for iy
:=8 to getHeight
/16 do
1380 drawimage(bg
[0],ix
*16,iy
*16);
1385 fillrect(32,24,getWidth
-64,96);
1386 setclip(32,24,getWidth
-64,96);
1387 drawimage(im_game
,(getWidth
/2)-(32),32);
1388 drawfonttext(names
[cur_name
],(getWidth
/2)-(length(names
[cur_name
])*8/2),104);
1389 setclip(0,0,getWidth
,getHeight
);
1390 setcolor(128,128,128);
1391 drawrect(32,24,getWidth
-64,96);
1392 if cur_name
>0 then drawimage(gui
[20],0,58);
1393 if cur_name
<max_r
then drawimage(gui
[21],getWidth
-9,58);
1396 drw_btn('Done',0,m_cur
,32,1);
1397 drw_btn('Back',1,m_cur
,32,1);
1404 procedure menu_sett
;
1406 ix
,iy
,m_cur
:integer;
1411 if clickedKey(KEY_MENU_UP
) then
1414 if m_cur
<-3 then m_cur
:=5;
1416 if clickedKey(KEY_MENU_DOWN
) then
1419 if m_cur
>5 then m_cur
:=-3;
1421 if clickedKey(KEY_MENU_SELECT
) then
1425 light_type
:=light_type
+1;
1426 if light_type
>2 then light_type
:=0;
1434 Particles
.enabled
:= not Particles
.enabled
;
1438 drawgui
:=not drawgui
;
1442 if question('Are you sure?')=true then
1444 if load_key_tex
=0 then
1448 //load_virt_tex(ld_tex('touch.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','gui/'));
1451 if load_key_tex
=1 then
1454 resetVirtualKeyboard(-1);
1460 s_jpeg_quality
:=stringtointeger(gettext('JPEG quality:',''+s_jpeg_quality
,3,TF_NUMERIC
));
1461 if s_jpeg_quality
>100 then s_jpeg_quality
:=100; else
1462 if s_jpeg_quality
<0 then s_jpeg_quality
:=0;
1470 deleteRecordStore('S');
1471 deleteRecordStore('SD');
1472 deleteRecordStore('TX');
1482 for ix
:=0 to getWidth
/16 do
1483 for iy
:=0 to getHeight
/16 do
1484 drawimage(bg
[0],ix
*16,iy
*16);
1486 drw_btn('Light:'+light_type
,-3,m_cur
,0,1);
1487 drw_btn('Weather:'+ifosad
,-2,m_cur
,0,1);
1488 drw_btn('Particles:' + Particles
.enabled
, -1, m_cur
, 0, 1);
1489 drw_btn('Hide GUI:'+not drawgui
,0,m_cur
,0,1);
1490 drw_btn('Touch:'+(load_key_tex
>0),1,m_cur
,0,1);
1491 drw_btn('JPEG:'+s_jpeg_quality
,2,m_cur
,0,1);
1492 drw_btn('Set Root',3,m_cur
,0,1);
1493 drw_btn('Reset',4,m_cur
,0,1);
1494 drw_btn('Back',5,m_cur
,0,1);
1501 procedure menu_help
;
1507 if clickedKey(KEY_MENU_SELECT
) then break
;
1508 if pressedKey(KEY_MENU_UP
) then cur
:=cur
+1;
1509 if pressedKey(KEY_MENU_DOWN
) then cur
:=cur
-1;
1511 for ix
:=0 to getWidth
/16 do
1512 for iy
:=2 to (getHeight
/16)-2 do
1513 drawimage(bg
[1],ix
*16,iy
*16);
1515 for ix
:=0 to getWidth
/16 do
1517 drawimage(bg
[0],ix
*16,iy
*16);
1519 for ix
:=0 to getWidth
/16 do
1520 for iy
:=(getHeight
/16)-2 to getHeight
/16 do
1521 drawimage(bg
[0],ix
*16,iy
*16);
1523 setclip(0,32,getWidth
,(getHeight
/16-4)*16);
1525 drw_txt('Controls:',cur
,0,1);
1526 drw_txt('Left - Move left',cur
,1,0);
1527 drw_txt('Right - Move right',cur
,2,0);
1528 drw_txt('Up - Jump',cur
,3,0);
1529 drw_txt('Down - Put a block under you',cur
,4,0);
1530 drw_txt('1 - Inventory',cur
,5,0);
1531 drw_txt('Duble 1 - Craft',cur
,6,0);
1532 drw_txt('3 - Use block',cur
,7,0);
1533 drw_txt('7 - Debug info',cur
,8,0);
1534 drw_txt('Hold 7 - Console',cur
,9,0);
1535 drw_txt('9 - Pause',cur
,10,0);
1536 drw_txt('*, # - Browse inventory',cur
,11,0);
1537 drw_txt('0 - Edit mode',cur
,12,0);
1539 drw_txt('In inventory/chest:',cur
,14,1);
1540 drw_txt('3 - Enject object',cur
,15,0);
1541 drw_txt('Hold 3 - Enject stack',cur
,16,0);
1542 drw_txt('5 - Move the stack',cur
,17,0);
1543 drw_txt('Hold 5 - Divide stack',cur
,18,0);
1545 setclip(0,0,getWidth
,getHeight
);
1547 drw_btn('Back',0,0,getHeight
-getHeight
/2-16-6,1);
1554 procedure menu_about
;
1560 if clickedKey(KEY_MENU_SELECT
) then break
;
1561 if pressedKey(KEY_MENU_UP
) then cur
:=cur
+1;
1562 if pressedKey(KEY_MENU_DOWN
) then cur
:=cur
-1;
1564 for ix
:=0 to getWidth
/16 do
1565 for iy
:=2 to (getHeight
/16)-2 do
1566 drawimage(bg
[1],ix
*16,iy
*16);
1568 for ix
:=0 to getWidth
/16 do
1570 drawimage(bg
[0],ix
*16,iy
*16);
1572 for ix
:=0 to getWidth
/16 do
1573 for iy
:=(getHeight
/16)-2 to getHeight
/16 do
1574 drawimage(bg
[0],ix
*16,iy
*16);
1576 setclip(0,32,getWidth
,(getHeight
/16-4)*16);
1578 drw_txt('Developers:',cur
,0,1);
1579 drw_txt(#68+#101+#97+#68+#68+#111+#111+#77+#69+#82+' - Programmer',cur
,1,0);//dead
1580 drw_txt(#102+#114+#101+#100+#45+#98+#111+#121+' - Programmer',cur
,2,0);//fred-boy
1581 drw_txt(#65+#110+#100+#114+#101+#121+#53+#57+' - Programmer',cur
,3,0);//andrey59
1582 drw_txt(#89+#117+#82+#97+#78+#110+#78+#122+#90+#90+' - Artist',cur
,4,0);//yura
1583 drw_txt(#83+#97+#115+#104+#97+#71+' - Artist and idea generator',cur
,5,0);//sasha
1584 drw_txt(#66+#97+#74+#108+#101+#72+#84+#105+#72+' - Artist and tester',cur
,6,0);//valentin
1585 drw_txt(#65+#103+#114+#101+#115+#115+#111+#82+' - Tester',cur
,7,0);//agressor
1586 drw_txt(#118+#111+#108+#121+#97+#95+#110+#97+#115+#116+#97+#110+#101+' - Tester',cur
,8,0);//volya
1587 drw_txt(#97+#98+#97+#100+#111+#110+' - Tester',cur
,9,0);//abadon
1588 drw_txt(#77+#111+#110+#111+#103+#114+#111+#109+' - Tester',cur
,10,0);//monogrom
1589 drw_txt(#75+#97+#108+#116+#101+#114+' - Tester',cur
,11,0);//kalter
1591 drw_txt('Thanks:',cur
,12,1);
1592 drw_txt('Piligrim and 0vZ - Lib_jsr75i',cur
,13,0);
1593 drw_txt('Piligrim - Lib_effects',cur
,14,0);
1594 drw_txt('Kurdt - Lib_canvas',cur
,15,0);
1595 drw_txt('ViNT - Lib_png and Lib_bmp',cur
,16,0);
1596 drw_txt('aleshka - Lib_jpeg',cur
,17,0);
1597 drw_txt('Roman_V - Lib_safeload',cur
,18,0);
1599 drw_txt('Site: '+#104+#116+#116+#112+#58+#47+#47+#100+#101+#97+#100+#115+#111+#102+#116+#119+#97+#114+#101+#46+#114+#117,cur
,21,0);
1600 drw_txt(#68+#101+#97+#68+#83+#111+#102+#116+#87+#97+#114+#101+' 2012-2014',cur
,22,0);
1602 drw_txt('Hello! :D',cur
,100,1);
1604 setclip(0,0,getWidth
,getHeight
);
1606 drw_btn('Back',0,0,getHeight
-getHeight
/2-16-6,1);
1613 function sm_siz
:integer;
1615 sm_siz
:=(getWidth
+getHeight
)/5;
1618 function sm_siz4
:integer;
1623 procedure draw_menu_back
;
1627 for ix
:=0 to getWidth
/16 do
1628 for iy
:=0 to getHeight
/16 do
1629 drawimage(bg
[0],ix
*16,iy
*16);
1634 m_cur
,ix
,iy
,iz
:integer;
1640 spl_y
,spl_del
:integer;
1643 cavelogo
:=ld_tex('cavelogo.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','title/');
1645 spl_y
:=getimageheight(cavelogo
);
1647 spl_del
:=getrelativetimems
;
1648 res
:=openResource('/title/splashes.txt');
1649 if ResourceAvailable(res
) then
1651 spl_i
:=stringtointeger(readline(res
));
1652 iy
:=random(spl_i
-1)+1;
1653 debug('SPLASH #'+iy
);
1655 splash
:=readline(res
);
1658 time
:=getcurrenttime
;
1659 if (getmonth(time
)=5) and (getday(time
)=7) then splash
:='Happy birthday, DeaDDooMER!';
1660 if ((getmonth(time
)=0) and (getday(time
)<3)) or ((getmonth(time
)=11) and (getday(time
)>29)) then splash
:='Happy New Year!';
1664 if clickedKey(KEY_MENU_UP
) then
1667 if m_cur
<0 then m_cur
:=5;
1669 if clickedKey(KEY_MENU_DOWN
) then
1672 if m_cur
>5 then m_cur
:=0;
1674 if clickedKey(KEY_MENU_SELECT
) then
1676 if m_cur
=0 then begin if menu_game
then break
; end;
1678 if m_cur
=1 then menu_tex
;
1680 if m_cur
=2 then menu_sett
;
1682 if m_cur
=3 then menu_help
;
1684 if m_cur
=4 then menu_about
;
1686 if m_cur
=5 then begin save_settings
; halt
; end;
1691 drawimage(cavelogo
,(getWidth
/2)-(getimagewidth(cavelogo
)/2),0);
1692 setcolor(255,255,0);
1694 DrawFontTextSpec(splash
, (getWidth
/2)-(length(splash
)*FONT_SYM_SIZE
/2), spl_y
, FONT_YELLOW_COLOR
, true);
1696 if spl_y_b
then begin if getrelativetimems
-spl_del
>64 then begin spl_y
:=spl_y
+1; spl_del
:=getrelativetimems
; end; if spl_y
>getimageheight(cavelogo
)+2 then spl_y_b
:=false; end;
1697 if not spl_y_b
then begin if getrelativetimems
-spl_del
>64 then begin spl_y
:=spl_y
-1; spl_del
:=getrelativetimems
; end; if spl_y
<getimageheight(cavelogo
)+1 then spl_y_b
:=true; end;
1698 drawfonttext(version
,0,getHeight
-8);
1700 drw_btn('Singleplayer',0,m_cur
,0,1);
1701 drw_btn('Texture Packs',1,m_cur
,0,1);
1702 drw_btn('Options',2,m_cur
,0,1);
1703 drw_btn('Help',3,m_cur
,0,1);
1704 drw_btn('About',4,m_cur
,0,1);
1705 drw_btn('Quit Game',5,m_cur
,0,1);
1712 function setBlock(invcur
, x
, y
:integer):boolean;
1714 item
, sum
, block
, sblock
:integer;
1716 item
:=inv
.getItem(invcur
);
1717 sum
:=inv
.getSum(invcur
);
1718 block
:=getMap(x
, y
);
1719 sblock
:= Items
.GetData(item
);
1721 if (Items
.GetType(item
) = Items
.block
) and (Inv
.IsNull(invcur
) = false) then
1722 if Blocks
.IsOverlapped(block
) then
1723 // if (coll_xy(x, y)=false) or (getBlockColl(item)=0) then
1725 if set_block_code(sblock
, x
, y
)=false then
1728 setmap(sblock
, x
, y
);
1731 inv
.setSum(inv
.getSum(invcur
)-1, invcur
);
1732 inv
.fixNull(invcur
);
1746 if (getrelativetimems
-fish_time
>5000) and (getmap(fx
,fy
)=50) then
1748 if (random(3)=2) and (getmap(fx
,fy
)=50) then
1750 drop
.create(210,1,x
,y
);
1753 inv
.setSum(inv
.getSum(invslot
)-1, invslot
);
1754 inv
.fixNull(invslot
);
1757 if (getrelativetimems
-fish_time
<5000) and (getmap(fx
,fy
)=50) and (fish
=true) then
1759 if getmap(fx
,fy
-1)=50 then fy
:=fy
-1;
1763 procedure drawminimap
;
1765 ix
,iy
,tmp_gx
,tmp_gy
,minx
,miny
,maxx
,maxy
,loc_camx
,loc_camy
,x
,y
:integer;
1769 if load_minimap_tex
then
1771 tmp_gx
:=(getWidth
/2)-(getimagewidth(gui
[16])/2);
1772 tmp_gy
:=(getHeight
/2)-(getimageheight(gui
[16])/2);
1776 tmp_gx
:=(getWidth
/2)-(64/2);
1777 tmp_gy
:=(getHeight
/2)-(64/2);
1780 loc_camx
:=(x
+4)-(864/2);
1781 loc_camy
:=(y
+4)-(864/2);
1782 if loc_camx
<0 then loc_camx
:=0;
1783 if loc_camx
>4096-864 then loc_camx
:=4096-864;
1784 if loc_camy
<0 then loc_camy
:=0;
1785 if loc_camy
>2048-864 then loc_camy
:=2048-864;
1788 maxx
:=(loc_camx
+864)/16;
1789 maxy
:=(loc_camy
+864)/16;
1790 if minx
<0 then minx
:=0;
1791 if miny
<0 then miny
:=0;
1792 if maxx
>255 then maxx
:=255;
1793 if maxy
>127 then maxy
:=127;
1795 if load_minimap_tex
then
1796 drawimage(gui
[16],tmp_gx
,tmp_gy
);
1799 setcolor(214,190,150);
1800 fillrect(tmp_gx
,tmp_gy
,64,64);
1803 for ix
:=minx
to maxx
do
1804 for iy
:=miny
to maxy
do
1806 if (getmap(ix
,iy
)=1) or (getmap(ix
,iy
)=2) or (getmap(ix
,iy
)=74) then setcolor(121,85,58); else
1807 if (getmap(ix
,iy
)=4) or (getmap(ix
,iy
)=9) or (getmap(ix
,iy
)=11) or (getmap(ix
,iy
)=28) or (getmap(ix
,iy
)=29) or ((getmap(ix
,iy
)>=77) and (getmap(ix
,iy
)<=86)) or ((getmap(ix
,iy
)>=88) and (getmap(ix
,iy
)<=101)) then setcolor(188,152,98); else
1808 if (getmap(ix
,iy
)=50) or (getmap(ix
,iy
)=62) then setcolor(38,92,255); else
1809 if getmap(ix
,iy
)=51 then setcolor(255,0,0); else
1810 if (getmap(ix
,iy
)=61) or (getmap(ix
,iy
)=32) then setcolor(255,255,255); else
1811 setcolor(127,127,127);
1813 if (getmap(ix
,iy
)<>0) then plot(tmp_gx
+4+ix
-minx
,tmp_gy
+4+iy
-miny
);
1818 procedure draw_sign
;
1821 str
:array[0..3] of string;
1822 i
,j
,tmp_gx
,tmp_gy
:integer;
1824 if load_gui_tex
then
1826 tmp_gx
:=(getWidth
/2)-(getimagewidth(sign_im
)/2);
1827 tmp_gy
:=(getHeight
/2)-(getimageheight(sign_im
)/2);
1831 tmp_gx
:=(getWidth
/2)-(120/2);
1832 tmp_gy
:=(getHeight
/2)-(60/2);
1835 tmp
:=t_sign
[getmapinfo(curx
,cury
)];
1836 while pos(tmp
,#13)<>-1 do
1839 str
[j
]:=copy(tmp
,0,i
);
1840 tmp
:=copy(tmp
,i
+1,length(tmp
));
1844 if load_gui_tex
then
1845 drawimage(sign_im
,tmp_gx
,tmp_gy
);
1848 setcolor(159,132,77);
1849 fillrect(tmp_gx
,tmp_gy
,120,60);
1852 drawfonttext(str
[0],tmp_gx
+(120/2)-(length(str
[0])*8/2),tmp_gy
+(60/4/2)+4);
1853 drawfonttext(str
[1],tmp_gx
+(120/2)-(length(str
[1])*8/2),tmp_gy
+(60/4/2)+8+4);
1854 drawfonttext(str
[2],tmp_gx
+(120/2)-(length(str
[2])*8/2),tmp_gy
+(60/4/2)+16+4);
1855 drawfonttext(str
[3],tmp_gx
+(120/2)-(length(str
[3])*8/2),tmp_gy
+(60/4/2)+24+4);
1858 procedure draw_back(ix
,iy
:integer);
1860 if getBiomMap(ix
)=0 then
1862 if (getBackMap(ix
)=iy
) then drawimage(back
[0],(ix
*16)-camx
,(iy
*16)-camy
); else
1863 if (getBackMap(ix
)+1=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1864 if (getBackMap(ix
)+2=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1865 if (getBackMap(ix
)+3=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1866 if (getBackMap(ix
)<iy
) then drawimage(back
[2],(ix
*16)-camx
,(iy
*16)-camy
);
1868 if getBiomMap(ix
)=1 then
1870 if (getBackMap(ix
)=iy
) then drawimage(back
[4],(ix
*16)-camx
,(iy
*16)-camy
); else
1871 if (getBackMap(ix
)+1=iy
) then drawimage(back
[4],(ix
*16)-camx
,(iy
*16)-camy
); else
1872 if (getBackMap(ix
)+2=iy
) then drawimage(back
[6],(ix
*16)-camx
,(iy
*16)-camy
); else
1873 if (getBackMap(ix
)+3=iy
) then drawimage(back
[6],(ix
*16)-camx
,(iy
*16)-camy
); else
1874 if (getBackMap(ix
)<iy
) then drawimage(back
[2],(ix
*16)-camx
,(iy
*16)-camy
);
1876 if getBiomMap(ix
)=2 then
1878 if (getBackMap(ix
)=iy
) then drawimage(back
[5],(ix
*16)-camx
,(iy
*16)-camy
); else
1879 if (getBackMap(ix
)+1=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1880 if (getBackMap(ix
)+2=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1881 if (getBackMap(ix
)+3=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1882 if (getBackMap(ix
)<iy
) then drawimage(back
[2],(ix
*16)-camx
,(iy
*16)-camy
);
1884 if getBiomMap(ix
)=3 then
1886 if (getBackMap(ix
)=iy
) then drawimage(back
[7],(ix
*16)-camx
,(iy
*16)-camy
); else
1887 if (getBackMap(ix
)+1=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1888 if (getBackMap(ix
)+2=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1889 if (getBackMap(ix
)+3=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1890 if (getBackMap(ix
)<iy
) then drawimage(back
[2],(ix
*16)-camx
,(iy
*16)-camy
);
1892 if getBiomMap(ix
)=4 then
1894 drawimage(back
[8],(ix
*16)-camx
,(iy
*16)-camy
);
1900 ix
,iy
,iz
,minx
,miny
,maxx
,maxy
,tmp_ax
,tim
,smy
,pa_xo
, x
, y
:integer;
1904 {===================[sky]===================}
1905 tim
:=10000*getimagewidth(sky
)/600000*game_time
/10000;
1906 setcolor(effects
.get(sky
,tim
,0,1),effects
.get(sky
,tim
,0,2),effects
.get(sky
,tim
,0,3));
1907 fillrect(0,0,getWidth
,getHeight
);
1911 setcolor(effects
.get(sky
,tim
,2,1),effects
.get(sky
,tim
,2,2),effects
.get(sky
,tim
,2,3));
1912 smy
:=10000*getWidth
*2/600000*game_time
/10000;
1913 for iz
:=1 to getWidth
do
1915 ix
:=rnd(getWidth
*2)-getWidth
+smy
;
1916 if ix
>getWidth
then ix
:=ix
-getWidth
*2;
1918 if (ix
>-1) and (ix
<getWidth
) then plot(ix
,iy
);
1926 smy
:=10000*(getWidth
+getimagewidth(sun
))/300000*game_time
/10000;
1927 drawimage(sun
,smy
-getimagewidth(sun
),getHeight
/2-getimageheight(sun
)/2);
1931 setcolor(255,213,74);
1932 smy
:=10000*(getWidth
+sm_siz
)/300000*game_time
/10000;
1933 fillrect(smy
-sm_siz
+sm_siz4
,getHeight
/2-sm_siz
/2+sm_siz4
,sm_siz
-sm_siz4
,sm_siz
-sm_siz4
);
1938 smy
:=10000*(getWidth
+getimagewidth(moon
))/300000*(game_time
-300000)/10000;
1939 drawimage(moon
,smy
-getimagewidth(moon
),getHeight
/2-getimageheight(moon
)/2);
1943 setcolor(175,184,204);
1944 smy
:=10000*(getWidth
+sm_siz
)/300000*(game_time
-300000)/10000;
1945 fillrect(smy
-sm_siz
+sm_siz4
,getHeight
/2-sm_siz
/2+sm_siz4
,sm_siz
-sm_siz4
,sm_siz
-sm_siz4
);
1948 {===================[camera]===================}
1949 camx
:=(x
+4)-(getWidth
/2);
1950 camy
:=(y
+4)-(getHeight
/2);
1951 if camx
<0 then camx
:=0;
1952 if camx
>4096-getWidth
then camx
:=4096-getWidth
;
1953 if camy
>2048-getHeight
then camy
:=2048-getHeight
;
1954 {===================[max_draw]===================}
1957 maxx
:=(camx
+getWidth
)/16;
1958 maxy
:=(camy
+getHeight
)/16;
1959 if minx
<0 then minx
:=0;
1960 if miny
<0 then miny
:=0;
1961 if maxx
>255 then maxx
:=255;
1962 if maxy
>127 then maxy
:=127;
1963 {===================[draw_back]===================}
1964 for ix
:=minx
to maxx
do
1965 for iy
:=miny
to maxy
do
1967 if ifosad
and osadki
and (getBackMap(ix
) >= iy
) and Blocks
.IsTransporent(getmap(ix
, iy
)) then begin
1968 if getBiomMap(ix
) = 0 then drawimage(osad
[0, osadki_ani
], (ix
* 16) - camx
, (iy
* 16) - camy
)
1969 else if getBiomMap(ix
) = 2 then drawimage(osad
[1, osadki_ani
], (ix
* 16) - camx
, (iy
* 16) - camy
)
1970 else if getBiomMap(ix
) = 3 then drawimage(osad
[0, osadki_ani
], (ix
* 16) - camx
, (iy
* 16) - camy
)
1972 if drw_back
and Blocks
.IsTransporent(getmap(ix
, iy
)) then draw_back(ix
, iy
);
1973 if Blocks
.IsForeground(getmap(ix
,iy
)) = false then BlocksLogic
.Draw(ix
, iy
, camx
, camy
);
1975 {===================[drop]===================}
1976 Drop
.Draw(camx
, camy
);
1977 {===================[particles]===================}
1978 Particles
.Draw(camx
, camy
);
1979 {===================[player]===================}
1980 Player
.Draw(camx
, camy
);
1981 {===================[mobs]===================}
1982 Mobs
.Draw(camx
, camy
);
1983 {===================[draw_blocks]===================}
1984 for ix
:=minx
to maxx
do
1985 for iy
:=miny
to maxy
do
1987 if Blocks
.IsForeground(getmap(ix
, iy
)) then BlocksLogic
.Draw(ix
, iy
, camx
, camy
);
1990 if light_type
= 1 then
1992 if getmaplight(ix
,iy
) = 0 then
1993 fillrect((ix
* 16) - camx
, (iy
* 16) - camy
, 16, 16);
1995 else if light_type
= 2 then
1997 if getmaplight(ix
, iy
) < 15 then
1998 drawimage(light
[getmaplight(ix
, iy
)], (ix
* 16) - camx
, (iy
* 16) - camy
);
2003 // drawimage(light[getmaplight(player.getX div 16, player.getY div 16)], 0, 0);
2005 if (toolus
> 0) and (toolind
< 10) and (getmap(curx
,cury
) > 0) then
2009 drawimage(tue
[toolind
], curx
* 16 - camx
, cury
* 16 - camy
);
2011 {===================[gui]===================}
2014 tmp_ax
:=(getWidth
/2)-(getImageWidth(gui
[1])/2);
2017 drawimage(gui
[0],curx
*16-camx
,cury
*16-camy
);
2022 DrawPlayerInventory
;
2025 if keymode
=3 then drawcraft
; else
2026 if keymode
=4 then drawchest
; else
2027 if keymode
=5 then draw_sign
; else
2028 if keymode
=6 then drawfurnace
; else
2029 if ifminimap
then drawminimap
;*/
2031 drawimage(gui
[1],tmp_ax
,0);
2034 ItemsLogic
.Draw(inv
.getItem(ix
), inv
.getSum(ix
), (ix
*16)+tmp_ax
+ix
*2+4, 1, true);
2036 drawimage(gui
[17],(invslot
*16)+tmp_ax
+invslot
*2+2,0);
2042 for ix
:=0 to (hp
div 2)-1 do drawimage(gui
[13],ix
*9,getHeight
-9);
2043 if (hp
mod 2)<>0 then begin drawimage(gui
[14],ix
*9,getHeight
-9); ix
:=ix
+1 end;
2044 for ix
:=ix
to 9 do drawimage(gui
[15],ix
*9,getHeight
-9);
2048 for ix
:=0 to (hp
div 2)-1 do drawimage(gui
[31],ix
*9,getHeight
-9);
2049 if (hp
mod 2)<>0 then begin drawimage(gui
[32],ix
*9,getHeight
-9); ix
:=ix
+1 end;
2050 for ix
:=ix
to 9 do drawimage(gui
[33],ix
*9,getHeight
-9);
2053 for ix
:=0 to (hunger
div 2)-1 do drawimage(gui
[26],ix
*9,getHeight
-18);
2054 if (hunger
mod 2)<>0 then begin drawimage(gui
[27],ix
*9,getHeight
-18); ix
:=ix
+1 end;
2055 for ix
:=ix
to 9 do drawimage(gui
[28],ix
*9,getHeight
-18);
2057 if getmap((x
+4)/16,y
/16)=50 then
2059 for ix
:=0 to (air
div 2)-1 do drawimage(gui
[29],ix
*9,getHeight
-27);
2060 if (air
mod 2)<>0 then begin drawimage(gui
[30],ix
*9,getHeight
-27); ix
:=ix
+1 end;
2066 drawfonttext(msg
[ix
],0,getHeight
-20-ix
*9);
2067 if getrelativetimems
-msg_time
[ix
]>5000 then msg
[ix
]:='';
2072 procedure load_moon(path
:string;phase
:integer);
2079 moon
:=ld_tex('moon_phase_'+phase
+'.png',path
,'terrain/moon_phases/');
2083 moon
:=resize_image(ld_tex('moon_phase_'+phase
+'.png',path
,'terrain/moon_phases/'),(getWidth
+getHeight
)/5,(getWidth
+getHeight
)/5);
2091 if game_time
>300000 then
2093 if load_light_tex
then
2099 for iy
:=0 to getheight
/16 do
2100 for ix
:=0 to getwidth
/16 do
2101 drawimage(light
[i
],ix
*16,iy
*16);
2106 moon_phase
:=moon_phase
+1;
2107 if moon_phase
>7 then moon_phase
:=0;
2108 load_moon('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/',moon_phase
);
2111 last_sleep_y
:=cury
-1;
2116 for iy
:=0 to getheight
/16 do
2117 for ix
:=0 to getwidth
/16 do
2118 drawimage(light
[i
],ix
*16,iy
*16);
2128 while i
<=getheight
do
2131 fillrect(0,0,getwidth
,i
);
2136 moon_phase
:=moon_phase
+1;
2137 if moon_phase
>7 then moon_phase
:=0;
2138 load_moon('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/',moon_phase
);
2141 last_sleep_y
:=cury
-1;
2143 while i
<=getheight
do
2147 fillrect(0,i
,getwidth
,getheight
);
2153 end; else create_msg('You can sleep only at night');
2156 procedure resetToolProgerss
;
2162 procedure usetools(invcur
, x
, y
: integer);
2164 item
, sum
, block
, tool
: integer;
2166 block
:= GetMap(x
, y
);
2167 item
:= Inv
.GetItem(invcur
);
2168 sum
:= Inv
.GetSum(invcur
);
2169 tool
:= Items
.GetData(item
);
2171 if gamemode
= 1 then begin
2172 destroy_block_cr(block
, x
, y
);
2173 end else if block
<> 0 then begin
2174 if (Items
.GetType(item
) = Items
.tool
) and (Blocks
.GetTool(block
) = Tools
.GetType(tool
)) then begin
2175 toolus
:= toolus
+ Tools
.GetSpeed(tool
);
2177 toolus
:= toolus
+ 1;
2180 if toolus
>= Blocks
.GetResistant(block
) then begin
2181 Debug('usetools: tool = ' + tool
);
2182 if ((Items
.GetType(item
) = Items
.tool
) and (Blocks
.GetTool(block
) = Tools
.GetType(tool
)) and (Tools
.GetLevel(tool
) >= Blocks
.GetLevel(block
))) or (Blocks
.GetLevel(block
) <= 0) then begin
2184 destroy_block_1(block
, x
, y
);
2185 SetMapInfo(0, x
, y
);
2188 destroy_block_0(block
, x
, y
);
2189 SetMapInfo(0, x
, y
);
2192 if Items
.GetType(item
) = Items
.tool
then begin
2193 Inv
.SetSum(Inv
.GetSum(invcur
) - 1, invcur
);
2194 Inv
.FixNull(invcur
);
2202 if (toolus
> 0) and (toolus
<= Blocks
.GetResistant(block
)) then begin
2203 toolind
:= ((toolus
* 100) div Blocks
.GetResistant(block
)) div 10;
2207 function rt_useweap
:boolean;
2210 x
, y
, w
, h
, i
, damg
: integer;
2216 item
:= Inv
.GetItem(invslot
);
2217 if Items
.GetType(item
) = Items
.tool
then damg
:= Tools
.GetDamage(item
) else damg
:= 1;
2219 if posi
=0 then i
:= Mobs
.FindAndHit(damg
, x
- TILE_SIZE
, y
, TILE_SIZE
+ (w
/ 2), h
, -2, -3);
2220 else i
:= Mobs
.FindAndHit(damg
, x
+ (w
/ 2), y
, TILE_SIZE
+ (w
/ 2), h
, 2, -3);
2222 if i
>= 0 then begin
2223 Inv
.SetSum(Inv
.GetSum(invslot
) - 1, invslot
);
2224 Inv
.FixNull(invslot
);
2229 procedure rt_usetools
;
2236 if posi
=0 then curx
:=(x
div 16)-1; else curx
:=(x
div 16)+1;
2238 if getmap(curx
,cury
)=0 then cury
:=cury
+1;
2240 if curx
<0 then curx
:=0;
2241 if curx
>255 then curx
:=255;
2242 if cury
<0 then cury
:=0;
2243 if cury
>127 then cury
:=127;
2245 usetools(invslot
, curx
, cury
);
2248 procedure rt_usemob
;
2255 if posi
=0 then curx
:=(x
div 16)-1; else curx
:=(x
div 16)+1;
2257 if getmap(curx
,cury
)=0 then cury
:=cury
+1;
2259 if curx
<0 then curx
:=0;
2260 if curx
>255 then curx
:=255;
2261 if cury
<0 then cury
:=0;
2262 if cury
>127 then cury
:=127;
2264 //usemob(curx,cury);
2267 procedure actionUse(invcur
, x
, y
:integer);
2269 if setBlock(invcur
, x
, y
)=false then
2270 if useBlock(invcur
, x
, y
) then
2271 if useItem(invcur
, x
, y
) then
2274 procedure rt_useblock
;
2281 if posi
=0 then curx
:=(x
div 16)-1; else curx
:=(x
div 16)+1;
2283 if getmap(curx
,cury
)=0 then cury
:=cury
+1;
2285 if curx
<0 then curx
:=0;
2286 if curx
>255 then curx
:=255;
2287 if cury
<0 then cury
:=0;
2288 if cury
>127 then cury
:=127;
2290 actionUse(invslot
, curx
, cury
);
2293 procedure go_to_nether
;
2297 portal_time
:=getrelativetimems
;
2298 savegame('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/');
2300 drw_load_line('Matrix',10);
2301 if loadworld('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/')=true then
2303 player
.setX(get_spawn_x
*16+4);
2304 player
.setY((get_up(get_spawn_x
)-1)*16);
2317 mob[ix].m_min_vely:=0;
2320 mob[ix].m_fall:=false;
2321 mob[ix].m_jmp:=false;
2322 mob[ix].m_velani:=false;
2331 procedure go_to_world
;
2333 portal_time
:=getrelativetimems
;
2334 savegame('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/');
2336 drw_load_line('Matrix',10);
2337 if loadworld('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/')=true then
2350 procedure plr_is_dead_hardcore
;
2358 if clickedKey(KEY_MENU_SELECT
) then
2360 deleteworld('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/');
2365 drawfonttext('You died!',getwidth
/2-32,getheight
/2-16);
2367 drw_btn('Delete world',0,0,0,1);
2375 procedure plr_is_dead
;
2387 if clickedKey(KEY_MENU_UP
) then
2390 if m_cur
<0 then m_cur
:=1;
2392 if clickedKey(KEY_MENU_DOWN
) then
2395 if m_cur
>1 then m_cur
:=0;
2397 if clickedKey(KEY_MENU_SELECT
) then
2403 if last_sleep_x
=0 then
2405 x
:=get_spawn_x
*16+4;
2409 x
:=last_sleep_x
*16+4;
2416 if last_sleep_x
=0 then
2418 x
:=get_spawn_x
*16+4;
2422 x
:=last_sleep_x
*16+4;
2438 if m_cur
=1 then begin menu
; exit
; end;
2443 drawfonttext('You died!',getwidth
/2-32,getheight
/2-16);
2445 drw_btn('Respawn',0,m_cur
,0,1);
2446 drw_btn('Main menu',1,m_cur
,0,1);
2453 procedure fast_menu
;
2459 if clickedKey(KEY_MENU_UP
) then begin m_cur
:=m_cur
-1; if m_cur
<0 then m_cur
:=3; end;
2460 if clickedKey(KEY_MENU_DOWN
) then begin m_cur
:=m_cur
+1; if m_cur
>3 then m_cur
:=0; end;
2461 if clickedKey(KEY_MENU_SELECT
) then
2469 savegame('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/');
2478 //clear_gui(keymode);
2484 drawfonttext('Game menu',getwidth
/2-36,getheight
/2-20);
2485 drw_btn('Back to Game',0,m_cur
,0,1);
2486 drw_btn('Save Game',1,m_cur
,0,1);
2487 drw_btn('Options',2,m_cur
,0,1);
2488 drw_btn('Quit to Title',3,m_cur
,0,1);
2495 procedure keyFastInv
;
2497 if clickedKey(KEY_FASTINV_NEXT
) then
2504 if clickedKey(KEY_FASTINV_PREV
) then
2512 procedure keyConsole
;
2514 if clickedKey(KEY_CHAT
) then
2515 SetTimer(1000,T_CONSOLE
);
2517 if pressedKey(KEY_CHAT
) then
2519 if GetTimer(T_CONSOLE
)=TIMER_OK
then
2522 ResetTimer(T_CONSOLE
);
2527 if GetTimer(T_CONSOLE
)>TIMER_OK
then
2530 ResetTimer(T_CONSOLE
);
2535 procedure keyInventory
;
2537 if clickedKey(KEY_PLR_OPENINV
) then
2539 OpenPlayerInventory
;
2544 procedure keyhandler
;
2548 if WindowKeyHanler
then
2556 if clickedKey(KEY_PLR_EDITMODE
) then
2559 curx
:=player
.getX
div 16;
2560 cury
:=player
.getY
div 16;
2563 if clickedKey(KEY_PLR_USE
) then
2566 if clickedKey(KEY_MENU
) then
2569 if clickedKey(KEY_PLR_ATTACK
) then
2570 if rt_useweap
=false then
2573 if pressedKey(KEY_PLR_ATTACK
) then
2576 playAnim(ANIM_HAND
);
2581 cancelAnim(ANIM_HAND
);
2584 if pressedKey(KEY_PLR_UP
) then
2586 if pressedKey(KEY_PLR_DOWN
) then
2588 if pressedKey(KEY_PLR_LEFT
) then
2590 if pressedKey(KEY_PLR_RIGHT
) then
2600 if clickedKey(KEY_PLR_UP
) then
2606 if clickedKey(KEY_PLR_DOWN
) then
2612 if clickedKey(KEY_PLR_LEFT
) then
2618 if clickedKey(KEY_PLR_RIGHT
) then
2625 if clickedKey(KEY_PLR_EDITMODE
) then
2628 if clickedKey(KEY_PLR_USE
) then
2629 actionUse(invslot
, curx
, cury
);
2631 if pressedKey(KEY_PLR_ATTACK
) then
2633 usetools(invslot
, curx
, cury
);
2634 playAnim(ANIM_HAND
);
2639 cancelAnim(ANIM_HAND
);
2642 if clickedKey(KEY_MENU
) then
2650 procedure phyhandler
;
2659 procedure light_fillrect(l
,x
,y
,r
:integer);
2661 ix
,iy
,ym
,yp
,xm
,xp
:integer;
2669 setmaplight(getmaplight(ix
,iy
)+l
,ix
,iy
);
2672 procedure light_rect(l
,x
,y
,r
:integer);
2674 ix
,iy
,ym
,yp
,xm
,xp
:integer;
2682 setmaplight(getmaplight(ix
,ym
)+l
,ix
,ym
);
2683 setmaplight(getmaplight(ix
,yp
)+l
,ix
,yp
);
2685 for iy
:=ym
+1 to yp
-1 do
2687 setmaplight(getmaplight(xm
,iy
)+l
,xm
,iy
);
2688 setmaplight(getmaplight(xp
,iy
)+l
,xp
,iy
);
2692 procedure calc_light(m
,x
,y
:integer);
2694 ix
,iy
,l
,ss
,sf
:integer;
2696 if light_type
=1 then light_fillrect(m
,x
,y
,m
/2); else
2697 for l
:=m
downto 1 do
2699 if ss
mod 2=0 then light_rect(l
,x
,y
,ss
/2);
2704 procedure calc_sun(ix
,m
:integer);
2711 setmaplight(ss
,ix
,iy
);
2713 ss
:= ss
- Blocks
.GetLightAbsorbtion(getmap(ix
, iy
));
2716 for iy
:=iy
+1 to 127 do
2718 setmaplight(0,ix
,iy
);
2727 for i
:=0 to INV_SIZE
do
2729 if inv
.isNull(i
)=false then
2730 player
.dropItem(inv
.getItem(i
), inv
.getSum(i
));
2734 if gamemode
<2 then plr_is_dead
; else plr_is_dead_hardcore
;
2737 procedure hunger_and_air
;
2745 if getrelativetimems
-hung_time
>=90000/(gamemode
+1) then
2747 hung_time
:=getrelativetimems
;
2750 if getrelativetimems
-hp_time
>=5000*(gamemode
+1) then
2754 hp_time
:=getrelativetimems
;
2756 if hp
>20 then hp
:=20;
2760 hp_time
:=getrelativetimems
;
2762 if hp
<1 then if gamemode
<2 then hp
:=1;
2766 if getmap((x
+4)/16,y
/16)=50 then
2768 if getrelativetimems
-air_time
>=500 then
2771 air_time
:=getrelativetimems
;
2774 hp_time
:=getrelativetimems
;
2785 ix
,iy
,minx
,maxx
,miny
,maxy
,fps_t
,tim
, x
, y
:integer;
2792 if hunger
<0 then hunger
:=0;
2793 if air
<0 then air
:=0;
2796 if fps_t
<1 then fps_t
:=1;
2799 if bl_ani5_v
=false then
2805 bl_ani5_v
:=not bl_ani5_v
;
2814 bl_ani5_v
:=not bl_ani5_v
;
2817 bl_ani5_d
:=not bl_ani5_d
;
2822 game_time
:=game_time
+(600000 div (fps_t
*1000));
2824 // Ускорение игрового времени в 10 раз
2825 // game_time := game_time + (600000 div (fps_t*100));
2827 if (game_time
>600000) or (game_time
<0) then
2830 moon_phase
:=moon_phase
+1;
2831 if moon_phase
>7 then moon_phase
:=0;
2832 load_moon('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/',moon_phase
);
2835 tim
:= 10000 * getimagewidth(sky
) / 600000 * game_time
/ 10000;
2836 global_light
:= effects
.get(sky
, tim
, 1, 1) div 16;
2838 if clock_stage
<>game_time
div 75000 then begin clock_stage
:=clock_stage
+1; if clock_stage
>7 then clock_stage
:=0; end;
2840 if x
< 0 then x
:= 0;
2841 else if x
+ 8 > 4094 then x
:= 4086;
2842 if Blocks
.IsSolid(getmap(x
div 16, y
div 16)) then hp
:= hp
- 1;
2844 if random(4096)=random(4096) then begin osadki
:=not osadki
; end;
2845 osadki_ani
:=osadki_ani
+1;
2846 if osadki_ani
>7 then osadki_ani
:=0;
2848 if Random(20) = Random(20) then Particles
.Create(Particles
.bubble
, x
, y
);
2850 if gamemode
=1 then begin hp
:=666; hunger
:=666; end;
2852 if inv
.getItem(invslot
)=186 then
2857 //if s_spawn_mob then if random(4096)=1547 then megaspawn;
2862 if light_type
>0 then
2865 maxx
:=(camx
+getWidth
)/16+1;
2866 if minx
<0 then minx
:=0;
2867 if maxx
>255 then maxx
:=255;
2868 for ix
:=minx
to maxx
do calc_sun(ix
,global_light
);
2872 maxx
:=(camx
+getWidth
)/16+16;
2874 maxy
:=(camy
+getHeight
)/16+16;
2875 if minx
<0 then minx
:=0;
2876 if maxx
>255 then maxx
:=255;
2877 if miny
<0 then miny
:=0;
2878 if maxy
>127 then maxy
:=127;
2879 for ix
:=minx
to maxx
do
2880 for iy
:=miny
to maxy
do
2882 if light_type
= 0 then begin
2883 SetMapLight(15, ix
, iy
);
2884 end else if (light_type
> 0) and (Blocks
.GetLightEmission(getmap(ix
, iy
)) > 0) then begin
2885 calc_light(Blocks
.GetLightEmission(GetMap(ix
, iy
)), ix
, iy
);
2889 minx
:=(camx
/16)-((getwidth
/2)/16);
2890 miny
:=(camy
/16)-((getheight
/2)/16);
2891 maxx
:=(camx
+(getWidth
+getWidth
/2))/16;
2892 maxy
:=(camy
+(getHeight
+getHeight
/2))/16;
2893 if minx
<0 then minx
:=0;
2894 if miny
<0 then miny
:=0;
2895 if maxx
>255 then maxx
:=255;
2896 if maxy
>127 then maxy
:=127;
2897 if updx
<minx
then updx
:=minx
;
2898 if updy
<miny
then updy
:=miny
;
2899 if updx
>maxx
then updx
:=minx
;
2900 if updy
>maxy
then updy
:=miny
;
2904 for ix
:=0 to (((2*getWidth
/16)*(2*getHeight
/16))-1) div ((fps_t
*bl_upd
)) do
2906 updateBlock(updx
, updy
);
2912 if updy
>maxy
then updy
:=miny
;
2917 {if coll_bl(110)=true then
2919 if getrelativetimems-portal_time>5000 then
2921 if pl_world=0 then begin go_to_nether; portal_time:=getrelativetimems; end; else
2922 if pl_world=1 then begin go_to_world; portal_time:=getrelativetimems; end;
2926 if coll_bl(51)=true then hp:=hp-1;
2928 if coll_bl(59)=true then
2930 if vely<0 then vely:=-1;
2932 if vely>0 then vely:=1;
2937 if hp
>20 then hp
:=20;
2938 if hunger
>20 then hunger
:=20;
2941 if y
>2048 then kill_plr
;
2942 if (hp
<1) and (gamemode
<>1) then kill_plr
;
2943 if fish
=true then fishing
;
2945 if (fish
=true) and (inv
.getItem(invslot
)<>152) then fish
:=false;
2947 //if (keymode>3) and (cury<(y div 16)-4) then begin clear_gui(keymode); keymode:=0; curx:=x div 16; cury:=y div 16; end;
2951 if cury
<(y
div 16)-4 then cury
:=(y
div 16)-4;
2952 if cury
>(y
div 16)+5 then cury
:=(y
div 16)+5;
2953 if curx
<(x
div 16)-4 then curx
:=(x
div 16)-4;
2954 if curx
>(x
div 16)+4 then curx
:=(x
div 16)+4;
2965 LoadDrawFont('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
2968 if load_key_tex
=1 then init_touch
;
2972 msg_time
[i
]:=getrelativetimems
;
2974 InitMap(MAP_W
, MAP_H
);
2978 procedure draw_debug
;
2982 //drawfonttext('X:'+(x div 16-128),0,0);
2983 //drawfonttext('Y:'+integertostring(127-(y div 16)),0,8);
2984 drawfonttext('CURX:'+(curx
-128),0,16);
2985 drawfonttext('CURY:'+cury
,0,24);
2986 drawfonttext('UPDX:'+updx
,0,32);
2987 drawfonttext('UPDY:'+updy
,0,40);
2988 drawfonttext('FPS:'+fps
,0,56);
2989 drawfonttext('Free RAM:'+free_ram
/1024+' KB',0,64);
2990 drawfonttext('Total RAM:'+memory
.get_totalmemory
div 1024+' KB',0,72);
2991 drawfonttext('SEED:'+seed
,0,88);
2992 drawfonttext('Game time:'+game_time
,0,96);
2993 drawfonttext('Global light:' + global_light
, 0, 104);
2996 drawImage(light
[i
], getWidth
- 16, 16 * i
);
3001 hung_time
:=getrelativetimems
;
3002 hp_time
:=getrelativetimems
;
3003 air_time
:=getrelativetimems
;
3004 portal_time
:=getrelativetimems
;
3012 drawfonttext(version
,getWidth
-(length(version
)*8),getHeight
-8);
3013 if getrelativetimems
-msg_time
[4]>500 then begin free_ram
:=memory
.get_freememory
; if free_ram
<0 then free_ram
:=-free_ram
; msg_time
[4]:=getrelativetimems
; end;