38 keymode
,updx
,updy
:integer;
39 seed
,nextseed
:integer;
42 light
:array [0..15] of image
;
43 bg
:array[0..1] of image
;
44 osad
:array [0..1,0..7] of image
;
45 back
:array [0..8] of image
;
46 gui
:array [0..34] of image
;
47 tue
:array [0..9] of image
;
54 toolus
,toolind
:integer;
61 msg
:array [0..4] of string;
62 msg_time
:array[0..4] of integer;
63 last_sleep_x
,last_sleep_y
:integer;
76 if nextseed
=0 then seed
:=getrelativetimems
; else seed
:=nextseed
;
79 if world_typ
=0 then genworld
;
81 if world_typ
=1 then genflat
;
83 player
.setX(get_spawn_x
*16+4);
84 player
.setY(get_spawn_y
*16);
88 procedure drwrect(x
,y
,w
,h
,t
:integer);
93 drawrect(x
+i
,y
+i
,w
-i
*2,h
-i
*2);
98 dt
:=GetRelativeTimeMs
- time
;
99 time
:=GetRelativeTimeMs
;
105 if fps
<s_max_fps
then if del
>0 then del
:=del
-1;
106 if fps
>s_max_fps
then if del
<200 then del
:=del
+1;
110 procedure ClearTextures
;
113 ix
, iy
, iz
: integer;
122 for ix
:= 0 to maxBlockTex
do
127 for ix
:= 0 to maxItemTex
do
169 for ix
:= 0 to CONST_MAX_CURS
do
172 //resetVirtualKeyboard(-1);
175 procedure create_msg(s
:string);
182 msg_time
[i
]:=msg_time
[i
-1];
185 msg_time
[0]:=getrelativetimems
;
189 procedure loadtexture(path
:string);
195 im
:=ld_tex('background.png',path
,'title/');
197 bg
[ix
]:=rotate_image_from_image(im
,ix
*16,0,16,16,0);
198 float
:=ld_tex('float.png',path
,'gui/');
199 compas
:=ld_tex('compass.png',path
,'gui/');
200 im
:=ld_tex('clock.png',path
,'gui/');
202 clock
[ix
]:=rotate_image_from_image(im
,ix
*16,0,16,16,0);
203 if load_back_tex
then
205 im
:=ld_tex('back.png',path
,'');
206 for ix
:=0 to 8 do back
[ix
]:=rotate_image_from_image(im
,ix
*16,0,16,16,0);
209 console
.exec('textures.cfg', 'AUTO');
211 player
.loadSkin('char_ani.png', path
);
212 Mobs
.LoadTextures(path
);
214 im
:=ld_tex('gui.png',path
,'gui/');
215 gui
[0]:=rotate_image_from_image(im
,0,0,16,16,0);
216 LoadCurImg(gui
[0], CUR_SELECT1
);
217 gui
[1]:=rotate_image_from_image(im
,0,16,168,21,0);
218 gui
[3]:=rotate_image_from_image(im
,16,0,16,16,0);
219 LoadCurImg(gui
[3], CUR_SELECT2
);
220 gui
[6]:=rotate_image_from_image(im
,0,56,120,12,0);
221 gui
[7]:=rotate_image_from_image(im
,0,68,120,12,0);
222 gui
[8]:=rotate_image_from_image(im
,0,80,120,12,0);
223 gui
[13]:=rotate_image_from_image(im
,1,93,9,9,0);//hp
224 gui
[14]:=rotate_image_from_image(im
,12,93,9,9,0);//hp
225 gui
[15]:=rotate_image_from_image(im
,23,93,9,9,0);//hp
226 gui
[17]:=rotate_image_from_image(im
,120,56,18,18,0);
228 gui
[26]:=rotate_image_from_image(im
,89,93,9,9,0);//hunger
229 gui
[27]:=rotate_image_from_image(im
,100,93,9,9,0);//hunger
230 gui
[28]:=rotate_image_from_image(im
,111,93,9,9,0);//hunger
232 gui
[29]:=rotate_image_from_image(im
,67,93,9,9,0);//air
233 gui
[30]:=rotate_image_from_image(im
,78,93,9,9,0);//air
235 gui
[31]:=rotate_image_from_image(im
,122,93,9,9,0);//hp hardcore
236 gui
[32]:=rotate_image_from_image(im
,133,93,9,9,0);//hp hardcore
237 gui
[33]:=rotate_image_from_image(im
,144,93,9,9,0);//hp hardcore
239 gui
[20]:=rotate_image_from_image(im
,121,75,9,13,0);
240 gui
[21]:=rotate_image_from_image(im
,130,75,9,13,0);
241 gui
[22]:=rotate_image_from_image(im
,0,103,120,12,0);
243 if load_minimap_tex
then gui
[16]:=ld_tex('mapbg.png',path
,'gui/');
245 for ix
:=0 to 9 do tue
[ix
]:=rotate_image_from_image(im
,16*ix
,40,16,16,0);
247 if load_weather_tex
then
249 im
:=ld_tex('rain.png',path
,'terrain/');
250 for ix
:=0 to 7 do osad
[0,ix
]:=rotate_image_from_image(im
,16*ix
,0,16,16,0);
251 im
:=ld_tex('snow.png',path
,'terrain/');
252 for ix
:=0 to 7 do osad
[1,ix
]:=rotate_image_from_image(im
,16*ix
,0,16,16,0);
255 if load_light_tex
then
257 im
:=ld_tex('light.png',path
,'terrain/');
258 for ix
:=0 to 15 do light
[ix
]:=rotate_image_from_image(im
,16*ix
,0,16,16,0);
261 if load_particles_tex
then
263 im
:=ld_tex('particles.png',path
,'terrain/');
266 pr_1
[ix
]:=rotate_image_from_image(im
,8*ix
,0,8,8,0);
267 pr_2
[ix
]:=rotate_image_from_image(im
,8*ix
,8,8,8,0);
268 pr_3
[ix
]:=rotate_image_from_image(im
,8*ix
,16,8,8,0);
269 pr_4
[ix
]:=rotate_image_from_image(im
,8*ix
,24,8,8,0);
270 pr_5
[ix
]:=rotate_image_from_image(im
,8*ix
,32,8,8,0);
272 bubble
:=rotate_image_from_image(im
,0,40,8,8,0);
273 im
:=ld_tex('explosion.png',path
,'terrain/');
275 pr_boom
[ix
]:=rotate_image_from_image(im
,32*ix
,0,32,32,0);
278 im
:=ld_tex('partition.png',path
,'gui/');
279 gui
[18]:=rotate_image_from_image(im
,0,0,84,42,0);
280 gui
[19]:=rotate_image_from_image(im
,0,42,4,4,0);
282 if load_sky_siz
<=0 then
283 sky
:=ld_tex('sky.png',path
,'terrain/');
285 sky
:=resize_image(ld_tex('sky.png',path
,'terrain/'),load_sky_siz
,2);
289 sun
:=ld_tex('sun.png',path
,'terrain/');
290 moon
:=ld_tex('moon_phase_0.png',path
,'terrain/moon_phases/');
294 sun
:=resize_image(ld_tex('sun.png',path
,'terrain/'),(getWidth
+getHeight
)/5,(getWidth
+getHeight
)/5);
295 moon
:=resize_image(ld_tex('moon_phase_0.png',path
,'terrain/moon_phases/'),(getWidth
+getHeight
)/5,(getWidth
+getHeight
)/5);
298 //load_virt_tex(ld_tex('touch.png',path,'gui/'));
352 reset_particles(max_particles
+1);
362 setmaplight(0,ix
,iy
);
372 for ix
:=0 to CONST_MAX_LAYERS
do
376 procedure drw_load_line(s
:string;percent
:integer);
380 for ix
:=0 to getWidth
/16 do
381 for iy
:=0 to getHeight
/16 do
382 drawimage(bg
[0],ix
*16,iy
*16);
383 drawfonttext(s
,(getWidth
/2)-(length(s
)*8/2),(getHeight
/2)-8);
384 setcolor(128,128,128);
385 fillrect(getwidth
/2-50,getheight
/2+6,100,3);
386 setcolor(128,255,128);
387 fillrect(getwidth
/2-50,getheight
/2+6,percent
,3);
388 drawfonttext(integertostring(percent
)+'%',getwidth
/2-(length(integertostring(percent
)+'%')*8)/2,getheight
/2+12);
392 function getFlatMap(i
:integer):integer;
398 getFlatMap
:=getmap(ix
,iy
);
401 procedure setFlatMap(n
, i
:integer);
410 function getFlatMapInfo(i
:integer):integer;
416 getFlatMapInfo
:=getmapinfo(ix
,iy
);
419 procedure setFlatMapInfo(n
, i
:integer);
428 procedure SaveMapRLE
;
436 if (id
<>getFlatMap(i
+s
)) or (i
+s
>32767) then
446 procedure SaveMapInfoRLE
;
452 id
:=getFlatMapInfo(i
);
454 if (id
<>getFlatMapInfo(i
+s
)) or (i
+s
>32767) then
464 procedure LoadMapRLE
;
479 procedure LoadMapInfoRLE
;
488 setFlatMapInfo(id
, i
+j
);
494 procedure saveworld(path
:string);
499 if pl_world
=0 then world_name
:='world.sav';
501 if pl_world
=1 then world_name
:='nether.sav';
502 if file_exists(path
)<>1 then if create_folder(path
)=1 then debug('Folder created!');
503 if file_exists(path
+world_name
)>0 then delete_file(path
+world_name
);
504 if file_exists(path
+world_name
)<>1 then file_create(path
+world_name
);
505 if open_file(path
+world_name
)=1 then
507 writeint(player
.getX
);
508 writeint(player
.getY
);
512 drw_load_line('Background',50);
513 //Background and biomes
516 write_byte(getBackMap(ix
));
517 write_byte(getBiomMap(ix
));
519 drw_load_line('Chests',55);
522 drw_load_line('Furnaces',60);
525 drw_load_line('Mobs',70);
528 drw_load_line('Drop',80);
531 drw_load_line('Particles',85);
533 writeint(max_particles
);
534 write_byte(gb_up_pa
);
535 for ix
:=0 to max_particles
do
537 write_byte(get_particle_type(ix
));
538 write_byte(get_particle_ani(ix
));
539 writeint(get_particle_x(ix
));
540 writeint(get_particle_y(ix
));
542 drw_load_line('Other',90);
547 write_byte(osadki_ani
);
548 write_byte(global_light
);
551 write_byte(clock_stage
);
554 writebool(b_sign
[ix
]);
555 writestr(t_sign
[ix
]);
558 drw_load_line('Ready',100);
559 if close_file(path
+world_name
)=1 then debug('World Saved!');
563 procedure savegame(path
:string);
567 drw_load_line('Basic',0);
568 if file_exists(path
+'player.dat')=1 then delete_file(path
+'player.dat');
569 if file_exists(path
)<>1 then if create_folder(path
)=1 then debug('Folder created!');
570 if file_exists(path
+'player.dat')<>1 then file_create(path
+'player.dat');
571 if open_file(path
+'player.dat')=1 then
574 write_byte(version_map
);
575 write_byte(gamemode
);
578 write_byte(pl_world
);
580 writeint(last_sleep_x
);
581 writeint(last_sleep_y
);
588 write_byte(moon_phase
);
591 if close_file(path
+'player.dat')=1 then debug('Saved!');
592 drw_load_line('Matrix',10);
598 function version_err(ver
:integer):boolean;
602 for ix
:=0 to getWidth
/16 do
603 for iy
:=0 to getHeight
/16 do
605 drawimage(bg
[0],ix
*16,iy
*16);
607 if version_map
=ver
then version_err
:=true; else
608 if version_map
>ver
then
610 drawfonttext('Old save format!',(getWidth
/2)-60,(getHeight
/2)-4);
615 if version_map
<ver
then
617 drawfonttext('New save format!',(getWidth
/2)-60,(getHeight
/2)-4);
625 function loadworld(path
:string):boolean;
630 if pl_world
=0 then world_name
:='world.sav';
632 if pl_world
=1 then world_name
:='nether.sav';
633 if file_exists(path
)=1 then
635 if file_exists(path
+world_name
)=1 then
637 if open_file(path
+world_name
)=1 then
639 player
.setX(readint
);
640 player
.setY(readint
);
644 drw_load_line('Background',50);
645 //Background and biomes
648 setBackMap(read_byte
, ix
);
649 setBiomMap(read_byte
, ix
);
651 drw_load_line('Chests',55);
654 drw_load_line('Furnaces',60);
659 drw_load_line('Drop',80);
662 drw_load_line('Particles',85);
664 max_particles
:=readint
;
665 reset_particles(max_particles
+1);
667 for ix
:=0 to max_particles
do
669 set_particle_type(ix
,read_byte
);
670 set_particle_ani(ix
,read_byte
);
671 set_particle_x(ix
,readint
);
672 set_particle_y(ix
,readint
);
674 drw_load_line('Other',90);
679 osadki_ani
:=read_byte
;
680 global_light
:=read_byte
;
683 clock_stage
:=read_byte
;
686 b_sign
[ix
]:=readbool
;
689 drw_load_line('Ready',100);
690 ///////////////////////
691 if close_file(path
+world_name
)=1 then begin loadworld
:=true; debug('World loaded!'); end;
692 end; else begin loadworld
:=false; debug('File not opened!'); end;
693 end; else begin loadworld
:=false; debug('File not exists!'); end;
694 end; else begin loadworld
:=false; debug('Folder not exists!'); end;
697 function loadgame(path
:string):boolean;
701 drw_load_line('Basic',0);
702 if file_exists(path
)=1 then
704 if file_exists(path
+'player.dat')=1 then
706 if open_file(path
+'player.dat')=1 then
710 if version_err(ver
)=false then
712 if close_file(path
+'player.dat')=1 then loadgame
:=false;
720 last_sleep_x
:=readint
;
721 last_sleep_y
:=readint
;
728 moon_phase
:=read_byte
;
731 drw_load_line('Matrix',10);
732 if close_file(path
+'player.dat')=1 then loadgame
:=loadworld(path
);
733 end; else loadgame
:=false;
734 end; else loadgame
:=false;
735 end; else loadgame
:=false;
738 procedure drawdeadlogo
;
743 fillrect(0,0,getWidth
,getHeight
);
744 dead
:=loadimage('/dl');
745 drawimage(dead
,(getWidth
/2)-(getimagewidth(dead
)/2),(getHeight
/2)-(getimageheight(dead
)/2));
746 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));
747 drawfonttext('Loading...',(getWidth
/2)-(40),getHeight
-8);
756 for ix
:=0 to getWidth
/16 do
757 for iy
:=0 to getHeight
/16 do
759 drawimage(bg
[0],ix
*16,iy
*16);
761 drawfonttext('Generation World...',(getWidth
/2)-(76),(getHeight
/2)-4);
767 //if s_spawn_mob then begin if pl_world=0 then begin megaspawn; end; else begin netherspawn; end; end;
768 if gamemode
=1 then fly
:=true else fly
:=false;
772 function gettext(text,text_f
:string; max
,typ
:integer;):string;
774 textField_id
:integer;
778 exitCmd
:=createCommand('Ok',CM_OK
,1);
781 textField_id
:=formAddTextField(text,text_f
,max
,typ
);
785 cli
:=getClickedCommand
;
787 gettext
:=formGetText(textField_id
);
791 procedure drw_btn(text:string; cur
,ccur
,h
,ty
:integer);
795 m_x
:=(getWidth
/2)-(120/2);
796 m_y
:=h
+((getHeight
/2))-((getimageheight(gui
[7])-2*cur
)/2)+((getimageheight(gui
[7])+2)*cur
);
799 if ccur
=cur
then drawimage(gui
[22],m_x
+i
*4,m_y
); else drawimage(gui
[6],m_x
+i
*8,m_y
);
803 if ccur
=cur
then drawimage(gui
[8],m_x
+i
*8,m_y
); else drawimage(gui
[7],m_x
+i
*8,m_y
);
805 setclip(0,0,getwidth
,getheight
);
806 m_x
:=(getWidth
/2)-(length(text)*8/2);
807 m_y
:=h
+((getHeight
/2))-((getimageheight(gui
[7])-2*cur
)/2)+((getimageheight(gui
[7])+2)*cur
)+((getimageheight(gui
[7])-8)/2);
808 drawfonttext(text,m_x
,m_y
);
811 procedure drw_txt(str
:string; xx
,n
,t
:integer);
815 m_x
:=(getWidth
/2)-(length(str
)*8/2);
817 if t
=0 then drawfonttext(str
,0,m_y
); else
818 if t
=1 then drawfonttext(str
,m_x
,m_y
);
821 function pos_end(s
:string; c
:char):integer;
825 for i
:=length(s
)-1 downto 0 do
827 if getchar(s
,i
)=c
then
836 function getroot(cancel_b
:boolean):string;
838 m_cur
,max_r
,pars
,ix
,iy
:integer;
841 roots
:array [0..15] of string;
843 im
:=rotate_image_from_image(ld_tex('background.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','title/'),16,0,16,16,0);
845 if cancel_b
then roots
[0]:='<CANCEL>';
846 if cancel_b
then max_r
:=1; else max_r
:=0;
847 while pos(rr
,'|')<>-1 do
850 roots
[max_r
]:=copy(rr
,0,pars
-1);
851 rr
:=copy(rr
,pars
+1,length(rr
));
857 if clickedKey(KEY_FM_UP
) then begin m_cur
:=m_cur
-1; if m_cur
<0 then m_cur
:=max_r
; end;
858 if clickedKey(KEY_FM_DOWN
) then begin m_cur
:=m_cur
+1; if m_cur
>max_r
then m_cur
:=0; end;
859 if clickedKey(KEY_FM_SELECT
) then
861 if (m_cur
=0) and (cancel_b
) then
868 getroot
:=roots
[m_cur
];
873 for ix
:=0 to getWidth
/16 do
874 for iy
:=0 to getHeight
/16 do
875 drawimage(im
,ix
*16,iy
*16);
878 fillrect(0,m_cur
*8,getWidth
-1,8);
879 for ix
:=0 to max_r
do
881 drawfonttext(roots
[ix
],0,ix
*8);
883 setcolor(255,255,255);
884 drawrect(0,m_cur
*8,getWidth
-1,8);
891 function filemanager(cancel_b
:boolean):string;
893 m_cur
,ix
,iy
,max_r
,pars
:integer;
895 last
,rr
,root
,path
:string;
896 names
:array [0..255] of string;
898 im
:=rotate_image_from_image(ld_tex('background.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','title/'),16,0,16,16,0);
901 root
:=getroot(cancel_b
);
908 if cancel_b
then names
[2]:='<CANCEL>';
910 if cancel_b
then max_r
:=3; else max_r
:=2;
911 while pos(rr
,'|')<>-1 do
914 names
[max_r
]:=copy(rr
,0,pars
-1);
915 rr
:=copy(rr
,pars
+1,length(rr
));
922 if clickedKey(KEY_FM_UP
) then begin m_cur
:=m_cur
-1; if m_cur
<0 then m_cur
:=max_r
; end;
923 if clickedKey(KEY_FM_DOWN
) then begin m_cur
:=m_cur
+1; if m_cur
>max_r
then m_cur
:=0; end;
924 if clickedKey(KEY_FM_SELECT
) then
929 debug('lol:'+pos_end(path
,'/'));
930 if (path
=root
) or (path
=root
+'/') then
932 root
:=getroot(cancel_b
);
942 path
:=copy(path
,0,pos_end(path
,'/'));
943 if cancel_b
then names
[2]:='<CANCEL>';
945 if cancel_b
then max_r
:=3; else max_r
:=2;
946 while pos(rr
,'|')<>-1 do
949 names
[max_r
]:=copy(rr
,0,pars
-1);
950 rr
:=copy(rr
,pars
+1,length(rr
));
962 if (m_cur
=2) and (cancel_b
) then
969 path
:=path
+'/'+names
[m_cur
];
971 if cancel_b
then names
[2]:='<CANCEL>';
973 if cancel_b
then max_r
:=3; else max_r
:=2;
974 while pos(rr
,'|')<>-1 do
977 names
[max_r
]:=copy(rr
,0,pars
-1);
978 rr
:=copy(rr
,pars
+1,length(rr
));
987 for ix
:=0 to getWidth
/16 do
988 for iy
:=0 to getHeight
/16 do
989 drawimage(im
,ix
*16,iy
*16);
992 fillrect(0,m_cur
*8,getWidth
-1,8);
993 for ix
:=0 to max_r
do
995 drawfonttext(names
[ix
],0,ix
*8);
997 setcolor(255,255,255);
998 drawrect(0,m_cur
*8,getWidth
-1,8);
1006 procedure setsd(cancel_b
:boolean);
1012 s
:=filemanager(cancel_b
);
1016 if file_exists('/'+sd
+'/cavecraft')<>1 then
1017 if create_folder('/'+sd
+'/cavecraft')=1 then debug('/cavecraft created!');
1019 if file_exists('/'+sd
+'/cavecraft/saves')<>1 then
1020 if create_folder('/'+sd
+'/cavecraft/saves')=1 then debug('/saves created!');
1022 if file_exists('/'+sd
+'/cavecraft/screenshots')<>1 then
1023 if create_folder('/'+sd
+'/cavecraft/screenshots')=1 then debug('/screenshots created!');
1025 if file_exists('/'+sd
+'/cavecraft/texturepacks')<>1 then
1026 if create_folder('/'+sd
+'/cavecraft/texturepacks')=1 then debug('/texturepacks created!');
1028 deleteRecordStore('SD');
1029 rs
:=openRecordStore('SD');
1030 t
:=addRecordStoreEntry(rs
,sd
);
1031 closeRecordStore(rs
);
1042 rs
:=openRecordStore('SD');
1043 sd
:=readRecordStoreEntry(rs
,1);
1044 closeRecordStore(rs
);
1045 console
.exec('autoexec.cfg', 'AUTO');
1053 //load_virt_tex(loadimage('/gui/touch.png'));
1057 if file_exists('/'+sd
+'/cavecraft')<>1 then
1058 if create_folder('/'+sd
+'/cavecraft')=1 then debug('/cavecraft created!');
1060 if file_exists('/'+sd
+'/cavecraft/saves')<>1 then
1061 if create_folder('/'+sd
+'/cavecraft/saves')=1 then debug('/saves created!');
1063 if file_exists('/'+sd
+'/cavecraft/screenshots')<>1 then
1064 if create_folder('/'+sd
+'/cavecraft/screenshots')=1 then debug('/screenshots created!');
1066 if file_exists('/'+sd
+'/cavecraft/texturepacks')<>1 then
1067 if create_folder('/'+sd
+'/cavecraft/texturepacks')=1 then debug('/texturepacks created!');
1069 rs
:=openRecordStore('TX');
1070 ss
:=readRecordStoreEntry(rs
,1);
1071 closeRecordStore(rs
);
1076 LoadDrawFont('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1077 loadtexture('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1086 function question(text:string):boolean;
1088 ix
,iy
,m_cur
:integer;
1092 if clickedKey(KEY_MENU_UP
) then begin m_cur
:=m_cur
-1; if m_cur
<0 then m_cur
:=1; end;
1093 if clickedKey(KEY_MENU_DOWN
) then begin m_cur
:=m_cur
+1; if m_cur
>1 then m_cur
:=0; end;
1094 if clickedKey(KEY_MENU_SELECT
) then begin if m_cur
=0 then question
:=true; else question
:=false; exit
; end;
1095 for ix
:=0 to getwidth
/16 do for iy
:=0 to getheight
/16 do drawimage(bg
[0],ix
*16,iy
*16);
1096 drawfonttext(text,getwidth
/2-(length(text)*8)/2,getheight
/2-16);
1097 drw_btn('Yes',0,m_cur
,0,1);
1098 drw_btn('No',1,m_cur
,0,1);
1104 function menu_game_new
:boolean;
1106 m_cur
,tmp_gm
,ix
,iy
,lol
:integer;
1107 tmp_cheats
,tmp_bon_chest
:boolean;
1108 newgametxt
:array[0..4] of string;
1112 newgametxt
[0]:='Survival';
1113 newgametxt
[1]:='Creative';
1114 newgametxt
[2]:='Hardcore';
1115 newgametxt
[3]:='Normal';
1116 newgametxt
[4]:='Flat';
1120 if clickedKey(KEY_MENU_UP
) then begin m_cur
:=m_cur
-1; if m_cur
<-2 then m_cur
:=5; end;
1121 if clickedKey(KEY_MENU_DOWN
) then begin m_cur
:=m_cur
+1; if m_cur
>5 then m_cur
:=-2; end;
1122 if clickedKey(KEY_MENU_SELECT
) then
1126 name
:=gettext('Name:',name
,10,TF_ANY
);
1130 tmp_gm
:=tmp_gm
+1; if tmp_gm
>2 then tmp_gm
:=0;
1131 if tmp_gm
=0 then tmp_cheats
:=false;
1132 if tmp_gm
=1 then tmp_cheats
:=true;
1133 if tmp_gm
=2 then begin tmp_cheats
:=false; tmp_bon_chest
:=false; end;
1137 nextseed
:=stringtointeger(gettext('Seed:',''+nextseed
,10,TF_NUMERIC
));
1141 world_typ
:=world_typ
+1;
1142 if world_typ
>1 then world_typ
:=0;
1146 if tmp_gm
<2 then tmp_cheats
:= not tmp_cheats
;
1150 if tmp_gm
<2 then tmp_bon_chest
:= not tmp_bon_chest
;
1156 bon_chest
:=tmp_bon_chest
;
1158 while file_exists('/'+sd
+'/cavecraft/saves/'+name
)=1 do
1165 menu_game_new
:=true;
1173 for ix
:=0 to getWidth
/16 do
1174 for iy
:=0 to getHeight
/16 do
1175 drawimage(bg
[0],ix
*16,iy
*16);
1177 drw_btn('Name:'+name
,-2,m_cur
,0,1);
1178 drw_btn('Mode:'+newgametxt
[tmp_gm
],-1,m_cur
,0,1);
1179 drw_btn('Seed:'+nextseed
,0,m_cur
,0,1);
1180 drw_btn('Type:'+newgametxt
[world_typ
+3],1,m_cur
,0,1);
1182 drw_btn('Cheats:'+tmp_cheats
,2,m_cur
,0,1);
1184 drw_btn('Cheats:'+tmp_cheats
,2,m_cur
,0,0);
1186 drw_btn('Chest:'+tmp_bon_chest
,3,m_cur
,0,1);
1188 drw_btn('Chest:'+tmp_bon_chest
,3,m_cur
,0,0);
1189 drw_btn('Create',4,m_cur
,0,1);
1190 drw_btn('Cancel',5,m_cur
,0,1);
1197 procedure deleteworld(path
:string);
1199 if file_exists(path
+'player.dat')=1 then delete_file(path
+'player.dat');
1200 if file_exists(path
+'world.sav')=1 then delete_file(path
+'world.sav');
1201 if file_exists(path
+'nether.sav')=1 then delete_file(path
+'nether.sav');
1202 if file_exists(path
+'pic.png')=1 then delete_file(path
+'pic.png');
1203 if file_exists(path
)=1 then delete_file(path
);
1204 if file_exists(path
)=0 then debug('World deleted!');
1207 function menu_game
:boolean;
1209 ix
,iy
,pars
,max_r
,cur_name
,m_cur
:integer;
1213 names
:array[0..255] of string;
1215 rr
:=get_dirs('/'+sd
+'/cavecraft/saves/');
1216 while pos(rr
,'|')<>-1 do
1219 names
[max_r
]:=copy(rr
,0,pars
-1);
1220 rr
:=copy(rr
,pars
+1,length(rr
));
1221 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[max_r
]+'/player.dat')=1 then max_r
:=max_r
+1;
1224 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png')=1 then
1225 im_game
:=safely_load_image_fs('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png');
1226 else im_game
:=ld_tex('maps.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','');
1228 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/player.dat')=1 then
1229 mm_t_b
:=true; else mm_t_b
:=false;
1233 if clickedKey(KEY_MENU_UP
) then
1236 if m_cur
<0 then m_cur
:=3;
1238 if clickedKey(KEY_MENU_DOWN
) then
1241 if m_cur
>3 then m_cur
:=0;
1244 if (max_r
>= 0) and clickedKey(KEY_MENU_LEFT
) then
1246 cur_name
:=cur_name
-1;
1247 if cur_name
<0 then cur_name
:=0;
1248 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png')=1 then
1249 im_game
:=safely_load_image_fs('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png');
1250 else im_game
:=ld_tex('maps.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','');
1252 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/player.dat')=1 then
1254 if (max_r
>= 0) and clickedKey(KEY_MENU_RIGHT
) then
1256 cur_name
:=cur_name
+1;
1257 if cur_name
>max_r
then cur_name
:=max_r
;
1258 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png')=1 then
1259 im_game
:=safely_load_image_fs('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png');
1260 else im_game
:=ld_tex('maps.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','');
1262 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/player.dat')=1 then
1264 if clickedKey(KEY_MENU_SELECT
) then
1269 if loadgame('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/') then
1271 sav_fl
:=names
[cur_name
];
1278 if menu_game_new
then begin menu_game
:=true; break
; end;
1282 debug('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/');
1284 if question('Are you sure?')=true then deleteworld('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/');
1287 rr
:=get_dirs('/'+sd
+'/cavecraft/saves/');
1288 while pos(rr
,'|')<>-1 do
1291 names
[max_r
]:=copy(rr
,0,pars
-1);
1292 rr
:=copy(rr
,pars
+1,length(rr
));
1296 if file_exists('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png')=1 then
1297 im_game
:=safely_load_image_fs('/'+sd
+'/cavecraft/saves/'+names
[cur_name
]+'/pic.png');
1298 else im_game
:=ld_tex('maps.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','');
1306 for ix
:=0 to getWidth
/16 do
1308 drawimage(bg
[1],ix
*16,iy
*16);
1309 for ix
:=0 to getWidth
/16 do
1310 drawimage(bg
[0],ix
*16,0);
1311 for ix
:=0 to getWidth
/16 do
1312 for iy
:=8 to getHeight
/16 do
1313 drawimage(bg
[0],ix
*16,iy
*16);
1318 fillrect(32,24,getWidth
-64,96);
1319 setclip(32,24,getWidth
-64,96);
1320 drawimage(im_game
,(getWidth
/2)-(32),32);
1321 drawfonttext(names
[cur_name
],(getWidth
/2)-(length(names
[cur_name
])*8/2),104);
1322 setclip(0,0,getWidth
,getHeight
);
1323 setcolor(128,128,128);
1324 drawrect(32,24,getWidth
-64,96);
1325 if cur_name
>0 then drawimage(gui
[20],0,58);
1326 if cur_name
<max_r
then drawimage(gui
[21],getWidth
-9,58);
1331 fillrect(32,24,getWidth
-64,96);
1332 setclip(32,24,getWidth
-64,96);
1333 drawfonttext('No saves!',(getWidth
/2)-(length('No saves!')*8/2),104);
1334 setclip(0,0,getWidth
,getHeight
);
1335 setcolor(128,128,128);
1336 drawrect(32,24,getWidth
-64,96);
1339 if mm_t_b
then drw_btn('Play',0,m_cur
,32,1); else drw_btn('Play',0,m_cur
,32,0);
1340 drw_btn('Create new',1,m_cur
,32,1);
1341 if mm_t_b
then drw_btn('Delete',2,m_cur
,32,1); else drw_btn('Delete',2,m_cur
,32,0);
1342 drw_btn('Back',3,m_cur
,32,1);
1343 if not mm_t_b
then cur_name
:=cur_name
+1;
1352 ix
,iy
,pars
,max_r
,cur_name
,m_cur
,t
:integer;
1355 names
:array[0..255] of string;
1358 rr
:=get_dirs('/'+sd
+'/cavecraft/texturepacks/');
1359 names
[0]:='Default';
1361 while pos(rr
,'|')<>-1 do
1364 names
[max_r
]:=copy(rr
,0,pars
-1);
1365 rr
:=copy(rr
,pars
+1,length(rr
));
1369 im_game
:=loadimage('/pack.png');
1373 if clickedKey(KEY_MENU_UP
) then
1376 if m_cur
<0 then m_cur
:=1;
1378 if clickedKey(KEY_MENU_DOWN
) then
1381 if m_cur
>1 then m_cur
:=0;
1384 if clickedKey(KEY_MENU_LEFT
) then
1386 cur_name
:=cur_name
-1;
1387 if cur_name
<0 then cur_name
:=0;
1388 im_game
:=ld_tex('pack.png','/'+sd
+'/cavecraft/texturepacks/'+names
[cur_name
]+'/','');
1390 if clickedKey(KEY_MENU_RIGHT
) then
1392 cur_name
:=cur_name
+1;
1393 if cur_name
>max_r
then cur_name
:=max_r
;
1394 im_game
:=ld_tex('pack.png','/'+sd
+'/cavecraft/texturepacks/'+names
[cur_name
]+'/','');
1396 if clickedKey(KEY_MENU_SELECT
) then
1398 if m_cur
=0 then begin
1401 debug("Select TexturePack @ /" + sd
+ "/cavecraft/texturepacks/" + names
[cur_name
]);
1402 tex_pack
:=names
[cur_name
];
1403 LoadDrawFont('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1404 loadtexture('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1405 deleteRecordStore('TX');
1406 rs
:=openRecordStore('TX');
1407 t
:=addRecordStoreEntry(rs
,tex_pack
);
1408 closeRecordStore(rs
);
1410 LoadDrawFont('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1411 loadtexture('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
1415 debug("Cancel Select TecturePack");
1418 deleteRecordStore('TX');
1419 rs
:=openRecordStore('TX');
1420 t
:=addRecordStoreEntry(rs
,'');
1421 closeRecordStore(rs
);
1424 if m_cur
=1 then break
;
1428 for ix
:=0 to getWidth
/16 do
1430 drawimage(bg
[1],ix
*16,iy
*16);
1431 for ix
:=0 to getWidth
/16 do
1432 drawimage(bg
[0],ix
*16,0);
1433 for ix
:=0 to getWidth
/16 do
1434 for iy
:=8 to getHeight
/16 do
1435 drawimage(bg
[0],ix
*16,iy
*16);
1440 fillrect(32,24,getWidth
-64,96);
1441 setclip(32,24,getWidth
-64,96);
1442 drawimage(im_game
,(getWidth
/2)-(32),32);
1443 drawfonttext(names
[cur_name
],(getWidth
/2)-(length(names
[cur_name
])*8/2),104);
1444 setclip(0,0,getWidth
,getHeight
);
1445 setcolor(128,128,128);
1446 drawrect(32,24,getWidth
-64,96);
1447 if cur_name
>0 then drawimage(gui
[20],0,58);
1448 if cur_name
<max_r
then drawimage(gui
[21],getWidth
-9,58);
1451 drw_btn('Done',0,m_cur
,32,1);
1452 drw_btn('Back',1,m_cur
,32,1);
1459 procedure menu_sett
;
1461 ix
,iy
,m_cur
:integer;
1466 if clickedKey(KEY_MENU_UP
) then
1469 if m_cur
<-3 then m_cur
:=5;
1471 if clickedKey(KEY_MENU_DOWN
) then
1474 if m_cur
>5 then m_cur
:=-3;
1476 if clickedKey(KEY_MENU_SELECT
) then
1480 light_type
:=light_type
+1;
1481 if light_type
>2 then light_type
:=0;
1489 s_particles
:=not s_particles
;
1493 drawgui
:=not drawgui
;
1497 if question('Are you sure?')=true then
1499 if load_key_tex
=0 then
1503 //load_virt_tex(ld_tex('touch.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','gui/'));
1506 if load_key_tex
=1 then
1509 resetVirtualKeyboard(-1);
1515 s_jpeg_quality
:=stringtointeger(gettext('JPEG quality:',''+s_jpeg_quality
,3,TF_NUMERIC
));
1516 if s_jpeg_quality
>100 then s_jpeg_quality
:=100; else
1517 if s_jpeg_quality
<0 then s_jpeg_quality
:=0;
1525 deleteRecordStore('S');
1526 deleteRecordStore('SD');
1527 deleteRecordStore('TX');
1537 for ix
:=0 to getWidth
/16 do
1538 for iy
:=0 to getHeight
/16 do
1539 drawimage(bg
[0],ix
*16,iy
*16);
1541 drw_btn('Light:'+light_type
,-3,m_cur
,0,1);
1542 drw_btn('Weather:'+ifosad
,-2,m_cur
,0,1);
1543 drw_btn('Particles:'+s_particles
,-1,m_cur
,0,1);
1544 drw_btn('Hide GUI:'+not drawgui
,0,m_cur
,0,1);
1545 drw_btn('Touch:'+(load_key_tex
>0),1,m_cur
,0,1);
1546 drw_btn('JPEG:'+s_jpeg_quality
,2,m_cur
,0,1);
1547 drw_btn('Set Root',3,m_cur
,0,1);
1548 drw_btn('Reset',4,m_cur
,0,1);
1549 drw_btn('Back',5,m_cur
,0,1);
1556 procedure menu_help
;
1562 if clickedKey(KEY_MENU_SELECT
) then break
;
1563 if pressedKey(KEY_MENU_UP
) then cur
:=cur
+1;
1564 if pressedKey(KEY_MENU_DOWN
) then cur
:=cur
-1;
1566 for ix
:=0 to getWidth
/16 do
1567 for iy
:=2 to (getHeight
/16)-2 do
1568 drawimage(bg
[1],ix
*16,iy
*16);
1570 for ix
:=0 to getWidth
/16 do
1572 drawimage(bg
[0],ix
*16,iy
*16);
1574 for ix
:=0 to getWidth
/16 do
1575 for iy
:=(getHeight
/16)-2 to getHeight
/16 do
1576 drawimage(bg
[0],ix
*16,iy
*16);
1578 setclip(0,32,getWidth
,(getHeight
/16-4)*16);
1580 drw_txt('Controls:',cur
,0,1);
1581 drw_txt('Left - Move left',cur
,1,0);
1582 drw_txt('Right - Move right',cur
,2,0);
1583 drw_txt('Up - Jump',cur
,3,0);
1584 drw_txt('Down - Put a block under you',cur
,4,0);
1585 drw_txt('1 - Inventory',cur
,5,0);
1586 drw_txt('Duble 1 - Craft',cur
,6,0);
1587 drw_txt('3 - Use block',cur
,7,0);
1588 drw_txt('7 - Debug info',cur
,8,0);
1589 drw_txt('Hold 7 - Console',cur
,9,0);
1590 drw_txt('9 - Pause',cur
,10,0);
1591 drw_txt('*, # - Browse inventory',cur
,11,0);
1592 drw_txt('0 - Edit mode',cur
,12,0);
1594 drw_txt('In inventory/chest:',cur
,14,1);
1595 drw_txt('3 - Enject object',cur
,15,0);
1596 drw_txt('Hold 3 - Enject stack',cur
,16,0);
1597 drw_txt('5 - Move the stack',cur
,17,0);
1598 drw_txt('Hold 5 - Divide stack',cur
,18,0);
1600 setclip(0,0,getWidth
,getHeight
);
1602 drw_btn('Back',0,0,getHeight
-getHeight
/2-16-6,1);
1609 procedure menu_about
;
1615 if clickedKey(KEY_MENU_SELECT
) then break
;
1616 if pressedKey(KEY_MENU_UP
) then cur
:=cur
+1;
1617 if pressedKey(KEY_MENU_DOWN
) then cur
:=cur
-1;
1619 for ix
:=0 to getWidth
/16 do
1620 for iy
:=2 to (getHeight
/16)-2 do
1621 drawimage(bg
[1],ix
*16,iy
*16);
1623 for ix
:=0 to getWidth
/16 do
1625 drawimage(bg
[0],ix
*16,iy
*16);
1627 for ix
:=0 to getWidth
/16 do
1628 for iy
:=(getHeight
/16)-2 to getHeight
/16 do
1629 drawimage(bg
[0],ix
*16,iy
*16);
1631 setclip(0,32,getWidth
,(getHeight
/16-4)*16);
1633 drw_txt('Developers:',cur
,0,1);
1634 drw_txt(#68+#101+#97+#68+#68+#111+#111+#77+#69+#82+' - Programmer',cur
,1,0);//dead
1635 drw_txt(#102+#114+#101+#100+#45+#98+#111+#121+' - Programmer',cur
,2,0);//fred-boy
1636 drw_txt(#65+#110+#100+#114+#101+#121+#53+#57+' - Programmer',cur
,3,0);//andrey59
1637 drw_txt(#89+#117+#82+#97+#78+#110+#78+#122+#90+#90+' - Artist',cur
,4,0);//yura
1638 drw_txt(#83+#97+#115+#104+#97+#71+' - Artist and idea generator',cur
,5,0);//sasha
1639 drw_txt(#66+#97+#74+#108+#101+#72+#84+#105+#72+' - Artist and tester',cur
,6,0);//valentin
1640 drw_txt(#65+#103+#114+#101+#115+#115+#111+#82+' - Tester',cur
,7,0);//agressor
1641 drw_txt(#118+#111+#108+#121+#97+#95+#110+#97+#115+#116+#97+#110+#101+' - Tester',cur
,8,0);//volya
1642 drw_txt(#97+#98+#97+#100+#111+#110+' - Tester',cur
,9,0);//abadon
1643 drw_txt(#77+#111+#110+#111+#103+#114+#111+#109+' - Tester',cur
,10,0);//monogrom
1644 drw_txt(#75+#97+#108+#116+#101+#114+' - Tester',cur
,11,0);//kalter
1646 drw_txt('Thanks:',cur
,12,1);
1647 drw_txt('Piligrim and 0vZ - Lib_jsr75i',cur
,13,0);
1648 drw_txt('Piligrim - Lib_effects',cur
,14,0);
1649 drw_txt('Kurdt - Lib_canvas',cur
,15,0);
1650 drw_txt('ViNT - Lib_png and Lib_bmp',cur
,16,0);
1651 drw_txt('aleshka - Lib_jpeg',cur
,17,0);
1652 drw_txt('Roman_V - Lib_safeload',cur
,18,0);
1654 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);
1655 drw_txt(#68+#101+#97+#68+#83+#111+#102+#116+#87+#97+#114+#101+' 2012-'+getyear(getcurrenttime
),cur
,22,0);
1657 drw_txt('Hello! :D',cur
,100,1);
1659 setclip(0,0,getWidth
,getHeight
);
1661 drw_btn('Back',0,0,getHeight
-getHeight
/2-16-6,1);
1668 function sm_siz
:integer;
1670 sm_siz
:=(getWidth
+getHeight
)/5;
1673 function sm_siz4
:integer;
1678 procedure draw_menu_back
;
1682 for ix
:=0 to getWidth
/16 do
1683 for iy
:=0 to getHeight
/16 do
1684 drawimage(bg
[0],ix
*16,iy
*16);
1689 m_cur
,ix
,iy
,iz
:integer;
1695 spl_y
,spl_del
:integer;
1698 cavelogo
:=ld_tex('cavelogo.png','/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/','title/');
1700 spl_y
:=getimageheight(cavelogo
);
1702 spl_del
:=getrelativetimems
;
1703 res
:=openResource('/title/splashes.txt');
1704 if ResourceAvailable(res
) then
1706 spl_i
:=stringtointeger(readline(res
));
1707 iy
:=random(spl_i
-1)+1;
1708 debug('SPLASH #'+iy
);
1710 splash
:=readline(res
);
1713 time
:=getcurrenttime
;
1714 if (getmonth(time
)=5) and (getday(time
)=7) then splash
:='Happy birthday, DeaDDooMER!';
1715 if ((getmonth(time
)=0) and (getday(time
)<3)) or ((getmonth(time
)=11) and (getday(time
)>29)) then splash
:='Happy New Year!';
1719 if clickedKey(KEY_MENU_UP
) then
1722 if m_cur
<0 then m_cur
:=5;
1724 if clickedKey(KEY_MENU_DOWN
) then
1727 if m_cur
>5 then m_cur
:=0;
1729 if clickedKey(KEY_MENU_SELECT
) then
1731 if m_cur
=0 then begin if menu_game
then break
; end;
1733 if m_cur
=1 then menu_tex
;
1735 if m_cur
=2 then menu_sett
;
1737 if m_cur
=3 then menu_help
;
1739 if m_cur
=4 then menu_about
;
1741 if m_cur
=5 then begin save_settings
; halt
; end;
1746 drawimage(cavelogo
,(getWidth
/2)-(getimagewidth(cavelogo
)/2),0);
1747 setcolor(255,255,0);
1749 DrawFontTextSpec(splash
, (getWidth
/2)-(length(splash
)*FONT_SYM_SIZE
/2), spl_y
, FONT_YELLOW_COLOR
, true);
1751 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;
1752 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;
1753 drawfonttext(version
,0,getHeight
-8);
1755 drw_btn('Singleplayer',0,m_cur
,0,1);
1756 drw_btn('Texture Packs',1,m_cur
,0,1);
1757 drw_btn('Options',2,m_cur
,0,1);
1758 drw_btn('Help',3,m_cur
,0,1);
1759 drw_btn('About',4,m_cur
,0,1);
1760 drw_btn('Quit Game',5,m_cur
,0,1);
1767 function setBlock(invcur
, x
, y
:integer):boolean;
1769 item
, sum
, block
, sblock
:integer;
1771 item
:=inv
.getItem(invcur
);
1772 sum
:=inv
.getSum(invcur
);
1773 block
:=getMap(x
, y
);
1774 sblock
:=getItemInfo(item
);
1776 if getItemType(item
)=ITEM_TYPE_BLOCK
then
1777 if inv
.isNull(invcur
)=false then
1778 if getBlockSet(block
)=true then
1779 // if (coll_xy(x, y)=false) or (getBlockColl(item)=0) then
1781 if set_block_code(sblock
, x
, y
)=false then
1784 setmap(sblock
, x
, y
);
1787 inv
.setSum(inv
.getSum(invcur
)-1, invcur
);
1788 inv
.fixNull(invcur
);
1802 if (getrelativetimems
-fish_time
>5000) and (getmap(fx
,fy
)=50) then
1804 if (random(3)=2) and (getmap(fx
,fy
)=50) then
1806 drop
.create(210,1,x
,y
);
1809 inv
.setSum(inv
.getSum(invslot
)-1, invslot
);
1810 inv
.fixNull(invslot
);
1813 if (getrelativetimems
-fish_time
<5000) and (getmap(fx
,fy
)=50) and (fish
=true) then
1815 if getmap(fx
,fy
-1)=50 then fy
:=fy
-1;
1819 procedure drawminimap
;
1821 ix
,iy
,tmp_gx
,tmp_gy
,minx
,miny
,maxx
,maxy
,loc_camx
,loc_camy
,x
,y
:integer;
1825 if load_minimap_tex
then
1827 tmp_gx
:=(getWidth
/2)-(getimagewidth(gui
[16])/2);
1828 tmp_gy
:=(getHeight
/2)-(getimageheight(gui
[16])/2);
1832 tmp_gx
:=(getWidth
/2)-(64/2);
1833 tmp_gy
:=(getHeight
/2)-(64/2);
1836 loc_camx
:=(x
+4)-(864/2);
1837 loc_camy
:=(y
+4)-(864/2);
1838 if loc_camx
<0 then loc_camx
:=0;
1839 if loc_camx
>4096-864 then loc_camx
:=4096-864;
1840 if loc_camy
<0 then loc_camy
:=0;
1841 if loc_camy
>2048-864 then loc_camy
:=2048-864;
1844 maxx
:=(loc_camx
+864)/16;
1845 maxy
:=(loc_camy
+864)/16;
1846 if minx
<0 then minx
:=0;
1847 if miny
<0 then miny
:=0;
1848 if maxx
>255 then maxx
:=255;
1849 if maxy
>127 then maxy
:=127;
1851 if load_minimap_tex
then
1852 drawimage(gui
[16],tmp_gx
,tmp_gy
);
1855 setcolor(214,190,150);
1856 fillrect(tmp_gx
,tmp_gy
,64,64);
1859 for ix
:=minx
to maxx
do
1860 for iy
:=miny
to maxy
do
1862 if (getmap(ix
,iy
)=1) or (getmap(ix
,iy
)=2) or (getmap(ix
,iy
)=74) then setcolor(121,85,58); else
1863 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
1864 if (getmap(ix
,iy
)=50) or (getmap(ix
,iy
)=62) then setcolor(38,92,255); else
1865 if getmap(ix
,iy
)=51 then setcolor(255,0,0); else
1866 if (getmap(ix
,iy
)=61) or (getmap(ix
,iy
)=32) then setcolor(255,255,255); else
1867 setcolor(127,127,127);
1869 if (getmap(ix
,iy
)<>0) then plot(tmp_gx
+4+ix
-minx
,tmp_gy
+4+iy
-miny
);
1874 procedure draw_sign
;
1877 str
:array[0..3] of string;
1878 i
,j
,tmp_gx
,tmp_gy
:integer;
1880 if load_gui_tex
then
1882 tmp_gx
:=(getWidth
/2)-(getimagewidth(sign_im
)/2);
1883 tmp_gy
:=(getHeight
/2)-(getimageheight(sign_im
)/2);
1887 tmp_gx
:=(getWidth
/2)-(120/2);
1888 tmp_gy
:=(getHeight
/2)-(60/2);
1891 tmp
:=t_sign
[getmapinfo(curx
,cury
)];
1892 while pos(tmp
,#13)<>-1 do
1895 str
[j
]:=copy(tmp
,0,i
);
1896 tmp
:=copy(tmp
,i
+1,length(tmp
));
1900 if load_gui_tex
then
1901 drawimage(sign_im
,tmp_gx
,tmp_gy
);
1904 setcolor(159,132,77);
1905 fillrect(tmp_gx
,tmp_gy
,120,60);
1908 drawfonttext(str
[0],tmp_gx
+(120/2)-(length(str
[0])*8/2),tmp_gy
+(60/4/2)+4);
1909 drawfonttext(str
[1],tmp_gx
+(120/2)-(length(str
[1])*8/2),tmp_gy
+(60/4/2)+8+4);
1910 drawfonttext(str
[2],tmp_gx
+(120/2)-(length(str
[2])*8/2),tmp_gy
+(60/4/2)+16+4);
1911 drawfonttext(str
[3],tmp_gx
+(120/2)-(length(str
[3])*8/2),tmp_gy
+(60/4/2)+24+4);
1914 procedure draw_back(ix
,iy
:integer);
1916 if getBiomMap(ix
)=0 then
1918 if (getBackMap(ix
)=iy
) then drawimage(back
[0],(ix
*16)-camx
,(iy
*16)-camy
); else
1919 if (getBackMap(ix
)+1=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1920 if (getBackMap(ix
)+2=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1921 if (getBackMap(ix
)+3=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1922 if (getBackMap(ix
)<iy
) then drawimage(back
[2],(ix
*16)-camx
,(iy
*16)-camy
);
1924 if getBiomMap(ix
)=1 then
1926 if (getBackMap(ix
)=iy
) then drawimage(back
[4],(ix
*16)-camx
,(iy
*16)-camy
); else
1927 if (getBackMap(ix
)+1=iy
) then drawimage(back
[4],(ix
*16)-camx
,(iy
*16)-camy
); else
1928 if (getBackMap(ix
)+2=iy
) then drawimage(back
[6],(ix
*16)-camx
,(iy
*16)-camy
); else
1929 if (getBackMap(ix
)+3=iy
) then drawimage(back
[6],(ix
*16)-camx
,(iy
*16)-camy
); else
1930 if (getBackMap(ix
)<iy
) then drawimage(back
[2],(ix
*16)-camx
,(iy
*16)-camy
);
1932 if getBiomMap(ix
)=2 then
1934 if (getBackMap(ix
)=iy
) then drawimage(back
[5],(ix
*16)-camx
,(iy
*16)-camy
); else
1935 if (getBackMap(ix
)+1=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1936 if (getBackMap(ix
)+2=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1937 if (getBackMap(ix
)+3=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1938 if (getBackMap(ix
)<iy
) then drawimage(back
[2],(ix
*16)-camx
,(iy
*16)-camy
);
1940 if getBiomMap(ix
)=3 then
1942 if (getBackMap(ix
)=iy
) then drawimage(back
[7],(ix
*16)-camx
,(iy
*16)-camy
); else
1943 if (getBackMap(ix
)+1=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1944 if (getBackMap(ix
)+2=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1945 if (getBackMap(ix
)+3=iy
) then drawimage(back
[1],(ix
*16)-camx
,(iy
*16)-camy
); else
1946 if (getBackMap(ix
)<iy
) then drawimage(back
[2],(ix
*16)-camx
,(iy
*16)-camy
);
1948 if getBiomMap(ix
)=4 then
1950 drawimage(back
[8],(ix
*16)-camx
,(iy
*16)-camy
);
1956 ix
,iy
,iz
,minx
,miny
,maxx
,maxy
,tmp_ax
,tim
,smy
,pa_xo
, x
, y
:integer;
1960 {===================[sky]===================}
1961 tim
:=10000*getimagewidth(sky
)/600000*game_time
/10000;
1962 setcolor(effects
.get(sky
,tim
,0,1),effects
.get(sky
,tim
,0,2),effects
.get(sky
,tim
,0,3));
1963 fillrect(0,0,getWidth
,getHeight
);
1967 setcolor(effects
.get(sky
,tim
,2,1),effects
.get(sky
,tim
,2,2),effects
.get(sky
,tim
,2,3));
1968 smy
:=10000*getWidth
*2/600000*game_time
/10000;
1969 for iz
:=1 to getWidth
do
1971 ix
:=rnd(getWidth
*2)-getWidth
+smy
;
1972 if ix
>getWidth
then ix
:=ix
-getWidth
*2;
1974 if (ix
>-1) and (ix
<getWidth
) then plot(ix
,iy
);
1982 smy
:=10000*(getWidth
+getimagewidth(sun
))/300000*game_time
/10000;
1983 drawimage(sun
,smy
-getimagewidth(sun
),getHeight
/2-getimageheight(sun
)/2);
1987 setcolor(255,213,74);
1988 smy
:=10000*(getWidth
+sm_siz
)/300000*game_time
/10000;
1989 fillrect(smy
-sm_siz
+sm_siz4
,getHeight
/2-sm_siz
/2+sm_siz4
,sm_siz
-sm_siz4
,sm_siz
-sm_siz4
);
1994 smy
:=10000*(getWidth
+getimagewidth(moon
))/300000*(game_time
-300000)/10000;
1995 drawimage(moon
,smy
-getimagewidth(moon
),getHeight
/2-getimageheight(moon
)/2);
1999 setcolor(175,184,204);
2000 smy
:=10000*(getWidth
+sm_siz
)/300000*(game_time
-300000)/10000;
2001 fillrect(smy
-sm_siz
+sm_siz4
,getHeight
/2-sm_siz
/2+sm_siz4
,sm_siz
-sm_siz4
,sm_siz
-sm_siz4
);
2004 {===================[camera]===================}
2005 camx
:=(x
+4)-(getWidth
/2);
2006 camy
:=(y
+4)-(getHeight
/2);
2007 if camx
<0 then camx
:=0;
2008 if camx
>4096-getWidth
then camx
:=4096-getWidth
;
2009 if camy
>2048-getHeight
then camy
:=2048-getHeight
;
2010 {===================[max_draw]===================}
2013 maxx
:=(camx
+getWidth
)/16;
2014 maxy
:=(camy
+getHeight
)/16;
2015 if minx
<0 then minx
:=0;
2016 if miny
<0 then miny
:=0;
2017 if maxx
>255 then maxx
:=255;
2018 if maxy
>127 then maxy
:=127;
2019 {===================[draw_back]===================}
2020 for ix
:=minx
to maxx
do
2021 for iy
:=miny
to maxy
do
2023 if ifosad
then if (getBackMap(ix
)>=iy
) and (osadki
=true) and getBlockTrans(getmap(ix
,iy
)) then
2025 if getBiomMap(ix
)=0 then drawimage(osad
[0,osadki_ani
],(ix
*16)-camx
,(iy
*16)-camy
);
2027 if getBiomMap(ix
)=2 then drawimage(osad
[1,osadki_ani
],(ix
*16)-camx
,(iy
*16)-camy
);
2029 if getBiomMap(ix
)=3 then drawimage(osad
[0,osadki_ani
],(ix
*16)-camx
,(iy
*16)-camy
);
2032 if getBlockTrans(getmap(ix
,iy
)) then
2035 if getBlockFore(getmap(ix
,iy
))=false then
2038 {===================[drop]===================}
2039 drop
.draw(camx
, camy
);
2040 {===================[particles]===================}
2041 if s_particles
then draw_particle
;
2042 {===================[player]===================}
2045 player
.draw(camx
, camy
);
2048 {===================[mobs]===================}
2049 Mobs
.Draw(camx
, camy
);
2050 {===================[draw_blocks]===================}
2051 for ix
:=minx
to maxx
do
2052 for iy
:=miny
to maxy
do
2054 if getBlockFore(getmap(ix
, iy
)) then
2058 if light_type
= 1 then
2060 if getmaplight(ix
,iy
) = 0 then
2061 fillrect((ix
* 16) - camx
, (iy
* 16) - camy
, 16, 16);
2063 else if light_type
= 2 then
2065 if getmaplight(ix
, iy
) < 15 then
2066 drawimage(light
[getmaplight(ix
, iy
)], (ix
* 16) - camx
, (iy
* 16) - camy
);
2071 // drawimage(light[getmaplight(player.getX div 16, player.getY div 16)], 0, 0);
2073 if (toolus
> 0) and (toolind
< 10) and (getmap(curx
,cury
) > 0) then
2077 drawimage(tue
[toolind
], curx
* 16 - camx
, cury
* 16 - camy
);
2079 {===================[gui]===================}
2082 tmp_ax
:=(getWidth
/2)-(getImageWidth(gui
[1])/2);
2085 drawimage(gui
[0],curx
*16-camx
,cury
*16-camy
);
2090 DrawPlayerInventory
;
2093 if keymode
=3 then drawcraft
; else
2094 if keymode
=4 then drawchest
; else
2095 if keymode
=5 then draw_sign
; else
2096 if keymode
=6 then drawfurnace
; else
2097 if ifminimap
then drawminimap
;*/
2099 drawimage(gui
[1],tmp_ax
,0);
2102 drawItem(inv
.getItem(ix
), inv
.getSum(ix
), (ix
*16)+tmp_ax
+ix
*2+4, 1, true);
2104 drawimage(gui
[17],(invslot
*16)+tmp_ax
+invslot
*2+2,0);
2110 for ix
:=0 to (hp
div 2)-1 do drawimage(gui
[13],ix
*9,getHeight
-9);
2111 if (hp
mod 2)<>0 then begin drawimage(gui
[14],ix
*9,getHeight
-9); ix
:=ix
+1 end;
2112 for ix
:=ix
to 9 do drawimage(gui
[15],ix
*9,getHeight
-9);
2116 for ix
:=0 to (hp
div 2)-1 do drawimage(gui
[31],ix
*9,getHeight
-9);
2117 if (hp
mod 2)<>0 then begin drawimage(gui
[32],ix
*9,getHeight
-9); ix
:=ix
+1 end;
2118 for ix
:=ix
to 9 do drawimage(gui
[33],ix
*9,getHeight
-9);
2121 for ix
:=0 to (hunger
div 2)-1 do drawimage(gui
[26],ix
*9,getHeight
-18);
2122 if (hunger
mod 2)<>0 then begin drawimage(gui
[27],ix
*9,getHeight
-18); ix
:=ix
+1 end;
2123 for ix
:=ix
to 9 do drawimage(gui
[28],ix
*9,getHeight
-18);
2125 if getmap((x
+4)/16,y
/16)=50 then
2127 for ix
:=0 to (air
div 2)-1 do drawimage(gui
[29],ix
*9,getHeight
-27);
2128 if (air
mod 2)<>0 then begin drawimage(gui
[30],ix
*9,getHeight
-27); ix
:=ix
+1 end;
2134 drawfonttext(msg
[ix
],0,getHeight
-20-ix
*9);
2135 if getrelativetimems
-msg_time
[ix
]>5000 then msg
[ix
]:='';
2140 procedure load_moon(path
:string;phase
:integer);
2147 moon
:=ld_tex('moon_phase_'+phase
+'.png',path
,'terrain/moon_phases/');
2151 moon
:=resize_image(ld_tex('moon_phase_'+phase
+'.png',path
,'terrain/moon_phases/'),(getWidth
+getHeight
)/5,(getWidth
+getHeight
)/5);
2159 if game_time
>300000 then
2161 if load_light_tex
then
2167 for iy
:=0 to getheight
/16 do
2168 for ix
:=0 to getwidth
/16 do
2169 drawimage(light
[i
],ix
*16,iy
*16);
2174 moon_phase
:=moon_phase
+1;
2175 if moon_phase
>7 then moon_phase
:=0;
2176 load_moon('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/',moon_phase
);
2179 last_sleep_y
:=cury
-1;
2184 for iy
:=0 to getheight
/16 do
2185 for ix
:=0 to getwidth
/16 do
2186 drawimage(light
[i
],ix
*16,iy
*16);
2196 while i
<=getheight
do
2199 fillrect(0,0,getwidth
,i
);
2204 moon_phase
:=moon_phase
+1;
2205 if moon_phase
>7 then moon_phase
:=0;
2206 load_moon('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/',moon_phase
);
2209 last_sleep_y
:=cury
-1;
2211 while i
<=getheight
do
2215 fillrect(0,i
,getwidth
,getheight
);
2221 end; else create_msg('You can sleep only at night');
2224 procedure resetToolProgerss
;
2230 procedure usetools(invcur
, x
, y
:integer);
2232 item
, sum
, block
:integer;
2234 block
:=getmap(x
, y
);
2235 item
:=inv
.getItem(invcur
);
2236 sum
:=inv
.getSum(invcur
);
2239 destroy_block_cr(block
, x
, y
);
2243 if (getItemType(item
)=ITEM_TYPE_TOOL
) and (getBlockTool(block
)=getToolType(item
)) then
2244 toolus
:=toolus
+getToolSpeed(item
);
2248 if toolus
>=getBlockHP(block
) then
2250 if ((getItemType(item
)=ITEM_TYPE_TOOL
) and (getBlockTool(block
)=getToolType(item
)) and (getToolLvl(item
)>=getBlockLvl(block
))) or (getBlockLvl(block
)<=0) then
2253 destroy_block_1(block
, x
, y
);
2254 setMapInfo(0, x
, y
);
2259 destroy_block_0(block
, x
, y
);
2260 setMapInfo(0, x
, y
);
2263 if getItemType(item
)=ITEM_TYPE_TOOL
then
2265 inv
.setSum(inv
.getSum(invcur
)-1, invcur
);
2266 inv
.fixNull(invcur
);
2274 if (toolus
>0) and (toolus
<=getBlockHP(block
)) then
2275 toolind
:=((toolus
*100) div getBlockHP(block
)) div 10;
2278 function rt_useweap
:boolean;
2280 x
, y
, w
, h
, i
, damg
:integer;
2287 item
:=inv
.getItem(invslot
);
2289 if getItemType(item
)=1 then
2290 damg
:=getToolDamg(item
);
2295 i
:=Mobs
.findAndHit(damg
, x
-TILE_SIZE
, y
, TILE_SIZE
+(w
/2), h
, -2, -3);
2297 i
:=Mobs
.findAndHit(damg
, x
+(w
/2), y
, TILE_SIZE
+(w
/2), h
, 2, -3);
2301 inv
.setSum(inv
.getSum(invslot
)-1, invslot
);
2302 inv
.fixNull(invslot
);
2307 procedure rt_usetools
;
2314 if posi
=0 then curx
:=(x
div 16)-1; else curx
:=(x
div 16)+1;
2316 if getmap(curx
,cury
)=0 then cury
:=cury
+1;
2318 if curx
<0 then curx
:=0;
2319 if curx
>255 then curx
:=255;
2320 if cury
<0 then cury
:=0;
2321 if cury
>127 then cury
:=127;
2323 usetools(invslot
, curx
, cury
);
2326 procedure rt_usemob
;
2333 if posi
=0 then curx
:=(x
div 16)-1; else curx
:=(x
div 16)+1;
2335 if getmap(curx
,cury
)=0 then cury
:=cury
+1;
2337 if curx
<0 then curx
:=0;
2338 if curx
>255 then curx
:=255;
2339 if cury
<0 then cury
:=0;
2340 if cury
>127 then cury
:=127;
2342 //usemob(curx,cury);
2345 procedure actionUse(invcur
, x
, y
:integer);
2347 if setBlock(invcur
, x
, y
)=false then
2348 if useBlock(invcur
, x
, y
) then
2349 if useItem(invcur
, x
, y
) then
2352 procedure rt_useblock
;
2359 if posi
=0 then curx
:=(x
div 16)-1; else curx
:=(x
div 16)+1;
2361 if getmap(curx
,cury
)=0 then cury
:=cury
+1;
2363 if curx
<0 then curx
:=0;
2364 if curx
>255 then curx
:=255;
2365 if cury
<0 then cury
:=0;
2366 if cury
>127 then cury
:=127;
2368 actionUse(invslot
, curx
, cury
);
2371 procedure go_to_nether
;
2375 portal_time
:=getrelativetimems
;
2376 savegame('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/');
2378 drw_load_line('Matrix',10);
2379 if loadworld('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/')=true then
2381 player
.setX(get_spawn_x
*16+4);
2382 player
.setY((get_up(get_spawn_x
)-1)*16);
2395 mob[ix].m_min_vely:=0;
2398 mob[ix].m_fall:=false;
2399 mob[ix].m_jmp:=false;
2400 mob[ix].m_velani:=false;
2409 procedure go_to_world
;
2411 portal_time
:=getrelativetimems
;
2412 savegame('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/');
2414 drw_load_line('Matrix',10);
2415 if loadworld('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/')=true then
2428 procedure plr_is_dead_hardcore
;
2436 if clickedKey(KEY_MENU_SELECT
) then
2438 deleteworld('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/');
2443 drawfonttext('You died!',getwidth
/2-32,getheight
/2-16);
2445 drw_btn('Delete world',0,0,0,1);
2453 procedure plr_is_dead
;
2465 if clickedKey(KEY_MENU_UP
) then
2468 if m_cur
<0 then m_cur
:=1;
2470 if clickedKey(KEY_MENU_DOWN
) then
2473 if m_cur
>1 then m_cur
:=0;
2475 if clickedKey(KEY_MENU_SELECT
) then
2481 if last_sleep_x
=0 then
2483 x
:=get_spawn_x
*16+4;
2487 x
:=last_sleep_x
*16+4;
2494 if last_sleep_x
=0 then
2496 x
:=get_spawn_x
*16+4;
2500 x
:=last_sleep_x
*16+4;
2516 if m_cur
=1 then begin menu
; exit
; end;
2521 drawfonttext('You died!',getwidth
/2-32,getheight
/2-16);
2523 drw_btn('Respawn',0,m_cur
,0,1);
2524 drw_btn('Main menu',1,m_cur
,0,1);
2531 procedure fast_menu
;
2537 if clickedKey(KEY_MENU_UP
) then begin m_cur
:=m_cur
-1; if m_cur
<0 then m_cur
:=3; end;
2538 if clickedKey(KEY_MENU_DOWN
) then begin m_cur
:=m_cur
+1; if m_cur
>3 then m_cur
:=0; end;
2539 if clickedKey(KEY_MENU_SELECT
) then
2547 savegame('/'+sd
+'/cavecraft/saves/'+sav_fl
+'/');
2556 //clear_gui(keymode);
2562 drawfonttext('Game menu',getwidth
/2-36,getheight
/2-20);
2563 drw_btn('Back to Game',0,m_cur
,0,1);
2564 drw_btn('Save Game',1,m_cur
,0,1);
2565 drw_btn('Options',2,m_cur
,0,1);
2566 drw_btn('Quit to Title',3,m_cur
,0,1);
2573 procedure keyFastInv
;
2575 if clickedKey(KEY_FASTINV_NEXT
) then
2582 if clickedKey(KEY_FASTINV_PREV
) then
2590 procedure keyConsole
;
2592 if clickedKey(KEY_CHAT
) then
2593 SetTimer(1000,T_CONSOLE
);
2595 if pressedKey(KEY_CHAT
) then
2597 if GetTimer(T_CONSOLE
)=TIMER_OK
then
2600 ResetTimer(T_CONSOLE
);
2605 if GetTimer(T_CONSOLE
)>TIMER_OK
then
2608 ResetTimer(T_CONSOLE
);
2613 procedure keyInventory
;
2615 if clickedKey(KEY_PLR_OPENINV
) then
2617 OpenPlayerInventory
;
2622 procedure keyhandler
;
2626 if WindowKeyHanler
then
2634 if clickedKey(KEY_PLR_EDITMODE
) then
2637 curx
:=player
.getX
div 16;
2638 cury
:=player
.getY
div 16;
2641 if clickedKey(KEY_PLR_USE
) then
2644 if clickedKey(KEY_MENU
) then
2647 if clickedKey(KEY_PLR_ATTACK
) then
2648 if rt_useweap
=false then
2651 if pressedKey(KEY_PLR_ATTACK
) then
2654 playAnim(ANIM_HAND
);
2659 cancelAnim(ANIM_HAND
);
2662 if pressedKey(KEY_PLR_UP
) then
2664 if pressedKey(KEY_PLR_DOWN
) then
2666 if pressedKey(KEY_PLR_LEFT
) then
2668 if pressedKey(KEY_PLR_RIGHT
) then
2678 if clickedKey(KEY_PLR_UP
) then
2684 if clickedKey(KEY_PLR_DOWN
) then
2690 if clickedKey(KEY_PLR_LEFT
) then
2696 if clickedKey(KEY_PLR_RIGHT
) then
2703 if clickedKey(KEY_PLR_EDITMODE
) then
2706 if clickedKey(KEY_PLR_USE
) then
2707 actionUse(invslot
, curx
, cury
);
2709 if pressedKey(KEY_PLR_ATTACK
) then
2711 usetools(invslot
, curx
, cury
);
2712 playAnim(ANIM_HAND
);
2717 cancelAnim(ANIM_HAND
);
2720 if clickedKey(KEY_MENU
) then
2728 procedure phyhandler
;
2737 procedure light_fillrect(l
,x
,y
,r
:integer);
2739 ix
,iy
,ym
,yp
,xm
,xp
:integer;
2747 setmaplight(getmaplight(ix
,iy
)+l
,ix
,iy
);
2750 procedure light_rect(l
,x
,y
,r
:integer);
2752 ix
,iy
,ym
,yp
,xm
,xp
:integer;
2760 setmaplight(getmaplight(ix
,ym
)+l
,ix
,ym
);
2761 setmaplight(getmaplight(ix
,yp
)+l
,ix
,yp
);
2763 for iy
:=ym
+1 to yp
-1 do
2765 setmaplight(getmaplight(xm
,iy
)+l
,xm
,iy
);
2766 setmaplight(getmaplight(xp
,iy
)+l
,xp
,iy
);
2770 procedure calc_light(m
,x
,y
:integer);
2772 ix
,iy
,l
,ss
,sf
:integer;
2774 if light_type
=1 then light_fillrect(m
,x
,y
,m
/2); else
2775 for l
:=m
downto 1 do
2777 if ss
mod 2=0 then light_rect(l
,x
,y
,ss
/2);
2782 procedure calc_sun(ix
,m
:integer);
2789 setmaplight(ss
,ix
,iy
);
2791 ss
:=ss
-getBlockTr(getmap(ix
,iy
));
2794 for iy
:=iy
+1 to 127 do
2796 setmaplight(0,ix
,iy
);
2805 for i
:=0 to INV_SIZE
do
2807 if inv
.isNull(i
)=false then
2808 player
.dropItem(inv
.getItem(i
), inv
.getSum(i
));
2812 if gamemode
<2 then plr_is_dead
; else plr_is_dead_hardcore
;
2815 procedure hunger_and_air
;
2823 if getrelativetimems
-hung_time
>=90000/(gamemode
+1) then
2825 hung_time
:=getrelativetimems
;
2828 if getrelativetimems
-hp_time
>=5000*(gamemode
+1) then
2832 hp_time
:=getrelativetimems
;
2834 if hp
>20 then hp
:=20;
2838 hp_time
:=getrelativetimems
;
2840 if hp
<1 then if gamemode
<2 then hp
:=1;
2844 if getmap((x
+4)/16,y
/16)=50 then
2846 if getrelativetimems
-air_time
>=500 then
2849 air_time
:=getrelativetimems
;
2852 hp_time
:=getrelativetimems
;
2863 ix
,iy
,minx
,maxx
,miny
,maxy
,fps_t
,tim
, x
, y
:integer;
2870 if hunger
<0 then hunger
:=0;
2871 if air
<0 then air
:=0;
2874 if fps_t
<1 then fps_t
:=1;
2877 if bl_ani5_v
=false then
2883 bl_ani5_v
:=not bl_ani5_v
;
2892 bl_ani5_v
:=not bl_ani5_v
;
2895 bl_ani5_d
:=not bl_ani5_d
;
2900 game_time
:=game_time
+(600000 div (fps_t
*1000));
2902 // Ускорение игрового времени в 10 раз
2903 // game_time := game_time + (600000 div (fps_t*100));
2905 if (game_time
>600000) or (game_time
<0) then
2908 moon_phase
:=moon_phase
+1;
2909 if moon_phase
>7 then moon_phase
:=0;
2910 load_moon('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/',moon_phase
);
2913 tim
:= 10000 * getimagewidth(sky
) / 600000 * game_time
/ 10000;
2914 global_light
:= effects
.get(sky
, tim
, 1, 1) div 16;
2916 if clock_stage
<>game_time
div 75000 then begin clock_stage
:=clock_stage
+1; if clock_stage
>7 then clock_stage
:=0; end;
2919 if x
+8>4094 then x
:=4086;
2920 if getBlockColl(getmap(x
div 16, y
div 16))>0 then hp
:=hp
-1;
2921 if random(4096)=random(4096) then begin osadki
:=not osadki
; end;
2922 osadki_ani
:=osadki_ani
+1;
2923 if osadki_ani
>7 then osadki_ani
:=0;
2925 if random(20)=random(20) then create_particle(6,x
,y
);
2927 if gamemode
=1 then begin hp
:=666; hunger
:=666; end;
2929 if inv
.getItem(invslot
)=186 then
2934 //if s_spawn_mob then if random(4096)=1547 then megaspawn;
2938 if particle_upd
then update_particle
;
2940 if light_type
>0 then
2943 maxx
:=(camx
+getWidth
)/16+1;
2944 if minx
<0 then minx
:=0;
2945 if maxx
>255 then maxx
:=255;
2946 for ix
:=minx
to maxx
do calc_sun(ix
,global_light
);
2950 maxx
:=(camx
+getWidth
)/16+16;
2952 maxy
:=(camy
+getHeight
)/16+16;
2953 if minx
<0 then minx
:=0;
2954 if maxx
>255 then maxx
:=255;
2955 if miny
<0 then miny
:=0;
2956 if maxy
>127 then maxy
:=127;
2957 for ix
:=minx
to maxx
do
2958 for iy
:=miny
to maxy
do
2960 if light_type
=0 then setmaplight(15,ix
,iy
);
2962 if light_type
>0 then if getBlockLi(getmap(ix
,iy
))>0 then calc_light(getBlockLi(getmap(ix
,iy
)),ix
,iy
);
2965 minx
:=(camx
/16)-((getwidth
/2)/16);
2966 miny
:=(camy
/16)-((getheight
/2)/16);
2967 maxx
:=(camx
+(getWidth
+getWidth
/2))/16;
2968 maxy
:=(camy
+(getHeight
+getHeight
/2))/16;
2969 if minx
<0 then minx
:=0;
2970 if miny
<0 then miny
:=0;
2971 if maxx
>255 then maxx
:=255;
2972 if maxy
>127 then maxy
:=127;
2973 if updx
<minx
then updx
:=minx
;
2974 if updy
<miny
then updy
:=miny
;
2975 if updx
>maxx
then updx
:=minx
;
2976 if updy
>maxy
then updy
:=miny
;
2980 for ix
:=0 to (((2*getWidth
/16)*(2*getHeight
/16))-1) div ((fps_t
*bl_upd
)) do
2982 updateBlock(updx
, updy
);
2988 if updy
>maxy
then updy
:=miny
;
2993 {if coll_bl(110)=true then
2995 if getrelativetimems-portal_time>5000 then
2997 if pl_world=0 then begin go_to_nether; portal_time:=getrelativetimems; end; else
2998 if pl_world=1 then begin go_to_world; portal_time:=getrelativetimems; end;
3002 if coll_bl(51)=true then hp:=hp-1;
3004 if coll_bl(59)=true then
3006 if vely<0 then vely:=-1;
3008 if vely>0 then vely:=1;
3013 if hp
>20 then hp
:=20;
3014 if hunger
>20 then hunger
:=20;
3017 if y
>2048 then kill_plr
;
3018 if (hp
<1) and (gamemode
<>1) then kill_plr
;
3019 if fish
=true then fishing
;
3021 if (fish
=true) and (inv
.getItem(invslot
)<>152) then fish
:=false;
3023 //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;
3027 if cury
<(y
div 16)-4 then cury
:=(y
div 16)-4;
3028 if cury
>(y
div 16)+5 then cury
:=(y
div 16)+5;
3029 if curx
<(x
div 16)-4 then curx
:=(x
div 16)-4;
3030 if curx
>(x
div 16)+4 then curx
:=(x
div 16)+4;
3041 LoadDrawFont('/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/');
3044 if load_key_tex
=1 then init_touch
;
3048 msg_time
[i
]:=getrelativetimems
;
3050 InitMap(MAP_W
, MAP_H
);
3054 procedure draw_debug
;
3058 //drawfonttext('X:'+(x div 16-128),0,0);
3059 //drawfonttext('Y:'+integertostring(127-(y div 16)),0,8);
3060 drawfonttext('CURX:'+(curx
-128),0,16);
3061 drawfonttext('CURY:'+cury
,0,24);
3062 drawfonttext('UPDX:'+updx
,0,32);
3063 drawfonttext('UPDY:'+updy
,0,40);
3064 drawfonttext('FPS:'+fps
,0,56);
3065 drawfonttext('Free RAM:'+free_ram
/1024+' KB',0,64);
3066 drawfonttext('Total RAM:'+memory
.get_totalmemory
div 1024+' KB',0,72);
3067 drawfonttext('SEED:'+seed
,0,88);
3068 drawfonttext('Game time:'+game_time
,0,96);
3069 drawfonttext('Global light:' + global_light
, 0, 104);
3072 drawImage(light
[i
], getWidth
- 16, 16 * i
);
3077 hung_time
:=getrelativetimems
;
3078 hp_time
:=getrelativetimems
;
3079 air_time
:=getrelativetimems
;
3080 portal_time
:=getrelativetimems
;
3087 drawfonttext(version
,getWidth
-(length(version
)*8),getHeight
-8);
3088 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;