0d305849e358ef1108de30fb24a68376cf90e8e9
37 keymode
,updx
,updy
:integer;
38 seed
,nextseed
:integer;
41 light
:array [0..15] of image
;
42 bg
:array[0..1] of image
;
43 osad
:array [0..1,0..7] of image
;
44 back
:array [0..8] of image
;
45 gui
:array [0..34] of image
;
46 tue
:array [0..9] of image
;
53 toolus
,toolind
:integer;
60 msg
:array [0..4] of string;
61 msg_time
:array[0..4] of integer;
62 last_sleep_x
,last_sleep_y
:integer;
75 if nextseed
=0 then seed
:=getrelativetimems
; else seed
:=nextseed
;
78 if world_typ
=0 then genworld
;
80 if world_typ
=1 then genflat
;
82 player
.setX(get_spawn_x
*16+4);
83 player
.setY(get_spawn_y
*16);
87 procedure drwrect(x
,y
,w
,h
,t
:integer);
92 drawrect(x
+i
,y
+i
,w
-i
*2,h
-i
*2);
97 dt
:=GetRelativeTimeMs
- time
;
98 time
:=GetRelativeTimeMs
;
104 if fps
<s_max_fps
then if del
>0 then del
:=del
-1;
105 if fps
>s_max_fps
then if del
<200 then del
:=del
+1;
109 procedure ClearTextures
;
112 ix
, iy
, iz
: integer;
121 for ix
:= 0 to maxBlockTex
do
126 for ix
:= 0 to maxItemTex
do
149 Particles
.FreeTextures
;
157 for ix
:= 0 to CONST_MAX_CURS
do
160 //resetVirtualKeyboard(-1);
163 procedure create_msg(s
:string);
170 msg_time
[i
]:=msg_time
[i
-1];
173 msg_time
[0]:=getrelativetimems
;
177 procedure loadtexture(path
:string);
183 im
:=ld_tex('background.png',path
,'title/');
185 bg
[ix
]:=rotate_image_from_image(im
,ix
*16,0,16,16,0);
186 float
:=ld_tex('float.png',path
,'gui/');
187 compas
:=ld_tex('compass.png',path
,'gui/');
188 im
:=ld_tex('clock.png',path
,'gui/');
190 clock
[ix
]:=rotate_image_from_image(im
,ix
*16,0,16,16,0);
191 if load_back_tex
then
193 im
:=ld_tex('back.png',path
,'');
194 for ix
:=0 to 8 do back
[ix
]:=rotate_image_from_image(im
,ix
*16,0,16,16,0);
197 console
.exec('textures.cfg', 'AUTO');
199 Player
.LoadSkin('char_ani.png', path
);
200 Mobs
.LoadTextures(path
);
202 im
:=ld_tex('gui.png',path
,'gui/');
203 gui
[0]:=rotate_image_from_image(im
,0,0,16,16,0);
204 LoadCurImg(gui
[0], CUR_SELECT1
);
205 gui
[1]:=rotate_image_from_image(im
,0,16,168,21,0);
206 gui
[3]:=rotate_image_from_image(im
,16,0,16,16,0);
207 LoadCurImg(gui
[3], CUR_SELECT2
);
208 gui
[6]:=rotate_image_from_image(im
,0,56,120,12,0);
209 gui
[7]:=rotate_image_from_image(im
,0,68,120,12,0);
210 gui
[8]:=rotate_image_from_image(im
,0,80,120,12,0);
211 gui
[13]:=rotate_image_from_image(im
,1,93,9,9,0);//hp
212 gui
[14]:=rotate_image_from_image(im
,12,93,9,9,0);//hp
213 gui
[15]:=rotate_image_from_image(im
,23,93,9,9,0);//hp
214 gui
[17]:=rotate_image_from_image(im
,120,56,18,18,0);
216 gui
[26]:=rotate_image_from_image(im
,89,93,9,9,0);//hunger
217 gui
[27]:=rotate_image_from_image(im
,100,93,9,9,0);//hunger
218 gui
[28]:=rotate_image_from_image(im
,111,93,9,9,0);//hunger
220 gui
[29]:=rotate_image_from_image(im
,67,93,9,9,0);//air
221 gui
[30]:=rotate_image_from_image(im
,78,93,9,9,0);//air
223 gui
[31]:=rotate_image_from_image(im
,122,93,9,9,0);//hp hardcore
224 gui
[32]:=rotate_image_from_image(im
,133,93,9,9,0);//hp hardcore
225 gui
[33]:=rotate_image_from_image(im
,144,93,9,9,0);//hp hardcore
227 gui
[20]:=rotate_image_from_image(im
,121,75,9,13,0);
228 gui
[21]:=rotate_image_from_image(im
,130,75,9,13,0);
229 gui
[22]:=rotate_image_from_image(im
,0,103,120,12,0);
231 if load_minimap_tex
then gui
[16]:=ld_tex('mapbg.png',path
,'gui/');
233 for ix
:=0 to 9 do tue
[ix
]:=rotate_image_from_image(im
,16*ix
,40,16,16,0);
235 if load_weather_tex
then
237 im
:=ld_tex('rain.png',path
,'terrain/');
238 for ix
:=0 to 7 do osad
[0,ix
]:=rotate_image_from_image(im
,16*ix
,0,16,16,0);
239 im
:=ld_tex('snow.png',path
,'terrain/');
240 for ix
:=0 to 7 do osad
[1,ix
]:=rotate_image_from_image(im
,16*ix
,0,16,16,0);
243 if load_light_tex
then
245 im
:=ld_tex('light.png',path
,'terrain/');
246 for ix
:=0 to 15 do light
[ix
]:=rotate_image_from_image(im
,16*ix
,0,16,16,0);
249 Particles
.LoadTextures(path
);
251 im
:=ld_tex('partition.png',path
,'gui/');
252 gui
[18]:=rotate_image_from_image(im
,0,0,84,42,0);
253 gui
[19]:=rotate_image_from_image(im
,0,42,4,4,0);
255 if load_sky_siz
<=0 then
256 sky
:=ld_tex('sky.png',path
,'terrain/');
258 sky
:=resize_image(ld_tex('sky.png',path
,'terrain/'),load_sky_siz
,2);
262 sun
:=ld_tex('sun.png',path
,'terrain/');
263 moon
:=ld_tex('moon_phase_0.png',path
,'terrain/moon_phases/');
267 sun
:=resize_image(ld_tex('sun.png',path
,'terrain/'),(getWidth
+getHeight
)/5,(getWidth
+getHeight
)/5);
268 moon
:=resize_image(ld_tex('moon_phase_0.png',path
,'terrain/moon_phases/'),(getWidth
+getHeight
)/5,(getWidth
+getHeight
)/5);
271 //load_virt_tex(ld_tex('touch.png',path,'gui/'));
329 setmaplight(0,ix
,iy
);
339 for ix
:=0 to CONST_MAX_LAYERS
do
343 procedure drw_load_line(s
:string;percent
:integer);
347 for ix
:=0 to getWidth
/16 do
348 for iy
:=0 to getHeight
/16 do
349 drawimage(bg
[0],ix
*16,iy
*16);
350 drawfonttext(s
,(getWidth
/2)-(length(s
)*8/2),(getHeight
/2)-8);
351 setcolor(128,128,128);
352 fillrect(getwidth
/2-50,getheight
/2+6,100,3);
353 setcolor(128,255,128);
354 fillrect(getwidth
/2-50,getheight
/2+6,percent
,3);
355 drawfonttext(integertostring(percent
)+'%',getwidth
/2-(length(integertostring(percent
)+'%')*8)/2,getheight
/2+12);
359 function getFlatMap(i
:integer):integer;
365 getFlatMap
:=getmap(ix
,iy
);
368 procedure setFlatMap(n
, i
:integer);
377 function getFlatMapInfo(i
:integer):integer;
383 getFlatMapInfo
:=getmapinfo(ix
,iy
);
386 procedure setFlatMapInfo(n
, i
:integer);
395 procedure SaveMapRLE
;
403 if (id
<>getFlatMap(i
+s
)) or (i
+s
>32767) then
413 procedure SaveMapInfoRLE
;
419 id
:=getFlatMapInfo(i
);
421 if (id
<>getFlatMapInfo(i
+s
)) or (i
+s
>32767) then
431 procedure LoadMapRLE
;
446 procedure LoadMapInfoRLE
;
455 setFlatMapInfo(id
, i
+j
);
461 procedure saveworld(path
:string);
466 if pl_world
=0 then world_name
:='world.sav';
468 if pl_world
=1 then world_name
:='nether.sav';
469 if file_exists(path
)<>1 then if create_folder(path
)=1 then debug('Folder created!');
470 if file_exists(path
+world_name
)>0 then delete_file(path
+world_name
);
471 if file_exists(path
+world_name
)<>1 then file_create(path
+world_name
);
472 if open_file(path
+world_name
)=1 then
474 writeint(player
.getX
);
475 writeint(player
.getY
);
479 drw_load_line('Background',50);
480 //Background and biomes
483 write_byte(getBackMap(ix
));
484 write_byte(getBiomMap(ix
));
487 drw_load_line('Chests', 55);
489 drw_load_line('Furnaces', 60);
491 drw_load_line('Mobs', 70);
493 drw_load_line('Drop', 80);
495 drw_load_line('Particles', 85);
498 drw_load_line('Other', 90);
502 write_byte(osadki_ani
);
503 write_byte(global_light
);
506 write_byte(clock_stage
);
509 writebool(b_sign
[ix
]);
510 writestr(t_sign
[ix
]);
513 drw_load_line('Ready',100);
514 if close_file(path
+world_name
)=1 then debug('World Saved!');
518 procedure savegame(path
:string);
522 drw_load_line('Basic',0);
523 if file_exists(path
+'player.dat')=1 then delete_file(path
+'player.dat');
524 if file_exists(path
)<>1 then if create_folder(path
)=1 then debug('Folder created!');
525 if file_exists(path
+'player.dat')<>1 then file_create(path
+'player.dat');
526 if open_file(path
+'player.dat')=1 then
529 write_byte(version_map
);
530 write_byte(gamemode
);
533 write_byte(pl_world
);
535 writeint(last_sleep_x
);
536 writeint(last_sleep_y
);
543 write_byte(moon_phase
);
546 if close_file(path
+'player.dat')=1 then debug('Saved!');
547 drw_load_line('Matrix',10);
553 function version_err(ver
:integer):boolean;
557 for ix
:=0 to getWidth
/16 do
558 for iy
:=0 to getHeight
/16 do
560 drawimage(bg
[0],ix
*16,iy
*16);
562 if version_map
=ver
then version_err
:=true; else
563 if version_map
>ver
then
565 drawfonttext('Old save format!',(getWidth
/2)-60,(getHeight
/2)-4);
570 if version_map
<ver
then
572 drawfonttext('New save format!',(getWidth
/2)-60,(getHeight
/2)-4);
580 function loadworld(path
:string):boolean;
585 if pl_world
=0 then world_name
:='world.sav';
587 if pl_world
=1 then world_name
:='nether.sav';
588 if file_exists(path
)=1 then
590 if file_exists(path
+world_name
)=1 then
592 if open_file(path
+world_name
)=1 then
594 player
.setX(readint
);
595 player
.setY(readint
);
599 drw_load_line('Background',50);
600 //Background and biomes
603 setBackMap(read_byte
, ix
);
604 setBiomMap(read_byte
, ix
);
606 drw_load_line('Chests', 55);
608 drw_load_line('Furnaces', 60);
611 drw_load_line('Drop', 80);
613 drw_load_line('Particles', 85);
616 drw_load_line('Other',90);
620 osadki_ani
:=read_byte
;
621 global_light
:=read_byte
;
624 clock_stage
:=read_byte
;
627 b_sign
[ix
]:=readbool
;
630 drw_load_line('Ready',100);
631 ///////////////////////
632 if close_file(path
+world_name
)=1 then begin loadworld
:=true; debug('World loaded!'); end;
633 end; else begin loadworld
:=false; debug('File not opened!'); end;
634 end; else begin loadworld
:=false; debug('File not exists!'); end;
635 end; else begin loadworld
:=false; debug('Folder not exists!'); end;
638 function loadgame(path
:string):boolean;
642 drw_load_line('Basic',0);
643 if file_exists(path
)=1 then
645 if file_exists(path
+'player.dat')=1 then
647 if open_file(path
+'player.dat')=1 then
651 if version_err(ver
)=false then
653 if close_file(path
+'player.dat')=1 then loadgame
:=false;
661 last_sleep_x
:=readint
;
662 last_sleep_y
:=readint
;
669 moon_phase
:=read_byte
;
672 drw_load_line('Matrix',10);
673 if close_file(path
+'player.dat')=1 then loadgame
:=loadworld(path
);
674 end; else loadgame
:=false;
675 end; else loadgame
:=false;
676 end; else loadgame
:=false;
679 procedure drawdeadlogo
;
684 fillrect(0,0,getWidth
,getHeight
);
685 dead
:=loadimage('/dl');
686 drawimage(dead
,(getWidth
/2)-(getimagewidth(dead
)/2),(getHeight
/2)-(getimageheight(dead
)/2));
687 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));
688 drawfonttext('Loading...',(getWidth
/2)-(40),getHeight
-8);
697 for ix
:=0 to getWidth
/16 do
698 for iy
:=0 to getHeight
/16 do
700 drawimage(bg
[0],ix
*16,iy
*16);
702 drawfonttext('Generation World...',(getWidth
/2)-(76),(getHeight
/2)-4);
708 //if s_spawn_mob then begin if pl_world=0 then begin megaspawn; end; else begin netherspawn; end; end;
709 if gamemode
=1 then fly
:=true else fly
:=false;
713 function gettext(text,text_f
:string; max
,typ
:integer;):string;
715 textField_id
:integer;
719 exitCmd
:=createCommand('Ok',CM_OK
,1);
722 textField_id
:=formAddTextField(text,text_f
,max
,typ
);
726 cli
:=getClickedCommand
;
728 gettext
:=formGetText(textField_id
);
732 procedure drw_btn(text:string; cur
,ccur
,h
,ty
:integer);
736 m_x
:=(getWidth
/2)-(120/2);
737 m_y
:=h
+((getHeight
/2))-((getimageheight(gui
[7])-2*cur
)/2)+((getimageheight(gui
[7])+2)*cur
);
740 if ccur
=cur
then drawimage(gui
[22],m_x
+i
*4,m_y
); else drawimage(gui
[6],m_x
+i
*8,m_y
);
744 if ccur
=cur
then drawimage(gui
[8],m_x
+i
*8,m_y
); else drawimage(gui
[7],m_x
+i
*8,m_y
);
746 setclip(0,0,getwidth
,getheight
);
747 m_x
:=(getWidth
/2)-(length(text)*8/2);
748 m_y
:=h
+((getHeight
/2))-((getimageheight(gui
[7])-2*cur
)/2)+((getimageheight(gui
[7])+2)*cur
)+((getimageheight(gui
[7])-8)/2);
749 drawfonttext(text,m_x
,m_y
);
752 procedure drw_txt(str
:string; xx
,n
,t
:integer);
756 m_x
:=(getWidth
/2)-(length(str
)*8/2);
758 if t
=0 then drawfonttext(str
,0,m_y
); else
759 if t
=1 then drawfonttext(str
,m_x
,m_y
);
762 function pos_end(s
:string; c
:char):integer;
766 for i
:=length(s
)-1 downto 0 do
768 if getchar(s
,i
)=c
then
777 function getroot(cancel_b
:boolean):string;
779 m_cur
,max_r
,pars
,ix
,iy
:integer;
782 roots
:array [0..15] of string;
784 im
:=rotate_image_from_image(ld_tex('background.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','title/'),16,0,16,16,0);
786 if cancel_b
then roots
[0]:='<CANCEL>';
787 if cancel_b
then max_r
:=1; else max_r
:=0;
788 while pos(rr
,'|')<>-1 do
791 roots
[max_r
]:=copy(rr
,0,pars
-1);
792 rr
:=copy(rr
,pars
+1,length(rr
));
798 if clickedKey(KEY_FM_UP
) then begin m_cur
:=m_cur
-1; if m_cur
<0 then m_cur
:=max_r
; end;
799 if clickedKey(KEY_FM_DOWN
) then begin m_cur
:=m_cur
+1; if m_cur
>max_r
then m_cur
:=0; end;
800 if clickedKey(KEY_FM_SELECT
) then
802 if (m_cur
=0) and (cancel_b
) then
809 getroot
:=roots
[m_cur
];
814 for ix
:=0 to getWidth
/16 do
815 for iy
:=0 to getHeight
/16 do
816 drawimage(im
,ix
*16,iy
*16);
819 fillrect(0,m_cur
*8,getWidth
-1,8);
820 for ix
:=0 to max_r
do
822 drawfonttext(roots
[ix
],0,ix
*8);
824 setcolor(255,255,255);
825 drawrect(0,m_cur
*8,getWidth
-1,8);
832 function filemanager(cancel_b
:boolean):string;
834 m_cur
,ix
,iy
,max_r
,pars
:integer;
836 last
,rr
,root
,path
:string;
837 names
:array [0..255] of string;
839 im
:=rotate_image_from_image(ld_tex('background.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','title/'),16,0,16,16,0);
842 root
:=getroot(cancel_b
);
849 if cancel_b
then names
[2]:='<CANCEL>';
851 if cancel_b
then max_r
:=3; else max_r
:=2;
852 while pos(rr
,'|')<>-1 do
855 names
[max_r
]:=copy(rr
,0,pars
-1);
856 rr
:=copy(rr
,pars
+1,length(rr
));
863 if clickedKey(KEY_FM_UP
) then begin m_cur
:=m_cur
-1; if m_cur
<0 then m_cur
:=max_r
; end;
864 if clickedKey(KEY_FM_DOWN
) then begin m_cur
:=m_cur
+1; if m_cur
>max_r
then m_cur
:=0; end;
865 if clickedKey(KEY_FM_SELECT
) then
870 debug('lol:'+pos_end(path
,'/'));
871 if (path
=root
) or (path
=root
+'/') then
873 root
:=getroot(cancel_b
);
883 path
:=copy(path
,0,pos_end(path
,'/'));
884 if cancel_b
then names
[2]:='<CANCEL>';
886 if cancel_b
then max_r
:=3; else max_r
:=2;
887 while pos(rr
,'|')<>-1 do
890 names
[max_r
]:=copy(rr
,0,pars
-1);
891 rr
:=copy(rr
,pars
+1,length(rr
));
903 if (m_cur
=2) and (cancel_b
) then
910 path
:=path
+'/'+names
[m_cur
];
912 if cancel_b
then names
[2]:='<CANCEL>';
914 if cancel_b
then max_r
:=3; else max_r
:=2;
915 while pos(rr
,'|')<>-1 do
918 names
[max_r
]:=copy(rr
,0,pars
-1);
919 rr
:=copy(rr
,pars
+1,length(rr
));
928 for ix
:=0 to getWidth
/16 do
929 for iy
:=0 to getHeight
/16 do
930 drawimage(im
,ix
*16,iy
*16);
933 fillrect(0,m_cur
*8,getWidth
-1,8);
934 for ix
:=0 to max_r
do
936 drawfonttext(names
[ix
],0,ix
*8);
938 setcolor(255,255,255);
939 drawrect(0,m_cur
*8,getWidth
-1,8);
947 procedure setsd(cancel_b
:boolean);
953 s
:=filemanager(cancel_b
);
957 if file_exists('/'+sd
+'/cavecraft')<>1 then
958 if create_folder('/'+sd
+'/cavecraft')=1 then debug('/cavecraft created!');
960 if file_exists('/'+sd
+'/cavecraft/saves')<>1 then
961 if create_folder('/'+sd
+'/cavecraft/saves')=1 then debug('/saves created!');
963 if file_exists('/'+sd
+'/cavecraft/screenshots')<>1 then
964 if create_folder('/'+sd
+'/cavecraft/screenshots')=1 then debug('/screenshots created!');
966 if file_exists('/'+sd
+'/cavecraft/texturepacks')<>1 then
967 if create_folder('/'+sd
+'/cavecraft/texturepacks')=1 then debug('/texturepacks created!');
969 deleteRecordStore('SD');
970 rs
:=openRecordStore('SD');
971 t
:=addRecordStoreEntry(rs
,sd
);
972 closeRecordStore(rs
);
983 rs
:=openRecordStore('SD');
984 sd
:=readRecordStoreEntry(rs
,1);
985 closeRecordStore(rs
);
986 console
.exec('autoexec.cfg', 'AUTO');
994 //load_virt_tex(loadimage('/gui/touch.png'));
998 if file_exists('/'+sd
+'/cavecraft')<>1 then
999 if create_folder('/'+sd
+'/cavecraft')=1 then debug('/cavecraft created!');
1001 if file_exists('/'+sd
+'/cavecraft/saves')<>1 then
1002 if create_folder('/'+sd
+'/cavecraft/saves')=1 then debug('/saves created!');
1004 if file_exists('/'+sd
+'/cavecraft/screenshots')<>1 then
1005 if create_folder('/'+sd
+'/cavecraft/screenshots')=1 then debug('/screenshots created!');
1007 if file_exists('/'+sd
+'/cavecraft/texturepacks')<>1 then
1008 if create_folder('/'+sd
+'/cavecraft/texturepacks')=1 then debug('/texturepacks created!');
1010 rs
:=openRecordStore('TX');
1011 ss
:=readRecordStoreEntry(rs
,1);
1012 closeRecordStore(rs
);
1017 LoadDrawFont('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1018 loadtexture('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1027 function question(text:string):boolean;
1029 ix
,iy
,m_cur
:integer;
1033 if clickedKey(KEY_MENU_UP
) then begin m_cur
:=m_cur
-1; if m_cur
<0 then m_cur
:=1; end;
1034 if clickedKey(KEY_MENU_DOWN
) then begin m_cur
:=m_cur
+1; if m_cur
>1 then m_cur
:=0; end;
1035 if clickedKey(KEY_MENU_SELECT
) then begin if m_cur
=0 then question
:=true; else question
:=false; exit
; end;
1036 for ix
:=0 to getwidth
/16 do for iy
:=0 to getheight
/16 do drawimage(bg
[0],ix
*16,iy
*16);
1037 drawfonttext(text,getwidth
/2-(length(text)*8)/2,getheight
/2-16);
1038 drw_btn('Yes',0,m_cur
,0,1);
1039 drw_btn('No',1,m_cur
,0,1);
1045 function menu_game_new
:boolean;
1047 m_cur
,tmp_gm
,ix
,iy
,lol
:integer;
1048 tmp_cheats
,tmp_bon_chest
:boolean;
1049 newgametxt
:array[0..4] of string;
1053 newgametxt
[0]:='Survival';
1054 newgametxt
[1]:='Creative';
1055 newgametxt
[2]:='Hardcore';
1056 newgametxt
[3]:='Normal';
1057 newgametxt
[4]:='Flat';
1061 if clickedKey(KEY_MENU_UP
) then begin m_cur
:=m_cur
-1; if m_cur
<-2 then m_cur
:=5; end;
1062 if clickedKey(KEY_MENU_DOWN
) then begin m_cur
:=m_cur
+1; if m_cur
>5 then m_cur
:=-2; end;
1063 if clickedKey(KEY_MENU_SELECT
) then
1067 name
:=gettext('Name:',name
,10,TF_ANY
);
1071 tmp_gm
:=tmp_gm
+1; if tmp_gm
>2 then tmp_gm
:=0;
1072 if tmp_gm
=0 then tmp_cheats
:=false;
1073 if tmp_gm
=1 then tmp_cheats
:=true;
1074 if tmp_gm
=2 then begin tmp_cheats
:=false; tmp_bon_chest
:=false; end;
1078 nextseed
:=stringtointeger(gettext('Seed:',''+nextseed
,10,TF_NUMERIC
));
1082 world_typ
:=world_typ
+1;
1083 if world_typ
>1 then world_typ
:=0;
1087 if tmp_gm
<2 then tmp_cheats
:= not tmp_cheats
;
1091 if tmp_gm
<2 then tmp_bon_chest
:= not tmp_bon_chest
;
1097 bon_chest
:=tmp_bon_chest
;
1099 while file_exists('/'+sd
+'/cavecraft/saves/'+name
)=1 do
1106 menu_game_new
:=true;
1114 for ix
:=0 to getWidth
/16 do
1115 for iy
:=0 to getHeight
/16 do
1116 drawimage(bg
[0],ix
*16,iy
*16);
1118 drw_btn('Name:'+name
,-2,m_cur
,0,1);
1119 drw_btn('Mode:'+newgametxt
[tmp_gm
],-1,m_cur
,0,1);
1120 drw_btn('Seed:'+nextseed
,0,m_cur
,0,1);
1121 drw_btn('Type:'+newgametxt
[world_typ
+3],1,m_cur
,0,1);
1123 drw_btn('Cheats:'+tmp_cheats
,2,m_cur
,0,1);
1125 drw_btn('Cheats:'+tmp_cheats
,2,m_cur
,0,0);
1127 drw_btn('Chest:'+tmp_bon_chest
,3,m_cur
,0,1);
1129 drw_btn('Chest:'+tmp_bon_chest
,3,m_cur
,0,0);
1130 drw_btn('Create',4,m_cur
,0,1);
1131 drw_btn('Cancel',5,m_cur
,0,1);
1138 procedure deleteworld(path
:string);
1140 if file_exists(path
+'player.dat')=1 then delete_file(path
+'player.dat');
1141 if file_exists(path
+'world.sav')=1 then delete_file(path
+'world.sav');
1142 if file_exists(path
+'nether.sav')=1 then delete_file(path
+'nether.sav');
1143 if file_exists(path
+'pic.png')=1 then delete_file(path
+'pic.png');
1144 if file_exists(path
)=1 then delete_file(path
);
1145 if file_exists(path
)=0 then debug('World deleted!');
1148 function menu_game
:boolean;
1150 ix
,iy
,pars
,max_r
,cur_name
,m_cur
:integer;
1154 names
:array[0..255] of string;
1156 rr
:=get_dirs('/'+sd
+'/cavecraft/saves/');
1157 while pos(rr
,'|')<>-1 do
1160 names
[max_r
]:=copy(rr
,0,pars
-1);
1161 rr
:=copy(rr
,pars
+1,length(rr
));
1162 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[max_r
]+'/player.dat')=1 then max_r
:=max_r
+1;
1165 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png')=1 then
1166 im_game
:=safely_load_image_fs('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png');
1167 else im_game
:=ld_tex('maps.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','');
1169 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/player.dat')=1 then
1170 mm_t_b
:=true; else mm_t_b
:=false;
1174 if clickedKey(KEY_MENU_UP
) then
1177 if m_cur
<0 then m_cur
:=3;
1179 if clickedKey(KEY_MENU_DOWN
) then
1182 if m_cur
>3 then m_cur
:=0;
1185 if (max_r
>= 0) and clickedKey(KEY_MENU_LEFT
) then
1187 cur_name
:=cur_name
-1;
1188 if cur_name
<0 then cur_name
:=0;
1189 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png')=1 then
1190 im_game
:=safely_load_image_fs('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png');
1191 else im_game
:=ld_tex('maps.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','');
1193 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/player.dat')=1 then
1195 if (max_r
>= 0) and clickedKey(KEY_MENU_RIGHT
) then
1197 cur_name
:=cur_name
+1;
1198 if cur_name
>max_r
then cur_name
:=max_r
;
1199 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png')=1 then
1200 im_game
:=safely_load_image_fs('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png');
1201 else im_game
:=ld_tex('maps.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','');
1203 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/player.dat')=1 then
1205 if clickedKey(KEY_MENU_SELECT
) then
1210 if loadgame('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/') then
1212 sav_fl
:=names
[cur_name
];
1219 if menu_game_new
then begin menu_game
:=true; break
; end;
1223 debug('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/');
1225 if question('Are you sure?')=true then deleteworld('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/');
1228 rr
:=get_dirs('/'+sd
+'/cavecraft/saves/');
1229 while pos(rr
,'|')<>-1 do
1232 names
[max_r
]:=copy(rr
,0,pars
-1);
1233 rr
:=copy(rr
,pars
+1,length(rr
));
1237 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png')=1 then
1238 im_game
:=safely_load_image_fs('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png');
1239 else im_game
:=ld_tex('maps.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','');
1247 for ix
:=0 to getWidth
/16 do
1249 drawimage(bg
[1],ix
*16,iy
*16);
1250 for ix
:=0 to getWidth
/16 do
1251 drawimage(bg
[0],ix
*16,0);
1252 for ix
:=0 to getWidth
/16 do
1253 for iy
:=8 to getHeight
/16 do
1254 drawimage(bg
[0],ix
*16,iy
*16);
1259 fillrect(32,24,getWidth
-64,96);
1260 setclip(32,24,getWidth
-64,96);
1261 drawimage(im_game
,(getWidth
/2)-(32),32);
1262 drawfonttext(names
[cur_name
],(getWidth
/2)-(length(names
[cur_name
])*8/2),104);
1263 setclip(0,0,getWidth
,getHeight
);
1264 setcolor(128,128,128);
1265 drawrect(32,24,getWidth
-64,96);
1266 if cur_name
>0 then drawimage(gui
[20],0,58);
1267 if cur_name
<max_r
then drawimage(gui
[21],getWidth
-9,58);
1272 fillrect(32,24,getWidth
-64,96);
1273 setclip(32,24,getWidth
-64,96);
1274 drawfonttext('No saves!',(getWidth
/2)-(length('No saves!')*8/2),104);
1275 setclip(0,0,getWidth
,getHeight
);
1276 setcolor(128,128,128);
1277 drawrect(32,24,getWidth
-64,96);
1280 if mm_t_b
then drw_btn('Play',0,m_cur
,32,1); else drw_btn('Play',0,m_cur
,32,0);
1281 drw_btn('Create new',1,m_cur
,32,1);
1282 if mm_t_b
then drw_btn('Delete',2,m_cur
,32,1); else drw_btn('Delete',2,m_cur
,32,0);
1283 drw_btn('Back',3,m_cur
,32,1);
1284 if not mm_t_b
then cur_name
:=cur_name
+1;
1293 ix
,iy
,pars
,max_r
,cur_name
,m_cur
,t
:integer;
1296 names
:array[0..255] of string;
1299 rr
:=get_dirs('/'+sd
+'/cavecraft/texturepacks/');
1300 names
[0]:='Default';
1302 while pos(rr
,'|')<>-1 do
1305 names
[max_r
]:=copy(rr
,0,pars
-1);
1306 rr
:=copy(rr
,pars
+1,length(rr
));
1310 im_game
:=loadimage('/pack.png');
1314 if clickedKey(KEY_MENU_UP
) then
1317 if m_cur
<0 then m_cur
:=1;
1319 if clickedKey(KEY_MENU_DOWN
) then
1322 if m_cur
>1 then m_cur
:=0;
1325 if clickedKey(KEY_MENU_LEFT
) then
1327 cur_name
:=cur_name
-1;
1328 if cur_name
<0 then cur_name
:=0;
1329 im_game
:=ld_tex('pack.png','/'+sd
+'/cavecraft/texturepacks/'+names
[cur_name
]+'/','');
1331 if clickedKey(KEY_MENU_RIGHT
) then
1333 cur_name
:=cur_name
+1;
1334 if cur_name
>max_r
then cur_name
:=max_r
;
1335 im_game
:=ld_tex('pack.png','/'+sd
+'/cavecraft/texturepacks/'+names
[cur_name
]+'/','');
1337 if clickedKey(KEY_MENU_SELECT
) then
1339 if m_cur
=0 then begin
1342 debug("Select TexturePack @ /" + sd
+ "/cavecraft/texturepacks/" + names
[cur_name
]);
1343 tex_pack
:=names
[cur_name
];
1344 LoadDrawFont('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1345 loadtexture('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1346 deleteRecordStore('TX');
1347 rs
:=openRecordStore('TX');
1348 t
:=addRecordStoreEntry(rs
,tex_pack
);
1349 closeRecordStore(rs
);
1351 LoadDrawFont('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1352 loadtexture('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1356 debug("Cancel Select TecturePack");
1359 deleteRecordStore('TX');
1360 rs
:=openRecordStore('TX');
1361 t
:=addRecordStoreEntry(rs
,'');
1362 closeRecordStore(rs
);
1365 if m_cur
=1 then break
;
1369 for ix
:=0 to getWidth
/16 do
1371 drawimage(bg
[1],ix
*16,iy
*16);
1372 for ix
:=0 to getWidth
/16 do
1373 drawimage(bg
[0],ix
*16,0);
1374 for ix
:=0 to getWidth
/16 do
1375 for iy
:=8 to getHeight
/16 do
1376 drawimage(bg
[0],ix
*16,iy
*16);
1381 fillrect(32,24,getWidth
-64,96);
1382 setclip(32,24,getWidth
-64,96);
1383 drawimage(im_game
,(getWidth
/2)-(32),32);
1384 drawfonttext(names
[cur_name
],(getWidth
/2)-(length(names
[cur_name
])*8/2),104);
1385 setclip(0,0,getWidth
,getHeight
);
1386 setcolor(128,128,128);
1387 drawrect(32,24,getWidth
-64,96);
1388 if cur_name
>0 then drawimage(gui
[20],0,58);
1389 if cur_name
<max_r
then drawimage(gui
[21],getWidth
-9,58);
1392 drw_btn('Done',0,m_cur
,32,1);
1393 drw_btn('Back',1,m_cur
,32,1);
1400 procedure menu_sett
;
1402 ix
,iy
,m_cur
:integer;
1407 if clickedKey(KEY_MENU_UP
) then
1410 if m_cur
<-3 then m_cur
:=5;
1412 if clickedKey(KEY_MENU_DOWN
) then
1415 if m_cur
>5 then m_cur
:=-3;
1417 if clickedKey(KEY_MENU_SELECT
) then
1421 light_type
:=light_type
+1;
1422 if light_type
>2 then light_type
:=0;
1430 Particles
.enabled
:= not Particles
.enabled
;
1434 drawgui
:=not drawgui
;
1438 if question('Are you sure?')=true then
1440 if load_key_tex
=0 then
1444 //load_virt_tex(ld_tex('touch.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','gui/'));
1447 if load_key_tex
=1 then
1450 resetVirtualKeyboard(-1);
1456 s_jpeg_quality
:=stringtointeger(gettext('JPEG quality:',''+s_jpeg_quality
,3,TF_NUMERIC
));
1457 if s_jpeg_quality
>100 then s_jpeg_quality
:=100; else
1458 if s_jpeg_quality
<0 then s_jpeg_quality
:=0;
1466 deleteRecordStore('S');
1467 deleteRecordStore('SD');
1468 deleteRecordStore('TX');
1478 for ix
:=0 to getWidth
/16 do
1479 for iy
:=0 to getHeight
/16 do
1480 drawimage(bg
[0],ix
*16,iy
*16);
1482 drw_btn('Light:'+light_type
,-3,m_cur
,0,1);
1483 drw_btn('Weather:'+ifosad
,-2,m_cur
,0,1);
1484 drw_btn('Particles:' + Particles
.enabled
, -1, m_cur
, 0, 1);
1485 drw_btn('Hide GUI:'+not drawgui
,0,m_cur
,0,1);
1486 drw_btn('Touch:'+(load_key_tex
>0),1,m_cur
,0,1);
1487 drw_btn('JPEG:'+s_jpeg_quality
,2,m_cur
,0,1);
1488 drw_btn('Set Root',3,m_cur
,0,1);
1489 drw_btn('Reset',4,m_cur
,0,1);
1490 drw_btn('Back',5,m_cur
,0,1);
1497 procedure menu_help
;
1503 if clickedKey(KEY_MENU_SELECT
) then break
;
1504 if pressedKey(KEY_MENU_UP
) then cur
:=cur
+1;
1505 if pressedKey(KEY_MENU_DOWN
) then cur
:=cur
-1;
1507 for ix
:=0 to getWidth
/16 do
1508 for iy
:=2 to (getHeight
/16)-2 do
1509 drawimage(bg
[1],ix
*16,iy
*16);
1511 for ix
:=0 to getWidth
/16 do
1513 drawimage(bg
[0],ix
*16,iy
*16);
1515 for ix
:=0 to getWidth
/16 do
1516 for iy
:=(getHeight
/16)-2 to getHeight
/16 do
1517 drawimage(bg
[0],ix
*16,iy
*16);
1519 setclip(0,32,getWidth
,(getHeight
/16-4)*16);
1521 drw_txt('Controls:',cur
,0,1);
1522 drw_txt('Left - Move left',cur
,1,0);
1523 drw_txt('Right - Move right',cur
,2,0);
1524 drw_txt('Up - Jump',cur
,3,0);
1525 drw_txt('Down - Put a block under you',cur
,4,0);
1526 drw_txt('1 - Inventory',cur
,5,0);
1527 drw_txt('Duble 1 - Craft',cur
,6,0);
1528 drw_txt('3 - Use block',cur
,7,0);
1529 drw_txt('7 - Debug info',cur
,8,0);
1530 drw_txt('Hold 7 - Console',cur
,9,0);
1531 drw_txt('9 - Pause',cur
,10,0);
1532 drw_txt('*, # - Browse inventory',cur
,11,0);
1533 drw_txt('0 - Edit mode',cur
,12,0);
1535 drw_txt('In inventory/chest:',cur
,14,1);
1536 drw_txt('3 - Enject object',cur
,15,0);
1537 drw_txt('Hold 3 - Enject stack',cur
,16,0);
1538 drw_txt('5 - Move the stack',cur
,17,0);
1539 drw_txt('Hold 5 - Divide stack',cur
,18,0);
1541 setclip(0,0,getWidth
,getHeight
);
1543 drw_btn('Back',0,0,getHeight
-getHeight
/2-16-6,1);
1550 procedure menu_about
;
1556 if clickedKey(KEY_MENU_SELECT
) then break
;
1557 if pressedKey(KEY_MENU_UP
) then cur
:=cur
+1;
1558 if pressedKey(KEY_MENU_DOWN
) then cur
:=cur
-1;
1560 for ix
:=0 to getWidth
/16 do
1561 for iy
:=2 to (getHeight
/16)-2 do
1562 drawimage(bg
[1],ix
*16,iy
*16);
1564 for ix
:=0 to getWidth
/16 do
1566 drawimage(bg
[0],ix
*16,iy
*16);
1568 for ix
:=0 to getWidth
/16 do
1569 for iy
:=(getHeight
/16)-2 to getHeight
/16 do
1570 drawimage(bg
[0],ix
*16,iy
*16);
1572 setclip(0,32,getWidth
,(getHeight
/16-4)*16);
1574 drw_txt('Developers:',cur
,0,1);
1575 drw_txt(#68+#101+#97+#68+#68+#111+#111+#77+#69+#82+' - Programmer',cur
,1,0);//dead
1576 drw_txt(#102+#114+#101+#100+#45+#98+#111+#121+' - Programmer',cur
,2,0);//fred-boy
1577 drw_txt(#65+#110+#100+#114+#101+#121+#53+#57+' - Programmer',cur
,3,0);//andrey59
1578 drw_txt(#89+#117+#82+#97+#78+#110+#78+#122+#90+#90+' - Artist',cur
,4,0);//yura
1579 drw_txt(#83+#97+#115+#104+#97+#71+' - Artist and idea generator',cur
,5,0);//sasha
1580 drw_txt(#66+#97+#74+#108+#101+#72+#84+#105+#72+' - Artist and tester',cur
,6,0);//valentin
1581 drw_txt(#65+#103+#114+#101+#115+#115+#111+#82+' - Tester',cur
,7,0);//agressor
1582 drw_txt(#118+#111+#108+#121+#97+#95+#110+#97+#115+#116+#97+#110+#101+' - Tester',cur
,8,0);//volya
1583 drw_txt(#97+#98+#97+#100+#111+#110+' - Tester',cur
,9,0);//abadon
1584 drw_txt(#77+#111+#110+#111+#103+#114+#111+#109+' - Tester',cur
,10,0);//monogrom
1585 drw_txt(#75+#97+#108+#116+#101+#114+' - Tester',cur
,11,0);//kalter
1587 drw_txt('Thanks:',cur
,12,1);
1588 drw_txt('Piligrim and 0vZ - Lib_jsr75i',cur
,13,0);
1589 drw_txt('Piligrim - Lib_effects',cur
,14,0);
1590 drw_txt('Kurdt - Lib_canvas',cur
,15,0);
1591 drw_txt('ViNT - Lib_png and Lib_bmp',cur
,16,0);
1592 drw_txt('aleshka - Lib_jpeg',cur
,17,0);
1593 drw_txt('Roman_V - Lib_safeload',cur
,18,0);
1595 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);
1596 drw_txt(#68+#101+#97+#68+#83+#111+#102+#116+#87+#97+#114+#101+' 2012-'+getyear(getcurrenttime
),cur
,22,0);
1598 drw_txt('Hello! :D',cur
,100,1);
1600 setclip(0,0,getWidth
,getHeight
);
1602 drw_btn('Back',0,0,getHeight
-getHeight
/2-16-6,1);
1609 function sm_siz
:integer;
1611 sm_siz
:=(getWidth
+getHeight
)/5;
1614 function sm_siz4
:integer;
1619 procedure draw_menu_back
;
1623 for ix
:=0 to getWidth
/16 do
1624 for iy
:=0 to getHeight
/16 do
1625 drawimage(bg
[0],ix
*16,iy
*16);
1630 m_cur
,ix
,iy
,iz
:integer;
1636 spl_y
,spl_del
:integer;
1639 cavelogo
:=ld_tex('cavelogo.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','title/');
1641 spl_y
:=getimageheight(cavelogo
);
1643 spl_del
:=getrelativetimems
;
1644 res
:=openResource('/title/splashes.txt');
1645 if ResourceAvailable(res
) then
1647 spl_i
:=stringtointeger(readline(res
));
1648 iy
:=random(spl_i
-1)+1;
1649 debug('SPLASH #'+iy
);
1651 splash
:=readline(res
);
1654 time
:=getcurrenttime
;
1655 if (getmonth(time
)=5) and (getday(time
)=7) then splash
:='Happy birthday, DeaDDooMER!';
1656 if ((getmonth(time
)=0) and (getday(time
)<3)) or ((getmonth(time
)=11) and (getday(time
)>29)) then splash
:='Happy New Year!';
1660 if clickedKey(KEY_MENU_UP
) then
1663 if m_cur
<0 then m_cur
:=5;
1665 if clickedKey(KEY_MENU_DOWN
) then
1668 if m_cur
>5 then m_cur
:=0;
1670 if clickedKey(KEY_MENU_SELECT
) then
1672 if m_cur
=0 then begin if menu_game
then break
; end;
1674 if m_cur
=1 then menu_tex
;
1676 if m_cur
=2 then menu_sett
;
1678 if m_cur
=3 then menu_help
;
1680 if m_cur
=4 then menu_about
;
1682 if m_cur
=5 then begin save_settings
; halt
; end;
1687 drawimage(cavelogo
,(getWidth
/2)-(getimagewidth(cavelogo
)/2),0);
1688 setcolor(255,255,0);
1690 DrawFontTextSpec(splash
, (getWidth
/2)-(length(splash
)*FONT_SYM_SIZE
/2), spl_y
, FONT_YELLOW_COLOR
, true);
1692 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;
1693 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;
1694 drawfonttext(version
,0,getHeight
-8);
1696 drw_btn('Singleplayer',0,m_cur
,0,1);
1697 drw_btn('Texture Packs',1,m_cur
,0,1);
1698 drw_btn('Options',2,m_cur
,0,1);
1699 drw_btn('Help',3,m_cur
,0,1);
1700 drw_btn('About',4,m_cur
,0,1);
1701 drw_btn('Quit Game',5,m_cur
,0,1);
1708 function setBlock(invcur
, x
, y
:integer):boolean;
1710 item
, sum
, block
, sblock
:integer;
1712 item
:=inv
.getItem(invcur
);
1713 sum
:=inv
.getSum(invcur
);
1714 block
:=getMap(x
, y
);
1715 sblock
:=getItemInfo(item
);
1717 if getItemType(item
)=ITEM_TYPE_BLOCK
then
1718 if inv
.isNull(invcur
)=false then
1719 if getBlockSet(block
)=true then
1720 // if (coll_xy(x, y)=false) or (getBlockColl(item)=0) then
1722 if set_block_code(sblock
, x
, y
)=false then
1725 setmap(sblock
, x
, y
);
1728 inv
.setSum(inv
.getSum(invcur
)-1, invcur
);
1729 inv
.fixNull(invcur
);
1743 if (getrelativetimems
-fish_time
>5000) and (getmap(fx
,fy
)=50) then
1745 if (random(3)=2) and (getmap(fx
,fy
)=50) then
1747 drop
.create(210,1,x
,y
);
1750 inv
.setSum(inv
.getSum(invslot
)-1, invslot
);
1751 inv
.fixNull(invslot
);
1754 if (getrelativetimems
-fish_time
<5000) and (getmap(fx
,fy
)=50) and (fish
=true) then
1756 if getmap(fx
,fy
-1)=50 then fy
:=fy
-1;
1760 procedure drawminimap
;
1762 ix
,iy
,tmp_gx
,tmp_gy
,minx
,miny
,maxx
,maxy
,loc_camx
,loc_camy
,x
,y
:integer;
1766 if load_minimap_tex
then
1768 tmp_gx
:=(getWidth
/2)-(getimagewidth(gui
[16])/2);
1769 tmp_gy
:=(getHeight
/2)-(getimageheight(gui
[16])/2);
1773 tmp_gx
:=(getWidth
/2)-(64/2);
1774 tmp_gy
:=(getHeight
/2)-(64/2);
1777 loc_camx
:=(x
+4)-(864/2);
1778 loc_camy
:=(y
+4)-(864/2);
1779 if loc_camx
<0 then loc_camx
:=0;
1780 if loc_camx
>4096-864 then loc_camx
:=4096-864;
1781 if loc_camy
<0 then loc_camy
:=0;
1782 if loc_camy
>2048-864 then loc_camy
:=2048-864;
1785 maxx
:=(loc_camx
+864)/16;
1786 maxy
:=(loc_camy
+864)/16;
1787 if minx
<0 then minx
:=0;
1788 if miny
<0 then miny
:=0;
1789 if maxx
>255 then maxx
:=255;
1790 if maxy
>127 then maxy
:=127;
1792 if load_minimap_tex
then
1793 drawimage(gui
[16],tmp_gx
,tmp_gy
);
1796 setcolor(214,190,150);
1797 fillrect(tmp_gx
,tmp_gy
,64,64);
1800 for ix
:=minx
to maxx
do
1801 for iy
:=miny
to maxy
do
1803 if (getmap(ix
,iy
)=1) or (getmap(ix
,iy
)=2) or (getmap(ix
,iy
)=74) then setcolor(121,85,58); else
1804 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
1805 if (getmap(ix
,iy
)=50) or (getmap(ix
,iy
)=62) then setcolor(38,92,255); else
1806 if getmap(ix
,iy
)=51 then setcolor(255,0,0); else
1807 if (getmap(ix
,iy
)=61) or (getmap(ix
,iy
)=32) then setcolor(255,255,255); else
1808 setcolor(127,127,127);
1810 if (getmap(ix
,iy
)<>0) then plot(tmp_gx
+4+ix
-minx
,tmp_gy
+4+iy
-miny
);
1815 procedure draw_sign
;
1818 str
:array[0..3] of string;
1819 i
,j
,tmp_gx
,tmp_gy
:integer;
1821 if load_gui_tex
then
1823 tmp_gx
:=(getWidth
/2)-(getimagewidth(sign_im
)/2);
1824 tmp_gy
:=(getHeight
/2)-(getimageheight(sign_im
)/2);
1828 tmp_gx
:=(getWidth
/2)-(120/2);
1829 tmp_gy
:=(getHeight
/2)-(60/2);
1832 tmp
:=t_sign
[getmapinfo(curx
,cury
)];
1833 while pos(tmp
,#13)<>-1 do
1836 str
[j
]:=copy(tmp
,0,i
);
1837 tmp
:=copy(tmp
,i
+1,length(tmp
));
1841 if load_gui_tex
then
1842 drawimage(sign_im
,tmp_gx
,tmp_gy
);
1845 setcolor(159,132,77);
1846 fillrect(tmp_gx
,tmp_gy
,120,60);
1849 drawfonttext(str
[0],tmp_gx
+(120/2)-(length(str
[0])*8/2),tmp_gy
+(60/4/2)+4);
1850 drawfonttext(str
[1],tmp_gx
+(120/2)-(length(str
[1])*8/2),tmp_gy
+(60/4/2)+8+4);
1851 drawfonttext(str
[2],tmp_gx
+(120/2)-(length(str
[2])*8/2),tmp_gy
+(60/4/2)+16+4);
1852 drawfonttext(str
[3],tmp_gx
+(120/2)-(length(str
[3])*8/2),tmp_gy
+(60/4/2)+24+4);
1855 procedure draw_back(ix
,iy
:integer);
1857 if getBiomMap(ix
)=0 then
1859 if (getBackMap(ix
)=iy
) then drawimage(back
[0],(ix
*16)-camx
,(iy
*16)-camy
); else
1860 if (getBackMap(ix
)+1=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1861 if (getBackMap(ix
)+2=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1862 if (getBackMap(ix
)+3=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1863 if (getBackMap(ix
)<iy
) then drawimage(back
[2],(ix
*16)-camx
,(iy
*16)-camy
);
1865 if getBiomMap(ix
)=1 then
1867 if (getBackMap(ix
)=iy
) then drawimage(back
[4],(ix
*16)-camx
,(iy
*16)-camy
); else
1868 if (getBackMap(ix
)+1=iy
) then drawimage(back
[4],(ix
*16)-camx
,(iy
*16)-camy
); else
1869 if (getBackMap(ix
)+2=iy
) then drawimage(back
[6],(ix
*16)-camx
,(iy
*16)-camy
); else
1870 if (getBackMap(ix
)+3=iy
) then drawimage(back
[6],(ix
*16)-camx
,(iy
*16)-camy
); else
1871 if (getBackMap(ix
)<iy
) then drawimage(back
[2],(ix
*16)-camx
,(iy
*16)-camy
);
1873 if getBiomMap(ix
)=2 then
1875 if (getBackMap(ix
)=iy
) then drawimage(back
[5],(ix
*16)-camx
,(iy
*16)-camy
); else
1876 if (getBackMap(ix
)+1=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1877 if (getBackMap(ix
)+2=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1878 if (getBackMap(ix
)+3=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1879 if (getBackMap(ix
)<iy
) then drawimage(back
[2],(ix
*16)-camx
,(iy
*16)-camy
);
1881 if getBiomMap(ix
)=3 then
1883 if (getBackMap(ix
)=iy
) then drawimage(back
[7],(ix
*16)-camx
,(iy
*16)-camy
); else
1884 if (getBackMap(ix
)+1=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1885 if (getBackMap(ix
)+2=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1886 if (getBackMap(ix
)+3=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1887 if (getBackMap(ix
)<iy
) then drawimage(back
[2],(ix
*16)-camx
,(iy
*16)-camy
);
1889 if getBiomMap(ix
)=4 then
1891 drawimage(back
[8],(ix
*16)-camx
,(iy
*16)-camy
);
1897 ix
,iy
,iz
,minx
,miny
,maxx
,maxy
,tmp_ax
,tim
,smy
,pa_xo
, x
, y
:integer;
1901 {===================[sky]===================}
1902 tim
:=10000*getimagewidth(sky
)/600000*game_time
/10000;
1903 setcolor(effects
.get(sky
,tim
,0,1),effects
.get(sky
,tim
,0,2),effects
.get(sky
,tim
,0,3));
1904 fillrect(0,0,getWidth
,getHeight
);
1908 setcolor(effects
.get(sky
,tim
,2,1),effects
.get(sky
,tim
,2,2),effects
.get(sky
,tim
,2,3));
1909 smy
:=10000*getWidth
*2/600000*game_time
/10000;
1910 for iz
:=1 to getWidth
do
1912 ix
:=rnd(getWidth
*2)-getWidth
+smy
;
1913 if ix
>getWidth
then ix
:=ix
-getWidth
*2;
1915 if (ix
>-1) and (ix
<getWidth
) then plot(ix
,iy
);
1923 smy
:=10000*(getWidth
+getimagewidth(sun
))/300000*game_time
/10000;
1924 drawimage(sun
,smy
-getimagewidth(sun
),getHeight
/2-getimageheight(sun
)/2);
1928 setcolor(255,213,74);
1929 smy
:=10000*(getWidth
+sm_siz
)/300000*game_time
/10000;
1930 fillrect(smy
-sm_siz
+sm_siz4
,getHeight
/2-sm_siz
/2+sm_siz4
,sm_siz
-sm_siz4
,sm_siz
-sm_siz4
);
1935 smy
:=10000*(getWidth
+getimagewidth(moon
))/300000*(game_time
-300000)/10000;
1936 drawimage(moon
,smy
-getimagewidth(moon
),getHeight
/2-getimageheight(moon
)/2);
1940 setcolor(175,184,204);
1941 smy
:=10000*(getWidth
+sm_siz
)/300000*(game_time
-300000)/10000;
1942 fillrect(smy
-sm_siz
+sm_siz4
,getHeight
/2-sm_siz
/2+sm_siz4
,sm_siz
-sm_siz4
,sm_siz
-sm_siz4
);
1945 {===================[camera]===================}
1946 camx
:=(x
+4)-(getWidth
/2);
1947 camy
:=(y
+4)-(getHeight
/2);
1948 if camx
<0 then camx
:=0;
1949 if camx
>4096-getWidth
then camx
:=4096-getWidth
;
1950 if camy
>2048-getHeight
then camy
:=2048-getHeight
;
1951 {===================[max_draw]===================}
1954 maxx
:=(camx
+getWidth
)/16;
1955 maxy
:=(camy
+getHeight
)/16;
1956 if minx
<0 then minx
:=0;
1957 if miny
<0 then miny
:=0;
1958 if maxx
>255 then maxx
:=255;
1959 if maxy
>127 then maxy
:=127;
1960 {===================[draw_back]===================}
1961 for ix
:=minx
to maxx
do
1962 for iy
:=miny
to maxy
do
1964 if ifosad
then if (getBackMap(ix
)>=iy
) and (osadki
=true) and getBlockTrans(getmap(ix
,iy
)) then
1966 if getBiomMap(ix
)=0 then drawimage(osad
[0,osadki_ani
],(ix
*16)-camx
,(iy
*16)-camy
);
1968 if getBiomMap(ix
)=2 then drawimage(osad
[1,osadki_ani
],(ix
*16)-camx
,(iy
*16)-camy
);
1970 if getBiomMap(ix
)=3 then drawimage(osad
[0,osadki_ani
],(ix
*16)-camx
,(iy
*16)-camy
);
1973 if getBlockTrans(getmap(ix
,iy
)) then
1976 if getBlockFore(getmap(ix
,iy
))=false then
1979 {===================[drop]===================}
1980 Drop
.Draw(camx
, camy
);
1981 {===================[particles]===================}
1982 Particles
.Draw(camx
, camy
);
1983 {===================[player]===================}
1984 Player
.Draw(camx
, camy
);
1985 {===================[mobs]===================}
1986 Mobs
.Draw(camx
, camy
);
1987 {===================[draw_blocks]===================}
1988 for ix
:=minx
to maxx
do
1989 for iy
:=miny
to maxy
do
1991 if getBlockFore(getmap(ix
, iy
)) then
1995 if light_type
= 1 then
1997 if getmaplight(ix
,iy
) = 0 then
1998 fillrect((ix
* 16) - camx
, (iy
* 16) - camy
, 16, 16);
2000 else if light_type
= 2 then
2002 if getmaplight(ix
, iy
) < 15 then
2003 drawimage(light
[getmaplight(ix
, iy
)], (ix
* 16) - camx
, (iy
* 16) - camy
);
2008 // drawimage(light[getmaplight(player.getX div 16, player.getY div 16)], 0, 0);
2010 if (toolus
> 0) and (toolind
< 10) and (getmap(curx
,cury
) > 0) then
2014 drawimage(tue
[toolind
], curx
* 16 - camx
, cury
* 16 - camy
);
2016 {===================[gui]===================}
2019 tmp_ax
:=(getWidth
/2)-(getImageWidth(gui
[1])/2);
2022 drawimage(gui
[0],curx
*16-camx
,cury
*16-camy
);
2027 DrawPlayerInventory
;
2030 if keymode
=3 then drawcraft
; else
2031 if keymode
=4 then drawchest
; else
2032 if keymode
=5 then draw_sign
; else
2033 if keymode
=6 then drawfurnace
; else
2034 if ifminimap
then drawminimap
;*/
2036 drawimage(gui
[1],tmp_ax
,0);
2039 drawItem(inv
.getItem(ix
), inv
.getSum(ix
), (ix
*16)+tmp_ax
+ix
*2+4, 1, true);
2041 drawimage(gui
[17],(invslot
*16)+tmp_ax
+invslot
*2+2,0);
2047 for ix
:=0 to (hp
div 2)-1 do drawimage(gui
[13],ix
*9,getHeight
-9);
2048 if (hp
mod 2)<>0 then begin drawimage(gui
[14],ix
*9,getHeight
-9); ix
:=ix
+1 end;
2049 for ix
:=ix
to 9 do drawimage(gui
[15],ix
*9,getHeight
-9);
2053 for ix
:=0 to (hp
div 2)-1 do drawimage(gui
[31],ix
*9,getHeight
-9);
2054 if (hp
mod 2)<>0 then begin drawimage(gui
[32],ix
*9,getHeight
-9); ix
:=ix
+1 end;
2055 for ix
:=ix
to 9 do drawimage(gui
[33],ix
*9,getHeight
-9);
2058 for ix
:=0 to (hunger
div 2)-1 do drawimage(gui
[26],ix
*9,getHeight
-18);
2059 if (hunger
mod 2)<>0 then begin drawimage(gui
[27],ix
*9,getHeight
-18); ix
:=ix
+1 end;
2060 for ix
:=ix
to 9 do drawimage(gui
[28],ix
*9,getHeight
-18);
2062 if getmap((x
+4)/16,y
/16)=50 then
2064 for ix
:=0 to (air
div 2)-1 do drawimage(gui
[29],ix
*9,getHeight
-27);
2065 if (air
mod 2)<>0 then begin drawimage(gui
[30],ix
*9,getHeight
-27); ix
:=ix
+1 end;
2071 drawfonttext(msg
[ix
],0,getHeight
-20-ix
*9);
2072 if getrelativetimems
-msg_time
[ix
]>5000 then msg
[ix
]:='';
2077 procedure load_moon(path
:string;phase
:integer);
2084 moon
:=ld_tex('moon_phase_'+phase
+'.png',path
,'terrain/moon_phases/');
2088 moon
:=resize_image(ld_tex('moon_phase_'+phase
+'.png',path
,'terrain/moon_phases/'),(getWidth
+getHeight
)/5,(getWidth
+getHeight
)/5);
2096 if game_time
>300000 then
2098 if load_light_tex
then
2104 for iy
:=0 to getheight
/16 do
2105 for ix
:=0 to getwidth
/16 do
2106 drawimage(light
[i
],ix
*16,iy
*16);
2111 moon_phase
:=moon_phase
+1;
2112 if moon_phase
>7 then moon_phase
:=0;
2113 load_moon('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/',moon_phase
);
2116 last_sleep_y
:=cury
-1;
2121 for iy
:=0 to getheight
/16 do
2122 for ix
:=0 to getwidth
/16 do
2123 drawimage(light
[i
],ix
*16,iy
*16);
2133 while i
<=getheight
do
2136 fillrect(0,0,getwidth
,i
);
2141 moon_phase
:=moon_phase
+1;
2142 if moon_phase
>7 then moon_phase
:=0;
2143 load_moon('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/',moon_phase
);
2146 last_sleep_y
:=cury
-1;
2148 while i
<=getheight
do
2152 fillrect(0,i
,getwidth
,getheight
);
2158 end; else create_msg('You can sleep only at night');
2161 procedure resetToolProgerss
;
2167 procedure usetools(invcur
, x
, y
:integer);
2169 item
, sum
, block
:integer;
2171 block
:=getmap(x
, y
);
2172 item
:=inv
.getItem(invcur
);
2173 sum
:=inv
.getSum(invcur
);
2176 destroy_block_cr(block
, x
, y
);
2180 if (getItemType(item
)=ITEM_TYPE_TOOL
) and (getBlockTool(block
)=getToolType(item
)) then
2181 toolus
:=toolus
+getToolSpeed(item
);
2185 if toolus
>=getBlockHP(block
) then
2187 if ((getItemType(item
)=ITEM_TYPE_TOOL
) and (getBlockTool(block
)=getToolType(item
)) and (getToolLvl(item
)>=getBlockLvl(block
))) or (getBlockLvl(block
)<=0) then
2190 destroy_block_1(block
, x
, y
);
2191 setMapInfo(0, x
, y
);
2196 destroy_block_0(block
, x
, y
);
2197 setMapInfo(0, x
, y
);
2200 if getItemType(item
)=ITEM_TYPE_TOOL
then
2202 inv
.setSum(inv
.getSum(invcur
)-1, invcur
);
2203 inv
.fixNull(invcur
);
2211 if (toolus
>0) and (toolus
<=getBlockHP(block
)) then
2212 toolind
:=((toolus
*100) div getBlockHP(block
)) div 10;
2215 function rt_useweap
:boolean;
2217 x
, y
, w
, h
, i
, damg
:integer;
2224 item
:=inv
.getItem(invslot
);
2226 if getItemType(item
)=1 then
2227 damg
:=getToolDamg(item
);
2232 i
:=Mobs
.findAndHit(damg
, x
-TILE_SIZE
, y
, TILE_SIZE
+(w
/2), h
, -2, -3);
2234 i
:=Mobs
.findAndHit(damg
, x
+(w
/2), y
, TILE_SIZE
+(w
/2), h
, 2, -3);
2238 inv
.setSum(inv
.getSum(invslot
)-1, invslot
);
2239 inv
.fixNull(invslot
);
2244 procedure rt_usetools
;
2251 if posi
=0 then curx
:=(x
div 16)-1; else curx
:=(x
div 16)+1;
2253 if getmap(curx
,cury
)=0 then cury
:=cury
+1;
2255 if curx
<0 then curx
:=0;
2256 if curx
>255 then curx
:=255;
2257 if cury
<0 then cury
:=0;
2258 if cury
>127 then cury
:=127;
2260 usetools(invslot
, curx
, cury
);
2263 procedure rt_usemob
;
2270 if posi
=0 then curx
:=(x
div 16)-1; else curx
:=(x
div 16)+1;
2272 if getmap(curx
,cury
)=0 then cury
:=cury
+1;
2274 if curx
<0 then curx
:=0;
2275 if curx
>255 then curx
:=255;
2276 if cury
<0 then cury
:=0;
2277 if cury
>127 then cury
:=127;
2279 //usemob(curx,cury);
2282 procedure actionUse(invcur
, x
, y
:integer);
2284 if setBlock(invcur
, x
, y
)=false then
2285 if useBlock(invcur
, x
, y
) then
2286 if useItem(invcur
, x
, y
) then
2289 procedure rt_useblock
;
2296 if posi
=0 then curx
:=(x
div 16)-1; else curx
:=(x
div 16)+1;
2298 if getmap(curx
,cury
)=0 then cury
:=cury
+1;
2300 if curx
<0 then curx
:=0;
2301 if curx
>255 then curx
:=255;
2302 if cury
<0 then cury
:=0;
2303 if cury
>127 then cury
:=127;
2305 actionUse(invslot
, curx
, cury
);
2308 procedure go_to_nether
;
2312 portal_time
:=getrelativetimems
;
2313 savegame('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/');
2315 drw_load_line('Matrix',10);
2316 if loadworld('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/')=true then
2318 player
.setX(get_spawn_x
*16+4);
2319 player
.setY((get_up(get_spawn_x
)-1)*16);
2332 mob[ix].m_min_vely:=0;
2335 mob[ix].m_fall:=false;
2336 mob[ix].m_jmp:=false;
2337 mob[ix].m_velani:=false;
2346 procedure go_to_world
;
2348 portal_time
:=getrelativetimems
;
2349 savegame('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/');
2351 drw_load_line('Matrix',10);
2352 if loadworld('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/')=true then
2365 procedure plr_is_dead_hardcore
;
2373 if clickedKey(KEY_MENU_SELECT
) then
2375 deleteworld('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/');
2380 drawfonttext('You died!',getwidth
/2-32,getheight
/2-16);
2382 drw_btn('Delete world',0,0,0,1);
2390 procedure plr_is_dead
;
2402 if clickedKey(KEY_MENU_UP
) then
2405 if m_cur
<0 then m_cur
:=1;
2407 if clickedKey(KEY_MENU_DOWN
) then
2410 if m_cur
>1 then m_cur
:=0;
2412 if clickedKey(KEY_MENU_SELECT
) then
2418 if last_sleep_x
=0 then
2420 x
:=get_spawn_x
*16+4;
2424 x
:=last_sleep_x
*16+4;
2431 if last_sleep_x
=0 then
2433 x
:=get_spawn_x
*16+4;
2437 x
:=last_sleep_x
*16+4;
2453 if m_cur
=1 then begin menu
; exit
; end;
2458 drawfonttext('You died!',getwidth
/2-32,getheight
/2-16);
2460 drw_btn('Respawn',0,m_cur
,0,1);
2461 drw_btn('Main menu',1,m_cur
,0,1);
2468 procedure fast_menu
;
2474 if clickedKey(KEY_MENU_UP
) then begin m_cur
:=m_cur
-1; if m_cur
<0 then m_cur
:=3; end;
2475 if clickedKey(KEY_MENU_DOWN
) then begin m_cur
:=m_cur
+1; if m_cur
>3 then m_cur
:=0; end;
2476 if clickedKey(KEY_MENU_SELECT
) then
2484 savegame('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/');
2493 //clear_gui(keymode);
2499 drawfonttext('Game menu',getwidth
/2-36,getheight
/2-20);
2500 drw_btn('Back to Game',0,m_cur
,0,1);
2501 drw_btn('Save Game',1,m_cur
,0,1);
2502 drw_btn('Options',2,m_cur
,0,1);
2503 drw_btn('Quit to Title',3,m_cur
,0,1);
2510 procedure keyFastInv
;
2512 if clickedKey(KEY_FASTINV_NEXT
) then
2519 if clickedKey(KEY_FASTINV_PREV
) then
2527 procedure keyConsole
;
2529 if clickedKey(KEY_CHAT
) then
2530 SetTimer(1000,T_CONSOLE
);
2532 if pressedKey(KEY_CHAT
) then
2534 if GetTimer(T_CONSOLE
)=TIMER_OK
then
2537 ResetTimer(T_CONSOLE
);
2542 if GetTimer(T_CONSOLE
)>TIMER_OK
then
2545 ResetTimer(T_CONSOLE
);
2550 procedure keyInventory
;
2552 if clickedKey(KEY_PLR_OPENINV
) then
2554 OpenPlayerInventory
;
2559 procedure keyhandler
;
2563 if WindowKeyHanler
then
2571 if clickedKey(KEY_PLR_EDITMODE
) then
2574 curx
:=player
.getX
div 16;
2575 cury
:=player
.getY
div 16;
2578 if clickedKey(KEY_PLR_USE
) then
2581 if clickedKey(KEY_MENU
) then
2584 if clickedKey(KEY_PLR_ATTACK
) then
2585 if rt_useweap
=false then
2588 if pressedKey(KEY_PLR_ATTACK
) then
2591 playAnim(ANIM_HAND
);
2596 cancelAnim(ANIM_HAND
);
2599 if pressedKey(KEY_PLR_UP
) then
2601 if pressedKey(KEY_PLR_DOWN
) then
2603 if pressedKey(KEY_PLR_LEFT
) then
2605 if pressedKey(KEY_PLR_RIGHT
) then
2615 if clickedKey(KEY_PLR_UP
) then
2621 if clickedKey(KEY_PLR_DOWN
) then
2627 if clickedKey(KEY_PLR_LEFT
) then
2633 if clickedKey(KEY_PLR_RIGHT
) then
2640 if clickedKey(KEY_PLR_EDITMODE
) then
2643 if clickedKey(KEY_PLR_USE
) then
2644 actionUse(invslot
, curx
, cury
);
2646 if pressedKey(KEY_PLR_ATTACK
) then
2648 usetools(invslot
, curx
, cury
);
2649 playAnim(ANIM_HAND
);
2654 cancelAnim(ANIM_HAND
);
2657 if clickedKey(KEY_MENU
) then
2665 procedure phyhandler
;
2674 procedure light_fillrect(l
,x
,y
,r
:integer);
2676 ix
,iy
,ym
,yp
,xm
,xp
:integer;
2684 setmaplight(getmaplight(ix
,iy
)+l
,ix
,iy
);
2687 procedure light_rect(l
,x
,y
,r
:integer);
2689 ix
,iy
,ym
,yp
,xm
,xp
:integer;
2697 setmaplight(getmaplight(ix
,ym
)+l
,ix
,ym
);
2698 setmaplight(getmaplight(ix
,yp
)+l
,ix
,yp
);
2700 for iy
:=ym
+1 to yp
-1 do
2702 setmaplight(getmaplight(xm
,iy
)+l
,xm
,iy
);
2703 setmaplight(getmaplight(xp
,iy
)+l
,xp
,iy
);
2707 procedure calc_light(m
,x
,y
:integer);
2709 ix
,iy
,l
,ss
,sf
:integer;
2711 if light_type
=1 then light_fillrect(m
,x
,y
,m
/2); else
2712 for l
:=m
downto 1 do
2714 if ss
mod 2=0 then light_rect(l
,x
,y
,ss
/2);
2719 procedure calc_sun(ix
,m
:integer);
2726 setmaplight(ss
,ix
,iy
);
2728 ss
:=ss
-getBlockTr(getmap(ix
,iy
));
2731 for iy
:=iy
+1 to 127 do
2733 setmaplight(0,ix
,iy
);
2742 for i
:=0 to INV_SIZE
do
2744 if inv
.isNull(i
)=false then
2745 player
.dropItem(inv
.getItem(i
), inv
.getSum(i
));
2749 if gamemode
<2 then plr_is_dead
; else plr_is_dead_hardcore
;
2752 procedure hunger_and_air
;
2760 if getrelativetimems
-hung_time
>=90000/(gamemode
+1) then
2762 hung_time
:=getrelativetimems
;
2765 if getrelativetimems
-hp_time
>=5000*(gamemode
+1) then
2769 hp_time
:=getrelativetimems
;
2771 if hp
>20 then hp
:=20;
2775 hp_time
:=getrelativetimems
;
2777 if hp
<1 then if gamemode
<2 then hp
:=1;
2781 if getmap((x
+4)/16,y
/16)=50 then
2783 if getrelativetimems
-air_time
>=500 then
2786 air_time
:=getrelativetimems
;
2789 hp_time
:=getrelativetimems
;
2800 ix
,iy
,minx
,maxx
,miny
,maxy
,fps_t
,tim
, x
, y
:integer;
2807 if hunger
<0 then hunger
:=0;
2808 if air
<0 then air
:=0;
2811 if fps_t
<1 then fps_t
:=1;
2814 if bl_ani5_v
=false then
2820 bl_ani5_v
:=not bl_ani5_v
;
2829 bl_ani5_v
:=not bl_ani5_v
;
2832 bl_ani5_d
:=not bl_ani5_d
;
2837 game_time
:=game_time
+(600000 div (fps_t
*1000));
2839 // Ускорение игрового времени в 10 раз
2840 // game_time := game_time + (600000 div (fps_t*100));
2842 if (game_time
>600000) or (game_time
<0) then
2845 moon_phase
:=moon_phase
+1;
2846 if moon_phase
>7 then moon_phase
:=0;
2847 load_moon('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/',moon_phase
);
2850 tim
:= 10000 * getimagewidth(sky
) / 600000 * game_time
/ 10000;
2851 global_light
:= effects
.get(sky
, tim
, 1, 1) div 16;
2853 if clock_stage
<>game_time
div 75000 then begin clock_stage
:=clock_stage
+1; if clock_stage
>7 then clock_stage
:=0; end;
2856 if x
+8>4094 then x
:=4086;
2857 if getBlockColl(getmap(x
div 16, y
div 16))>0 then hp
:=hp
-1;
2858 if random(4096)=random(4096) then begin osadki
:=not osadki
; end;
2859 osadki_ani
:=osadki_ani
+1;
2860 if osadki_ani
>7 then osadki_ani
:=0;
2862 if Random(20) = Random(20) then Particles
.Create(Particles
.bubble
, x
, y
);
2864 if gamemode
=1 then begin hp
:=666; hunger
:=666; end;
2866 if inv
.getItem(invslot
)=186 then
2871 //if s_spawn_mob then if random(4096)=1547 then megaspawn;
2876 if light_type
>0 then
2879 maxx
:=(camx
+getWidth
)/16+1;
2880 if minx
<0 then minx
:=0;
2881 if maxx
>255 then maxx
:=255;
2882 for ix
:=minx
to maxx
do calc_sun(ix
,global_light
);
2886 maxx
:=(camx
+getWidth
)/16+16;
2888 maxy
:=(camy
+getHeight
)/16+16;
2889 if minx
<0 then minx
:=0;
2890 if maxx
>255 then maxx
:=255;
2891 if miny
<0 then miny
:=0;
2892 if maxy
>127 then maxy
:=127;
2893 for ix
:=minx
to maxx
do
2894 for iy
:=miny
to maxy
do
2896 if light_type
=0 then setmaplight(15,ix
,iy
);
2898 if light_type
>0 then if getBlockLi(getmap(ix
,iy
))>0 then calc_light(getBlockLi(getmap(ix
,iy
)),ix
,iy
);
2901 minx
:=(camx
/16)-((getwidth
/2)/16);
2902 miny
:=(camy
/16)-((getheight
/2)/16);
2903 maxx
:=(camx
+(getWidth
+getWidth
/2))/16;
2904 maxy
:=(camy
+(getHeight
+getHeight
/2))/16;
2905 if minx
<0 then minx
:=0;
2906 if miny
<0 then miny
:=0;
2907 if maxx
>255 then maxx
:=255;
2908 if maxy
>127 then maxy
:=127;
2909 if updx
<minx
then updx
:=minx
;
2910 if updy
<miny
then updy
:=miny
;
2911 if updx
>maxx
then updx
:=minx
;
2912 if updy
>maxy
then updy
:=miny
;
2916 for ix
:=0 to (((2*getWidth
/16)*(2*getHeight
/16))-1) div ((fps_t
*bl_upd
)) do
2918 updateBlock(updx
, updy
);
2924 if updy
>maxy
then updy
:=miny
;
2929 {if coll_bl(110)=true then
2931 if getrelativetimems-portal_time>5000 then
2933 if pl_world=0 then begin go_to_nether; portal_time:=getrelativetimems; end; else
2934 if pl_world=1 then begin go_to_world; portal_time:=getrelativetimems; end;
2938 if coll_bl(51)=true then hp:=hp-1;
2940 if coll_bl(59)=true then
2942 if vely<0 then vely:=-1;
2944 if vely>0 then vely:=1;
2949 if hp
>20 then hp
:=20;
2950 if hunger
>20 then hunger
:=20;
2953 if y
>2048 then kill_plr
;
2954 if (hp
<1) and (gamemode
<>1) then kill_plr
;
2955 if fish
=true then fishing
;
2957 if (fish
=true) and (inv
.getItem(invslot
)<>152) then fish
:=false;
2959 //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;
2963 if cury
<(y
div 16)-4 then cury
:=(y
div 16)-4;
2964 if cury
>(y
div 16)+5 then cury
:=(y
div 16)+5;
2965 if curx
<(x
div 16)-4 then curx
:=(x
div 16)-4;
2966 if curx
>(x
div 16)+4 then curx
:=(x
div 16)+4;
2977 LoadDrawFont('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
2980 if load_key_tex
=1 then init_touch
;
2984 msg_time
[i
]:=getrelativetimems
;
2986 InitMap(MAP_W
, MAP_H
);
2990 procedure draw_debug
;
2994 //drawfonttext('X:'+(x div 16-128),0,0);
2995 //drawfonttext('Y:'+integertostring(127-(y div 16)),0,8);
2996 drawfonttext('CURX:'+(curx
-128),0,16);
2997 drawfonttext('CURY:'+cury
,0,24);
2998 drawfonttext('UPDX:'+updx
,0,32);
2999 drawfonttext('UPDY:'+updy
,0,40);
3000 drawfonttext('FPS:'+fps
,0,56);
3001 drawfonttext('Free RAM:'+free_ram
/1024+' KB',0,64);
3002 drawfonttext('Total RAM:'+memory
.get_totalmemory
div 1024+' KB',0,72);
3003 drawfonttext('SEED:'+seed
,0,88);
3004 drawfonttext('Game time:'+game_time
,0,96);
3005 drawfonttext('Global light:' + global_light
, 0, 104);
3008 drawImage(light
[i
], getWidth
- 16, 16 * i
);
3013 hung_time
:=getrelativetimems
;
3014 hp_time
:=getrelativetimems
;
3015 air_time
:=getrelativetimems
;
3016 portal_time
:=getrelativetimems
;
3023 drawfonttext(version
,getWidth
-(length(version
)*8),getHeight
-8);
3024 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;