DEADSOFTWARE

blocks.cfg -> Blocks.pas
[cavecraft.git] / src / CAVE.mpsrc
1 program CAVE;
3 uses
4 sign,
5 jsr75i,
6 drop,
7 invui,
8 vars,
9 randoms,
10 memory,
11 worldgen,
12 canvas,
13 safeload,
14 mobs,
15 console,
16 effects,
17 particles,
18 keyboard,
19 maps,
20 phy,
21 utils,
22 func,
23 CellUI,
24 furnace,
25 player,
26 items_logic,
27 chest,
28 inv,
29 items_store,
30 video,
31 Blocks,
32 BlocksLogic,
33 Items,
34 ItemsLogic;
36 const
37 version_map = 9;
39 var
40 keymode,updx,updy:integer;
41 seed,nextseed:integer;
42 free_ram:real;
44 light:array [0..15] of image;
45 bg:array[0..1] of image;
46 osad:array [0..1,0..7] of image;
47 back:array [0..8] of image;
48 gui:array [0..34] of image;
49 tue:array [0..9] of image;
51 sign_im:image;
52 sky:image;
53 sun:image;
54 moon:image;
55 moon_phase:integer;
56 toolus,toolind:integer;
57 osadki_ani:integer;
58 sav_fl:string;
59 global_light:integer;
60 world_typ:integer;
61 float:image;
63 msg:array [0..4] of string;
64 msg_time:array[0..4] of integer;
65 last_sleep_x,last_sleep_y:integer;
67 ifminimap:boolean;
68 gt:integer;
70 del,dt,time:integer;
72 deb:boolean;
74 procedure newworld;
75 var
76 ix,iy:integer;
77 begin
78 if nextseed=0 then seed:=getrelativetimems; else seed:=nextseed;
79 nextseed:=0;
80 srand(seed);
81 if world_typ=0 then genworld;
82 else
83 if world_typ=1 then genflat;
84 world_typ:=0;
85 player.setX(get_spawn_x*16+4);
86 player.setY(get_spawn_y*16);
87 pl_world:=0;
88 end;
90 procedure drwrect(x,y,w,h,t:integer);
91 var
92 i:integer;
93 begin
94 for i:=0 to t do
95 drawrect(x+i,y+i,w-i*2,h-i*2);
96 end;
98 procedure proc_fps;
99 begin
100 dt:=GetRelativeTimeMs - time;
101 time:=GetRelativeTimeMs;
102 fps:=1000/dt;
103 end;
105 procedure maxfps;
106 begin
107 if fps<s_max_fps then if del>0 then del:=del-1;
108 if fps>s_max_fps then if del<200 then del:=del+1;
109 delay(del);
110 end;
112 procedure ClearTextures;
113 var
114 no : image;
115 ix, iy, iz : integer;
116 begin
117 bg[0] := no;
118 bg[1] := no;
119 float := no;
120 compas := no;
121 for ix := 0 to 7 do
122 Vars.clock[ix] := no;
124 for ix := 0 to maxBlockTex do
125 begin
126 tex[ix] := no;
127 tex8[ix] := no;
128 end;
129 for ix := 0 to maxItemTex do
130 begin
131 item[ix] := no;
132 item8[ix] := no;
133 end;
135 for ix := 0 to 8 do
136 back[ix]:=no;
138 player.freeSkin;
140 for ix := 0 to 34 do
141 gui[ix] := no;
142 for ix := 0 to 9 do
143 tue[ix] := no;
144 for ix := 0 to 7 do
145 osad[0, ix] := no;
146 for ix := 0 to 7 do
147 osad[1, ix] := no;
149 for ix := 0 to 15 do
150 light[ix] := no;
152 Particles.FreeTextures;
153 Mobs.FreeTextures;
155 sky := no;
156 sun := no;
157 moon := no;
158 sign_im := no;
160 for ix := 0 to CONST_MAX_CURS do
161 LoadCurImg(no, ix);
163 //resetVirtualKeyboard(-1);
164 end;
166 procedure create_msg(s:string);
167 var
168 i,t:integer;
169 begin
170 for i:=3 downto 0 do
171 begin
172 if i=0 then break;
173 msg_time[i]:=msg_time[i-1];
174 msg[i]:=msg[i-1];
175 end;
176 msg_time[0]:=getrelativetimems;
177 msg[0]:=s;
178 end;
180 procedure loadtexture(path:string);
181 var
182 ix,iy,iz:integer;
183 im:image;
184 begin
185 cleartextures;
186 im:=ld_tex('background.png',path,'title/');
187 for ix:=0 to 1 do
188 bg[ix]:=rotate_image_from_image(im,ix*16,0,16,16,0);
189 float:=ld_tex('float.png',path,'gui/');
190 compas:=ld_tex('compass.png',path,'gui/');
191 im:=ld_tex('clock.png',path,'gui/');
192 for ix:=0 to 7 do
193 Vars.clock[ix]:=rotate_image_from_image(im,ix*16,0,16,16,0);
194 if load_back_tex then
195 begin
196 im:=ld_tex('back.png',path,'');
197 for ix:=0 to 8 do back[ix]:=rotate_image_from_image(im,ix*16,0,16,16,0);
198 end;
200 console.exec('textures.cfg', 'AUTO');
202 Player.LoadSkin('char_ani.png', path);
203 Mobs.LoadTextures(path);
205 im:=ld_tex('gui.png',path,'gui/');
206 gui[0]:=rotate_image_from_image(im,0,0,16,16,0);
207 LoadCurImg(gui[0], CUR_SELECT1);
208 gui[1]:=rotate_image_from_image(im,0,16,168,21,0);
209 gui[3]:=rotate_image_from_image(im,16,0,16,16,0);
210 LoadCurImg(gui[3], CUR_SELECT2);
211 gui[6]:=rotate_image_from_image(im,0,56,120,12,0);
212 gui[7]:=rotate_image_from_image(im,0,68,120,12,0);
213 gui[8]:=rotate_image_from_image(im,0,80,120,12,0);
214 gui[13]:=rotate_image_from_image(im,1,93,9,9,0);//hp
215 gui[14]:=rotate_image_from_image(im,12,93,9,9,0);//hp
216 gui[15]:=rotate_image_from_image(im,23,93,9,9,0);//hp
217 gui[17]:=rotate_image_from_image(im,120,56,18,18,0);
219 gui[26]:=rotate_image_from_image(im,89,93,9,9,0);//hunger
220 gui[27]:=rotate_image_from_image(im,100,93,9,9,0);//hunger
221 gui[28]:=rotate_image_from_image(im,111,93,9,9,0);//hunger
223 gui[29]:=rotate_image_from_image(im,67,93,9,9,0);//air
224 gui[30]:=rotate_image_from_image(im,78,93,9,9,0);//air
226 gui[31]:=rotate_image_from_image(im,122,93,9,9,0);//hp hardcore
227 gui[32]:=rotate_image_from_image(im,133,93,9,9,0);//hp hardcore
228 gui[33]:=rotate_image_from_image(im,144,93,9,9,0);//hp hardcore
230 gui[20]:=rotate_image_from_image(im,121,75,9,13,0);
231 gui[21]:=rotate_image_from_image(im,130,75,9,13,0);
232 gui[22]:=rotate_image_from_image(im,0,103,120,12,0);
234 if load_minimap_tex then gui[16]:=ld_tex('mapbg.png',path,'gui/');
236 for ix:=0 to 9 do tue[ix]:=rotate_image_from_image(im,16*ix,40,16,16,0);
238 if load_weather_tex then
239 begin
240 im:=ld_tex('rain.png',path,'terrain/');
241 for ix:=0 to 7 do osad[0,ix]:=rotate_image_from_image(im,16*ix,0,16,16,0);
242 im:=ld_tex('snow.png',path,'terrain/');
243 for ix:=0 to 7 do osad[1,ix]:=rotate_image_from_image(im,16*ix,0,16,16,0);
244 end;
246 if load_light_tex then
247 begin
248 im:=ld_tex('light.png',path,'terrain/');
249 for ix:=0 to 15 do light[ix]:=rotate_image_from_image(im,16*ix,0,16,16,0);
250 end;
252 Particles.LoadTextures(path);
254 im:=ld_tex('partition.png',path,'gui/');
255 gui[18]:=rotate_image_from_image(im,0,0,84,42,0);
256 gui[19]:=rotate_image_from_image(im,0,42,4,4,0);
258 if load_sky_siz<=0 then
259 sky:=ld_tex('sky.png',path,'terrain/');
260 else
261 sky:=resize_image(ld_tex('sky.png',path,'terrain/'),load_sky_siz,2);
263 if load_sm=1 then
264 begin
265 sun:=ld_tex('sun.png',path,'terrain/');
266 moon:=ld_tex('moon_phase_0.png',path,'terrain/moon_phases/');
267 end; else
268 if load_sm=2 then
269 begin
270 sun:=resize_image(ld_tex('sun.png',path,'terrain/'),(getWidth+getHeight)/5,(getWidth+getHeight)/5);
271 moon:=resize_image(ld_tex('moon_phase_0.png',path,'terrain/moon_phases/'),(getWidth+getHeight)/5,(getWidth+getHeight)/5);
272 end;
274 //load_virt_tex(ld_tex('touch.png',path,'gui/'));
275 end;
277 procedure cleargame;
278 var
279 ix,iy:integer;
280 begin
281 jmp:=false;
282 keymode:=0;
283 updx:=0;
284 updy:=0;
285 toolus:=0;
286 toolind:=0;
287 osadki_ani:=0;
288 global_light:=15;
289 pl_world:=0;
291 camx:=0;
292 camy:=0;
293 curx:=0;
294 cury:=0;
296 player.setX(0);
297 player.setY(0);
298 last_sleep_x:=0;
299 last_sleep_y:=0;
301 fly:=false;
302 game_time:=0;
303 clock_stage:=0;
304 hp:=20;
305 hunger:=20;
306 air:=21;
307 moon_phase:=0;
308 posi:=0;
309 velx:=0;
310 vely:=0;
311 invslot:=0;
313 osadki:=false;
315 //anim_del2:=0;
317 Inv.ResetData;
318 Chest.ResetData;
319 Furnace.ResetData;
320 Drop.ResetData;
321 Mobs.ResetData;
322 Particles.ResetData;
324 for ix:=0 to 255 do
325 begin
326 setBackMap(0, ix);
327 setBiomMap(0, ix);
328 for iy:=0 to 127 do
329 begin
330 setmap(0,ix,iy);
331 setmapinfo(0,ix,iy);
332 setmaplight(0,ix,iy);
333 end;
334 end;
336 for ix:=0 to 31 do
337 begin
338 b_sign[ix]:=false;
339 t_sign[ix]:='';
340 end;
342 for ix:=0 to CONST_MAX_LAYERS do
343 ClearLayer(ix);
344 end;
346 procedure drw_load_line(s:string;percent:integer);
347 var
348 ix,iy:integer;
349 begin
350 for ix:=0 to getWidth/16 do
351 for iy:=0 to getHeight/16 do
352 drawimage(bg[0],ix*16,iy*16);
353 drawfonttext(s,(getWidth/2)-(length(s)*8/2),(getHeight/2)-8);
354 setcolor(128,128,128);
355 fillrect(getwidth/2-50,getheight/2+6,100,3);
356 setcolor(128,255,128);
357 fillrect(getwidth/2-50,getheight/2+6,percent,3);
358 drawfonttext(integertostring(percent)+'%',getwidth/2-(length(integertostring(percent)+'%')*8)/2,getheight/2+12);
359 drawVideo;
360 end;
362 function getFlatMap(i:integer):integer;
363 var
364 ix, iy:integer;
365 begin
366 iy:=i div 256;
367 ix:=i-iy*256;
368 getFlatMap:=getmap(ix,iy);
369 end;
371 procedure setFlatMap(n, i:integer);
372 var
373 ix, iy:integer;
374 begin
375 iy:=i div 256;
376 ix:=i-iy*256;
377 setmap(n,ix,iy);
378 end;
380 function getFlatMapInfo(i:integer):integer;
381 var
382 ix, iy:integer;
383 begin
384 iy:=i div 256;
385 ix:=i-iy*256;
386 getFlatMapInfo:=getmapinfo(ix,iy);
387 end;
389 procedure setFlatMapInfo(n, i:integer);
390 var
391 ix, iy:integer;
392 begin
393 iy:=i div 256;
394 ix:=i-iy*256;
395 setmapinfo(n,ix,iy);
396 end;
398 procedure SaveMapRLE;
399 var
400 i:integer;
401 id, s:integer;
402 begin
403 repeat
404 id:=getFlatMap(i);
405 for s:=0 to 255 do
406 if (id<>getFlatMap(i+s)) or (i+s>32767) then
407 break;
409 write_byte(id);
410 write_byte(s-1);
412 i:=i+s;
413 until i>32767;
414 end;
416 procedure SaveMapInfoRLE;
417 var
418 i:integer;
419 id, s:integer;
420 begin
421 repeat
422 id:=getFlatMapInfo(i);
423 for s:=0 to 255 do
424 if (id<>getFlatMapInfo(i+s)) or (i+s>32767) then
425 break;
427 write_byte(id);
428 write_byte(s-1);
430 i:=i+s;
431 until i>32767;
432 end;
434 procedure LoadMapRLE;
435 var
436 i:integer;
437 id, s, j:integer;
438 begin
439 repeat
440 id:=read_byte;
441 s:=read_byte;
442 for j:=0 to s do
443 setFlatMap(id, i+j);
445 i:=i+s+1;
446 until i>32767;
447 end;
449 procedure LoadMapInfoRLE;
450 var
451 i:integer;
452 id, s, j:integer;
453 begin
454 repeat
455 id:=read_byte;
456 s:=read_byte;
457 for j:=0 to s do
458 setFlatMapInfo(id, i+j);
460 i:=i+s+1;
461 until i>32767;
462 end;
464 procedure saveworld(path:string);
465 var
466 ix,iy:integer;
467 world_name:string;
468 begin
469 if pl_world=0 then world_name:='world.sav';
470 else
471 if pl_world=1 then world_name:='nether.sav';
472 if file_exists(path)<>1 then if create_folder(path)=1 then debug('Folder created!');
473 if file_exists(path+world_name)>0 then delete_file(path+world_name);
474 if file_exists(path+world_name)<>1 then file_create(path+world_name);
475 if open_file(path+world_name)=1 then
476 begin
477 writeint(player.getX);
478 writeint(player.getY);
479 //Matrix
480 SaveMapRLE;
481 SaveMapInfoRLE;
482 drw_load_line('Background',50);
483 //Background and biomes
484 for ix:=0 to 255 do
485 begin
486 write_byte(getBackMap(ix));
487 write_byte(getBiomMap(ix));
488 end;
490 drw_load_line('Chests', 55);
491 Chest.SaveData;
492 drw_load_line('Furnaces', 60);
493 Furnace.SaveData;
494 drw_load_line('Mobs', 70);
495 Mobs.SaveData;
496 drw_load_line('Drop', 80);
497 Drop.SaveData;
498 drw_load_line('Particles', 85);
499 Particles.SaveData;
501 drw_load_line('Other', 90);
502 write_byte(updx);
503 write_byte(updy);
504 writebool(osadki);
505 write_byte(osadki_ani);
506 write_byte(global_light);
507 writebool(fly);
508 writeint(game_time);
509 write_byte(clock_stage);
510 for ix:=0 to 31 do
511 begin
512 writebool(b_sign[ix]);
513 writestr(t_sign[ix]);
514 end;
515 flush;
516 drw_load_line('Ready',100);
517 if close_file(path+world_name)=1 then debug('World Saved!');
518 end;
519 end;
521 procedure savegame(path:string);
522 var
523 ix,iy:integer;
524 begin
525 drw_load_line('Basic',0);
526 if file_exists(path+'player.dat')=1 then delete_file(path+'player.dat');
527 if file_exists(path)<>1 then if create_folder(path)=1 then debug('Folder created!');
528 if file_exists(path+'player.dat')<>1 then file_create(path+'player.dat');
529 if open_file(path+'player.dat')=1 then
530 begin
531 //Head
532 write_byte(version_map);
533 write_byte(gamemode);
534 writebool(cheats);
535 writeint(seed);
536 write_byte(pl_world);
537 //Player
538 writeint(last_sleep_x);
539 writeint(last_sleep_y);
540 write_byte(velx);
541 write_byte(vely);
542 write_byte(invslot);
543 write_byte(posi);
544 write_byte(hp);
545 write_byte(hunger);
546 write_byte(moon_phase);
547 writebool(jmp);
548 inv.saveData;
549 if close_file(path+'player.dat')=1 then debug('Saved!');
550 drw_load_line('Matrix',10);
551 saveworld(path);
552 end;
553 end;
556 function version_err(ver:integer):boolean;
557 var
558 ix,iy:integer;
559 begin
560 for ix:=0 to getWidth/16 do
561 for iy:=0 to getHeight/16 do
562 begin
563 drawimage(bg[0],ix*16,iy*16);
564 end;
565 if version_map=ver then version_err:=true; else
566 if version_map>ver then
567 begin
568 drawfonttext('Old save format!',(getWidth/2)-60,(getHeight/2)-4);
569 drawVideo;
570 delay(3000);
571 version_err:=false;
572 end; else
573 if version_map<ver then
574 begin
575 drawfonttext('New save format!',(getWidth/2)-60,(getHeight/2)-4);
576 drawVideo;
577 delay(3000);
578 version_err:=false;
579 end;
580 end;
583 function loadworld(path:string):boolean;
584 var
585 ix,iy,ver:integer;
586 world_name:string;
587 begin
588 if pl_world=0 then world_name:='world.sav';
589 else
590 if pl_world=1 then world_name:='nether.sav';
591 if file_exists(path)=1 then
592 begin
593 if file_exists(path+world_name)=1 then
594 begin
595 if open_file(path+world_name)=1 then
596 begin
597 player.setX(readint);
598 player.setY(readint);
599 //Matrix
600 LoadMapRLE;
601 LoadMapInfoRLE;
602 drw_load_line('Background',50);
603 //Background and biomes
604 for ix:=0 to 255 do
605 begin
606 setBackMap(read_byte, ix);
607 setBiomMap(read_byte, ix);
608 end;
609 drw_load_line('Chests', 55);
610 Chest.LoadData;
611 drw_load_line('Furnaces', 60);
612 Furnace.LoadData;
613 Mobs.LoadData;
614 drw_load_line('Drop', 80);
615 Drop.LoadData;
616 drw_load_line('Particles', 85);
617 Particles.LoadData;
619 drw_load_line('Other',90);
620 updx:=read_byte;
621 updy:=read_byte;
622 osadki:=readbool;
623 osadki_ani:=read_byte;
624 global_light:=read_byte;
625 fly:=readbool;
626 game_time:=readint;
627 clock_stage:=read_byte;
628 for ix:=0 to 31 do
629 begin
630 b_sign[ix]:=readbool;
631 t_sign[ix]:=readstr;
632 end;
633 drw_load_line('Ready',100);
634 ///////////////////////
635 if close_file(path+world_name)=1 then begin loadworld:=true; debug('World loaded!'); end;
636 end; else begin loadworld:=false; debug('File not opened!'); end;
637 end; else begin loadworld:=false; debug('File not exists!'); end;
638 end; else begin loadworld:=false; debug('Folder not exists!'); end;
639 end;
641 function loadgame(path:string):boolean;
642 var
643 ix,iy,ver:integer;
644 begin
645 drw_load_line('Basic',0);
646 if file_exists(path)=1 then
647 begin
648 if file_exists(path+'player.dat')=1 then
649 begin
650 if open_file(path+'player.dat')=1 then
651 begin
652 //Head
653 ver:=read_byte;
654 if version_err(ver)=false then
655 begin
656 if close_file(path+'player.dat')=1 then loadgame:=false;
657 exit;
658 end;
659 gamemode:=read_byte;
660 cheats:=readbool;
661 seed:=readint;
662 pl_world:=read_byte;
663 //Player;
664 last_sleep_x:=readint;
665 last_sleep_y:=readint;
666 velx:=read_byte;
667 vely:=read_byte;
668 invslot:=read_byte;
669 posi:=read_byte;
670 hp:=read_byte;
671 hunger:=read_byte;
672 moon_phase:=read_byte;
673 jmp:=readbool;
674 inv.loadData;
675 drw_load_line('Matrix',10);
676 if close_file(path+'player.dat')=1 then loadgame:=loadworld(path);
677 end; else loadgame:=false;
678 end; else loadgame:=false;
679 end; else loadgame:=false;
680 end;
682 procedure drawdeadlogo;
683 var
684 dead:image;
685 begin
686 setcolor(0,0,0);
687 fillrect(0,0,getWidth,getHeight);
688 dead:=loadimage('/dl');
689 drawimage(dead,(getWidth/2)-(getimagewidth(dead)/2),(getHeight/2)-(getimageheight(dead)/2));
690 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));
691 drawfonttext('Loading...',(getWidth/2)-(40),getHeight-8);
692 drawVideo;
693 delay(500);
694 end;
696 procedure newgame;
697 var
698 ix,iy:integer;
699 begin
700 for ix:=0 to getWidth/16 do
701 for iy:=0 to getHeight/16 do
702 begin
703 drawimage(bg[0],ix*16,iy*16);
704 end;
705 drawfonttext('Generation World...',(getWidth/2)-(76),(getHeight/2)-4);
706 drawVideo;
707 delay(1);
708 cleargame;
709 game_time:=45000;
710 newworld;
711 //if s_spawn_mob then begin if pl_world=0 then begin megaspawn; end; else begin netherspawn; end; end;
712 if gamemode=1 then fly:=true else fly:=false;
713 debug('New game!');
714 end;
716 function gettext(text,text_f:string; max,typ:integer;):string;
717 var
718 textField_id:integer;
719 exitCmd,cli:command;
720 begin
721 clearForm;
722 exitCmd:=createCommand('Ok',CM_OK,1);
723 showForm;
724 addCommand(exitCmd);
725 textField_id:=formAddTextField(text,text_f,max,typ);
726 drawVideo;
727 delay(100);
728 repeat
729 cli:=getClickedCommand;
730 until cli=exitCmd;
731 gettext:=formGetText(textField_id);
732 showCanvas;
733 end;
735 procedure drw_btn(text:string; cur,ccur,h,ty:integer);
736 var
737 m_x,m_y,i:integer;
738 begin
739 m_x:=(getWidth/2)-(120/2);
740 m_y:=h+((getHeight/2))-((getimageheight(gui[7])-2*cur)/2)+((getimageheight(gui[7])+2)*cur);
741 if ty=0 then
742 begin
743 if ccur=cur then drawimage(gui[22],m_x+i*4,m_y); else drawimage(gui[6],m_x+i*8,m_y);
744 end; else
745 if ty=1 then
746 begin
747 if ccur=cur then drawimage(gui[8],m_x+i*8,m_y); else drawimage(gui[7],m_x+i*8,m_y);
748 end;
749 setclip(0,0,getwidth,getheight);
750 m_x:=(getWidth/2)-(length(text)*8/2);
751 m_y:=h+((getHeight/2))-((getimageheight(gui[7])-2*cur)/2)+((getimageheight(gui[7])+2)*cur)+((getimageheight(gui[7])-8)/2);
752 drawfonttext(text,m_x,m_y);
753 end;
755 procedure drw_txt(str:string; xx,n,t:integer);
756 var
757 m_x,m_y:integer;
758 begin
759 m_x:=(getWidth/2)-(length(str)*8/2);
760 m_y:=xx+32+(8*n);
761 if t=0 then drawfonttext(str,0,m_y); else
762 if t=1 then drawfonttext(str,m_x,m_y);
763 end;
765 function pos_end(s:string; c:char):integer;
766 var
767 i:integer;
768 begin
769 for i:=length(s)-1 downto 0 do
770 begin
771 if getchar(s,i)=c then
772 begin
773 pos_end:=i;
774 exit;
775 end;
776 end;
777 pos_end:=-1;
778 end;
780 function getroot(cancel_b:boolean):string;
781 var
782 m_cur,max_r,pars,ix,iy:integer;
783 rr:string;
784 im:image;
785 roots:array [0..15] of string;
786 begin
787 im:=rotate_image_from_image(ld_tex('background.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','title/'),16,0,16,16,0);
788 rr:=get_roots;
789 if cancel_b then roots[0]:='<CANCEL>';
790 if cancel_b then max_r:=1; else max_r:=0;
791 while pos(rr,'|')<>-1 do
792 begin
793 pars:=pos(rr,'|');
794 roots[max_r]:=copy(rr,0,pars-1);
795 rr:=copy(rr,pars+1,length(rr));
796 max_r:=max_r+1;
797 end;
798 max_r:=max_r-1;
799 repeat
800 updateKeys;
801 if clickedKey(KEY_FM_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=max_r; end;
802 if clickedKey(KEY_FM_DOWN) then begin m_cur:=m_cur+1; if m_cur>max_r then m_cur:=0; end;
803 if clickedKey(KEY_FM_SELECT) then
804 begin
805 if (m_cur=0) and (cancel_b) then
806 begin
807 getroot:='';
808 exit;
809 end;
810 else
811 begin
812 getroot:=roots[m_cur];
813 exit;
814 end;
815 end;
817 for ix:=0 to getWidth/16 do
818 for iy:=0 to getHeight/16 do
819 drawimage(im,ix*16,iy*16);
821 setcolor(0,0,0);
822 fillrect(0,m_cur*8,getWidth-1,8);
823 for ix:=0 to max_r do
824 begin
825 drawfonttext(roots[ix],0,ix*8);
826 end;
827 setcolor(255,255,255);
828 drawrect(0,m_cur*8,getWidth-1,8);
830 drawVideo;
831 delay(1);
832 until false;
833 end;
835 function filemanager(cancel_b:boolean):string;
836 var
837 m_cur,ix,iy,max_r,pars:integer;
838 im:image;
839 last,rr,root,path:string;
840 names:array [0..255] of string;
841 begin
842 im:=rotate_image_from_image(ld_tex('background.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','title/'),16,0,16,16,0);
843 names[0]:='<..>';
844 names[1]:='<OK>';
845 root:=getroot(cancel_b);
846 if root='' then
847 begin
848 filemanager:='';
849 exit;
850 end;
851 path:=root;
852 if cancel_b then names[2]:='<CANCEL>';
853 rr:=get_dirs(path);
854 if cancel_b then max_r:=3; else max_r:=2;
855 while pos(rr,'|')<>-1 do
856 begin
857 pars:=pos(rr,'|');
858 names[max_r]:=copy(rr,0,pars-1);
859 rr:=copy(rr,pars+1,length(rr));
860 max_r:=max_r+1;
861 end;
862 max_r:=max_r-1;
864 repeat
865 updateKeys;
866 if clickedKey(KEY_FM_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=max_r; end;
867 if clickedKey(KEY_FM_DOWN) then begin m_cur:=m_cur+1; if m_cur>max_r then m_cur:=0; end;
868 if clickedKey(KEY_FM_SELECT) then
869 begin
870 if m_cur=0 then
871 begin
872 debug('path:'+path);
873 debug('lol:'+pos_end(path,'/'));
874 if (path=root) or (path=root+'/') then
875 begin
876 root:=getroot(cancel_b);
877 if root='' then
878 begin
879 filemanager:='';
880 exit;
881 end;
882 path:=root;
883 end;
884 else
885 begin
886 path:=copy(path,0,pos_end(path,'/'));
887 if cancel_b then names[2]:='<CANCEL>';
888 rr:=get_dirs(path);
889 if cancel_b then max_r:=3; else max_r:=2;
890 while pos(rr,'|')<>-1 do
891 begin
892 pars:=pos(rr,'|');
893 names[max_r]:=copy(rr,0,pars-1);
894 rr:=copy(rr,pars+1,length(rr));
895 max_r:=max_r+1;
896 end;
897 max_r:=max_r-1;
898 end;
899 end; else
900 if m_cur=1 then
901 begin
902 debug('<OK>');
903 filemanager:=path;
904 exit;
905 end; else
906 if (m_cur=2) and (cancel_b) then
907 begin
908 debug('<CANCEL>');
909 filemanager:='';
910 exit;
911 end; else
912 begin
913 path:=path+'/'+names[m_cur];
915 if cancel_b then names[2]:='<CANCEL>';
916 rr:=get_dirs(path);
917 if cancel_b then max_r:=3; else max_r:=2;
918 while pos(rr,'|')<>-1 do
919 begin
920 pars:=pos(rr,'|');
921 names[max_r]:=copy(rr,0,pars-1);
922 rr:=copy(rr,pars+1,length(rr));
923 max_r:=max_r+1;
924 end;
925 max_r:=max_r-1;
926 m_cur:=0;
927 debug('path:'+path);
928 end;
929 end;
931 for ix:=0 to getWidth/16 do
932 for iy:=0 to getHeight/16 do
933 drawimage(im,ix*16,iy*16);
935 setcolor(0,0,0);
936 fillrect(0,m_cur*8,getWidth-1,8);
937 for ix:=0 to max_r do
938 begin
939 drawfonttext(names[ix],0,ix*8);
940 end;
941 setcolor(255,255,255);
942 drawrect(0,m_cur*8,getWidth-1,8);
944 drawVideo;
945 delay(1);
947 until false;
948 end;
950 procedure setsd(cancel_b:boolean);
951 var
952 s:string;
953 t:integer;
954 rs:recordstore;
955 begin
956 s:=filemanager(cancel_b);
957 if s<>'' then
958 begin
959 sd:=s;
960 if file_exists('/'+sd+'/cavecraft')<>1 then
961 if create_folder('/'+sd+'/cavecraft')=1 then debug('/cavecraft created!');
963 if file_exists('/'+sd+'/cavecraft/saves')<>1 then
964 if create_folder('/'+sd+'/cavecraft/saves')=1 then debug('/saves created!');
966 if file_exists('/'+sd+'/cavecraft/screenshots')<>1 then
967 if create_folder('/'+sd+'/cavecraft/screenshots')=1 then debug('/screenshots created!');
969 if file_exists('/'+sd+'/cavecraft/texturepacks')<>1 then
970 if create_folder('/'+sd+'/cavecraft/texturepacks')=1 then debug('/texturepacks created!');
972 deleteRecordStore('SD');
973 rs:=openRecordStore('SD');
974 t:=addRecordStoreEntry(rs,sd);
975 closeRecordStore(rs);
976 end;
977 end;
979 procedure start_uu;
980 var
981 rs:recordstore;
982 ss:string;
983 begin
984 drawdeadlogo;
985 //Load SD
986 rs:=openRecordStore('SD');
987 sd:=readRecordStoreEntry(rs,1);
988 closeRecordStore(rs);
989 console.exec('autoexec.cfg', 'AUTO');
990 if sd='' then
991 begin
992 init_touch;
993 if touchscreen then
994 load_key_tex:=1;
995 else
996 load_key_tex:=0;
997 //load_virt_tex(loadimage('/gui/touch.png'));
998 setsd(false);
999 end;
1001 if file_exists('/'+sd+'/cavecraft')<>1 then
1002 if create_folder('/'+sd+'/cavecraft')=1 then debug('/cavecraft created!');
1004 if file_exists('/'+sd+'/cavecraft/saves')<>1 then
1005 if create_folder('/'+sd+'/cavecraft/saves')=1 then debug('/saves created!');
1007 if file_exists('/'+sd+'/cavecraft/screenshots')<>1 then
1008 if create_folder('/'+sd+'/cavecraft/screenshots')=1 then debug('/screenshots created!');
1010 if file_exists('/'+sd+'/cavecraft/texturepacks')<>1 then
1011 if create_folder('/'+sd+'/cavecraft/texturepacks')=1 then debug('/texturepacks created!');
1013 rs:=openRecordStore('TX');
1014 ss:=readRecordStoreEntry(rs,1);
1015 closeRecordStore(rs);
1017 if ss<>'' then
1018 begin
1019 tex_pack:=ss;
1020 LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1021 loadtexture('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1022 end;
1023 else
1024 begin
1025 LoadDrawFont('/');
1026 loadtexture('/');
1027 end;
1028 end;
1030 function question(text:string):boolean;
1031 var
1032 ix,iy,m_cur:integer;
1033 begin
1034 repeat
1035 updateKeys;
1036 if clickedKey(KEY_MENU_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=1; end;
1037 if clickedKey(KEY_MENU_DOWN) then begin m_cur:=m_cur+1; if m_cur>1 then m_cur:=0; end;
1038 if clickedKey(KEY_MENU_SELECT) then begin if m_cur=0 then question:=true; else question:=false; exit; end;
1039 for ix:=0 to getwidth/16 do for iy:=0 to getheight/16 do drawimage(bg[0],ix*16,iy*16);
1040 drawfonttext(text,getwidth/2-(length(text)*8)/2,getheight/2-16);
1041 drw_btn('Yes',0,m_cur,0,1);
1042 drw_btn('No',1,m_cur,0,1);
1043 drawVideo;
1044 delay(1);
1045 until false;
1046 end;
1048 function menu_game_new:boolean;
1049 var
1050 m_cur,tmp_gm,ix,iy,lol:integer;
1051 tmp_cheats,tmp_bon_chest:boolean;
1052 newgametxt:array[0..4] of string;
1053 name,tmp:string;
1054 begin
1055 m_cur:=-2;
1056 newgametxt[0]:='Survival';
1057 newgametxt[1]:='Creative';
1058 newgametxt[2]:='Hardcore';
1059 newgametxt[3]:='Normal';
1060 newgametxt[4]:='Flat';
1061 name:='New World';
1062 repeat
1063 updateKeys;
1064 if clickedKey(KEY_MENU_UP) then begin m_cur:=m_cur-1; if m_cur<-2 then m_cur:=5; end;
1065 if clickedKey(KEY_MENU_DOWN) then begin m_cur:=m_cur+1; if m_cur>5 then m_cur:=-2; end;
1066 if clickedKey(KEY_MENU_SELECT) then
1067 begin
1068 if m_cur=-2 then
1069 begin
1070 name:=gettext('Name:',name,10,TF_ANY);
1071 end; else
1072 if m_cur=-1 then
1073 begin
1074 tmp_gm:=tmp_gm+1; if tmp_gm>2 then tmp_gm:=0;
1075 if tmp_gm=0 then tmp_cheats:=false;
1076 if tmp_gm=1 then tmp_cheats:=true;
1077 if tmp_gm=2 then begin tmp_cheats:=false; tmp_bon_chest:=false; end;
1078 end; else
1079 if m_cur=0 then
1080 begin
1081 nextseed:=stringtointeger(gettext('Seed:',''+nextseed,10,TF_NUMERIC));
1082 end; else
1083 if m_cur=1 then
1084 begin
1085 world_typ:=world_typ+1;
1086 if world_typ>1 then world_typ:=0;
1087 end; else
1088 if m_cur=2 then
1089 begin
1090 if tmp_gm<2 then tmp_cheats:= not tmp_cheats;
1091 end; else
1092 if m_cur=3 then
1093 begin
1094 if tmp_gm<2 then tmp_bon_chest:= not tmp_bon_chest;
1095 end; else
1096 if m_cur=4 then
1097 begin
1098 gamemode:=tmp_gm;
1099 cheats:=tmp_cheats;
1100 bon_chest:=tmp_bon_chest;
1101 tmp:=name;
1102 while file_exists('/'+sd+'/cavecraft/saves/'+name)=1 do
1103 begin
1104 lol:=lol+1;
1105 name:=tmp+' '+lol;
1106 end;
1107 sav_fl:=name;
1108 newgame;
1109 menu_game_new:=true;
1110 break;
1111 end; else
1112 if m_cur=5 then
1113 begin
1114 break;
1115 end; else
1116 end;
1117 for ix:=0 to getWidth/16 do
1118 for iy:=0 to getHeight/16 do
1119 drawimage(bg[0],ix*16,iy*16);
1121 drw_btn('Name:'+name,-2,m_cur,0,1);
1122 drw_btn('Mode:'+newgametxt[tmp_gm],-1,m_cur,0,1);
1123 drw_btn('Seed:'+nextseed,0,m_cur,0,1);
1124 drw_btn('Type:'+newgametxt[world_typ+3],1,m_cur,0,1);
1125 if tmp_gm<2 then
1126 drw_btn('Cheats:'+tmp_cheats,2,m_cur,0,1);
1127 else
1128 drw_btn('Cheats:'+tmp_cheats,2,m_cur,0,0);
1129 if tmp_gm<2 then
1130 drw_btn('Chest:'+tmp_bon_chest,3,m_cur,0,1);
1131 else
1132 drw_btn('Chest:'+tmp_bon_chest,3,m_cur,0,0);
1133 drw_btn('Create',4,m_cur,0,1);
1134 drw_btn('Cancel',5,m_cur,0,1);
1136 drawVideo;
1137 delay(1);
1138 until false;
1139 end;
1141 procedure deleteworld(path:string);
1142 begin
1143 if file_exists(path+'player.dat')=1 then delete_file(path+'player.dat');
1144 if file_exists(path+'world.sav')=1 then delete_file(path+'world.sav');
1145 if file_exists(path+'nether.sav')=1 then delete_file(path+'nether.sav');
1146 if file_exists(path+'pic.png')=1 then delete_file(path+'pic.png');
1147 if file_exists(path)=1 then delete_file(path);
1148 if file_exists(path)=0 then debug('World deleted!');
1149 end;
1151 function menu_game:boolean;
1152 var
1153 ix,iy,pars,max_r,cur_name,m_cur:integer;
1154 mm_t_b:boolean;
1155 im_game:image;
1156 rr:string;
1157 names:array[0..255] of string;
1158 begin
1159 rr:=get_dirs('/'+sd+'/cavecraft/saves/');
1160 while pos(rr,'|')<>-1 do
1161 begin
1162 pars:=pos(rr,'|');
1163 names[max_r]:=copy(rr,0,pars-1);
1164 rr:=copy(rr,pars+1,length(rr));
1165 if file_exists('/'+sd+'/cavecraft/saves/'+names[max_r]+'/player.dat')=1 then max_r:=max_r+1;
1166 end;
1167 max_r:=max_r-1;
1168 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1169 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1170 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1172 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/player.dat')=1 then
1173 mm_t_b:=true; else mm_t_b:=false;
1175 repeat
1176 updateKeys;
1177 if clickedKey(KEY_MENU_UP) then
1178 begin
1179 m_cur:=m_cur-1;
1180 if m_cur<0 then m_cur:=3;
1181 end;
1182 if clickedKey(KEY_MENU_DOWN) then
1183 begin
1184 m_cur:=m_cur+1;
1185 if m_cur>3 then m_cur:=0;
1186 end;
1188 if (max_r >= 0) and clickedKey(KEY_MENU_LEFT) then
1189 begin
1190 cur_name:=cur_name-1;
1191 if cur_name<0 then cur_name:=0;
1192 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1193 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1194 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1196 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/player.dat')=1 then
1197 end;
1198 if (max_r >= 0) and clickedKey(KEY_MENU_RIGHT) then
1199 begin
1200 cur_name:=cur_name+1;
1201 if cur_name>max_r then cur_name:=max_r;
1202 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1203 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1204 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1206 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/player.dat')=1 then
1207 end;
1208 if clickedKey(KEY_MENU_SELECT) then
1209 begin
1210 if m_cur=0 then
1211 begin
1212 if max_r>-1 then
1213 if loadgame('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/') then
1214 begin
1215 sav_fl:=names[cur_name];
1216 menu_game:=true;
1217 break;
1218 end;
1219 end; else
1220 if m_cur=1 then
1221 begin
1222 if menu_game_new then begin menu_game:=true; break; end;
1223 end; else
1224 if m_cur=2 then
1225 begin
1226 debug('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/');
1227 if max_r>-1 then
1228 if question('Are you sure?')=true then deleteworld('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/');
1229 cur_name:=0;
1230 max_r:=0;
1231 rr:=get_dirs('/'+sd+'/cavecraft/saves/');
1232 while pos(rr,'|')<>-1 do
1233 begin
1234 pars:=pos(rr,'|');
1235 names[max_r]:=copy(rr,0,pars-1);
1236 rr:=copy(rr,pars+1,length(rr));
1237 max_r:=max_r+1;
1238 end;
1239 max_r:=max_r-1;
1240 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1241 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1242 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1243 end; else
1244 if m_cur=3 then
1245 begin
1246 break;
1247 end;
1248 end;
1250 for ix:=0 to getWidth/16 do
1251 for iy:=1 to 7 do
1252 drawimage(bg[1],ix*16,iy*16);
1253 for ix:=0 to getWidth/16 do
1254 drawimage(bg[0],ix*16,0);
1255 for ix:=0 to getWidth/16 do
1256 for iy:=8 to getHeight/16 do
1257 drawimage(bg[0],ix*16,iy*16);
1259 if max_r>-1 then
1260 begin
1261 setcolor(0,0,0);
1262 fillrect(32,24,getWidth-64,96);
1263 setclip(32,24,getWidth-64,96);
1264 drawimage(im_game,(getWidth/2)-(32),32);
1265 drawfonttext(names[cur_name],(getWidth/2)-(length(names[cur_name])*8/2),104);
1266 setclip(0,0,getWidth,getHeight);
1267 setcolor(128,128,128);
1268 drawrect(32,24,getWidth-64,96);
1269 if cur_name>0 then drawimage(gui[20],0,58);
1270 if cur_name<max_r then drawimage(gui[21],getWidth-9,58);
1271 end;
1272 else
1273 begin
1274 setcolor(0,0,0);
1275 fillrect(32,24,getWidth-64,96);
1276 setclip(32,24,getWidth-64,96);
1277 drawfonttext('No saves!',(getWidth/2)-(length('No saves!')*8/2),104);
1278 setclip(0,0,getWidth,getHeight);
1279 setcolor(128,128,128);
1280 drawrect(32,24,getWidth-64,96);
1281 end;
1283 if mm_t_b then drw_btn('Play',0,m_cur,32,1); else drw_btn('Play',0,m_cur,32,0);
1284 drw_btn('Create new',1,m_cur,32,1);
1285 if mm_t_b then drw_btn('Delete',2,m_cur,32,1); else drw_btn('Delete',2,m_cur,32,0);
1286 drw_btn('Back',3,m_cur,32,1);
1287 if not mm_t_b then cur_name:=cur_name+1;
1289 drawVideo;
1290 delay(1);
1291 until false;
1292 end;
1294 procedure menu_tex;
1295 var
1296 ix,iy,pars,max_r,cur_name,m_cur,t:integer;
1297 im_game:image;
1298 rr:string;
1299 names:array[0..255] of string;
1300 rs:recordstore;
1301 begin
1302 rr:=get_dirs('/'+sd+'/cavecraft/texturepacks/');
1303 names[0]:='Default';
1304 max_r:=1;
1305 while pos(rr,'|')<>-1 do
1306 begin
1307 pars:=pos(rr,'|');
1308 names[max_r]:=copy(rr,0,pars-1);
1309 rr:=copy(rr,pars+1,length(rr));
1310 max_r:=max_r+1;
1311 end;
1312 max_r:=max_r-1;
1313 im_game:=loadimage('/pack.png');
1315 repeat
1316 updateKeys;
1317 if clickedKey(KEY_MENU_UP) then
1318 begin
1319 m_cur:=m_cur-1;
1320 if m_cur<0 then m_cur:=1;
1321 end;
1322 if clickedKey(KEY_MENU_DOWN) then
1323 begin
1324 m_cur:=m_cur+1;
1325 if m_cur>1 then m_cur:=0;
1326 end;
1328 if clickedKey(KEY_MENU_LEFT) then
1329 begin
1330 cur_name:=cur_name-1;
1331 if cur_name<0 then cur_name:=0;
1332 im_game:=ld_tex('pack.png','/'+sd+'/cavecraft/texturepacks/'+names[cur_name]+'/','');
1333 end;
1334 if clickedKey(KEY_MENU_RIGHT) then
1335 begin
1336 cur_name:=cur_name+1;
1337 if cur_name>max_r then cur_name:=max_r;
1338 im_game:=ld_tex('pack.png','/'+sd+'/cavecraft/texturepacks/'+names[cur_name]+'/','');
1339 end;
1340 if clickedKey(KEY_MENU_SELECT) then
1341 begin
1342 if m_cur=0 then begin
1343 if cur_name>0 then
1344 begin
1345 debug("Select TexturePack @ /" + sd + "/cavecraft/texturepacks/" + names[cur_name]);
1346 tex_pack:=names[cur_name];
1347 LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1348 loadtexture('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1349 deleteRecordStore('TX');
1350 rs:=openRecordStore('TX');
1351 t:=addRecordStoreEntry(rs,tex_pack);
1352 closeRecordStore(rs);
1354 LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1355 loadtexture('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1356 end;
1357 else
1358 begin
1359 debug("Cancel Select TecturePack");
1360 tex_pack:='';
1361 loadtexture('/');
1362 deleteRecordStore('TX');
1363 rs:=openRecordStore('TX');
1364 t:=addRecordStoreEntry(rs,'');
1365 closeRecordStore(rs);
1366 end;
1367 end;
1368 if m_cur=1 then break;
1369 break;
1370 end;
1372 for ix:=0 to getWidth/16 do
1373 for iy:=1 to 7 do
1374 drawimage(bg[1],ix*16,iy*16);
1375 for ix:=0 to getWidth/16 do
1376 drawimage(bg[0],ix*16,0);
1377 for ix:=0 to getWidth/16 do
1378 for iy:=8 to getHeight/16 do
1379 drawimage(bg[0],ix*16,iy*16);
1381 if max_r>-1 then
1382 begin
1383 setcolor(0,0,0);
1384 fillrect(32,24,getWidth-64,96);
1385 setclip(32,24,getWidth-64,96);
1386 drawimage(im_game,(getWidth/2)-(32),32);
1387 drawfonttext(names[cur_name],(getWidth/2)-(length(names[cur_name])*8/2),104);
1388 setclip(0,0,getWidth,getHeight);
1389 setcolor(128,128,128);
1390 drawrect(32,24,getWidth-64,96);
1391 if cur_name>0 then drawimage(gui[20],0,58);
1392 if cur_name<max_r then drawimage(gui[21],getWidth-9,58);
1393 end;
1395 drw_btn('Done',0,m_cur,32,1);
1396 drw_btn('Back',1,m_cur,32,1);
1398 drawVideo;
1399 delay(1);
1400 until false;
1401 end;
1403 procedure menu_sett;
1404 var
1405 ix,iy,m_cur:integer;
1406 begin
1407 m_cur:=-3;
1408 repeat
1409 updateKeys;
1410 if clickedKey(KEY_MENU_UP) then
1411 begin
1412 m_cur:=m_cur-1;
1413 if m_cur<-3 then m_cur:=5;
1414 end;
1415 if clickedKey(KEY_MENU_DOWN) then
1416 begin
1417 m_cur:=m_cur+1;
1418 if m_cur>5 then m_cur:=-3;
1419 end;
1420 if clickedKey(KEY_MENU_SELECT) then
1421 begin
1422 if m_cur=-3 then
1423 begin
1424 light_type:=light_type+1;
1425 if light_type>2 then light_type:=0;
1426 end; else
1427 if m_cur=-2 then
1428 begin
1429 ifosad:=not ifosad;
1430 end; else
1431 if m_cur=-1 then
1432 begin
1433 Particles.enabled := not Particles.enabled;
1434 end; else
1435 if m_cur=0 then
1436 begin
1437 drawgui:=not drawgui;
1438 end; else
1439 if m_cur=1 then
1440 begin
1441 if question('Are you sure?')=true then
1442 begin
1443 if load_key_tex=0 then
1444 begin
1445 load_key_tex:=1;
1446 init_touch;
1447 //load_virt_tex(ld_tex('touch.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','gui/'));
1448 end;
1449 else
1450 if load_key_tex=1 then
1451 begin
1452 load_key_tex:=0;
1453 resetVirtualKeyboard(-1);
1454 end;
1455 end;
1456 end;
1457 if m_cur=2 then
1458 begin
1459 s_jpeg_quality:=stringtointeger(gettext('JPEG quality:',''+s_jpeg_quality,3,TF_NUMERIC));
1460 if s_jpeg_quality>100 then s_jpeg_quality:=100; else
1461 if s_jpeg_quality<0 then s_jpeg_quality:=0;
1462 end; else
1463 if m_cur=3 then
1464 begin
1465 setsd(true);
1466 end; else
1467 if m_cur=4 then
1468 begin
1469 deleteRecordStore('S');
1470 deleteRecordStore('SD');
1471 deleteRecordStore('TX');
1472 halt;
1473 end; else
1474 if m_cur=5 then
1475 begin
1476 save_settings;
1477 break;
1478 end; else
1479 end;
1481 for ix:=0 to getWidth/16 do
1482 for iy:=0 to getHeight/16 do
1483 drawimage(bg[0],ix*16,iy*16);
1485 drw_btn('Light:'+light_type,-3,m_cur,0,1);
1486 drw_btn('Weather:'+ifosad,-2,m_cur,0,1);
1487 drw_btn('Particles:' + Particles.enabled, -1, m_cur, 0, 1);
1488 drw_btn('Hide GUI:'+not drawgui,0,m_cur,0,1);
1489 drw_btn('Touch:'+(load_key_tex>0),1,m_cur,0,1);
1490 drw_btn('JPEG:'+s_jpeg_quality,2,m_cur,0,1);
1491 drw_btn('Set Root',3,m_cur,0,1);
1492 drw_btn('Reset',4,m_cur,0,1);
1493 drw_btn('Back',5,m_cur,0,1);
1495 drawVideo;
1496 delay(1);
1497 until false;
1498 end;
1500 procedure menu_help;
1501 var
1502 ix,iy,cur:integer;
1503 begin
1504 repeat
1505 updateKeys;
1506 if clickedKey(KEY_MENU_SELECT) then break;
1507 if pressedKey(KEY_MENU_UP) then cur:=cur+1;
1508 if pressedKey(KEY_MENU_DOWN) then cur:=cur-1;
1510 for ix:=0 to getWidth/16 do
1511 for iy:=2 to (getHeight/16)-2 do
1512 drawimage(bg[1],ix*16,iy*16);
1514 for ix:=0 to getWidth/16 do
1515 for iy:=0 to 1 do
1516 drawimage(bg[0],ix*16,iy*16);
1518 for ix:=0 to getWidth/16 do
1519 for iy:=(getHeight/16)-2 to getHeight/16 do
1520 drawimage(bg[0],ix*16,iy*16);
1522 setclip(0,32,getWidth,(getHeight/16-4)*16);
1524 drw_txt('Controls:',cur,0,1);
1525 drw_txt('Left - Move left',cur,1,0);
1526 drw_txt('Right - Move right',cur,2,0);
1527 drw_txt('Up - Jump',cur,3,0);
1528 drw_txt('Down - Put a block under you',cur,4,0);
1529 drw_txt('1 - Inventory',cur,5,0);
1530 drw_txt('Duble 1 - Craft',cur,6,0);
1531 drw_txt('3 - Use block',cur,7,0);
1532 drw_txt('7 - Debug info',cur,8,0);
1533 drw_txt('Hold 7 - Console',cur,9,0);
1534 drw_txt('9 - Pause',cur,10,0);
1535 drw_txt('*, # - Browse inventory',cur,11,0);
1536 drw_txt('0 - Edit mode',cur,12,0);
1538 drw_txt('In inventory/chest:',cur,14,1);
1539 drw_txt('3 - Enject object',cur,15,0);
1540 drw_txt('Hold 3 - Enject stack',cur,16,0);
1541 drw_txt('5 - Move the stack',cur,17,0);
1542 drw_txt('Hold 5 - Divide stack',cur,18,0);
1544 setclip(0,0,getWidth,getHeight);
1546 drw_btn('Back',0,0,getHeight-getHeight/2-16-6,1);
1548 drawVideo;
1549 delay(1);
1550 until false;
1551 end;
1553 procedure menu_about;
1554 var
1555 ix,iy,cur:integer;
1556 begin
1557 repeat
1558 updateKeys;
1559 if clickedKey(KEY_MENU_SELECT) then break;
1560 if pressedKey(KEY_MENU_UP) then cur:=cur+1;
1561 if pressedKey(KEY_MENU_DOWN) then cur:=cur-1;
1563 for ix:=0 to getWidth/16 do
1564 for iy:=2 to (getHeight/16)-2 do
1565 drawimage(bg[1],ix*16,iy*16);
1567 for ix:=0 to getWidth/16 do
1568 for iy:=0 to 1 do
1569 drawimage(bg[0],ix*16,iy*16);
1571 for ix:=0 to getWidth/16 do
1572 for iy:=(getHeight/16)-2 to getHeight/16 do
1573 drawimage(bg[0],ix*16,iy*16);
1575 setclip(0,32,getWidth,(getHeight/16-4)*16);
1577 drw_txt('Developers:',cur,0,1);
1578 drw_txt(#68+#101+#97+#68+#68+#111+#111+#77+#69+#82+' - Programmer',cur,1,0);//dead
1579 drw_txt(#102+#114+#101+#100+#45+#98+#111+#121+' - Programmer',cur,2,0);//fred-boy
1580 drw_txt(#65+#110+#100+#114+#101+#121+#53+#57+' - Programmer',cur,3,0);//andrey59
1581 drw_txt(#89+#117+#82+#97+#78+#110+#78+#122+#90+#90+' - Artist',cur,4,0);//yura
1582 drw_txt(#83+#97+#115+#104+#97+#71+' - Artist and idea generator',cur,5,0);//sasha
1583 drw_txt(#66+#97+#74+#108+#101+#72+#84+#105+#72+' - Artist and tester',cur,6,0);//valentin
1584 drw_txt(#65+#103+#114+#101+#115+#115+#111+#82+' - Tester',cur,7,0);//agressor
1585 drw_txt(#118+#111+#108+#121+#97+#95+#110+#97+#115+#116+#97+#110+#101+' - Tester',cur,8,0);//volya
1586 drw_txt(#97+#98+#97+#100+#111+#110+' - Tester',cur,9,0);//abadon
1587 drw_txt(#77+#111+#110+#111+#103+#114+#111+#109+' - Tester',cur,10,0);//monogrom
1588 drw_txt(#75+#97+#108+#116+#101+#114+' - Tester',cur,11,0);//kalter
1590 drw_txt('Thanks:',cur,12,1);
1591 drw_txt('Piligrim and 0vZ - Lib_jsr75i',cur,13,0);
1592 drw_txt('Piligrim - Lib_effects',cur,14,0);
1593 drw_txt('Kurdt - Lib_canvas',cur,15,0);
1594 drw_txt('ViNT - Lib_png and Lib_bmp',cur,16,0);
1595 drw_txt('aleshka - Lib_jpeg',cur,17,0);
1596 drw_txt('Roman_V - Lib_safeload',cur,18,0);
1598 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);
1599 drw_txt(#68+#101+#97+#68+#83+#111+#102+#116+#87+#97+#114+#101+' 2012-'+getyear(getcurrenttime),cur,22,0);
1601 drw_txt('Hello! :D',cur,100,1);
1603 setclip(0,0,getWidth,getHeight);
1605 drw_btn('Back',0,0,getHeight-getHeight/2-16-6,1);
1607 drawVideo;
1608 delay(1);
1609 until false;
1610 end;
1612 function sm_siz:integer;
1613 begin
1614 sm_siz:=(getWidth+getHeight)/5;
1615 end;
1617 function sm_siz4:integer;
1618 begin
1619 sm_siz4:=sm_siz/4;
1620 end;
1622 procedure draw_menu_back;
1623 var
1624 ix, iy:integer;
1625 begin
1626 for ix:=0 to getWidth/16 do
1627 for iy:=0 to getHeight/16 do
1628 drawimage(bg[0],ix*16,iy*16);
1629 end;
1631 procedure menu;
1632 var
1633 m_cur,ix,iy,iz:integer;
1634 key,spl_i:integer;
1635 splash:string;
1636 res:resource;
1637 time:integer;
1638 cavelogo:image;
1639 spl_y,spl_del:integer;
1640 spl_y_b:boolean;
1641 begin
1642 cavelogo:=ld_tex('cavelogo.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','title/');
1643 splash:='#ERROR';
1644 spl_y:=getimageheight(cavelogo);
1645 spl_y_b:=true;
1646 spl_del:=getrelativetimems;
1647 res:=openResource('/title/splashes.txt');
1648 if ResourceAvailable(res) then
1649 begin
1650 spl_i:=stringtointeger(readline(res));
1651 iy:=random(spl_i-1)+1;
1652 debug('SPLASH #'+iy);
1653 for ix:=1 to iy do
1654 splash:=readline(res);
1655 closeresource(res);
1656 end;
1657 time:=getcurrenttime;
1658 if (getmonth(time)=5) and (getday(time)=7) then splash:='Happy birthday, DeaDDooMER!';
1659 if ((getmonth(time)=0) and (getday(time)<3)) or ((getmonth(time)=11) and (getday(time)>29)) then splash:='Happy New Year!';
1660 repeat
1661 proc_fps;
1662 updateKeys;
1663 if clickedKey(KEY_MENU_UP) then
1664 begin
1665 m_cur:=m_cur-1;
1666 if m_cur<0 then m_cur:=5;
1667 end;
1668 if clickedKey(KEY_MENU_DOWN) then
1669 begin
1670 m_cur:=m_cur+1;
1671 if m_cur>5 then m_cur:=0;
1672 end;
1673 if clickedKey(KEY_MENU_SELECT) then
1674 begin
1675 if m_cur=0 then begin if menu_game then break; end;
1676 else
1677 if m_cur=1 then menu_tex;
1678 else
1679 if m_cur=2 then menu_sett;
1680 else
1681 if m_cur=3 then menu_help;
1682 else
1683 if m_cur=4 then menu_about;
1684 else
1685 if m_cur=5 then begin save_settings; halt; end;
1686 end;
1688 draw_menu_back;
1690 drawimage(cavelogo,(getWidth/2)-(getimagewidth(cavelogo)/2),0);
1691 setcolor(255,255,0);
1693 DrawFontTextSpec(splash, (getWidth/2)-(length(splash)*FONT_SYM_SIZE/2), spl_y, FONT_YELLOW_COLOR, true);
1695 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;
1696 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;
1697 drawfonttext(version,0,getHeight-8);
1699 drw_btn('Singleplayer',0,m_cur,0,1);
1700 drw_btn('Texture Packs',1,m_cur,0,1);
1701 drw_btn('Options',2,m_cur,0,1);
1702 drw_btn('Help',3,m_cur,0,1);
1703 drw_btn('About',4,m_cur,0,1);
1704 drw_btn('Quit Game',5,m_cur,0,1);
1706 drawVideo;
1707 maxfps;
1708 until false;
1709 end;
1711 function setBlock(invcur, x, y:integer):boolean;
1712 var
1713 item, sum, block, sblock:integer;
1714 begin
1715 item:=inv.getItem(invcur);
1716 sum:=inv.getSum(invcur);
1717 block:=getMap(x, y);
1718 sblock := Items.GetData(item);
1720 if (Items.GetType(item) = Items.block) and (Inv.IsNull(invcur) = false) then
1721 if Blocks.IsOverlapped(block) then
1722 // if (coll_xy(x, y)=false) or (getBlockColl(item)=0) then
1723 begin
1724 if set_block_code(sblock, x, y)=false then
1725 begin
1727 setmap(sblock, x, y);
1728 if gamemode<>1 then
1729 begin
1730 inv.setSum(inv.getSum(invcur)-1, invcur);
1731 inv.fixNull(invcur);
1732 end;
1734 setBlock:=true;
1735 end;
1736 end;
1737 end;
1739 procedure fishing;
1740 var
1741 x, y:integer;
1742 begin
1743 x:=player.getX;
1744 y:=player.getY;
1745 if (getrelativetimems-fish_time>5000) and (getmap(fx,fy)=50) then
1746 begin
1747 if (random(3)=2) and (getmap(fx,fy)=50) then
1748 begin
1749 drop.create(210,1,x,y);
1750 fish:=false;
1751 end;
1752 inv.setSum(inv.getSum(invslot)-1, invslot);
1753 inv.fixNull(invslot);
1754 fish:=false;
1755 end; else
1756 if (getrelativetimems-fish_time<5000) and (getmap(fx,fy)=50) and (fish=true) then
1757 begin
1758 if getmap(fx,fy-1)=50 then fy:=fy-1;
1759 end;
1760 end;
1762 procedure drawminimap;
1763 var
1764 ix,iy,tmp_gx,tmp_gy,minx,miny,maxx,maxy,loc_camx,loc_camy,x,y:integer;
1765 begin
1766 x:=player.getX;
1767 y:=player.getY;
1768 if load_minimap_tex then
1769 begin
1770 tmp_gx:=(getWidth/2)-(getimagewidth(gui[16])/2);
1771 tmp_gy:=(getHeight/2)-(getimageheight(gui[16])/2);
1772 end;
1773 else
1774 begin
1775 tmp_gx:=(getWidth/2)-(64/2);
1776 tmp_gy:=(getHeight/2)-(64/2);
1777 end;
1779 loc_camx:=(x+4)-(864/2);
1780 loc_camy:=(y+4)-(864/2);
1781 if loc_camx<0 then loc_camx:=0;
1782 if loc_camx>4096-864 then loc_camx:=4096-864;
1783 if loc_camy<0 then loc_camy:=0;
1784 if loc_camy>2048-864 then loc_camy:=2048-864;
1785 minx:=loc_camx/16;
1786 miny:=loc_camy/16;
1787 maxx:=(loc_camx+864)/16;
1788 maxy:=(loc_camy+864)/16;
1789 if minx<0 then minx:=0;
1790 if miny<0 then miny:=0;
1791 if maxx>255 then maxx:=255;
1792 if maxy>127 then maxy:=127;
1794 if load_minimap_tex then
1795 drawimage(gui[16],tmp_gx,tmp_gy);
1796 else
1797 begin
1798 setcolor(214,190,150);
1799 fillrect(tmp_gx,tmp_gy,64,64);
1800 end;
1802 for ix:=minx to maxx do
1803 for iy:=miny to maxy do
1804 begin
1805 if (getmap(ix,iy)=1) or (getmap(ix,iy)=2) or (getmap(ix,iy)=74) then setcolor(121,85,58); else
1806 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
1807 if (getmap(ix,iy)=50) or (getmap(ix,iy)=62) then setcolor(38,92,255); else
1808 if getmap(ix,iy)=51 then setcolor(255,0,0); else
1809 if (getmap(ix,iy)=61) or (getmap(ix,iy)=32) then setcolor(255,255,255); else
1810 setcolor(127,127,127);
1812 if (getmap(ix,iy)<>0) then plot(tmp_gx+4+ix-minx,tmp_gy+4+iy-miny);
1813 end;
1814 setcolor(0,0,255);
1815 end;
1817 procedure draw_sign;
1818 var
1819 tmp:string;
1820 str:array[0..3] of string;
1821 i,j,tmp_gx,tmp_gy:integer;
1822 begin
1823 if load_gui_tex then
1824 begin
1825 tmp_gx:=(getWidth/2)-(getimagewidth(sign_im)/2);
1826 tmp_gy:=(getHeight/2)-(getimageheight(sign_im)/2);
1827 end;
1828 else
1829 begin
1830 tmp_gx:=(getWidth/2)-(120/2);
1831 tmp_gy:=(getHeight/2)-(60/2);
1832 end;
1834 tmp:=t_sign[getmapinfo(curx,cury)];
1835 while pos(tmp,#13)<>-1 do
1836 begin
1837 i:=pos(tmp,#13);
1838 str[j]:=copy(tmp,0,i);
1839 tmp:=copy(tmp,i+1,length(tmp));
1840 j:=j+1;
1841 end;
1843 if load_gui_tex then
1844 drawimage(sign_im,tmp_gx,tmp_gy);
1845 else
1846 begin
1847 setcolor(159,132,77);
1848 fillrect(tmp_gx,tmp_gy,120,60);
1849 end;
1851 drawfonttext(str[0],tmp_gx+(120/2)-(length(str[0])*8/2),tmp_gy+(60/4/2)+4);
1852 drawfonttext(str[1],tmp_gx+(120/2)-(length(str[1])*8/2),tmp_gy+(60/4/2)+8+4);
1853 drawfonttext(str[2],tmp_gx+(120/2)-(length(str[2])*8/2),tmp_gy+(60/4/2)+16+4);
1854 drawfonttext(str[3],tmp_gx+(120/2)-(length(str[3])*8/2),tmp_gy+(60/4/2)+24+4);
1855 end;
1857 procedure draw_back(ix,iy:integer);
1858 begin
1859 if getBiomMap(ix)=0 then
1860 begin
1861 if (getBackMap(ix)=iy) then drawimage(back[0],(ix*16)-camx,(iy*16)-camy); else
1862 if (getBackMap(ix)+1=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1863 if (getBackMap(ix)+2=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1864 if (getBackMap(ix)+3=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1865 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1866 end; else
1867 if getBiomMap(ix)=1 then
1868 begin
1869 if (getBackMap(ix)=iy) then drawimage(back[4],(ix*16)-camx,(iy*16)-camy); else
1870 if (getBackMap(ix)+1=iy) then drawimage(back[4],(ix*16)-camx,(iy*16)-camy); else
1871 if (getBackMap(ix)+2=iy) then drawimage(back[6],(ix*16)-camx,(iy*16)-camy); else
1872 if (getBackMap(ix)+3=iy) then drawimage(back[6],(ix*16)-camx,(iy*16)-camy); else
1873 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1874 end; else
1875 if getBiomMap(ix)=2 then
1876 begin
1877 if (getBackMap(ix)=iy) then drawimage(back[5],(ix*16)-camx,(iy*16)-camy); else
1878 if (getBackMap(ix)+1=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1879 if (getBackMap(ix)+2=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1880 if (getBackMap(ix)+3=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1881 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1882 end; else
1883 if getBiomMap(ix)=3 then
1884 begin
1885 if (getBackMap(ix)=iy) then drawimage(back[7],(ix*16)-camx,(iy*16)-camy); else
1886 if (getBackMap(ix)+1=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1887 if (getBackMap(ix)+2=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1888 if (getBackMap(ix)+3=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1889 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1890 end; else
1891 if getBiomMap(ix)=4 then
1892 begin
1893 drawimage(back[8],(ix*16)-camx,(iy*16)-camy);
1894 end;
1895 end;
1897 procedure draw;
1898 var
1899 ix,iy,iz,minx,miny,maxx,maxy,tmp_ax,tim,smy,pa_xo, x, y:integer;
1900 begin
1901 x:=player.getX;
1902 y:=player.getY;
1903 {===================[sky]===================}
1904 tim:=10000*getimagewidth(sky)/600000*game_time/10000;
1905 setcolor(effects.get(sky,tim,0,1),effects.get(sky,tim,0,2),effects.get(sky,tim,0,3));
1906 fillrect(0,0,getWidth,getHeight);
1907 srand(seed);
1908 if drw_stars then
1909 begin
1910 setcolor(effects.get(sky,tim,2,1),effects.get(sky,tim,2,2),effects.get(sky,tim,2,3));
1911 smy:=10000*getWidth*2/600000*game_time/10000;
1912 for iz:=1 to getWidth do
1913 begin
1914 ix:=rnd(getWidth*2)-getWidth+smy;
1915 if ix>getWidth then ix:=ix-getWidth*2;
1916 iy:=rnd(getHeight);
1917 if (ix>-1) and (ix<getWidth) then plot(ix,iy);
1918 end;
1919 end;
1921 if drw_sm then
1922 begin
1923 if load_sm>0 then
1924 begin
1925 smy:=10000*(getWidth+getimagewidth(sun))/300000*game_time/10000;
1926 drawimage(sun,smy-getimagewidth(sun),getHeight/2-getimageheight(sun)/2);
1927 end;
1928 else
1929 begin
1930 setcolor(255,213,74);
1931 smy:=10000*(getWidth+sm_siz)/300000*game_time/10000;
1932 fillrect(smy-sm_siz+sm_siz4,getHeight/2-sm_siz/2+sm_siz4,sm_siz-sm_siz4,sm_siz-sm_siz4);
1933 end;
1935 if load_sm>0 then
1936 begin
1937 smy:=10000*(getWidth+getimagewidth(moon))/300000*(game_time-300000)/10000;
1938 drawimage(moon,smy-getimagewidth(moon),getHeight/2-getimageheight(moon)/2);
1939 end;
1940 else
1941 begin
1942 setcolor(175,184,204);
1943 smy:=10000*(getWidth+sm_siz)/300000*(game_time-300000)/10000;
1944 fillrect(smy-sm_siz+sm_siz4,getHeight/2-sm_siz/2+sm_siz4,sm_siz-sm_siz4,sm_siz-sm_siz4);
1945 end;
1946 end;
1947 {===================[camera]===================}
1948 camx:=(x+4)-(getWidth/2);
1949 camy:=(y+4)-(getHeight/2);
1950 if camx<0 then camx:=0;
1951 if camx>4096-getWidth then camx:=4096-getWidth;
1952 if camy>2048-getHeight then camy:=2048-getHeight;
1953 {===================[max_draw]===================}
1954 minx:=camx/16;
1955 miny:=camy/16;
1956 maxx:=(camx+getWidth)/16;
1957 maxy:=(camy+getHeight)/16;
1958 if minx<0 then minx:=0;
1959 if miny<0 then miny:=0;
1960 if maxx>255 then maxx:=255;
1961 if maxy>127 then maxy:=127;
1962 {===================[draw_back]===================}
1963 for ix:=minx to maxx do
1964 for iy:=miny to maxy do
1965 begin
1966 if ifosad and osadki and (getBackMap(ix) >= iy) and Blocks.IsTransporent(getmap(ix, iy)) then begin
1967 if getBiomMap(ix) = 0 then drawimage(osad[0, osadki_ani], (ix * 16) - camx, (iy * 16) - camy)
1968 else if getBiomMap(ix) = 2 then drawimage(osad[1, osadki_ani], (ix * 16) - camx, (iy * 16) - camy)
1969 else if getBiomMap(ix) = 3 then drawimage(osad[0, osadki_ani], (ix * 16) - camx, (iy * 16) - camy)
1970 end;
1971 if drw_back and Blocks.IsTransporent(getmap(ix, iy)) then draw_back(ix, iy);
1972 if Blocks.IsForeground(getmap(ix,iy)) = false then BlocksLogic.Draw(ix, iy, camx, camy);
1973 end;
1974 {===================[drop]===================}
1975 Drop.Draw(camx, camy);
1976 {===================[particles]===================}
1977 Particles.Draw(camx, camy);
1978 {===================[player]===================}
1979 Player.Draw(camx, camy);
1980 {===================[mobs]===================}
1981 Mobs.Draw(camx, camy);
1982 {===================[draw_blocks]===================}
1983 for ix:=minx to maxx do
1984 for iy:=miny to maxy do
1985 begin
1986 if Blocks.IsForeground(getmap(ix, iy)) then BlocksLogic.Draw(ix, iy, camx, camy);
1988 setcolor(0, 0, 0);
1989 if light_type = 1 then
1990 begin
1991 if getmaplight(ix,iy) = 0 then
1992 fillrect((ix * 16) - camx, (iy * 16) - camy, 16, 16);
1993 end;
1994 else if light_type = 2 then
1995 begin
1996 if getmaplight(ix, iy) < 15 then
1997 drawimage(light[getmaplight(ix, iy)], (ix * 16) - camx, (iy * 16) - camy);
1998 end;
1999 end;
2001 // debug
2002 // drawimage(light[getmaplight(player.getX div 16, player.getY div 16)], 0, 0);
2004 if (toolus > 0) and (toolind < 10) and (getmap(curx,cury) > 0) then
2005 begin
2006 if toolind > 9 then
2007 toolind:=9;
2008 drawimage(tue[toolind], curx * 16 - camx, cury * 16 - camy);
2009 end;
2010 {===================[gui]===================}
2011 if drawgui then
2012 begin
2013 tmp_ax:=(getWidth/2)-(getImageWidth(gui[1])/2);
2015 if keymode=1 then
2016 drawimage(gui[0],curx*16-camx,cury*16-camy);
2018 DrawWindows;
2019 /*if keymode=2 then
2020 if gamemode<>1 then
2021 DrawPlayerInventory;
2022 else
2023 drawinv_c; else
2024 if keymode=3 then drawcraft; else
2025 if keymode=4 then drawchest; else
2026 if keymode=5 then draw_sign; else
2027 if keymode=6 then drawfurnace; else
2028 if ifminimap then drawminimap;*/
2030 drawimage(gui[1],tmp_ax,0);
2031 for ix:=0 to 8 do
2032 begin
2033 ItemsLogic.Draw(inv.getItem(ix), inv.getSum(ix), (ix*16)+tmp_ax+ix*2+4, 1, true);
2034 end;
2035 drawimage(gui[17],(invslot*16)+tmp_ax+invslot*2+2,0);
2037 if gamemode<>1 then
2038 begin
2039 if gamemode=0 then
2040 begin
2041 for ix:=0 to (hp div 2)-1 do drawimage(gui[13],ix*9,getHeight-9);
2042 if (hp mod 2)<>0 then begin drawimage(gui[14],ix*9,getHeight-9); ix:=ix+1 end;
2043 for ix:=ix to 9 do drawimage(gui[15],ix*9,getHeight-9);
2044 end; else
2045 if gamemode=2 then
2046 begin
2047 for ix:=0 to (hp div 2)-1 do drawimage(gui[31],ix*9,getHeight-9);
2048 if (hp mod 2)<>0 then begin drawimage(gui[32],ix*9,getHeight-9); ix:=ix+1 end;
2049 for ix:=ix to 9 do drawimage(gui[33],ix*9,getHeight-9);
2050 end;
2052 for ix:=0 to (hunger div 2)-1 do drawimage(gui[26],ix*9,getHeight-18);
2053 if (hunger mod 2)<>0 then begin drawimage(gui[27],ix*9,getHeight-18); ix:=ix+1 end;
2054 for ix:=ix to 9 do drawimage(gui[28],ix*9,getHeight-18);
2056 if getmap((x+4)/16,y/16)=50 then
2057 begin
2058 for ix:=0 to (air div 2)-1 do drawimage(gui[29],ix*9,getHeight-27);
2059 if (air mod 2)<>0 then begin drawimage(gui[30],ix*9,getHeight-27); ix:=ix+1 end;
2060 end;
2061 end;
2063 for ix:=0 to 3 do
2064 begin
2065 drawfonttext(msg[ix],0,getHeight-20-ix*9);
2066 if getrelativetimems-msg_time[ix]>5000 then msg[ix]:='';
2067 end;
2068 end;
2069 end;
2071 procedure load_moon(path:string;phase:integer);
2072 var
2073 no:image;
2074 begin
2075 moon:=no;
2076 if load_sm=1 then
2077 begin
2078 moon:=ld_tex('moon_phase_'+phase+'.png',path,'terrain/moon_phases/');
2079 end; else
2080 if load_sm=2 then
2081 begin
2082 moon:=resize_image(ld_tex('moon_phase_'+phase+'.png',path,'terrain/moon_phases/'),(getWidth+getHeight)/5,(getWidth+getHeight)/5);
2083 end;
2084 end;
2086 procedure sleep;
2087 var
2088 i,ix,iy:integer;
2089 begin
2090 if game_time>300000 then
2091 begin
2092 if load_light_tex then
2093 begin
2094 keymode:=0;
2095 i:=15;
2096 while i>0 do
2097 begin
2098 for iy:=0 to getheight/16 do
2099 for ix:=0 to getwidth/16 do
2100 drawimage(light[i],ix*16,iy*16);
2101 i:=i-1;
2102 drawVideo;
2103 delay(100);
2104 end;
2105 moon_phase:=moon_phase+1;
2106 if moon_phase>7 then moon_phase:=0;
2107 load_moon('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/',moon_phase);
2108 game_time:=50000;
2109 last_sleep_x:=curx;
2110 last_sleep_y:=cury-1;
2111 i:=1;
2112 while i<15 do
2113 begin
2114 draw;
2115 for iy:=0 to getheight/16 do
2116 for ix:=0 to getwidth/16 do
2117 drawimage(light[i],ix*16,iy*16);
2118 i:=i+1;
2119 drawVideo;
2120 delay(100);
2121 end;
2122 end;
2123 else
2124 begin
2125 keymode:=0;
2126 i:=0;
2127 while i<=getheight do
2128 begin
2129 setcolor(0,0,0);
2130 fillrect(0,0,getwidth,i);
2131 i:=i+5;
2132 drawVideo;
2133 delay(50);
2134 end;
2135 moon_phase:=moon_phase+1;
2136 if moon_phase>7 then moon_phase:=0;
2137 load_moon('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/',moon_phase);
2138 game_time:=50000;
2139 last_sleep_x:=curx;
2140 last_sleep_y:=cury-1;
2141 i:=0;
2142 while i<=getheight do
2143 begin
2144 draw;
2145 setcolor(0,0,0);
2146 fillrect(0,i,getwidth,getheight);
2147 i:=i+5;
2148 drawVideo;
2149 delay(50);
2150 end;
2151 end;
2152 end; else create_msg('You can sleep only at night');
2153 end;
2155 procedure resetToolProgerss;
2156 begin
2157 toolus:=0;
2158 toolind:=0;
2159 end;
2161 procedure usetools(invcur, x, y:integer);
2162 var
2163 item, sum, block:integer;
2164 begin
2165 block:=getmap(x, y);
2166 item:=inv.getItem(invcur);
2167 sum:=inv.getSum(invcur);
2169 if gamemode=1 then
2170 destroy_block_cr(block, x, y);
2171 else
2172 if (block>0) then
2173 begin
2174 if (Items.GetType(item) = Items.tool) and (Blocks.GetTool(block) = getToolType(item)) then
2175 toolus:=toolus+getToolSpeed(item);
2176 else
2177 toolus:=toolus+1;
2179 if toolus >= Blocks.GetResistant(block) then
2180 begin
2181 if ((Items.GetType(item) = Items.tool) and (Blocks.GetTool(block) = getToolType(item)) and (getToolLvl(item) >= Blocks.GetLevel(block))) or (Blocks.GetLevel(block) <= 0) then
2182 begin
2183 setMap(0, x, y);
2184 destroy_block_1(block, x, y);
2185 setMapInfo(0, x, y);
2186 end;
2187 else
2188 begin
2189 setMap(0, x, y);
2190 destroy_block_0(block, x, y);
2191 setMapInfo(0, x, y);
2192 end;
2194 if Items.GetType(item) = Items.tool then
2195 begin
2196 inv.setSum(inv.getSum(invcur)-1, invcur);
2197 inv.fixNull(invcur);
2198 end;
2200 toolus:=0;
2201 toolind:=0;
2202 end;
2203 end;
2205 if (toolus > 0) and (toolus <= Blocks.GetResistant(block)) then begin
2206 toolind := ((toolus * 100) div Blocks.GetResistant(block)) div 10;
2207 end;
2208 end;
2210 function rt_useweap:boolean;
2211 var
2212 x, y, w, h, i, damg:integer;
2213 item:integer;
2214 begin
2215 x:=player.getX;
2216 y:=player.getY;
2217 w:=player.getW;
2218 h:=player.getH;
2219 item:=inv.getItem(invslot);
2221 if Items.GetType(item) = Items.tool then
2222 damg:=getToolDamg(item);
2223 else
2224 damg:=1;
2226 if posi=0 then
2227 i:=Mobs.findAndHit(damg, x-TILE_SIZE, y, TILE_SIZE+(w/2), h, -2, -3);
2228 else
2229 i:=Mobs.findAndHit(damg, x+(w/2), y, TILE_SIZE+(w/2), h, 2, -3);
2231 if i<>-1 then
2232 begin
2233 inv.setSum(inv.getSum(invslot)-1, invslot);
2234 inv.fixNull(invslot);
2235 rt_useweap:=true;
2236 end;
2237 end;
2239 procedure rt_usetools;
2240 var
2241 x, y:integer;
2242 begin
2243 x:=player.getX;
2244 y:=player.getY;
2246 if posi=0 then curx:=(x div 16)-1; else curx:=(x div 16)+1;
2247 cury:=y div 16;
2248 if getmap(curx,cury)=0 then cury:=cury+1;
2250 if curx<0 then curx:=0;
2251 if curx>255 then curx:=255;
2252 if cury<0 then cury:=0;
2253 if cury>127 then cury:=127;
2255 usetools(invslot, curx, cury);
2256 end;
2258 procedure rt_usemob;
2259 var
2260 x, y:integer;
2261 begin
2262 x:=player.getX;
2263 y:=player.getY;
2265 if posi=0 then curx:=(x div 16)-1; else curx:=(x div 16)+1;
2266 cury:=y div 16;
2267 if getmap(curx,cury)=0 then cury:=cury+1;
2269 if curx<0 then curx:=0;
2270 if curx>255 then curx:=255;
2271 if cury<0 then cury:=0;
2272 if cury>127 then cury:=127;
2274 //usemob(curx,cury);
2275 end;
2277 procedure actionUse(invcur, x, y:integer);
2278 begin
2279 if setBlock(invcur, x, y)=false then
2280 if useBlock(invcur, x, y) then
2281 if useItem(invcur, x, y) then
2282 end;
2284 procedure rt_useblock;
2285 var
2286 x, y:integer;
2287 begin
2288 x:=player.getX;
2289 y:=player.getY;
2291 if posi=0 then curx:=(x div 16)-1; else curx:=(x div 16)+1;
2292 cury:=y div 16;
2293 if getmap(curx,cury)=0 then cury:=cury+1;
2295 if curx<0 then curx:=0;
2296 if curx>255 then curx:=255;
2297 if cury<0 then cury:=0;
2298 if cury>127 then cury:=127;
2300 actionUse(invslot, curx, cury);
2301 end;
2303 procedure go_to_nether;
2304 var
2305 ix:integer;
2306 begin
2307 portal_time:=getrelativetimems;
2308 savegame('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2309 pl_world:=1;
2310 drw_load_line('Matrix',10);
2311 if loadworld('/'+sd+'/cavecraft/saves/'+sav_fl+'/')=true then
2312 begin
2313 player.setX(get_spawn_x*16+4);
2314 player.setY((get_up(get_spawn_x)-1)*16);
2315 end;
2316 else
2317 begin
2318 {for ix:=0 to 31 do
2319 begin
2320 mob[ix].m_type:=0;
2321 mob[ix].m_x:=0;
2322 mob[ix].m_y:=0;
2323 mob[ix].m_posi:=0;
2324 mob[ix].m_velx:=0;
2325 mob[ix].m_vely:=0;
2326 mob[ix].m_ani:=0;
2327 mob[ix].m_min_vely:=0;
2328 mob[ix].m_hp:=0;
2329 mob[ix].m_del:=0;
2330 mob[ix].m_fall:=false;
2331 mob[ix].m_jmp:=false;
2332 mob[ix].m_velani:=false;
2333 end;}
2335 drop.resetData;
2336 gennether;
2337 //netherspawn;
2338 end;
2339 end;
2341 procedure go_to_world;
2342 begin
2343 portal_time:=getrelativetimems;
2344 savegame('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2345 pl_world:=0;
2346 drw_load_line('Matrix',10);
2347 if loadworld('/'+sd+'/cavecraft/saves/'+sav_fl+'/')=true then
2348 begin
2349 pl_world:=0;
2350 end;
2351 else
2352 begin
2353 debug('ERROR!!!');
2354 pl_world:=0;
2355 genworld;
2356 //megaspawn;
2357 end;
2358 end;
2360 procedure plr_is_dead_hardcore;
2361 begin
2362 keymode:=0;
2363 toolus:=0;
2364 toolind:=0;
2366 repeat
2367 updateKeys;
2368 if clickedKey(KEY_MENU_SELECT) then
2369 begin
2370 deleteworld('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2371 menu;
2372 exit;
2373 end;
2374 draw;
2375 drawfonttext('You died!',getwidth/2-32,getheight/2-16);
2377 drw_btn('Delete world',0,0,0,1);
2379 drawVideo;
2380 delay(1);
2381 until false;
2383 end;
2385 procedure plr_is_dead;
2386 var
2387 m_cur:integer;
2388 x, y:integer;
2389 begin
2390 x:=player.getX;
2391 y:=player.getY;
2392 keymode:=0;
2393 toolus:=0;
2394 toolind:=0;
2395 repeat
2396 updateKeys;
2397 if clickedKey(KEY_MENU_UP) then
2398 begin
2399 m_cur:=m_cur-1;
2400 if m_cur<0 then m_cur:=1;
2401 end;
2402 if clickedKey(KEY_MENU_DOWN) then
2403 begin
2404 m_cur:=m_cur+1;
2405 if m_cur>1 then m_cur:=0;
2406 end;
2407 if clickedKey(KEY_MENU_SELECT) then
2408 begin
2409 if m_cur=0 then
2410 begin
2411 if pl_world=0 then
2412 begin
2413 if last_sleep_x=0 then
2414 begin
2415 x:=get_spawn_x*16+4;
2416 y:=get_spawn_y*16;
2417 end; else
2418 begin
2419 x:=last_sleep_x*16+4;
2420 y:=last_sleep_y*16;
2421 end;
2422 end; else
2423 if pl_world=1 then
2424 begin
2425 go_to_world;
2426 if last_sleep_x=0 then
2427 begin
2428 x:=get_spawn_x*16+4;
2429 y:=get_spawn_y*16;
2430 end; else
2431 begin
2432 x:=last_sleep_x*16+4;
2433 y:=last_sleep_y*16;
2434 end;
2435 end;
2436 player.setX(x);
2437 player.setY(y);
2438 posi:=0;
2439 curx:=0;
2440 cury:=0;
2441 vely:=0;
2442 jmp:=false;
2443 hp:=20;
2444 hunger:=20;
2445 exit;
2446 end;
2447 else
2448 if m_cur=1 then begin menu; exit; end;
2449 end;
2451 draw;
2453 drawfonttext('You died!',getwidth/2-32,getheight/2-16);
2455 drw_btn('Respawn',0,m_cur,0,1);
2456 drw_btn('Main menu',1,m_cur,0,1);
2458 drawVideo;
2459 delay(1);
2460 until false;
2461 end;
2463 procedure fast_menu;
2464 var
2465 m_cur,i:integer;
2466 begin
2467 repeat
2468 updateKeys;
2469 if clickedKey(KEY_MENU_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=3; end;
2470 if clickedKey(KEY_MENU_DOWN) then begin m_cur:=m_cur+1; if m_cur>3 then m_cur:=0; end;
2471 if clickedKey(KEY_MENU_SELECT) then
2472 begin
2473 if m_cur=0 then
2474 begin
2475 exit;
2476 end; else
2477 if m_cur=1 then
2478 begin
2479 savegame('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2480 exit;
2481 end; else
2482 if m_cur=2 then
2483 begin
2484 menu_sett;
2485 end; else
2486 if m_cur=3 then
2487 begin
2488 //clear_gui(keymode);
2489 menu;
2490 exit;
2491 end;
2492 end;
2493 draw;
2494 drawfonttext('Game menu',getwidth/2-36,getheight/2-20);
2495 drw_btn('Back to Game',0,m_cur,0,1);
2496 drw_btn('Save Game',1,m_cur,0,1);
2497 drw_btn('Options',2,m_cur,0,1);
2498 drw_btn('Quit to Title',3,m_cur,0,1);
2500 drawVideo;
2501 delay(1);
2502 until false;
2503 end;
2505 procedure keyFastInv;
2506 begin
2507 if clickedKey(KEY_FASTINV_NEXT) then
2508 begin
2509 invslot:=invslot-1;
2510 if invslot<0 then
2511 invslot:=8;
2512 end;
2514 if clickedKey(KEY_FASTINV_PREV) then
2515 begin
2516 invslot:=invslot+1;
2517 if invslot>8 then
2518 invslot:=0;
2519 end;
2520 end;
2522 procedure keyConsole;
2523 begin
2524 if clickedKey(KEY_CHAT) then
2525 SetTimer(1000,T_CONSOLE);
2527 if pressedKey(KEY_CHAT) then
2528 begin
2529 if GetTimer(T_CONSOLE)=TIMER_OK then
2530 begin
2531 call_console;
2532 ResetTimer(T_CONSOLE);
2533 end;
2534 end;
2535 else
2536 begin
2537 if GetTimer(T_CONSOLE)>TIMER_OK then
2538 begin
2539 deb:= not deb;
2540 ResetTimer(T_CONSOLE);
2541 end;
2542 end;
2543 end;
2545 procedure keyInventory;
2546 begin
2547 if clickedKey(KEY_PLR_OPENINV) then
2548 if gamemode<>1 then
2549 OpenPlayerInventory;
2550 else
2551 OpenCreativeWindow;
2552 end;
2554 procedure keyhandler;
2555 begin
2556 updateKeys;
2558 if WindowKeyHanler then
2559 begin
2560 if keymode=0 then
2561 begin
2562 keyInventory;
2563 keyFastInv;
2564 keyConsole;
2566 if clickedKey(KEY_PLR_EDITMODE) then
2567 begin
2568 keymode:=1;
2569 curx:=player.getX div 16;
2570 cury:=player.getY div 16;
2571 end;
2573 if clickedKey(KEY_PLR_USE) then
2574 rt_usemob;
2576 if clickedKey(KEY_MENU) then
2577 fast_menu;
2579 if clickedKey(KEY_PLR_ATTACK) then
2580 if rt_useweap=false then
2581 debug('useweap');
2583 if pressedKey(KEY_PLR_ATTACK) then
2584 begin
2585 rt_usetools;
2586 playAnim(ANIM_HAND);
2587 end;
2588 else
2589 begin
2590 resetToolProgerss;
2591 cancelAnim(ANIM_HAND);
2592 end;
2594 if pressedKey(KEY_PLR_UP) then
2595 player.gotoUP;
2596 if pressedKey(KEY_PLR_DOWN) then
2597 player.gotoDOWN;
2598 if pressedKey(KEY_PLR_LEFT) then
2599 player.gotoLEFT;
2600 if pressedKey(KEY_PLR_RIGHT) then
2601 player.gotoRIGHT;
2602 end;
2603 else
2604 if keymode=1 then
2605 begin
2606 keyInventory;
2607 keyFastInv;
2608 keyConsole;
2610 if clickedKey(KEY_PLR_UP) then
2611 begin
2612 cury:=cury-1;
2613 if cury<0 then
2614 cury:=0;
2615 end;
2616 if clickedKey(KEY_PLR_DOWN) then
2617 begin
2618 cury:=cury+1;
2619 if cury>127 then
2620 cury:=127;
2621 end;
2622 if clickedKey(KEY_PLR_LEFT) then
2623 begin
2624 curx:=curx-1;
2625 if curx<0 then
2626 curx:=0;
2627 end;
2628 if clickedKey(KEY_PLR_RIGHT) then
2629 begin
2630 curx:=curx+1;
2631 if curx>255 then
2632 curx:=255;
2633 end;
2635 if clickedKey(KEY_PLR_EDITMODE) then
2636 keymode:=0;
2638 if clickedKey(KEY_PLR_USE) then
2639 actionUse(invslot, curx, cury);
2641 if pressedKey(KEY_PLR_ATTACK) then
2642 begin
2643 usetools(invslot, curx, cury);
2644 playAnim(ANIM_HAND);
2645 end;
2646 else
2647 begin
2648 resetToolProgerss;
2649 cancelAnim(ANIM_HAND);
2650 end;
2652 if clickedKey(KEY_MENU) then
2653 fast_menu;
2654 end;
2656 end;
2658 end;
2660 procedure phyhandler;
2661 var
2662 i:integer;
2663 begin
2664 Player.CalcPhysics;
2665 Mobs.UpdatePhy;
2666 Drop.CalcPhy;
2667 end;
2669 procedure light_fillrect(l,x,y,r:integer);
2670 var
2671 ix,iy,ym,yp,xm,xp:integer;
2672 begin
2673 ym:=y-r;
2674 yp:=y+r;
2675 xm:=x-r;
2676 xp:=x+r;
2677 for ix:=xm to xp do
2678 for iy:=ym to yp do
2679 setmaplight(getmaplight(ix,iy)+l,ix,iy);
2680 end;
2682 procedure light_rect(l,x,y,r:integer);
2683 var
2684 ix,iy,ym,yp,xm,xp:integer;
2685 begin
2686 ym:=y-r;
2687 yp:=y+r;
2688 xm:=x-r;
2689 xp:=x+r;
2690 for ix:=xm to xp do
2691 begin
2692 setmaplight(getmaplight(ix,ym)+l,ix,ym);
2693 setmaplight(getmaplight(ix,yp)+l,ix,yp);
2694 end;
2695 for iy:=ym+1 to yp-1 do
2696 begin
2697 setmaplight(getmaplight(xm,iy)+l,xm,iy);
2698 setmaplight(getmaplight(xp,iy)+l,xp,iy);
2699 end;
2700 end;
2702 procedure calc_light(m,x,y:integer);
2703 var
2704 ix,iy,l,ss,sf:integer;
2705 begin
2706 if light_type=1 then light_fillrect(m,x,y,m/2); else
2707 for l:=m downto 1 do
2708 begin
2709 if ss mod 2=0 then light_rect(l,x,y,ss/2);
2710 ss:=ss+1;
2711 end;
2712 end;
2714 procedure calc_sun(ix,m:integer);
2715 var
2716 iy,ss:integer;
2717 begin
2718 ss:=m;
2719 for iy:=0 to 127 do
2720 begin
2721 setmaplight(ss,ix,iy);
2722 if ss=0 then break;
2723 ss := ss - Blocks.GetLightAbsorbtion(getmap(ix, iy));
2724 if ss<0 then ss:=0;
2725 end;
2726 for iy:=iy+1 to 127 do
2727 begin
2728 setmaplight(0,ix,iy);
2729 end;
2730 end;
2732 procedure kill_plr;
2733 var
2734 i:integer;
2735 begin
2736 hp:=0;
2737 for i:=0 to INV_SIZE do
2738 begin
2739 if inv.isNull(i)=false then
2740 player.dropItem(inv.getItem(i), inv.getSum(i));
2741 inv.setItem(0, i);
2742 inv.setSum(0, i);
2743 end;
2744 if gamemode<2 then plr_is_dead; else plr_is_dead_hardcore;
2745 end;
2747 procedure hunger_and_air;
2748 var
2749 x, y:integer;
2750 begin
2751 x:=player.getX;
2752 y:=player.getY;
2753 if gamemode<>1 then
2754 begin
2755 if getrelativetimems-hung_time>=90000/(gamemode+1) then
2756 begin
2757 hung_time:=getrelativetimems;
2758 hunger:=hunger-1;
2759 end;
2760 if getrelativetimems-hp_time>=5000*(gamemode+1) then
2761 begin
2762 if hunger>16 then
2763 begin
2764 hp_time:=getrelativetimems;
2765 hp:=hp+1;
2766 if hp>20 then hp:=20;
2767 end; else
2768 if hunger<1 then
2769 begin
2770 hp_time:=getrelativetimems;
2771 hp:=hp-1;
2772 if hp<1 then if gamemode<2 then hp:=1;
2773 end;
2774 end;
2776 if getmap((x+4)/16,y/16)=50 then
2777 begin
2778 if getrelativetimems-air_time>=500 then
2779 begin
2780 air:=air-1;
2781 air_time:=getrelativetimems;
2782 if air<1 then
2783 begin
2784 hp_time:=getrelativetimems;
2785 hp:=hp-2;
2786 end;
2787 end;
2788 end; else
2789 air:=21;
2790 end;
2791 end;
2793 procedure game;
2794 var
2795 ix,iy,minx,maxx,miny,maxy,fps_t,tim, x, y:integer;
2796 begin
2797 x:=player.getX;
2798 y:=player.getY;
2800 hunger_and_air;
2802 if hunger<0 then hunger:=0;
2803 if air<0 then air:=0;
2805 fps_t:=fps;
2806 if fps_t<1 then fps_t:=1;
2808 if bl_ani5_d then
2809 if bl_ani5_v=false then
2810 begin
2811 bl_ani5:=bl_ani5+1;
2812 if bl_ani5>4 then
2813 begin
2814 bl_ani5:=4;
2815 bl_ani5_v:=not bl_ani5_v;
2816 end;
2817 end;
2818 else
2819 begin
2820 bl_ani5:=bl_ani5-1;
2821 if bl_ani5<0 then
2822 begin
2823 bl_ani5:=0;
2824 bl_ani5_v:=not bl_ani5_v;
2825 end;
2826 end;
2827 bl_ani5_d:=not bl_ani5_d;
2829 drop.reflux;
2830 player.getDrop;
2832 game_time:=game_time+(600000 div (fps_t*1000));
2834 // Ускорение игрового времени в 10 раз
2835 // game_time := game_time + (600000 div (fps_t*100));
2837 if (game_time>600000) or (game_time<0) then
2838 begin
2839 game_time:=0;
2840 moon_phase:=moon_phase+1;
2841 if moon_phase>7 then moon_phase:=0;
2842 load_moon('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/',moon_phase);
2843 end;
2845 tim := 10000 * getimagewidth(sky) / 600000 * game_time / 10000;
2846 global_light := effects.get(sky, tim, 1, 1) div 16;
2848 if clock_stage<>game_time div 75000 then begin clock_stage:=clock_stage+1; if clock_stage>7 then clock_stage:=0; end;
2850 if x < 0 then x := 0;
2851 else if x + 8 > 4094 then x := 4086;
2852 if Blocks.IsSolid(getmap(x div 16, y div 16)) then hp := hp - 1;
2854 if random(4096)=random(4096) then begin osadki:=not osadki; end;
2855 osadki_ani:=osadki_ani+1;
2856 if osadki_ani>7 then osadki_ani:=0;
2858 if Random(20) = Random(20) then Particles.Create(Particles.bubble, x, y);
2860 if gamemode=1 then begin hp:=666; hunger:=666; end;
2862 if inv.getItem(invslot)=186 then
2863 ifminimap:=true;
2864 else
2865 ifminimap:=false;
2867 //if s_spawn_mob then if random(4096)=1547 then megaspawn;
2869 Mobs.Update;
2870 Particles.Update;
2872 if light_type>0 then
2873 begin
2874 minx:=camx/16-1;
2875 maxx:=(camx+getWidth)/16+1;
2876 if minx<0 then minx:=0;
2877 if maxx>255 then maxx:=255;
2878 for ix:=minx to maxx do calc_sun(ix,global_light);
2879 end;
2881 minx:=camx/16-8;
2882 maxx:=(camx+getWidth)/16+16;
2883 miny:=camy/16-8;
2884 maxy:=(camy+getHeight)/16+16;
2885 if minx<0 then minx:=0;
2886 if maxx>255 then maxx:=255;
2887 if miny<0 then miny:=0;
2888 if maxy>127 then maxy:=127;
2889 for ix:=minx to maxx do
2890 for iy:=miny to maxy do
2891 begin
2892 if light_type = 0 then begin
2893 SetMapLight(15, ix, iy);
2894 end else if (light_type > 0) and (Blocks.GetLightEmission(getmap(ix, iy)) > 0) then begin
2895 calc_light(Blocks.GetLightEmission(GetMap(ix, iy)), ix, iy);
2896 end;
2897 end;
2899 minx:=(camx/16)-((getwidth/2)/16);
2900 miny:=(camy/16)-((getheight/2)/16);
2901 maxx:=(camx+(getWidth+getWidth/2))/16;
2902 maxy:=(camy+(getHeight+getHeight/2))/16;
2903 if minx<0 then minx:=0;
2904 if miny<0 then miny:=0;
2905 if maxx>255 then maxx:=255;
2906 if maxy>127 then maxy:=127;
2907 if updx<minx then updx:=minx;
2908 if updy<miny then updy:=miny;
2909 if updx>maxx then updx:=minx;
2910 if updy>maxy then updy:=miny;
2912 if bl_upd>0 then
2913 begin
2914 for ix:=0 to (((2*getWidth/16)*(2*getHeight/16))-1) div ((fps_t*bl_upd)) do
2915 begin
2916 updateBlock(updx, updy);
2917 updx:=updx+1;
2918 if updx>maxx then
2919 begin
2920 updx:=minx;
2921 updy:=updy+1;
2922 if updy>maxy then updy:=miny;
2923 end;
2924 end;
2925 end;
2927 {if coll_bl(110)=true then
2928 begin
2929 if getrelativetimems-portal_time>5000 then
2930 begin
2931 if pl_world=0 then begin go_to_nether; portal_time:=getrelativetimems; end; else
2932 if pl_world=1 then begin go_to_world; portal_time:=getrelativetimems; end;
2933 end;
2934 end;
2936 if coll_bl(51)=true then hp:=hp-1;
2938 if coll_bl(59)=true then
2939 begin
2940 if vely<0 then vely:=-1;
2941 else
2942 if vely>0 then vely:=1;
2943 end;}
2945 if gamemode<>1 then
2946 begin
2947 if hp>20 then hp:=20;
2948 if hunger>20 then hunger:=20;
2949 end;
2951 if y>2048 then kill_plr;
2952 if (hp<1) and (gamemode<>1) then kill_plr;
2953 if fish=true then fishing;
2955 if (fish=true) and (inv.getItem(invslot)<>152) then fish:=false;
2957 //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;
2959 if gamemode<>1 then
2960 begin
2961 if cury<(y div 16)-4 then cury:=(y div 16)-4;
2962 if cury>(y div 16)+5 then cury:=(y div 16)+5;
2963 if curx<(x div 16)-4 then curx:=(x div 16)-4;
2964 if curx>(x div 16)+4 then curx:=(x div 16)+4;
2965 end;
2967 UpdateFurnaces;
2968 end;
2970 procedure qt_start;
2971 var
2972 i:integer;
2973 begin
2974 drawgui:=true;
2975 LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
2976 drawdeadlogo;
2977 start_uu;
2978 if load_key_tex=1 then init_touch;
2979 for i:=0 to 4 do
2980 begin
2981 msg[i]:='';
2982 msg_time[i]:=getrelativetimems;
2983 end;
2984 InitMap(MAP_W, MAP_H);
2985 menu;
2986 end;
2988 procedure draw_debug;
2989 var
2990 i : Integer;
2991 begin
2992 //drawfonttext('X:'+(x div 16-128),0,0);
2993 //drawfonttext('Y:'+integertostring(127-(y div 16)),0,8);
2994 drawfonttext('CURX:'+(curx-128),0,16);
2995 drawfonttext('CURY:'+cury,0,24);
2996 drawfonttext('UPDX:'+updx,0,32);
2997 drawfonttext('UPDY:'+updy,0,40);
2998 drawfonttext('FPS:'+fps,0,56);
2999 drawfonttext('Free RAM:'+free_ram/1024+' KB',0,64);
3000 drawfonttext('Total RAM:'+memory.get_totalmemory div 1024+' KB',0,72);
3001 drawfonttext('SEED:'+seed,0,88);
3002 drawfonttext('Game time:'+game_time,0,96);
3003 drawfonttext('Global light:' + global_light, 0, 104);
3005 for i := 0 to 15 do
3006 drawImage(light[i], getWidth - 16, 16 * i);
3007 end;
3009 function ItemToString(id : integer) : string;
3010 var
3011 name : string;
3012 begin
3013 if id = Items.none then name := 'none'
3014 else if id = Items.dirt then name := 'dirt'
3015 else if id = Items.grass then name := 'grass'
3016 else if id = Items.stone then name := 'stone'
3017 else if id = Items.oakWoodPlanks then name := 'oakWoodPlanks'
3018 else if id = Items.cobblestone then name := 'cobblestone'
3019 else if id = Items.bedrock then name := 'bedrock'
3020 else if id = Items.sand then name := 'sand'
3021 else if id = Items.gravel then name := 'gravel'
3022 else if id = Items.oakWood then name := 'oakWood'
3023 else if id = Items.obsidian then name := 'obsidian'
3024 else if id = Items.bookshelf then name := 'bookshelf'
3025 else if id = Items.mossStone then name := 'mossStone'
3026 else if id = Items.blockOfIron then name := 'blockOfIron'
3027 else if id = Items.blockOfGold then name := 'blockOfGold'
3028 else if id = Items.blockOfDiamond then name := 'blockOfDiamond'
3029 else if id = Items.goldOre then name := 'goldOre'
3030 else if id = Items.ironOre then name := 'ironOre'
3031 else if id = Items.coalOre then name := 'coalOre'
3032 else if id = Items.diamondOre then name := 'diamondOre'
3033 else if id = Items.redstoneOre then name := 'redstoneOre'
3034 else if id = Items.oakLeaves then name := 'oakLeaves'
3035 else if id = Items.redFlower then name := 'redFlower'
3036 else if id = Items.yellowFlower then name := 'yellowFlower'
3037 else if id = Items.redMooshroom then name := 'redMooshroom'
3038 else if id = Items.brownMooshroom then name := 'brownMooshroom'
3039 else if id = Items.torch then name := 'torch'
3040 else if id = Items.tnt then name := 'tnt'
3041 else if id = Items.chest then name := 'chest'
3042 else if id = Items.craftingTable then name := 'craftingTable'
3043 else if id = Items.cactus then name := 'cactus'
3044 else if id = Items.glass then name := 'glass'
3045 else if id = Items.wool1 then name := 'wool1'
3046 else if id = Items.wool2 then name := 'wool2'
3047 else if id = Items.wool3 then name := 'wool3'
3048 else if id = Items.wool4 then name := 'wool4'
3049 else if id = Items.wool5 then name := 'wool5'
3050 else if id = Items.wool6 then name := 'wool6'
3051 else if id = Items.wool7 then name := 'wool7'
3052 else if id = Items.wool8 then name := 'wool8'
3053 else if id = Items.wool9 then name := 'wool9'
3054 else if id = Items.wool10 then name := 'wool10'
3055 else if id = Items.wool11 then name := 'wool11'
3056 else if id = Items.wool12 then name := 'wool12'
3057 else if id = Items.wool13 then name := 'wool13'
3058 else if id = Items.wool14 then name := 'wool14'
3059 else if id = Items.wool15 then name := 'wool15'
3060 else if id = Items.wool16 then name := 'wool16'
3061 else if id = Items.snow then name := 'snow'
3062 else if id = Items.ladder then name := 'ladder'
3063 else if id = Items.water then name := 'water'
3064 else if id = Items.lava then name := 'lava'
3065 else if id = Items.oakSapling then name := 'oakSapling'
3066 else if id = Items.sponge then name := 'sponge'
3067 else if id = Items.lapisLazuliOre then name := 'lapisLazuliOre'
3068 else if id = Items.lapisLazuliBlock then name := 'lapisLazuliBlock'
3069 else if id = Items.sandstone then name := 'sandstone'
3070 else if id = Items.tallGrass then name := 'tallGrass'
3071 else if id = Items.deadBush then name := 'deadBush'
3072 else if id = Items.cobweb then name := 'cobweb'
3073 else if id = Items.bricks then name := 'bricks'
3074 else if id = Items.snowBlock then name := 'snowBlock'
3075 else if id = Items.ice then name := 'ice'
3076 else if id = Items.snowLayer then name := 'snowLayer'
3077 else if id = Items.clayBlock then name := 'clayBlock'
3078 else if id = Items.sugarCane then name := 'sugarCane'
3079 else if id = Items.pumpkin then name := 'pumpkin'
3080 else if id = Items.jackLantern then name := 'jackLantern'
3081 else if id = Items.stoneBricks then name := 'stoneBricks'
3082 else if id = Items.mossyStoneBricks then name := 'mossyStoneBricks'
3083 else if id = Items.crackedStoneBricks then name := 'crackedStoneBricks'
3084 else if id = Items.chiseledStokeBricks then name := 'chiseledStokeBricks'
3085 else if id = Items.ironBras then name := 'ironBras'
3086 else if id = Items.melonBlock then name := 'melonBlock'
3087 else if id = Items.mycelium then name := 'mycelium'
3088 else if id = Items.backgroundOakWood then name := 'backgroundOakWood'
3089 else if id = Items.spawner then name := 'spawner'
3090 else if id = Items.bed1 then name := 'bed1'
3091 else if id = Items.bed2 then name := 'bed2'
3092 else if id = Items.openWoodenDoor1 then name := 'openWoodenDoor1'
3093 else if id = Items.openWoodenDoor2 then name := 'openWoodenDoor2'
3094 else if id = Items.closedWoodenDoor1 then name := 'closedWoodenDoor1'
3095 else if id = Items.closedWoodenDoor2 then name := 'closedWoodenDoor2'
3096 else if id = Items.birchWood then name := 'birchWood'
3097 else if id = Items.backgroundBirchWood then name := 'backgroundBirchWood'
3098 else if id = Items.spruceWood then name := 'spruceWood'
3099 else if id = Items.backgroundSpruceWood then name := 'backgroundSpruceWood'
3100 else if id = Items.spruceLeaves then name := 'spruceLeaves'
3101 else if id = Items.redMushroomBlock1 then name := 'redMushroomBlock1'
3102 else if id = Items.redMushroomBlock2 then name := 'redMushroomBlock2'
3103 else if id = Items.brownMushroomBlock1 then name := 'brownMushroomBlock1'
3104 else if id = Items.brownMushroomBlock2 then name := 'brownMushroomBlock2'
3105 else if id = Items.oakFence then name := 'oakFence'
3106 else if id = Items.backgroundOakFence then name := 'backgroundOakFence'
3107 else if id = Items.backgroundOakWoodPlanks then name := 'backgroundOakWoodPlanks'
3108 else if id = Items.painting1 then name := 'painting1'
3109 else if id = Items.painting2 then name := 'painting2'
3110 else if id = Items.painting3 then name := 'painting3'
3111 else if id = Items.painting4 then name := 'painting4'
3112 else if id = Items.painting5 then name := 'painting5'
3113 else if id = Items.painting6 then name := 'painting6'
3114 else if id = Items.painting7 then name := 'painting7'
3115 else if id = Items.giftChest then name := 'giftChest'
3116 else if id = Items.vines then name := 'vines'
3117 else if id = Items.sign then name := 'sign'
3118 else if id = Items.redstoneTorch then name := 'redstoneTorch'
3119 else if id = Items.furnace then name := 'furnace'
3120 else if id = Items.closedWoodenTrapdoor then name := 'closedWoodenTrapdoor'
3121 else if id = Items.openWoodenTrapdoor then name := 'openWoodenTrapdoor'
3122 else if id = Items.netherrack then name := 'netherrack'
3123 else if id = Items.netherPortal then name := 'netherPortal'
3124 else if id = Items.glowstone then name := 'glowstone'
3125 else if id = Items.birchLeaves then name := 'birchLeaves'
3126 else if id = Items.soulSand then name := 'soulSand'
3127 else if id = Items.birchSapling then name := 'birchSapling'
3128 else if id = Items.spruceSapling then name := 'spruceSapling'
3129 else if id = Items.redstoneLampOff then name := 'redstoneLampOff'
3130 else if id = Items.redstoneLampOn then name := 'redstoneLampOn'
3131 else if id = Items.backgroundObsidian then name := 'backgroundObsidian'
3132 else if id = Items.glassPlane then name := 'glassPlane'
3133 else if id = Items.farmland then name := 'farmland'
3134 else if id = Items.cake then name := 'cake'
3135 else if id = Items.wheatBlock then name := 'wheatBlock'
3136 else if id = Items.melonStem then name := 'melonStem'
3137 else if id = Items.pumpkinStem then name := 'pumpkinStem'
3138 else if id = Items.burningFurnace then name := 'burningFurnace'
3139 else if id = Items.reservedBlockItem then name := 'reservedBlockItem'
3140 else if id = Items.stick then name := 'stick'
3141 else if id = Items.dandelionYellow then name := 'dandelionYellow'
3142 else if id = Items.roseRed then name := 'roseRed'
3143 else if id = Items.superSpecialUnneededTool then name := 'superSpecialUnneededTool'
3144 else if id = Items.pickaxe1 then name := 'pickaxe1'
3145 else if id = Items.pickaxe2 then name := 'pickaxe2'
3146 else if id = Items.pickaxe3 then name := 'pickaxe3'
3147 else if id = Items.pickaxe4 then name := 'pickaxe4'
3148 else if id = Items.pickaxe5 then name := 'pickaxe5'
3149 else if id = Items.shovel1 then name := 'shovel1'
3150 else if id = Items.shovel2 then name := 'shovel2'
3151 else if id = Items.shovel3 then name := 'shovel3'
3152 else if id = Items.shovel4 then name := 'shovel4'
3153 else if id = Items.shovel5 then name := 'shovel5'
3154 else if id = Items.axe1 then name := 'axe1'
3155 else if id = Items.axe2 then name := 'axe2'
3156 else if id = Items.axe3 then name := 'axe3'
3157 else if id = Items.axe4 then name := 'axe4'
3158 else if id = Items.axe5 then name := 'axe5'
3159 else if id = Items.shears then name := 'shears'
3160 else if id = Items.sword1 then name := 'sword1'
3161 else if id = Items.sword2 then name := 'sword2'
3162 else if id = Items.sword3 then name := 'sword3'
3163 else if id = Items.sword4 then name := 'sword4'
3164 else if id = Items.sword5 then name := 'sword5'
3165 else if id = Items.fishingRod then name := 'fishingRod'
3166 else if id = Items.lighter then name := 'lighter'
3167 else if id = Items.hoe1 then name := 'hoe1'
3168 else if id = Items.hoe2 then name := 'hoe2'
3169 else if id = Items.hoe3 then name := 'hoe3'
3170 else if id = Items.hoe4 then name := 'hoe4'
3171 else if id = Items.hoe5 then name := 'hoe5'
3172 else if id = Items.reservedToolItem then name := 'reservedToolItem'
3173 else if id = Items.coal then name := 'coal'
3174 else if id = Items.redstone then name := 'redstone'
3175 else if id = Items.diamond then name := 'diamond'
3176 else if id = Items.brick then name := 'brick'
3177 else if id = Items.ironIngot then name := 'ironIngot'
3178 else if id = Items.goldIngot then name := 'goldIngot'
3179 else if id = Items.lapisLazuli then name := 'lapisLazuli'
3180 else if id = Items.strand then name := 'strand'
3181 else if id = Items.snowball then name := 'snowball'
3182 else if id = Items.clay then name := 'clay'
3183 else if id = Items.book then name := 'book'
3184 else if id = Items.bucket then name := 'bucket'
3185 else if id = Items.waterBucket then name := 'waterBucket'
3186 else if id = Items.lavaBucket then name := 'lavaBucket'
3187 else if id = Items.milkBucket then name := 'milkBucket'
3188 else if id = Items.paper then name := 'paper'
3189 else if id = Items.melon then name := 'melon'
3190 else if id = Items.egg then name := 'egg'
3191 else if id = Items.door then name := 'door'
3192 else if id = Items.bed then name := 'bed'
3193 else if id = Items.spawnEggZombie then name := 'spawnEggZombie'
3194 else if id = Items.spawnEggSheep then name := 'spawnEggSheep'
3195 else if id = Items.spawnEggPig then name := 'spawnEggPig'
3196 else if id = Items.gunpowder then name := 'gunpowder'
3197 else if id = Items.bowl then name := 'bowl'
3198 else if id = Items.mushroomStew then name := 'mushroomStew'
3199 else if id = Items.map then name := 'map'
3200 else if id = Items.painting then name := 'painting'
3201 else if id = Items.rawPorkchop then name := 'rawPorkchop'
3202 else if id = Items.cookedPorkchop then name := 'cookedPorkchop'
3203 else if id = Items.rottenFlesh then name := 'rottenFlesh'
3204 else if id = Items.camera1 then name := 'camera1'
3205 else if id = Items.camera2 then name := 'camera2'
3206 else if id = Items.camera3 then name := 'camera3'
3207 else if id = Items.goldNugget then name := 'goldNugget'
3208 else if id = Items.sugar then name := 'sugar'
3209 else if id = Items.spiderEye then name := 'spiderEye'
3210 else if id = Items.feather then name := 'feather'
3211 else if id = Items.leather then name := 'leather'
3212 else if id = Items.rawBeef then name := 'rawBeef'
3213 else if id = Items.steak then name := 'steak'
3214 else if id = Items.apple then name := 'apple'
3215 else if id = Items.goldenApple then name := 'goldenApple'
3216 else if id = Items.rawChicken then name := 'rawChicken'
3217 else if id = Items.cookedChicken then name := 'cookedChicken'
3218 else if id = Items.spawnEggChicken then name := 'spawnEggChicken'
3219 else if id = Items.spawnEggCreeper then name := 'spawnEggCreeper'
3220 else if id = Items.flint then name := 'flint'
3221 else if id = Items.spawnEggCow then name := 'spawnEggCow'
3222 else if id = Items.spawnEggMooshroom then name := 'spawnEggMooshroom'
3223 else if id = Items.rawFish then name := 'rawFish'
3224 else if id = Items.cookedFish then name := 'cookedFish'
3225 else if id = Items.spawnEggPigman then name := 'spawnEggPigman'
3226 else if id = Items.spawnEggSpider then name := 'spawnEggSpider'
3227 else if id = Items.glowstoneDust then name := 'glowstoneDust'
3228 else if id = Items.clock then name := 'clock'
3229 else if id = Items.compass then name := 'compass'
3230 else if id = Items.seeds then name := 'seeds'
3231 else if id = Items.wheat then name := 'wheat'
3232 else if id = Items.bread then name := 'bread'
3233 else if id = Items.boneMeal then name := 'boneMeal'
3234 else if id = Items.melonSeeds then name := 'melonSeeds'
3235 else if id = Items.pumpkinSeeds then name := 'pumpkinSeeds'
3236 else name := '' + id;
3237 result := name;
3238 end;
3240 procedure PrintItem(id, typ, tex, max, info, texsource, indicator : integer; dividable : boolean);
3241 var
3242 name, tname, indname : string;
3243 begin
3244 name := ItemToString(id);
3246 if typ = Items.block then tname := 'block'
3247 else if typ = Items.tool then tname := 'tool'
3248 else if typ = Items.reserved then tname := 'reserved'
3249 else if typ = Items.orditem then tname := 'orditem'
3250 else tname := '' + typ;
3252 if indicator = Items.noindicator then indname := 'noindicator'
3253 else if indicator = Items.numeric then indname := 'numeric'
3254 else if indicator = Items.line then indname := 'line'
3255 else indname := '' + indicator;
3257 Debug(' InitItem(' + name + ', ' + tname + ', ' + tex + ', ' + max + ', ' + info + ', ' + texsource + ', ' + indname + ', ' + dividable + ');');
3258 end;
3260 procedure PrintItemTable;
3261 var
3262 id : integer;
3263 begin
3264 for id := 0 to 222 do begin
3265 PrintItem(
3266 id,
3267 Items.GetType(id),
3268 Items.GetTexture(id),
3269 Items.GetMaximum(id),
3270 Items.GetData(id),
3271 Items.GetTextureSource(id),
3272 Items.GetIndicatorType(id),
3273 Items.IsDividable(id)
3274 );
3275 end;
3277 for id := 0 to 194 do begin
3278 Debug(' InitOrdItem(' + ItemToString(Items.GetOrdinary(id)) + ');');
3279 end;
3281 for id := 0 to 125 do begin
3282 Debug(' InitBlock(' + ItemToString(id) + ', ' +
3283 Blocks.GetTexture(id) + ', ' +
3284 Blocks.GetResistant(id) + ', ' +
3285 Blocks.GetTool(id) + ', ' +
3286 Blocks.GetLevel(id) + ', ' +
3287 Blocks.GetLightAbsorbtion(id) + ', ' +
3288 Blocks.GetLightEmission(id) + ', ' +
3289 Blocks.IsSolid(id) + ', ' +
3290 Blocks.IsTransporent(id) + ', ' +
3291 Blocks.IsForeground(id) + ', ' +
3292 Blocks.IsOverlapped(id) + ');'
3293 );
3294 end;
3295 end;
3297 begin
3298 qt_start;
3299 hung_time:=getrelativetimems;
3300 hp_time:=getrelativetimems;
3301 air_time:=getrelativetimems;
3302 portal_time:=getrelativetimems;
3304 PrintItemTable;
3306 repeat
3307 proc_fps;
3308 keyhandler;
3309 phyhandler;
3310 game;
3311 draw;
3312 drawfonttext(version,getWidth-(length(version)*8),getHeight-8);
3313 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;
3314 if deb = true then
3315 draw_debug;
3317 drawVideo;
3318 maxfps;
3320 until false;
3321 end.