DEADSOFTWARE

Fix load cfg files and textures
[cavecraft.git] / src / CAVE.mpsrc
1 program CAVE;
3 uses
4 sign,
5 jsr75i,
6 drop,
7 invui,
8 vars,
9 particles_store,
10 randoms,
11 memory,
12 worldgen,
13 canvas,
14 items,
15 safeload,
16 mob,
17 console,
18 effects,
19 particles,
20 keyboard,
21 maps,
22 phy,
23 utils,
24 func,
25 CellUI,
26 furnace,
27 player,
28 items_logic,
29 chest,
30 inv,
31 items_store,
32 video;
34 const
35 version_map = 9;
37 var
38 keymode,updx,updy:integer;
39 seed,nextseed:integer;
40 free_ram:real;
42 light:array [0..15] of image;
43 bg:array[0..1] of image;
44 osad:array [0..1,0..7] of image;
45 back:array [0..8] of image;
46 gui:array [0..34] of image;
47 tue:array [0..9] of image;
49 sign_im:image;
50 sky:image;
51 sun:image;
52 moon:image;
53 moon_phase:integer;
54 toolus,toolind:integer;
55 osadki_ani:integer;
56 sav_fl:string;
57 global_light:integer;
58 world_typ:integer;
59 float:image;
61 msg:array [0..4] of string;
62 msg_time:array[0..4] of integer;
63 last_sleep_x,last_sleep_y:integer;
65 ifminimap:boolean;
66 gt:integer;
68 del,dt,time:integer;
70 deb:boolean;
72 procedure newworld;
73 var
74 ix,iy:integer;
75 begin
76 if nextseed=0 then seed:=getrelativetimems; else seed:=nextseed;
77 nextseed:=0;
78 srand(seed);
79 if world_typ=0 then genworld;
80 else
81 if world_typ=1 then genflat;
82 world_typ:=0;
83 player.setX(get_spawn_x*16+4);
84 player.setY(get_spawn_y*16);
85 pl_world:=0;
86 end;
88 procedure drwrect(x,y,w,h,t:integer);
89 var
90 i:integer;
91 begin
92 for i:=0 to t do
93 drawrect(x+i,y+i,w-i*2,h-i*2);
94 end;
96 procedure proc_fps;
97 begin
98 dt:=GetRelativeTimeMs - time;
99 time:=GetRelativeTimeMs;
100 fps:=1000/dt;
101 end;
103 procedure maxfps;
104 begin
105 if fps<s_max_fps then if del>0 then del:=del-1;
106 if fps>s_max_fps then if del<200 then del:=del+1;
107 delay(del);
108 end;
110 procedure ClearTextures;
111 var
112 no : image;
113 ix, iy, iz : integer;
114 begin
115 bg[0] := no;
116 bg[1] := no;
117 float := no;
118 compas := no;
119 for ix := 0 to 7 do
120 clock[ix] := no;
122 for ix := 0 to maxBlockTex do
123 begin
124 tex[ix] := no;
125 tex8[ix] := no;
126 end;
127 for ix := 0 to maxItemTex do
128 begin
129 item[ix] := no;
130 item8[ix] := no;
131 end;
133 for ix := 0 to 8 do
134 back[ix]:=no;
136 player.freeSkin;
138 for ix := 0 to 34 do
139 gui[ix] := no;
140 for ix := 0 to 9 do
141 tue[ix] := no;
142 for ix := 0 to 7 do
143 osad[0, ix] := no;
144 for ix := 0 to 7 do
145 osad[1, ix] := no;
147 for ix := 0 to 15 do
148 light[ix] := no;
149 for ix := 0 to 7 do
150 begin
151 pr_1[ix] := no;
152 pr_2[ix] := no;
153 pr_3[ix] := no;
154 pr_4[ix] := no;
155 pr_5[ix] := no;
156 end;
158 bubble := no;
159 for ix := 0 to 15 do
160 pr_boom[ix] := no;
162 mob.freeSkin;
164 sky := no;
165 sun := no;
166 moon := no;
167 sign_im := no;
169 for ix := 0 to CONST_MAX_CURS do
170 LoadCurImg(no, ix);
172 //resetVirtualKeyboard(-1);
173 end;
175 procedure create_msg(s:string);
176 var
177 i,t:integer;
178 begin
179 for i:=3 downto 0 do
180 begin
181 if i=0 then break;
182 msg_time[i]:=msg_time[i-1];
183 msg[i]:=msg[i-1];
184 end;
185 msg_time[0]:=getrelativetimems;
186 msg[0]:=s;
187 end;
189 procedure loadtexture(path:string);
190 var
191 ix,iy,iz:integer;
192 im:image;
193 begin
194 cleartextures;
195 im:=ld_tex('background.png',path,'title/');
196 for ix:=0 to 1 do
197 bg[ix]:=rotate_image_from_image(im,ix*16,0,16,16,0);
198 float:=ld_tex('float.png',path,'gui/');
199 compas:=ld_tex('compass.png',path,'gui/');
200 im:=ld_tex('clock.png',path,'gui/');
201 for ix:=0 to 7 do
202 clock[ix]:=rotate_image_from_image(im,ix*16,0,16,16,0);
203 if load_back_tex then
204 begin
205 im:=ld_tex('back.png',path,'');
206 for ix:=0 to 8 do back[ix]:=rotate_image_from_image(im,ix*16,0,16,16,0);
207 end;
209 console.exec('textures.cfg', 'AUTO');
211 player.loadSkin('char_ani.png', path);
212 mob.loadSkin(path);
214 im:=ld_tex('gui.png',path,'gui/');
215 gui[0]:=rotate_image_from_image(im,0,0,16,16,0);
216 LoadCurImg(gui[0], CUR_SELECT1);
217 gui[1]:=rotate_image_from_image(im,0,16,168,21,0);
218 gui[3]:=rotate_image_from_image(im,16,0,16,16,0);
219 LoadCurImg(gui[3], CUR_SELECT2);
220 gui[6]:=rotate_image_from_image(im,0,56,120,12,0);
221 gui[7]:=rotate_image_from_image(im,0,68,120,12,0);
222 gui[8]:=rotate_image_from_image(im,0,80,120,12,0);
223 gui[13]:=rotate_image_from_image(im,1,93,9,9,0);//hp
224 gui[14]:=rotate_image_from_image(im,12,93,9,9,0);//hp
225 gui[15]:=rotate_image_from_image(im,23,93,9,9,0);//hp
226 gui[17]:=rotate_image_from_image(im,120,56,18,18,0);
228 gui[26]:=rotate_image_from_image(im,89,93,9,9,0);//hunger
229 gui[27]:=rotate_image_from_image(im,100,93,9,9,0);//hunger
230 gui[28]:=rotate_image_from_image(im,111,93,9,9,0);//hunger
232 gui[29]:=rotate_image_from_image(im,67,93,9,9,0);//air
233 gui[30]:=rotate_image_from_image(im,78,93,9,9,0);//air
235 gui[31]:=rotate_image_from_image(im,122,93,9,9,0);//hp hardcore
236 gui[32]:=rotate_image_from_image(im,133,93,9,9,0);//hp hardcore
237 gui[33]:=rotate_image_from_image(im,144,93,9,9,0);//hp hardcore
239 gui[20]:=rotate_image_from_image(im,121,75,9,13,0);
240 gui[21]:=rotate_image_from_image(im,130,75,9,13,0);
241 gui[22]:=rotate_image_from_image(im,0,103,120,12,0);
243 if load_minimap_tex then gui[16]:=ld_tex('mapbg.png',path,'gui/');
245 for ix:=0 to 9 do tue[ix]:=rotate_image_from_image(im,16*ix,40,16,16,0);
247 if load_weather_tex then
248 begin
249 im:=ld_tex('rain.png',path,'terrain/');
250 for ix:=0 to 7 do osad[0,ix]:=rotate_image_from_image(im,16*ix,0,16,16,0);
251 im:=ld_tex('snow.png',path,'terrain/');
252 for ix:=0 to 7 do osad[1,ix]:=rotate_image_from_image(im,16*ix,0,16,16,0);
253 end;
255 if load_light_tex then
256 begin
257 im:=ld_tex('light.png',path,'terrain/');
258 for ix:=0 to 15 do light[ix]:=rotate_image_from_image(im,16*ix,0,16,16,0);
259 end;
261 if load_particles_tex then
262 begin
263 im:=ld_tex('particles.png',path,'terrain/');
264 for ix:=0 to 7 do
265 begin
266 pr_1[ix]:=rotate_image_from_image(im,8*ix,0,8,8,0);
267 pr_2[ix]:=rotate_image_from_image(im,8*ix,8,8,8,0);
268 pr_3[ix]:=rotate_image_from_image(im,8*ix,16,8,8,0);
269 pr_4[ix]:=rotate_image_from_image(im,8*ix,24,8,8,0);
270 pr_5[ix]:=rotate_image_from_image(im,8*ix,32,8,8,0);
271 end;
272 bubble:=rotate_image_from_image(im,0,40,8,8,0);
273 im:=ld_tex('explosion.png',path,'terrain/');
274 for ix:=0 to 15 do
275 pr_boom[ix]:=rotate_image_from_image(im,32*ix,0,32,32,0);
276 end;
278 im:=ld_tex('partition.png',path,'gui/');
279 gui[18]:=rotate_image_from_image(im,0,0,84,42,0);
280 gui[19]:=rotate_image_from_image(im,0,42,4,4,0);
282 if load_sky_siz<=0 then
283 sky:=ld_tex('sky.png',path,'terrain/');
284 else
285 sky:=resize_image(ld_tex('sky.png',path,'terrain/'),load_sky_siz,2);
287 if load_sm=1 then
288 begin
289 sun:=ld_tex('sun.png',path,'terrain/');
290 moon:=ld_tex('moon_phase_0.png',path,'terrain/moon_phases/');
291 end; else
292 if load_sm=2 then
293 begin
294 sun:=resize_image(ld_tex('sun.png',path,'terrain/'),(getWidth+getHeight)/5,(getWidth+getHeight)/5);
295 moon:=resize_image(ld_tex('moon_phase_0.png',path,'terrain/moon_phases/'),(getWidth+getHeight)/5,(getWidth+getHeight)/5);
296 end;
298 //load_virt_tex(ld_tex('touch.png',path,'gui/'));
299 end;
301 procedure cleargame;
302 var
303 ix,iy:integer;
304 begin
305 jmp:=false;
306 keymode:=0;
307 updx:=0;
308 updy:=0;
309 toolus:=0;
310 toolind:=0;
311 osadki_ani:=0;
312 global_light:=15;
313 pl_world:=0;
315 camx:=0;
316 camy:=0;
317 curx:=0;
318 cury:=0;
320 player.setX(0);
321 player.setY(0);
322 last_sleep_x:=0;
323 last_sleep_y:=0;
325 fly:=false;
326 game_time:=0;
327 clock_stage:=0;
328 hp:=20;
329 hunger:=20;
330 air:=21;
331 moon_phase:=0;
332 posi:=0;
333 velx:=0;
334 vely:=0;
335 invslot:=0;
337 osadki:=false;
339 //anim_del2:=0;
341 inv.resetData;
343 chest.resetData;
345 furnace.resetData;
347 drop.resetData;
349 mob.resetData;
351 //gb_up_pa:=0;
352 reset_particles(max_particles+1);
354 for ix:=0 to 255 do
355 begin
356 setBackMap(0, ix);
357 setBiomMap(0, ix);
358 for iy:=0 to 127 do
359 begin
360 setmap(0,ix,iy);
361 setmapinfo(0,ix,iy);
362 setmaplight(0,ix,iy);
363 end;
364 end;
366 for ix:=0 to 31 do
367 begin
368 b_sign[ix]:=false;
369 t_sign[ix]:='';
370 end;
372 for ix:=0 to CONST_MAX_LAYERS do
373 ClearLayer(ix);
374 end;
376 procedure drw_load_line(s:string;percent:integer);
377 var
378 ix,iy:integer;
379 begin
380 for ix:=0 to getWidth/16 do
381 for iy:=0 to getHeight/16 do
382 drawimage(bg[0],ix*16,iy*16);
383 drawfonttext(s,(getWidth/2)-(length(s)*8/2),(getHeight/2)-8);
384 setcolor(128,128,128);
385 fillrect(getwidth/2-50,getheight/2+6,100,3);
386 setcolor(128,255,128);
387 fillrect(getwidth/2-50,getheight/2+6,percent,3);
388 drawfonttext(integertostring(percent)+'%',getwidth/2-(length(integertostring(percent)+'%')*8)/2,getheight/2+12);
389 drawVideo;
390 end;
392 function getFlatMap(i:integer):integer;
393 var
394 ix, iy:integer;
395 begin
396 iy:=i div 256;
397 ix:=i-iy*256;
398 getFlatMap:=getmap(ix,iy);
399 end;
401 procedure setFlatMap(n, i:integer);
402 var
403 ix, iy:integer;
404 begin
405 iy:=i div 256;
406 ix:=i-iy*256;
407 setmap(n,ix,iy);
408 end;
410 function getFlatMapInfo(i:integer):integer;
411 var
412 ix, iy:integer;
413 begin
414 iy:=i div 256;
415 ix:=i-iy*256;
416 getFlatMapInfo:=getmapinfo(ix,iy);
417 end;
419 procedure setFlatMapInfo(n, i:integer);
420 var
421 ix, iy:integer;
422 begin
423 iy:=i div 256;
424 ix:=i-iy*256;
425 setmapinfo(n,ix,iy);
426 end;
428 procedure SaveMapRLE;
429 var
430 i:integer;
431 id, s:integer;
432 begin
433 repeat
434 id:=getFlatMap(i);
435 for s:=0 to 255 do
436 if (id<>getFlatMap(i+s)) or (i+s>32767) then
437 break;
439 write_byte(id);
440 write_byte(s-1);
442 i:=i+s;
443 until i>32767;
444 end;
446 procedure SaveMapInfoRLE;
447 var
448 i:integer;
449 id, s:integer;
450 begin
451 repeat
452 id:=getFlatMapInfo(i);
453 for s:=0 to 255 do
454 if (id<>getFlatMapInfo(i+s)) or (i+s>32767) then
455 break;
457 write_byte(id);
458 write_byte(s-1);
460 i:=i+s;
461 until i>32767;
462 end;
464 procedure LoadMapRLE;
465 var
466 i:integer;
467 id, s, j:integer;
468 begin
469 repeat
470 id:=read_byte;
471 s:=read_byte;
472 for j:=0 to s do
473 setFlatMap(id, i+j);
475 i:=i+s+1;
476 until i>32767;
477 end;
479 procedure LoadMapInfoRLE;
480 var
481 i:integer;
482 id, s, j:integer;
483 begin
484 repeat
485 id:=read_byte;
486 s:=read_byte;
487 for j:=0 to s do
488 setFlatMapInfo(id, i+j);
490 i:=i+s+1;
491 until i>32767;
492 end;
494 procedure saveworld(path:string);
495 var
496 ix,iy:integer;
497 world_name:string;
498 begin
499 if pl_world=0 then world_name:='world.sav';
500 else
501 if pl_world=1 then world_name:='nether.sav';
502 if file_exists(path)<>1 then if create_folder(path)=1 then debug('Folder created!');
503 if file_exists(path+world_name)>0 then delete_file(path+world_name);
504 if file_exists(path+world_name)<>1 then file_create(path+world_name);
505 if open_file(path+world_name)=1 then
506 begin
507 writeint(player.getX);
508 writeint(player.getY);
509 //Matrix
510 SaveMapRLE;
511 SaveMapInfoRLE;
512 drw_load_line('Background',50);
513 //Background and biomes
514 for ix:=0 to 255 do
515 begin
516 write_byte(getBackMap(ix));
517 write_byte(getBiomMap(ix));
518 end;
519 drw_load_line('Chests',55);
520 //Chests
521 chest.saveData;
522 drw_load_line('Furnaces',60);
523 //Furnaces
524 furnace.saveData;
525 drw_load_line('Mobs',70);
526 //Mobs
527 mob.saveData;
528 drw_load_line('Drop',80);
529 //Drop
530 drop.saveData;
531 drw_load_line('Particles',85);
532 //Particles
533 writeint(max_particles);
534 write_byte(gb_up_pa);
535 for ix:=0 to max_particles do
536 begin
537 write_byte(get_particle_type(ix));
538 write_byte(get_particle_ani(ix));
539 writeint(get_particle_x(ix));
540 writeint(get_particle_y(ix));
541 end;
542 drw_load_line('Other',90);
543 //Other
544 write_byte(updx);
545 write_byte(updy);
546 writebool(osadki);
547 write_byte(osadki_ani);
548 write_byte(global_light);
549 writebool(fly);
550 writeint(game_time);
551 write_byte(clock_stage);
552 for ix:=0 to 31 do
553 begin
554 writebool(b_sign[ix]);
555 writestr(t_sign[ix]);
556 end;
557 flush;
558 drw_load_line('Ready',100);
559 if close_file(path+world_name)=1 then debug('World Saved!');
560 end;
561 end;
563 procedure savegame(path:string);
564 var
565 ix,iy:integer;
566 begin
567 drw_load_line('Basic',0);
568 if file_exists(path+'player.dat')=1 then delete_file(path+'player.dat');
569 if file_exists(path)<>1 then if create_folder(path)=1 then debug('Folder created!');
570 if file_exists(path+'player.dat')<>1 then file_create(path+'player.dat');
571 if open_file(path+'player.dat')=1 then
572 begin
573 //Head
574 write_byte(version_map);
575 write_byte(gamemode);
576 writebool(cheats);
577 writeint(seed);
578 write_byte(pl_world);
579 //Player
580 writeint(last_sleep_x);
581 writeint(last_sleep_y);
582 write_byte(velx);
583 write_byte(vely);
584 write_byte(invslot);
585 write_byte(posi);
586 write_byte(hp);
587 write_byte(hunger);
588 write_byte(moon_phase);
589 writebool(jmp);
590 inv.saveData;
591 if close_file(path+'player.dat')=1 then debug('Saved!');
592 drw_load_line('Matrix',10);
593 saveworld(path);
594 end;
595 end;
598 function version_err(ver:integer):boolean;
599 var
600 ix,iy:integer;
601 begin
602 for ix:=0 to getWidth/16 do
603 for iy:=0 to getHeight/16 do
604 begin
605 drawimage(bg[0],ix*16,iy*16);
606 end;
607 if version_map=ver then version_err:=true; else
608 if version_map>ver then
609 begin
610 drawfonttext('Old save format!',(getWidth/2)-60,(getHeight/2)-4);
611 drawVideo;
612 delay(3000);
613 version_err:=false;
614 end; else
615 if version_map<ver then
616 begin
617 drawfonttext('New save format!',(getWidth/2)-60,(getHeight/2)-4);
618 drawVideo;
619 delay(3000);
620 version_err:=false;
621 end;
622 end;
625 function loadworld(path:string):boolean;
626 var
627 ix,iy,ver:integer;
628 world_name:string;
629 begin
630 if pl_world=0 then world_name:='world.sav';
631 else
632 if pl_world=1 then world_name:='nether.sav';
633 if file_exists(path)=1 then
634 begin
635 if file_exists(path+world_name)=1 then
636 begin
637 if open_file(path+world_name)=1 then
638 begin
639 player.setX(readint);
640 player.setY(readint);
641 //Matrix
642 LoadMapRLE;
643 LoadMapInfoRLE;
644 drw_load_line('Background',50);
645 //Background and biomes
646 for ix:=0 to 255 do
647 begin
648 setBackMap(read_byte, ix);
649 setBiomMap(read_byte, ix);
650 end;
651 drw_load_line('Chests',55);
652 //Chests
653 chest.loadData;
654 drw_load_line('Furnaces',60);
655 //Furnaces
656 furnace.loadData;
657 //Mobs
658 mob.loadData;
659 drw_load_line('Drop',80);
660 //Drop
661 drop.loadData;
662 drw_load_line('Particles',85);
663 //Particles
664 max_particles:=readint;
665 reset_particles(max_particles+1);
666 gb_up_pa:=read_byte;
667 for ix:=0 to max_particles do
668 begin
669 set_particle_type(ix,read_byte);
670 set_particle_ani(ix,read_byte);
671 set_particle_x(ix,readint);
672 set_particle_y(ix,readint);
673 end;
674 drw_load_line('Other',90);
675 //Other
676 updx:=read_byte;
677 updy:=read_byte;
678 osadki:=readbool;
679 osadki_ani:=read_byte;
680 global_light:=read_byte;
681 fly:=readbool;
682 game_time:=readint;
683 clock_stage:=read_byte;
684 for ix:=0 to 31 do
685 begin
686 b_sign[ix]:=readbool;
687 t_sign[ix]:=readstr;
688 end;
689 drw_load_line('Ready',100);
690 ///////////////////////
691 if close_file(path+world_name)=1 then begin loadworld:=true; debug('World loaded!'); end;
692 end; else begin loadworld:=false; debug('File not opened!'); end;
693 end; else begin loadworld:=false; debug('File not exists!'); end;
694 end; else begin loadworld:=false; debug('Folder not exists!'); end;
695 end;
697 function loadgame(path:string):boolean;
698 var
699 ix,iy,ver:integer;
700 begin
701 drw_load_line('Basic',0);
702 if file_exists(path)=1 then
703 begin
704 if file_exists(path+'player.dat')=1 then
705 begin
706 if open_file(path+'player.dat')=1 then
707 begin
708 //Head
709 ver:=read_byte;
710 if version_err(ver)=false then
711 begin
712 if close_file(path+'player.dat')=1 then loadgame:=false;
713 exit;
714 end;
715 gamemode:=read_byte;
716 cheats:=readbool;
717 seed:=readint;
718 pl_world:=read_byte;
719 //Player;
720 last_sleep_x:=readint;
721 last_sleep_y:=readint;
722 velx:=read_byte;
723 vely:=read_byte;
724 invslot:=read_byte;
725 posi:=read_byte;
726 hp:=read_byte;
727 hunger:=read_byte;
728 moon_phase:=read_byte;
729 jmp:=readbool;
730 inv.loadData;
731 drw_load_line('Matrix',10);
732 if close_file(path+'player.dat')=1 then loadgame:=loadworld(path);
733 end; else loadgame:=false;
734 end; else loadgame:=false;
735 end; else loadgame:=false;
736 end;
738 procedure drawdeadlogo;
739 var
740 dead:image;
741 begin
742 setcolor(0,0,0);
743 fillrect(0,0,getWidth,getHeight);
744 dead:=loadimage('/dl');
745 drawimage(dead,(getWidth/2)-(getimagewidth(dead)/2),(getHeight/2)-(getimageheight(dead)/2));
746 drawfonttext(#119+#119+#119+#46+#100+#101+#97+#100+#115+#111+#102+#116+#119+#97+#114+#101+#46+#114+#117,getWidth/2-80,(getHeight/2)+(getimageheight(dead)/2));
747 drawfonttext('Loading...',(getWidth/2)-(40),getHeight-8);
748 drawVideo;
749 delay(500);
750 end;
752 procedure newgame;
753 var
754 ix,iy:integer;
755 begin
756 for ix:=0 to getWidth/16 do
757 for iy:=0 to getHeight/16 do
758 begin
759 drawimage(bg[0],ix*16,iy*16);
760 end;
761 drawfonttext('Generation World...',(getWidth/2)-(76),(getHeight/2)-4);
762 drawVideo;
763 delay(1);
764 cleargame;
765 game_time:=45000;
766 newworld;
767 //if s_spawn_mob then begin if pl_world=0 then begin megaspawn; end; else begin netherspawn; end; end;
768 if gamemode=1 then fly:=true else fly:=false;
769 debug('New game!');
770 end;
772 function gettext(text,text_f:string; max,typ:integer;):string;
773 var
774 textField_id:integer;
775 exitCmd,cli:command;
776 begin
777 clearForm;
778 exitCmd:=createCommand('Ok',CM_OK,1);
779 showForm;
780 addCommand(exitCmd);
781 textField_id:=formAddTextField(text,text_f,max,typ);
782 drawVideo;
783 delay(100);
784 repeat
785 cli:=getClickedCommand;
786 until cli=exitCmd;
787 gettext:=formGetText(textField_id);
788 showCanvas;
789 end;
791 procedure drw_btn(text:string; cur,ccur,h,ty:integer);
792 var
793 m_x,m_y,i:integer;
794 begin
795 m_x:=(getWidth/2)-(120/2);
796 m_y:=h+((getHeight/2))-((getimageheight(gui[7])-2*cur)/2)+((getimageheight(gui[7])+2)*cur);
797 if ty=0 then
798 begin
799 if ccur=cur then drawimage(gui[22],m_x+i*4,m_y); else drawimage(gui[6],m_x+i*8,m_y);
800 end; else
801 if ty=1 then
802 begin
803 if ccur=cur then drawimage(gui[8],m_x+i*8,m_y); else drawimage(gui[7],m_x+i*8,m_y);
804 end;
805 setclip(0,0,getwidth,getheight);
806 m_x:=(getWidth/2)-(length(text)*8/2);
807 m_y:=h+((getHeight/2))-((getimageheight(gui[7])-2*cur)/2)+((getimageheight(gui[7])+2)*cur)+((getimageheight(gui[7])-8)/2);
808 drawfonttext(text,m_x,m_y);
809 end;
811 procedure drw_txt(str:string; xx,n,t:integer);
812 var
813 m_x,m_y:integer;
814 begin
815 m_x:=(getWidth/2)-(length(str)*8/2);
816 m_y:=xx+32+(8*n);
817 if t=0 then drawfonttext(str,0,m_y); else
818 if t=1 then drawfonttext(str,m_x,m_y);
819 end;
821 function pos_end(s:string; c:char):integer;
822 var
823 i:integer;
824 begin
825 for i:=length(s)-1 downto 0 do
826 begin
827 if getchar(s,i)=c then
828 begin
829 pos_end:=i;
830 exit;
831 end;
832 end;
833 pos_end:=-1;
834 end;
836 function getroot(cancel_b:boolean):string;
837 var
838 m_cur,max_r,pars,ix,iy:integer;
839 rr:string;
840 im:image;
841 roots:array [0..15] of string;
842 begin
843 im:=rotate_image_from_image(ld_tex('background.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','title/'),16,0,16,16,0);
844 rr:=get_roots;
845 if cancel_b then roots[0]:='<CANCEL>';
846 if cancel_b then max_r:=1; else max_r:=0;
847 while pos(rr,'|')<>-1 do
848 begin
849 pars:=pos(rr,'|');
850 roots[max_r]:=copy(rr,0,pars-1);
851 rr:=copy(rr,pars+1,length(rr));
852 max_r:=max_r+1;
853 end;
854 max_r:=max_r-1;
855 repeat
856 updateKeys;
857 if clickedKey(KEY_FM_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=max_r; end;
858 if clickedKey(KEY_FM_DOWN) then begin m_cur:=m_cur+1; if m_cur>max_r then m_cur:=0; end;
859 if clickedKey(KEY_FM_SELECT) then
860 begin
861 if (m_cur=0) and (cancel_b) then
862 begin
863 getroot:='';
864 exit;
865 end;
866 else
867 begin
868 getroot:=roots[m_cur];
869 exit;
870 end;
871 end;
873 for ix:=0 to getWidth/16 do
874 for iy:=0 to getHeight/16 do
875 drawimage(im,ix*16,iy*16);
877 setcolor(0,0,0);
878 fillrect(0,m_cur*8,getWidth-1,8);
879 for ix:=0 to max_r do
880 begin
881 drawfonttext(roots[ix],0,ix*8);
882 end;
883 setcolor(255,255,255);
884 drawrect(0,m_cur*8,getWidth-1,8);
886 drawVideo;
887 delay(1);
888 until false;
889 end;
891 function filemanager(cancel_b:boolean):string;
892 var
893 m_cur,ix,iy,max_r,pars:integer;
894 im:image;
895 last,rr,root,path:string;
896 names:array [0..255] of string;
897 begin
898 im:=rotate_image_from_image(ld_tex('background.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','title/'),16,0,16,16,0);
899 names[0]:='<..>';
900 names[1]:='<OK>';
901 root:=getroot(cancel_b);
902 if root='' then
903 begin
904 filemanager:='';
905 exit;
906 end;
907 path:=root;
908 if cancel_b then names[2]:='<CANCEL>';
909 rr:=get_dirs(path);
910 if cancel_b then max_r:=3; else max_r:=2;
911 while pos(rr,'|')<>-1 do
912 begin
913 pars:=pos(rr,'|');
914 names[max_r]:=copy(rr,0,pars-1);
915 rr:=copy(rr,pars+1,length(rr));
916 max_r:=max_r+1;
917 end;
918 max_r:=max_r-1;
920 repeat
921 updateKeys;
922 if clickedKey(KEY_FM_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=max_r; end;
923 if clickedKey(KEY_FM_DOWN) then begin m_cur:=m_cur+1; if m_cur>max_r then m_cur:=0; end;
924 if clickedKey(KEY_FM_SELECT) then
925 begin
926 if m_cur=0 then
927 begin
928 debug('path:'+path);
929 debug('lol:'+pos_end(path,'/'));
930 if (path=root) or (path=root+'/') then
931 begin
932 root:=getroot(cancel_b);
933 if root='' then
934 begin
935 filemanager:='';
936 exit;
937 end;
938 path:=root;
939 end;
940 else
941 begin
942 path:=copy(path,0,pos_end(path,'/'));
943 if cancel_b then names[2]:='<CANCEL>';
944 rr:=get_dirs(path);
945 if cancel_b then max_r:=3; else max_r:=2;
946 while pos(rr,'|')<>-1 do
947 begin
948 pars:=pos(rr,'|');
949 names[max_r]:=copy(rr,0,pars-1);
950 rr:=copy(rr,pars+1,length(rr));
951 max_r:=max_r+1;
952 end;
953 max_r:=max_r-1;
954 end;
955 end; else
956 if m_cur=1 then
957 begin
958 debug('<OK>');
959 filemanager:=path;
960 exit;
961 end; else
962 if (m_cur=2) and (cancel_b) then
963 begin
964 debug('<CANCEL>');
965 filemanager:='';
966 exit;
967 end; else
968 begin
969 path:=path+'/'+names[m_cur];
971 if cancel_b then names[2]:='<CANCEL>';
972 rr:=get_dirs(path);
973 if cancel_b then max_r:=3; else max_r:=2;
974 while pos(rr,'|')<>-1 do
975 begin
976 pars:=pos(rr,'|');
977 names[max_r]:=copy(rr,0,pars-1);
978 rr:=copy(rr,pars+1,length(rr));
979 max_r:=max_r+1;
980 end;
981 max_r:=max_r-1;
982 m_cur:=0;
983 debug('path:'+path);
984 end;
985 end;
987 for ix:=0 to getWidth/16 do
988 for iy:=0 to getHeight/16 do
989 drawimage(im,ix*16,iy*16);
991 setcolor(0,0,0);
992 fillrect(0,m_cur*8,getWidth-1,8);
993 for ix:=0 to max_r do
994 begin
995 drawfonttext(names[ix],0,ix*8);
996 end;
997 setcolor(255,255,255);
998 drawrect(0,m_cur*8,getWidth-1,8);
1000 drawVideo;
1001 delay(1);
1003 until false;
1004 end;
1006 procedure setsd(cancel_b:boolean);
1007 var
1008 s:string;
1009 t:integer;
1010 rs:recordstore;
1011 begin
1012 s:=filemanager(cancel_b);
1013 if s<>'' then
1014 begin
1015 sd:=s;
1016 if file_exists('/'+sd+'/cavecraft')<>1 then
1017 if create_folder('/'+sd+'/cavecraft')=1 then debug('/cavecraft created!');
1019 if file_exists('/'+sd+'/cavecraft/saves')<>1 then
1020 if create_folder('/'+sd+'/cavecraft/saves')=1 then debug('/saves created!');
1022 if file_exists('/'+sd+'/cavecraft/screenshots')<>1 then
1023 if create_folder('/'+sd+'/cavecraft/screenshots')=1 then debug('/screenshots created!');
1025 if file_exists('/'+sd+'/cavecraft/texturepacks')<>1 then
1026 if create_folder('/'+sd+'/cavecraft/texturepacks')=1 then debug('/texturepacks created!');
1028 deleteRecordStore('SD');
1029 rs:=openRecordStore('SD');
1030 t:=addRecordStoreEntry(rs,sd);
1031 closeRecordStore(rs);
1032 end;
1033 end;
1035 procedure start_uu;
1036 var
1037 rs:recordstore;
1038 ss:string;
1039 begin
1040 drawdeadlogo;
1041 //Load SD
1042 rs:=openRecordStore('SD');
1043 sd:=readRecordStoreEntry(rs,1);
1044 closeRecordStore(rs);
1045 console.exec('autoexec.cfg', 'AUTO');
1046 if sd='' then
1047 begin
1048 init_touch;
1049 if touchscreen then
1050 load_key_tex:=1;
1051 else
1052 load_key_tex:=0;
1053 //load_virt_tex(loadimage('/gui/touch.png'));
1054 setsd(false);
1055 end;
1057 if file_exists('/'+sd+'/cavecraft')<>1 then
1058 if create_folder('/'+sd+'/cavecraft')=1 then debug('/cavecraft created!');
1060 if file_exists('/'+sd+'/cavecraft/saves')<>1 then
1061 if create_folder('/'+sd+'/cavecraft/saves')=1 then debug('/saves created!');
1063 if file_exists('/'+sd+'/cavecraft/screenshots')<>1 then
1064 if create_folder('/'+sd+'/cavecraft/screenshots')=1 then debug('/screenshots created!');
1066 if file_exists('/'+sd+'/cavecraft/texturepacks')<>1 then
1067 if create_folder('/'+sd+'/cavecraft/texturepacks')=1 then debug('/texturepacks created!');
1069 rs:=openRecordStore('TX');
1070 ss:=readRecordStoreEntry(rs,1);
1071 closeRecordStore(rs);
1073 if ss<>'' then
1074 begin
1075 tex_pack:=ss;
1076 LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1077 loadtexture('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1078 end;
1079 else
1080 begin
1081 LoadDrawFont('/');
1082 loadtexture('/');
1083 end;
1084 end;
1086 function question(text:string):boolean;
1087 var
1088 ix,iy,m_cur:integer;
1089 begin
1090 repeat
1091 updateKeys;
1092 if clickedKey(KEY_MENU_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=1; end;
1093 if clickedKey(KEY_MENU_DOWN) then begin m_cur:=m_cur+1; if m_cur>1 then m_cur:=0; end;
1094 if clickedKey(KEY_MENU_SELECT) then begin if m_cur=0 then question:=true; else question:=false; exit; end;
1095 for ix:=0 to getwidth/16 do for iy:=0 to getheight/16 do drawimage(bg[0],ix*16,iy*16);
1096 drawfonttext(text,getwidth/2-(length(text)*8)/2,getheight/2-16);
1097 drw_btn('Yes',0,m_cur,0,1);
1098 drw_btn('No',1,m_cur,0,1);
1099 drawVideo;
1100 delay(1);
1101 until false;
1102 end;
1104 function menu_game_new:boolean;
1105 var
1106 m_cur,tmp_gm,ix,iy,lol:integer;
1107 tmp_cheats,tmp_bon_chest:boolean;
1108 newgametxt:array[0..4] of string;
1109 name,tmp:string;
1110 begin
1111 m_cur:=-2;
1112 newgametxt[0]:='Survival';
1113 newgametxt[1]:='Creative';
1114 newgametxt[2]:='Hardcore';
1115 newgametxt[3]:='Normal';
1116 newgametxt[4]:='Flat';
1117 name:='New World';
1118 repeat
1119 updateKeys;
1120 if clickedKey(KEY_MENU_UP) then begin m_cur:=m_cur-1; if m_cur<-2 then m_cur:=5; end;
1121 if clickedKey(KEY_MENU_DOWN) then begin m_cur:=m_cur+1; if m_cur>5 then m_cur:=-2; end;
1122 if clickedKey(KEY_MENU_SELECT) then
1123 begin
1124 if m_cur=-2 then
1125 begin
1126 name:=gettext('Name:',name,10,TF_ANY);
1127 end; else
1128 if m_cur=-1 then
1129 begin
1130 tmp_gm:=tmp_gm+1; if tmp_gm>2 then tmp_gm:=0;
1131 if tmp_gm=0 then tmp_cheats:=false;
1132 if tmp_gm=1 then tmp_cheats:=true;
1133 if tmp_gm=2 then begin tmp_cheats:=false; tmp_bon_chest:=false; end;
1134 end; else
1135 if m_cur=0 then
1136 begin
1137 nextseed:=stringtointeger(gettext('Seed:',''+nextseed,10,TF_NUMERIC));
1138 end; else
1139 if m_cur=1 then
1140 begin
1141 world_typ:=world_typ+1;
1142 if world_typ>1 then world_typ:=0;
1143 end; else
1144 if m_cur=2 then
1145 begin
1146 if tmp_gm<2 then tmp_cheats:= not tmp_cheats;
1147 end; else
1148 if m_cur=3 then
1149 begin
1150 if tmp_gm<2 then tmp_bon_chest:= not tmp_bon_chest;
1151 end; else
1152 if m_cur=4 then
1153 begin
1154 gamemode:=tmp_gm;
1155 cheats:=tmp_cheats;
1156 bon_chest:=tmp_bon_chest;
1157 tmp:=name;
1158 while file_exists('/'+sd+'/cavecraft/saves/'+name)=1 do
1159 begin
1160 lol:=lol+1;
1161 name:=tmp+' '+lol;
1162 end;
1163 sav_fl:=name;
1164 newgame;
1165 menu_game_new:=true;
1166 break;
1167 end; else
1168 if m_cur=5 then
1169 begin
1170 break;
1171 end; else
1172 end;
1173 for ix:=0 to getWidth/16 do
1174 for iy:=0 to getHeight/16 do
1175 drawimage(bg[0],ix*16,iy*16);
1177 drw_btn('Name:'+name,-2,m_cur,0,1);
1178 drw_btn('Mode:'+newgametxt[tmp_gm],-1,m_cur,0,1);
1179 drw_btn('Seed:'+nextseed,0,m_cur,0,1);
1180 drw_btn('Type:'+newgametxt[world_typ+3],1,m_cur,0,1);
1181 if tmp_gm<2 then
1182 drw_btn('Cheats:'+tmp_cheats,2,m_cur,0,1);
1183 else
1184 drw_btn('Cheats:'+tmp_cheats,2,m_cur,0,0);
1185 if tmp_gm<2 then
1186 drw_btn('Chest:'+tmp_bon_chest,3,m_cur,0,1);
1187 else
1188 drw_btn('Chest:'+tmp_bon_chest,3,m_cur,0,0);
1189 drw_btn('Create',4,m_cur,0,1);
1190 drw_btn('Cancel',5,m_cur,0,1);
1192 drawVideo;
1193 delay(1);
1194 until false;
1195 end;
1197 procedure deleteworld(path:string);
1198 begin
1199 if file_exists(path+'player.dat')=1 then delete_file(path+'player.dat');
1200 if file_exists(path+'world.sav')=1 then delete_file(path+'world.sav');
1201 if file_exists(path+'nether.sav')=1 then delete_file(path+'nether.sav');
1202 if file_exists(path+'pic.png')=1 then delete_file(path+'pic.png');
1203 if file_exists(path)=1 then delete_file(path);
1204 if file_exists(path)=0 then debug('World deleted!');
1205 end;
1207 function menu_game:boolean;
1208 var
1209 ix,iy,pars,max_r,cur_name,m_cur:integer;
1210 mm_t_b:boolean;
1211 im_game:image;
1212 rr:string;
1213 names:array[0..255] of string;
1214 begin
1215 rr:=get_dirs('/'+sd+'/cavecraft/saves/');
1216 while pos(rr,'|')<>-1 do
1217 begin
1218 pars:=pos(rr,'|');
1219 names[max_r]:=copy(rr,0,pars-1);
1220 rr:=copy(rr,pars+1,length(rr));
1221 if file_exists('/'+sd+'/cavecraft/saves/'+names[max_r]+'/player.dat')=1 then max_r:=max_r+1;
1222 end;
1223 max_r:=max_r-1;
1224 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1225 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1226 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1228 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/player.dat')=1 then
1229 mm_t_b:=true; else mm_t_b:=false;
1231 repeat
1232 updateKeys;
1233 if clickedKey(KEY_MENU_UP) then
1234 begin
1235 m_cur:=m_cur-1;
1236 if m_cur<0 then m_cur:=3;
1237 end;
1238 if clickedKey(KEY_MENU_DOWN) then
1239 begin
1240 m_cur:=m_cur+1;
1241 if m_cur>3 then m_cur:=0;
1242 end;
1244 if (max_r >= 0) and clickedKey(KEY_MENU_LEFT) then
1245 begin
1246 cur_name:=cur_name-1;
1247 if cur_name<0 then cur_name:=0;
1248 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1249 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1250 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1252 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/player.dat')=1 then
1253 end;
1254 if (max_r >= 0) and clickedKey(KEY_MENU_RIGHT) then
1255 begin
1256 cur_name:=cur_name+1;
1257 if cur_name>max_r then cur_name:=max_r;
1258 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1259 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1260 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1262 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/player.dat')=1 then
1263 end;
1264 if clickedKey(KEY_MENU_SELECT) then
1265 begin
1266 if m_cur=0 then
1267 begin
1268 if max_r>-1 then
1269 if loadgame('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/') then
1270 begin
1271 sav_fl:=names[cur_name];
1272 menu_game:=true;
1273 break;
1274 end;
1275 end; else
1276 if m_cur=1 then
1277 begin
1278 if menu_game_new then begin menu_game:=true; break; end;
1279 end; else
1280 if m_cur=2 then
1281 begin
1282 debug('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/');
1283 if max_r>-1 then
1284 if question('Are you sure?')=true then deleteworld('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/');
1285 cur_name:=0;
1286 max_r:=0;
1287 rr:=get_dirs('/'+sd+'/cavecraft/saves/');
1288 while pos(rr,'|')<>-1 do
1289 begin
1290 pars:=pos(rr,'|');
1291 names[max_r]:=copy(rr,0,pars-1);
1292 rr:=copy(rr,pars+1,length(rr));
1293 max_r:=max_r+1;
1294 end;
1295 max_r:=max_r-1;
1296 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1297 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1298 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1299 end; else
1300 if m_cur=3 then
1301 begin
1302 break;
1303 end;
1304 end;
1306 for ix:=0 to getWidth/16 do
1307 for iy:=1 to 7 do
1308 drawimage(bg[1],ix*16,iy*16);
1309 for ix:=0 to getWidth/16 do
1310 drawimage(bg[0],ix*16,0);
1311 for ix:=0 to getWidth/16 do
1312 for iy:=8 to getHeight/16 do
1313 drawimage(bg[0],ix*16,iy*16);
1315 if max_r>-1 then
1316 begin
1317 setcolor(0,0,0);
1318 fillrect(32,24,getWidth-64,96);
1319 setclip(32,24,getWidth-64,96);
1320 drawimage(im_game,(getWidth/2)-(32),32);
1321 drawfonttext(names[cur_name],(getWidth/2)-(length(names[cur_name])*8/2),104);
1322 setclip(0,0,getWidth,getHeight);
1323 setcolor(128,128,128);
1324 drawrect(32,24,getWidth-64,96);
1325 if cur_name>0 then drawimage(gui[20],0,58);
1326 if cur_name<max_r then drawimage(gui[21],getWidth-9,58);
1327 end;
1328 else
1329 begin
1330 setcolor(0,0,0);
1331 fillrect(32,24,getWidth-64,96);
1332 setclip(32,24,getWidth-64,96);
1333 drawfonttext('No saves!',(getWidth/2)-(length('No saves!')*8/2),104);
1334 setclip(0,0,getWidth,getHeight);
1335 setcolor(128,128,128);
1336 drawrect(32,24,getWidth-64,96);
1337 end;
1339 if mm_t_b then drw_btn('Play',0,m_cur,32,1); else drw_btn('Play',0,m_cur,32,0);
1340 drw_btn('Create new',1,m_cur,32,1);
1341 if mm_t_b then drw_btn('Delete',2,m_cur,32,1); else drw_btn('Delete',2,m_cur,32,0);
1342 drw_btn('Back',3,m_cur,32,1);
1343 if not mm_t_b then cur_name:=cur_name+1;
1345 drawVideo;
1346 delay(1);
1347 until false;
1348 end;
1350 procedure menu_tex;
1351 var
1352 ix,iy,pars,max_r,cur_name,m_cur,t:integer;
1353 im_game:image;
1354 rr:string;
1355 names:array[0..255] of string;
1356 rs:recordstore;
1357 begin
1358 rr:=get_dirs('/'+sd+'/cavecraft/texturepacks/');
1359 names[0]:='Default';
1360 max_r:=1;
1361 while pos(rr,'|')<>-1 do
1362 begin
1363 pars:=pos(rr,'|');
1364 names[max_r]:=copy(rr,0,pars-1);
1365 rr:=copy(rr,pars+1,length(rr));
1366 max_r:=max_r+1;
1367 end;
1368 max_r:=max_r-1;
1369 im_game:=loadimage('/pack.png');
1371 repeat
1372 updateKeys;
1373 if clickedKey(KEY_MENU_UP) then
1374 begin
1375 m_cur:=m_cur-1;
1376 if m_cur<0 then m_cur:=1;
1377 end;
1378 if clickedKey(KEY_MENU_DOWN) then
1379 begin
1380 m_cur:=m_cur+1;
1381 if m_cur>1 then m_cur:=0;
1382 end;
1384 if clickedKey(KEY_MENU_LEFT) then
1385 begin
1386 cur_name:=cur_name-1;
1387 if cur_name<0 then cur_name:=0;
1388 im_game:=ld_tex('pack.png','/'+sd+'/cavecraft/texturepacks/'+names[cur_name]+'/','');
1389 end;
1390 if clickedKey(KEY_MENU_RIGHT) then
1391 begin
1392 cur_name:=cur_name+1;
1393 if cur_name>max_r then cur_name:=max_r;
1394 im_game:=ld_tex('pack.png','/'+sd+'/cavecraft/texturepacks/'+names[cur_name]+'/','');
1395 end;
1396 if clickedKey(KEY_MENU_SELECT) then
1397 begin
1398 if m_cur=0 then begin
1399 if cur_name>0 then
1400 begin
1401 debug("Select TexturePack @ /" + sd + "/cavecraft/texturepacks/" + names[cur_name]);
1402 tex_pack:=names[cur_name];
1403 LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1404 loadtexture('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1405 deleteRecordStore('TX');
1406 rs:=openRecordStore('TX');
1407 t:=addRecordStoreEntry(rs,tex_pack);
1408 closeRecordStore(rs);
1410 LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1411 loadtexture('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1412 end;
1413 else
1414 begin
1415 debug("Cancel Select TecturePack");
1416 tex_pack:='';
1417 loadtexture('/');
1418 deleteRecordStore('TX');
1419 rs:=openRecordStore('TX');
1420 t:=addRecordStoreEntry(rs,'');
1421 closeRecordStore(rs);
1422 end;
1423 end;
1424 if m_cur=1 then break;
1425 break;
1426 end;
1428 for ix:=0 to getWidth/16 do
1429 for iy:=1 to 7 do
1430 drawimage(bg[1],ix*16,iy*16);
1431 for ix:=0 to getWidth/16 do
1432 drawimage(bg[0],ix*16,0);
1433 for ix:=0 to getWidth/16 do
1434 for iy:=8 to getHeight/16 do
1435 drawimage(bg[0],ix*16,iy*16);
1437 if max_r>-1 then
1438 begin
1439 setcolor(0,0,0);
1440 fillrect(32,24,getWidth-64,96);
1441 setclip(32,24,getWidth-64,96);
1442 drawimage(im_game,(getWidth/2)-(32),32);
1443 drawfonttext(names[cur_name],(getWidth/2)-(length(names[cur_name])*8/2),104);
1444 setclip(0,0,getWidth,getHeight);
1445 setcolor(128,128,128);
1446 drawrect(32,24,getWidth-64,96);
1447 if cur_name>0 then drawimage(gui[20],0,58);
1448 if cur_name<max_r then drawimage(gui[21],getWidth-9,58);
1449 end;
1451 drw_btn('Done',0,m_cur,32,1);
1452 drw_btn('Back',1,m_cur,32,1);
1454 drawVideo;
1455 delay(1);
1456 until false;
1457 end;
1459 procedure menu_sett;
1460 var
1461 ix,iy,m_cur:integer;
1462 begin
1463 m_cur:=-3;
1464 repeat
1465 updateKeys;
1466 if clickedKey(KEY_MENU_UP) then
1467 begin
1468 m_cur:=m_cur-1;
1469 if m_cur<-3 then m_cur:=5;
1470 end;
1471 if clickedKey(KEY_MENU_DOWN) then
1472 begin
1473 m_cur:=m_cur+1;
1474 if m_cur>5 then m_cur:=-3;
1475 end;
1476 if clickedKey(KEY_MENU_SELECT) then
1477 begin
1478 if m_cur=-3 then
1479 begin
1480 light_type:=light_type+1;
1481 if light_type>2 then light_type:=0;
1482 end; else
1483 if m_cur=-2 then
1484 begin
1485 ifosad:=not ifosad;
1486 end; else
1487 if m_cur=-1 then
1488 begin
1489 s_particles:=not s_particles;
1490 end; else
1491 if m_cur=0 then
1492 begin
1493 drawgui:=not drawgui;
1494 end; else
1495 if m_cur=1 then
1496 begin
1497 if question('Are you sure?')=true then
1498 begin
1499 if load_key_tex=0 then
1500 begin
1501 load_key_tex:=1;
1502 init_touch;
1503 //load_virt_tex(ld_tex('touch.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','gui/'));
1504 end;
1505 else
1506 if load_key_tex=1 then
1507 begin
1508 load_key_tex:=0;
1509 resetVirtualKeyboard(-1);
1510 end;
1511 end;
1512 end;
1513 if m_cur=2 then
1514 begin
1515 s_jpeg_quality:=stringtointeger(gettext('JPEG quality:',''+s_jpeg_quality,3,TF_NUMERIC));
1516 if s_jpeg_quality>100 then s_jpeg_quality:=100; else
1517 if s_jpeg_quality<0 then s_jpeg_quality:=0;
1518 end; else
1519 if m_cur=3 then
1520 begin
1521 setsd(true);
1522 end; else
1523 if m_cur=4 then
1524 begin
1525 deleteRecordStore('S');
1526 deleteRecordStore('SD');
1527 deleteRecordStore('TX');
1528 halt;
1529 end; else
1530 if m_cur=5 then
1531 begin
1532 save_settings;
1533 break;
1534 end; else
1535 end;
1537 for ix:=0 to getWidth/16 do
1538 for iy:=0 to getHeight/16 do
1539 drawimage(bg[0],ix*16,iy*16);
1541 drw_btn('Light:'+light_type,-3,m_cur,0,1);
1542 drw_btn('Weather:'+ifosad,-2,m_cur,0,1);
1543 drw_btn('Particles:'+s_particles,-1,m_cur,0,1);
1544 drw_btn('Hide GUI:'+not drawgui,0,m_cur,0,1);
1545 drw_btn('Touch:'+(load_key_tex>0),1,m_cur,0,1);
1546 drw_btn('JPEG:'+s_jpeg_quality,2,m_cur,0,1);
1547 drw_btn('Set Root',3,m_cur,0,1);
1548 drw_btn('Reset',4,m_cur,0,1);
1549 drw_btn('Back',5,m_cur,0,1);
1551 drawVideo;
1552 delay(1);
1553 until false;
1554 end;
1556 procedure menu_help;
1557 var
1558 ix,iy,cur:integer;
1559 begin
1560 repeat
1561 updateKeys;
1562 if clickedKey(KEY_MENU_SELECT) then break;
1563 if pressedKey(KEY_MENU_UP) then cur:=cur+1;
1564 if pressedKey(KEY_MENU_DOWN) then cur:=cur-1;
1566 for ix:=0 to getWidth/16 do
1567 for iy:=2 to (getHeight/16)-2 do
1568 drawimage(bg[1],ix*16,iy*16);
1570 for ix:=0 to getWidth/16 do
1571 for iy:=0 to 1 do
1572 drawimage(bg[0],ix*16,iy*16);
1574 for ix:=0 to getWidth/16 do
1575 for iy:=(getHeight/16)-2 to getHeight/16 do
1576 drawimage(bg[0],ix*16,iy*16);
1578 setclip(0,32,getWidth,(getHeight/16-4)*16);
1580 drw_txt('Controls:',cur,0,1);
1581 drw_txt('Left - Move left',cur,1,0);
1582 drw_txt('Right - Move right',cur,2,0);
1583 drw_txt('Up - Jump',cur,3,0);
1584 drw_txt('Down - Put a block under you',cur,4,0);
1585 drw_txt('1 - Inventory',cur,5,0);
1586 drw_txt('Duble 1 - Craft',cur,6,0);
1587 drw_txt('3 - Use block',cur,7,0);
1588 drw_txt('7 - Debug info',cur,8,0);
1589 drw_txt('Hold 7 - Console',cur,9,0);
1590 drw_txt('9 - Pause',cur,10,0);
1591 drw_txt('*, # - Browse inventory',cur,11,0);
1592 drw_txt('0 - Edit mode',cur,12,0);
1594 drw_txt('In inventory/chest:',cur,14,1);
1595 drw_txt('3 - Enject object',cur,15,0);
1596 drw_txt('Hold 3 - Enject stack',cur,16,0);
1597 drw_txt('5 - Move the stack',cur,17,0);
1598 drw_txt('Hold 5 - Divide stack',cur,18,0);
1600 setclip(0,0,getWidth,getHeight);
1602 drw_btn('Back',0,0,getHeight-getHeight/2-16-6,1);
1604 drawVideo;
1605 delay(1);
1606 until false;
1607 end;
1609 procedure menu_about;
1610 var
1611 ix,iy,cur:integer;
1612 begin
1613 repeat
1614 updateKeys;
1615 if clickedKey(KEY_MENU_SELECT) then break;
1616 if pressedKey(KEY_MENU_UP) then cur:=cur+1;
1617 if pressedKey(KEY_MENU_DOWN) then cur:=cur-1;
1619 for ix:=0 to getWidth/16 do
1620 for iy:=2 to (getHeight/16)-2 do
1621 drawimage(bg[1],ix*16,iy*16);
1623 for ix:=0 to getWidth/16 do
1624 for iy:=0 to 1 do
1625 drawimage(bg[0],ix*16,iy*16);
1627 for ix:=0 to getWidth/16 do
1628 for iy:=(getHeight/16)-2 to getHeight/16 do
1629 drawimage(bg[0],ix*16,iy*16);
1631 setclip(0,32,getWidth,(getHeight/16-4)*16);
1633 drw_txt('Developers:',cur,0,1);
1634 drw_txt(#68+#101+#97+#68+#68+#111+#111+#77+#69+#82+' - Programmer',cur,1,0);//dead
1635 drw_txt(#102+#114+#101+#100+#45+#98+#111+#121+' - Programmer',cur,2,0);//fred-boy
1636 drw_txt(#65+#110+#100+#114+#101+#121+#53+#57+' - Programmer',cur,3,0);//andrey59
1637 drw_txt(#89+#117+#82+#97+#78+#110+#78+#122+#90+#90+' - Artist',cur,4,0);//yura
1638 drw_txt(#83+#97+#115+#104+#97+#71+' - Artist and idea generator',cur,5,0);//sasha
1639 drw_txt(#66+#97+#74+#108+#101+#72+#84+#105+#72+' - Artist and tester',cur,6,0);//valentin
1640 drw_txt(#65+#103+#114+#101+#115+#115+#111+#82+' - Tester',cur,7,0);//agressor
1641 drw_txt(#118+#111+#108+#121+#97+#95+#110+#97+#115+#116+#97+#110+#101+' - Tester',cur,8,0);//volya
1642 drw_txt(#97+#98+#97+#100+#111+#110+' - Tester',cur,9,0);//abadon
1643 drw_txt(#77+#111+#110+#111+#103+#114+#111+#109+' - Tester',cur,10,0);//monogrom
1644 drw_txt(#75+#97+#108+#116+#101+#114+' - Tester',cur,11,0);//kalter
1646 drw_txt('Thanks:',cur,12,1);
1647 drw_txt('Piligrim and 0vZ - Lib_jsr75i',cur,13,0);
1648 drw_txt('Piligrim - Lib_effects',cur,14,0);
1649 drw_txt('Kurdt - Lib_canvas',cur,15,0);
1650 drw_txt('ViNT - Lib_png and Lib_bmp',cur,16,0);
1651 drw_txt('aleshka - Lib_jpeg',cur,17,0);
1652 drw_txt('Roman_V - Lib_safeload',cur,18,0);
1654 drw_txt('Site: '+#104+#116+#116+#112+#58+#47+#47+#100+#101+#97+#100+#115+#111+#102+#116+#119+#97+#114+#101+#46+#114+#117,cur,21,0);
1655 drw_txt(#68+#101+#97+#68+#83+#111+#102+#116+#87+#97+#114+#101+' 2012-'+getyear(getcurrenttime),cur,22,0);
1657 drw_txt('Hello! :D',cur,100,1);
1659 setclip(0,0,getWidth,getHeight);
1661 drw_btn('Back',0,0,getHeight-getHeight/2-16-6,1);
1663 drawVideo;
1664 delay(1);
1665 until false;
1666 end;
1668 function sm_siz:integer;
1669 begin
1670 sm_siz:=(getWidth+getHeight)/5;
1671 end;
1673 function sm_siz4:integer;
1674 begin
1675 sm_siz4:=sm_siz/4;
1676 end;
1678 procedure draw_menu_back;
1679 var
1680 ix, iy:integer;
1681 begin
1682 for ix:=0 to getWidth/16 do
1683 for iy:=0 to getHeight/16 do
1684 drawimage(bg[0],ix*16,iy*16);
1685 end;
1687 procedure menu;
1688 var
1689 m_cur,ix,iy,iz:integer;
1690 key,spl_i:integer;
1691 splash:string;
1692 res:resource;
1693 time:integer;
1694 cavelogo:image;
1695 spl_y,spl_del:integer;
1696 spl_y_b:boolean;
1697 begin
1698 cavelogo:=ld_tex('cavelogo.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','title/');
1699 splash:='#ERROR';
1700 spl_y:=getimageheight(cavelogo);
1701 spl_y_b:=true;
1702 spl_del:=getrelativetimems;
1703 res:=openResource('/title/splashes.txt');
1704 if ResourceAvailable(res) then
1705 begin
1706 spl_i:=stringtointeger(readline(res));
1707 iy:=random(spl_i-1)+1;
1708 debug('SPLASH #'+iy);
1709 for ix:=1 to iy do
1710 splash:=readline(res);
1711 closeresource(res);
1712 end;
1713 time:=getcurrenttime;
1714 if (getmonth(time)=5) and (getday(time)=7) then splash:='Happy birthday, DeaDDooMER!';
1715 if ((getmonth(time)=0) and (getday(time)<3)) or ((getmonth(time)=11) and (getday(time)>29)) then splash:='Happy New Year!';
1716 repeat
1717 proc_fps;
1718 updateKeys;
1719 if clickedKey(KEY_MENU_UP) then
1720 begin
1721 m_cur:=m_cur-1;
1722 if m_cur<0 then m_cur:=5;
1723 end;
1724 if clickedKey(KEY_MENU_DOWN) then
1725 begin
1726 m_cur:=m_cur+1;
1727 if m_cur>5 then m_cur:=0;
1728 end;
1729 if clickedKey(KEY_MENU_SELECT) then
1730 begin
1731 if m_cur=0 then begin if menu_game then break; end;
1732 else
1733 if m_cur=1 then menu_tex;
1734 else
1735 if m_cur=2 then menu_sett;
1736 else
1737 if m_cur=3 then menu_help;
1738 else
1739 if m_cur=4 then menu_about;
1740 else
1741 if m_cur=5 then begin save_settings; halt; end;
1742 end;
1744 draw_menu_back;
1746 drawimage(cavelogo,(getWidth/2)-(getimagewidth(cavelogo)/2),0);
1747 setcolor(255,255,0);
1749 DrawFontTextSpec(splash, (getWidth/2)-(length(splash)*FONT_SYM_SIZE/2), spl_y, FONT_YELLOW_COLOR, true);
1751 if spl_y_b then begin if getrelativetimems-spl_del>64 then begin spl_y:=spl_y+1; spl_del:=getrelativetimems; end; if spl_y>getimageheight(cavelogo)+2 then spl_y_b:=false; end;
1752 if not spl_y_b then begin if getrelativetimems-spl_del>64 then begin spl_y:=spl_y-1; spl_del:=getrelativetimems; end; if spl_y<getimageheight(cavelogo)+1 then spl_y_b:=true; end;
1753 drawfonttext(version,0,getHeight-8);
1755 drw_btn('Singleplayer',0,m_cur,0,1);
1756 drw_btn('Texture Packs',1,m_cur,0,1);
1757 drw_btn('Options',2,m_cur,0,1);
1758 drw_btn('Help',3,m_cur,0,1);
1759 drw_btn('About',4,m_cur,0,1);
1760 drw_btn('Quit Game',5,m_cur,0,1);
1762 drawVideo;
1763 maxfps;
1764 until false;
1765 end;
1767 function setBlock(invcur, x, y:integer):boolean;
1768 var
1769 item, sum, block, sblock:integer;
1770 begin
1771 item:=inv.getItem(invcur);
1772 sum:=inv.getSum(invcur);
1773 block:=getMap(x, y);
1774 sblock:=getItemInfo(item);
1776 if getItemType(item)=ITEM_TYPE_BLOCK then
1777 if inv.isNull(invcur)=false then
1778 if getBlockSet(block)=true then
1779 // if (coll_xy(x, y)=false) or (getBlockColl(item)=0) then
1780 begin
1781 if set_block_code(sblock, x, y)=false then
1782 begin
1784 setmap(sblock, x, y);
1785 if gamemode<>1 then
1786 begin
1787 inv.setSum(inv.getSum(invcur)-1, invcur);
1788 inv.fixNull(invcur);
1789 end;
1791 setBlock:=true;
1792 end;
1793 end;
1794 end;
1796 procedure fishing;
1797 var
1798 x, y:integer;
1799 begin
1800 x:=player.getX;
1801 y:=player.getY;
1802 if (getrelativetimems-fish_time>5000) and (getmap(fx,fy)=50) then
1803 begin
1804 if (random(3)=2) and (getmap(fx,fy)=50) then
1805 begin
1806 drop.create(210,1,x,y);
1807 fish:=false;
1808 end;
1809 inv.setSum(inv.getSum(invslot)-1, invslot);
1810 inv.fixNull(invslot);
1811 fish:=false;
1812 end; else
1813 if (getrelativetimems-fish_time<5000) and (getmap(fx,fy)=50) and (fish=true) then
1814 begin
1815 if getmap(fx,fy-1)=50 then fy:=fy-1;
1816 end;
1817 end;
1819 procedure drawminimap;
1820 var
1821 ix,iy,tmp_gx,tmp_gy,minx,miny,maxx,maxy,loc_camx,loc_camy,x,y:integer;
1822 begin
1823 x:=player.getX;
1824 y:=player.getY;
1825 if load_minimap_tex then
1826 begin
1827 tmp_gx:=(getWidth/2)-(getimagewidth(gui[16])/2);
1828 tmp_gy:=(getHeight/2)-(getimageheight(gui[16])/2);
1829 end;
1830 else
1831 begin
1832 tmp_gx:=(getWidth/2)-(64/2);
1833 tmp_gy:=(getHeight/2)-(64/2);
1834 end;
1836 loc_camx:=(x+4)-(864/2);
1837 loc_camy:=(y+4)-(864/2);
1838 if loc_camx<0 then loc_camx:=0;
1839 if loc_camx>4096-864 then loc_camx:=4096-864;
1840 if loc_camy<0 then loc_camy:=0;
1841 if loc_camy>2048-864 then loc_camy:=2048-864;
1842 minx:=loc_camx/16;
1843 miny:=loc_camy/16;
1844 maxx:=(loc_camx+864)/16;
1845 maxy:=(loc_camy+864)/16;
1846 if minx<0 then minx:=0;
1847 if miny<0 then miny:=0;
1848 if maxx>255 then maxx:=255;
1849 if maxy>127 then maxy:=127;
1851 if load_minimap_tex then
1852 drawimage(gui[16],tmp_gx,tmp_gy);
1853 else
1854 begin
1855 setcolor(214,190,150);
1856 fillrect(tmp_gx,tmp_gy,64,64);
1857 end;
1859 for ix:=minx to maxx do
1860 for iy:=miny to maxy do
1861 begin
1862 if (getmap(ix,iy)=1) or (getmap(ix,iy)=2) or (getmap(ix,iy)=74) then setcolor(121,85,58); else
1863 if (getmap(ix,iy)=4) or (getmap(ix,iy)=9) or (getmap(ix,iy)=11) or (getmap(ix,iy)=28) or (getmap(ix,iy)=29) or ((getmap(ix,iy)>=77) and (getmap(ix,iy)<=86)) or ((getmap(ix,iy)>=88) and (getmap(ix,iy)<=101)) then setcolor(188,152,98); else
1864 if (getmap(ix,iy)=50) or (getmap(ix,iy)=62) then setcolor(38,92,255); else
1865 if getmap(ix,iy)=51 then setcolor(255,0,0); else
1866 if (getmap(ix,iy)=61) or (getmap(ix,iy)=32) then setcolor(255,255,255); else
1867 setcolor(127,127,127);
1869 if (getmap(ix,iy)<>0) then plot(tmp_gx+4+ix-minx,tmp_gy+4+iy-miny);
1870 end;
1871 setcolor(0,0,255);
1872 end;
1874 procedure draw_sign;
1875 var
1876 tmp:string;
1877 str:array[0..3] of string;
1878 i,j,tmp_gx,tmp_gy:integer;
1879 begin
1880 if load_gui_tex then
1881 begin
1882 tmp_gx:=(getWidth/2)-(getimagewidth(sign_im)/2);
1883 tmp_gy:=(getHeight/2)-(getimageheight(sign_im)/2);
1884 end;
1885 else
1886 begin
1887 tmp_gx:=(getWidth/2)-(120/2);
1888 tmp_gy:=(getHeight/2)-(60/2);
1889 end;
1891 tmp:=t_sign[getmapinfo(curx,cury)];
1892 while pos(tmp,#13)<>-1 do
1893 begin
1894 i:=pos(tmp,#13);
1895 str[j]:=copy(tmp,0,i);
1896 tmp:=copy(tmp,i+1,length(tmp));
1897 j:=j+1;
1898 end;
1900 if load_gui_tex then
1901 drawimage(sign_im,tmp_gx,tmp_gy);
1902 else
1903 begin
1904 setcolor(159,132,77);
1905 fillrect(tmp_gx,tmp_gy,120,60);
1906 end;
1908 drawfonttext(str[0],tmp_gx+(120/2)-(length(str[0])*8/2),tmp_gy+(60/4/2)+4);
1909 drawfonttext(str[1],tmp_gx+(120/2)-(length(str[1])*8/2),tmp_gy+(60/4/2)+8+4);
1910 drawfonttext(str[2],tmp_gx+(120/2)-(length(str[2])*8/2),tmp_gy+(60/4/2)+16+4);
1911 drawfonttext(str[3],tmp_gx+(120/2)-(length(str[3])*8/2),tmp_gy+(60/4/2)+24+4);
1912 end;
1914 procedure draw_back(ix,iy:integer);
1915 begin
1916 if getBiomMap(ix)=0 then
1917 begin
1918 if (getBackMap(ix)=iy) then drawimage(back[0],(ix*16)-camx,(iy*16)-camy); else
1919 if (getBackMap(ix)+1=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1920 if (getBackMap(ix)+2=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1921 if (getBackMap(ix)+3=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1922 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1923 end; else
1924 if getBiomMap(ix)=1 then
1925 begin
1926 if (getBackMap(ix)=iy) then drawimage(back[4],(ix*16)-camx,(iy*16)-camy); else
1927 if (getBackMap(ix)+1=iy) then drawimage(back[4],(ix*16)-camx,(iy*16)-camy); else
1928 if (getBackMap(ix)+2=iy) then drawimage(back[6],(ix*16)-camx,(iy*16)-camy); else
1929 if (getBackMap(ix)+3=iy) then drawimage(back[6],(ix*16)-camx,(iy*16)-camy); else
1930 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1931 end; else
1932 if getBiomMap(ix)=2 then
1933 begin
1934 if (getBackMap(ix)=iy) then drawimage(back[5],(ix*16)-camx,(iy*16)-camy); else
1935 if (getBackMap(ix)+1=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1936 if (getBackMap(ix)+2=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1937 if (getBackMap(ix)+3=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1938 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1939 end; else
1940 if getBiomMap(ix)=3 then
1941 begin
1942 if (getBackMap(ix)=iy) then drawimage(back[7],(ix*16)-camx,(iy*16)-camy); else
1943 if (getBackMap(ix)+1=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1944 if (getBackMap(ix)+2=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1945 if (getBackMap(ix)+3=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1946 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1947 end; else
1948 if getBiomMap(ix)=4 then
1949 begin
1950 drawimage(back[8],(ix*16)-camx,(iy*16)-camy);
1951 end;
1952 end;
1954 procedure draw;
1955 var
1956 ix,iy,iz,minx,miny,maxx,maxy,tmp_ax,tim,smy,pa_xo, x, y:integer;
1957 begin
1958 x:=player.getX;
1959 y:=player.getY;
1960 {===================[sky]===================}
1961 tim:=10000*getimagewidth(sky)/600000*game_time/10000;
1962 setcolor(effects.get(sky,tim,0,1),effects.get(sky,tim,0,2),effects.get(sky,tim,0,3));
1963 fillrect(0,0,getWidth,getHeight);
1964 srand(seed);
1965 if drw_stars then
1966 begin
1967 setcolor(effects.get(sky,tim,2,1),effects.get(sky,tim,2,2),effects.get(sky,tim,2,3));
1968 smy:=10000*getWidth*2/600000*game_time/10000;
1969 for iz:=1 to getWidth do
1970 begin
1971 ix:=rnd(getWidth*2)-getWidth+smy;
1972 if ix>getWidth then ix:=ix-getWidth*2;
1973 iy:=rnd(getHeight);
1974 if (ix>-1) and (ix<getWidth) then plot(ix,iy);
1975 end;
1976 end;
1978 if drw_sm then
1979 begin
1980 if load_sm>0 then
1981 begin
1982 smy:=10000*(getWidth+getimagewidth(sun))/300000*game_time/10000;
1983 drawimage(sun,smy-getimagewidth(sun),getHeight/2-getimageheight(sun)/2);
1984 end;
1985 else
1986 begin
1987 setcolor(255,213,74);
1988 smy:=10000*(getWidth+sm_siz)/300000*game_time/10000;
1989 fillrect(smy-sm_siz+sm_siz4,getHeight/2-sm_siz/2+sm_siz4,sm_siz-sm_siz4,sm_siz-sm_siz4);
1990 end;
1992 if load_sm>0 then
1993 begin
1994 smy:=10000*(getWidth+getimagewidth(moon))/300000*(game_time-300000)/10000;
1995 drawimage(moon,smy-getimagewidth(moon),getHeight/2-getimageheight(moon)/2);
1996 end;
1997 else
1998 begin
1999 setcolor(175,184,204);
2000 smy:=10000*(getWidth+sm_siz)/300000*(game_time-300000)/10000;
2001 fillrect(smy-sm_siz+sm_siz4,getHeight/2-sm_siz/2+sm_siz4,sm_siz-sm_siz4,sm_siz-sm_siz4);
2002 end;
2003 end;
2004 {===================[camera]===================}
2005 camx:=(x+4)-(getWidth/2);
2006 camy:=(y+4)-(getHeight/2);
2007 if camx<0 then camx:=0;
2008 if camx>4096-getWidth then camx:=4096-getWidth;
2009 if camy>2048-getHeight then camy:=2048-getHeight;
2010 {===================[max_draw]===================}
2011 minx:=camx/16;
2012 miny:=camy/16;
2013 maxx:=(camx+getWidth)/16;
2014 maxy:=(camy+getHeight)/16;
2015 if minx<0 then minx:=0;
2016 if miny<0 then miny:=0;
2017 if maxx>255 then maxx:=255;
2018 if maxy>127 then maxy:=127;
2019 {===================[draw_back]===================}
2020 for ix:=minx to maxx do
2021 for iy:=miny to maxy do
2022 begin
2023 if ifosad then if (getBackMap(ix)>=iy) and (osadki=true) and getBlockTrans(getmap(ix,iy)) then
2024 begin
2025 if getBiomMap(ix)=0 then drawimage(osad[0,osadki_ani],(ix*16)-camx,(iy*16)-camy);
2026 else
2027 if getBiomMap(ix)=2 then drawimage(osad[1,osadki_ani],(ix*16)-camx,(iy*16)-camy);
2028 else
2029 if getBiomMap(ix)=3 then drawimage(osad[0,osadki_ani],(ix*16)-camx,(iy*16)-camy);
2030 end;
2031 if drw_back then
2032 if getBlockTrans(getmap(ix,iy)) then
2033 draw_back(ix,iy);
2035 if getBlockFore(getmap(ix,iy))=false then
2036 draw_block(ix,iy);
2037 end;
2038 {===================[drop]===================}
2039 drop.draw(camx, camy);
2040 {===================[particles]===================}
2041 if s_particles then draw_particle;
2042 {===================[player]===================}
2043 if hp>0 then
2044 begin
2045 player.draw(camx, camy);
2046 end;
2048 {===================[mobs]===================}
2049 mob.draw(camx, camy);
2050 {===================[draw_blocks]===================}
2051 for ix:=minx to maxx do
2052 for iy:=miny to maxy do
2053 begin
2054 if getBlockFore(getmap(ix, iy)) then
2055 draw_block(ix, iy);
2057 setcolor(0, 0, 0);
2058 if light_type = 1 then
2059 begin
2060 if getmaplight(ix,iy) = 0 then
2061 fillrect((ix * 16) - camx, (iy * 16) - camy, 16, 16);
2062 end;
2063 else if light_type = 2 then
2064 begin
2065 if getmaplight(ix, iy) < 15 then
2066 drawimage(light[getmaplight(ix, iy)], (ix * 16) - camx, (iy * 16) - camy);
2067 end;
2068 end;
2070 // debug
2071 // drawimage(light[getmaplight(player.getX div 16, player.getY div 16)], 0, 0);
2073 if (toolus > 0) and (toolind < 10) and (getmap(curx,cury) > 0) then
2074 begin
2075 if toolind > 9 then
2076 toolind:=9;
2077 drawimage(tue[toolind], curx * 16 - camx, cury * 16 - camy);
2078 end;
2079 {===================[gui]===================}
2080 if drawgui then
2081 begin
2082 tmp_ax:=(getWidth/2)-(getImageWidth(gui[1])/2);
2084 if keymode=1 then
2085 drawimage(gui[0],curx*16-camx,cury*16-camy);
2087 DrawWindows;
2088 /*if keymode=2 then
2089 if gamemode<>1 then
2090 DrawPlayerInventory;
2091 else
2092 drawinv_c; else
2093 if keymode=3 then drawcraft; else
2094 if keymode=4 then drawchest; else
2095 if keymode=5 then draw_sign; else
2096 if keymode=6 then drawfurnace; else
2097 if ifminimap then drawminimap;*/
2099 drawimage(gui[1],tmp_ax,0);
2100 for ix:=0 to 8 do
2101 begin
2102 drawItem(inv.getItem(ix), inv.getSum(ix), (ix*16)+tmp_ax+ix*2+4, 1, true);
2103 end;
2104 drawimage(gui[17],(invslot*16)+tmp_ax+invslot*2+2,0);
2106 if gamemode<>1 then
2107 begin
2108 if gamemode=0 then
2109 begin
2110 for ix:=0 to (hp div 2)-1 do drawimage(gui[13],ix*9,getHeight-9);
2111 if (hp mod 2)<>0 then begin drawimage(gui[14],ix*9,getHeight-9); ix:=ix+1 end;
2112 for ix:=ix to 9 do drawimage(gui[15],ix*9,getHeight-9);
2113 end; else
2114 if gamemode=2 then
2115 begin
2116 for ix:=0 to (hp div 2)-1 do drawimage(gui[31],ix*9,getHeight-9);
2117 if (hp mod 2)<>0 then begin drawimage(gui[32],ix*9,getHeight-9); ix:=ix+1 end;
2118 for ix:=ix to 9 do drawimage(gui[33],ix*9,getHeight-9);
2119 end;
2121 for ix:=0 to (hunger div 2)-1 do drawimage(gui[26],ix*9,getHeight-18);
2122 if (hunger mod 2)<>0 then begin drawimage(gui[27],ix*9,getHeight-18); ix:=ix+1 end;
2123 for ix:=ix to 9 do drawimage(gui[28],ix*9,getHeight-18);
2125 if getmap((x+4)/16,y/16)=50 then
2126 begin
2127 for ix:=0 to (air div 2)-1 do drawimage(gui[29],ix*9,getHeight-27);
2128 if (air mod 2)<>0 then begin drawimage(gui[30],ix*9,getHeight-27); ix:=ix+1 end;
2129 end;
2130 end;
2132 for ix:=0 to 3 do
2133 begin
2134 drawfonttext(msg[ix],0,getHeight-20-ix*9);
2135 if getrelativetimems-msg_time[ix]>5000 then msg[ix]:='';
2136 end;
2137 end;
2138 end;
2140 procedure load_moon(path:string;phase:integer);
2141 var
2142 no:image;
2143 begin
2144 moon:=no;
2145 if load_sm=1 then
2146 begin
2147 moon:=ld_tex('moon_phase_'+phase+'.png',path,'terrain/moon_phases/');
2148 end; else
2149 if load_sm=2 then
2150 begin
2151 moon:=resize_image(ld_tex('moon_phase_'+phase+'.png',path,'terrain/moon_phases/'),(getWidth+getHeight)/5,(getWidth+getHeight)/5);
2152 end;
2153 end;
2155 procedure sleep;
2156 var
2157 i,ix,iy:integer;
2158 begin
2159 if game_time>300000 then
2160 begin
2161 if load_light_tex then
2162 begin
2163 keymode:=0;
2164 i:=15;
2165 while i>0 do
2166 begin
2167 for iy:=0 to getheight/16 do
2168 for ix:=0 to getwidth/16 do
2169 drawimage(light[i],ix*16,iy*16);
2170 i:=i-1;
2171 drawVideo;
2172 delay(100);
2173 end;
2174 moon_phase:=moon_phase+1;
2175 if moon_phase>7 then moon_phase:=0;
2176 load_moon('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/',moon_phase);
2177 game_time:=50000;
2178 last_sleep_x:=curx;
2179 last_sleep_y:=cury-1;
2180 i:=1;
2181 while i<15 do
2182 begin
2183 draw;
2184 for iy:=0 to getheight/16 do
2185 for ix:=0 to getwidth/16 do
2186 drawimage(light[i],ix*16,iy*16);
2187 i:=i+1;
2188 drawVideo;
2189 delay(100);
2190 end;
2191 end;
2192 else
2193 begin
2194 keymode:=0;
2195 i:=0;
2196 while i<=getheight do
2197 begin
2198 setcolor(0,0,0);
2199 fillrect(0,0,getwidth,i);
2200 i:=i+5;
2201 drawVideo;
2202 delay(50);
2203 end;
2204 moon_phase:=moon_phase+1;
2205 if moon_phase>7 then moon_phase:=0;
2206 load_moon('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/',moon_phase);
2207 game_time:=50000;
2208 last_sleep_x:=curx;
2209 last_sleep_y:=cury-1;
2210 i:=0;
2211 while i<=getheight do
2212 begin
2213 draw;
2214 setcolor(0,0,0);
2215 fillrect(0,i,getwidth,getheight);
2216 i:=i+5;
2217 drawVideo;
2218 delay(50);
2219 end;
2220 end;
2221 end; else create_msg('You can sleep only at night');
2222 end;
2224 procedure resetToolProgerss;
2225 begin
2226 toolus:=0;
2227 toolind:=0;
2228 end;
2230 procedure usetools(invcur, x, y:integer);
2231 var
2232 item, sum, block:integer;
2233 begin
2234 block:=getmap(x, y);
2235 item:=inv.getItem(invcur);
2236 sum:=inv.getSum(invcur);
2238 if gamemode=1 then
2239 destroy_block_cr(block, x, y);
2240 else
2241 if (block>0) then
2242 begin
2243 if (getItemType(item)=ITEM_TYPE_TOOL) and (getBlockTool(block)=getToolType(item)) then
2244 toolus:=toolus+getToolSpeed(item);
2245 else
2246 toolus:=toolus+1;
2248 if toolus>=getBlockHP(block) then
2249 begin
2250 if ((getItemType(item)=ITEM_TYPE_TOOL) and (getBlockTool(block)=getToolType(item)) and (getToolLvl(item)>=getBlockLvl(block))) or (getBlockLvl(block)<=0) then
2251 begin
2252 setMap(0, x, y);
2253 destroy_block_1(block, x, y);
2254 setMapInfo(0, x, y);
2255 end;
2256 else
2257 begin
2258 setMap(0, x, y);
2259 destroy_block_0(block, x, y);
2260 setMapInfo(0, x, y);
2261 end;
2263 if getItemType(item)=ITEM_TYPE_TOOL then
2264 begin
2265 inv.setSum(inv.getSum(invcur)-1, invcur);
2266 inv.fixNull(invcur);
2267 end;
2269 toolus:=0;
2270 toolind:=0;
2271 end;
2272 end;
2274 if (toolus>0) and (toolus<=getBlockHP(block)) then
2275 toolind:=((toolus*100) div getBlockHP(block)) div 10;
2276 end;
2278 function rt_useweap:boolean;
2279 var
2280 x, y, w, h, i, damg:integer;
2281 item:integer;
2282 begin
2283 x:=player.getX;
2284 y:=player.getY;
2285 w:=player.getW;
2286 h:=player.getH;
2287 item:=inv.getItem(invslot);
2289 if getItemType(item)=1 then
2290 damg:=getToolDamg(item);
2291 else
2292 damg:=1;
2294 if posi=0 then
2295 i:=mob.findAndHit(damg, x-TILE_SIZE, y, TILE_SIZE+(w/2), h, -2, -3);
2296 else
2297 i:=mob.findAndHit(damg, x+(w/2), y, TILE_SIZE+(w/2), h, 2, -3);
2299 if i<>-1 then
2300 begin
2301 inv.setSum(inv.getSum(invslot)-1, invslot);
2302 inv.fixNull(invslot);
2303 rt_useweap:=true;
2304 end;
2305 end;
2307 procedure rt_usetools;
2308 var
2309 x, y:integer;
2310 begin
2311 x:=player.getX;
2312 y:=player.getY;
2314 if posi=0 then curx:=(x div 16)-1; else curx:=(x div 16)+1;
2315 cury:=y div 16;
2316 if getmap(curx,cury)=0 then cury:=cury+1;
2318 if curx<0 then curx:=0;
2319 if curx>255 then curx:=255;
2320 if cury<0 then cury:=0;
2321 if cury>127 then cury:=127;
2323 usetools(invslot, curx, cury);
2324 end;
2326 procedure rt_usemob;
2327 var
2328 x, y:integer;
2329 begin
2330 x:=player.getX;
2331 y:=player.getY;
2333 if posi=0 then curx:=(x div 16)-1; else curx:=(x div 16)+1;
2334 cury:=y div 16;
2335 if getmap(curx,cury)=0 then cury:=cury+1;
2337 if curx<0 then curx:=0;
2338 if curx>255 then curx:=255;
2339 if cury<0 then cury:=0;
2340 if cury>127 then cury:=127;
2342 //usemob(curx,cury);
2343 end;
2345 procedure actionUse(invcur, x, y:integer);
2346 begin
2347 if setBlock(invcur, x, y)=false then
2348 if useBlock(invcur, x, y) then
2349 if useItem(invcur, x, y) then
2350 end;
2352 procedure rt_useblock;
2353 var
2354 x, y:integer;
2355 begin
2356 x:=player.getX;
2357 y:=player.getY;
2359 if posi=0 then curx:=(x div 16)-1; else curx:=(x div 16)+1;
2360 cury:=y div 16;
2361 if getmap(curx,cury)=0 then cury:=cury+1;
2363 if curx<0 then curx:=0;
2364 if curx>255 then curx:=255;
2365 if cury<0 then cury:=0;
2366 if cury>127 then cury:=127;
2368 actionUse(invslot, curx, cury);
2369 end;
2371 procedure go_to_nether;
2372 var
2373 ix:integer;
2374 begin
2375 portal_time:=getrelativetimems;
2376 savegame('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2377 pl_world:=1;
2378 drw_load_line('Matrix',10);
2379 if loadworld('/'+sd+'/cavecraft/saves/'+sav_fl+'/')=true then
2380 begin
2381 player.setX(get_spawn_x*16+4);
2382 player.setY((get_up(get_spawn_x)-1)*16);
2383 end;
2384 else
2385 begin
2386 {for ix:=0 to 31 do
2387 begin
2388 mob[ix].m_type:=0;
2389 mob[ix].m_x:=0;
2390 mob[ix].m_y:=0;
2391 mob[ix].m_posi:=0;
2392 mob[ix].m_velx:=0;
2393 mob[ix].m_vely:=0;
2394 mob[ix].m_ani:=0;
2395 mob[ix].m_min_vely:=0;
2396 mob[ix].m_hp:=0;
2397 mob[ix].m_del:=0;
2398 mob[ix].m_fall:=false;
2399 mob[ix].m_jmp:=false;
2400 mob[ix].m_velani:=false;
2401 end;}
2403 drop.resetData;
2404 gennether;
2405 //netherspawn;
2406 end;
2407 end;
2409 procedure go_to_world;
2410 begin
2411 portal_time:=getrelativetimems;
2412 savegame('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2413 pl_world:=0;
2414 drw_load_line('Matrix',10);
2415 if loadworld('/'+sd+'/cavecraft/saves/'+sav_fl+'/')=true then
2416 begin
2417 pl_world:=0;
2418 end;
2419 else
2420 begin
2421 debug('ERROR!!!');
2422 pl_world:=0;
2423 genworld;
2424 //megaspawn;
2425 end;
2426 end;
2428 procedure plr_is_dead_hardcore;
2429 begin
2430 keymode:=0;
2431 toolus:=0;
2432 toolind:=0;
2434 repeat
2435 updateKeys;
2436 if clickedKey(KEY_MENU_SELECT) then
2437 begin
2438 deleteworld('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2439 menu;
2440 exit;
2441 end;
2442 draw;
2443 drawfonttext('You died!',getwidth/2-32,getheight/2-16);
2445 drw_btn('Delete world',0,0,0,1);
2447 drawVideo;
2448 delay(1);
2449 until false;
2451 end;
2453 procedure plr_is_dead;
2454 var
2455 m_cur:integer;
2456 x, y:integer;
2457 begin
2458 x:=player.getX;
2459 y:=player.getY;
2460 keymode:=0;
2461 toolus:=0;
2462 toolind:=0;
2463 repeat
2464 updateKeys;
2465 if clickedKey(KEY_MENU_UP) then
2466 begin
2467 m_cur:=m_cur-1;
2468 if m_cur<0 then m_cur:=1;
2469 end;
2470 if clickedKey(KEY_MENU_DOWN) then
2471 begin
2472 m_cur:=m_cur+1;
2473 if m_cur>1 then m_cur:=0;
2474 end;
2475 if clickedKey(KEY_MENU_SELECT) then
2476 begin
2477 if m_cur=0 then
2478 begin
2479 if pl_world=0 then
2480 begin
2481 if last_sleep_x=0 then
2482 begin
2483 x:=get_spawn_x*16+4;
2484 y:=get_spawn_y*16;
2485 end; else
2486 begin
2487 x:=last_sleep_x*16+4;
2488 y:=last_sleep_y*16;
2489 end;
2490 end; else
2491 if pl_world=1 then
2492 begin
2493 go_to_world;
2494 if last_sleep_x=0 then
2495 begin
2496 x:=get_spawn_x*16+4;
2497 y:=get_spawn_y*16;
2498 end; else
2499 begin
2500 x:=last_sleep_x*16+4;
2501 y:=last_sleep_y*16;
2502 end;
2503 end;
2504 player.setX(x);
2505 player.setY(y);
2506 posi:=0;
2507 curx:=0;
2508 cury:=0;
2509 vely:=0;
2510 jmp:=false;
2511 hp:=20;
2512 hunger:=20;
2513 exit;
2514 end;
2515 else
2516 if m_cur=1 then begin menu; exit; end;
2517 end;
2519 draw;
2521 drawfonttext('You died!',getwidth/2-32,getheight/2-16);
2523 drw_btn('Respawn',0,m_cur,0,1);
2524 drw_btn('Main menu',1,m_cur,0,1);
2526 drawVideo;
2527 delay(1);
2528 until false;
2529 end;
2531 procedure fast_menu;
2532 var
2533 m_cur,i:integer;
2534 begin
2535 repeat
2536 updateKeys;
2537 if clickedKey(KEY_MENU_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=3; end;
2538 if clickedKey(KEY_MENU_DOWN) then begin m_cur:=m_cur+1; if m_cur>3 then m_cur:=0; end;
2539 if clickedKey(KEY_MENU_SELECT) then
2540 begin
2541 if m_cur=0 then
2542 begin
2543 exit;
2544 end; else
2545 if m_cur=1 then
2546 begin
2547 savegame('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2548 exit;
2549 end; else
2550 if m_cur=2 then
2551 begin
2552 menu_sett;
2553 end; else
2554 if m_cur=3 then
2555 begin
2556 //clear_gui(keymode);
2557 menu;
2558 exit;
2559 end;
2560 end;
2561 draw;
2562 drawfonttext('Game menu',getwidth/2-36,getheight/2-20);
2563 drw_btn('Back to Game',0,m_cur,0,1);
2564 drw_btn('Save Game',1,m_cur,0,1);
2565 drw_btn('Options',2,m_cur,0,1);
2566 drw_btn('Quit to Title',3,m_cur,0,1);
2568 drawVideo;
2569 delay(1);
2570 until false;
2571 end;
2573 procedure keyFastInv;
2574 begin
2575 if clickedKey(KEY_FASTINV_NEXT) then
2576 begin
2577 invslot:=invslot-1;
2578 if invslot<0 then
2579 invslot:=8;
2580 end;
2582 if clickedKey(KEY_FASTINV_PREV) then
2583 begin
2584 invslot:=invslot+1;
2585 if invslot>8 then
2586 invslot:=0;
2587 end;
2588 end;
2590 procedure keyConsole;
2591 begin
2592 if clickedKey(KEY_CHAT) then
2593 SetTimer(1000,T_CONSOLE);
2595 if pressedKey(KEY_CHAT) then
2596 begin
2597 if GetTimer(T_CONSOLE)=TIMER_OK then
2598 begin
2599 call_console;
2600 ResetTimer(T_CONSOLE);
2601 end;
2602 end;
2603 else
2604 begin
2605 if GetTimer(T_CONSOLE)>TIMER_OK then
2606 begin
2607 deb:= not deb;
2608 ResetTimer(T_CONSOLE);
2609 end;
2610 end;
2611 end;
2613 procedure keyInventory;
2614 begin
2615 if clickedKey(KEY_PLR_OPENINV) then
2616 if gamemode<>1 then
2617 OpenPlayerInventory;
2618 else
2619 OpenCreativeWindow;
2620 end;
2622 procedure keyhandler;
2623 begin
2624 updateKeys;
2626 if WindowKeyHanler then
2627 begin
2628 if keymode=0 then
2629 begin
2630 keyInventory;
2631 keyFastInv;
2632 keyConsole;
2634 if clickedKey(KEY_PLR_EDITMODE) then
2635 begin
2636 keymode:=1;
2637 curx:=player.getX div 16;
2638 cury:=player.getY div 16;
2639 end;
2641 if clickedKey(KEY_PLR_USE) then
2642 rt_usemob;
2644 if clickedKey(KEY_MENU) then
2645 fast_menu;
2647 if clickedKey(KEY_PLR_ATTACK) then
2648 if rt_useweap=false then
2649 debug('useweap');
2651 if pressedKey(KEY_PLR_ATTACK) then
2652 begin
2653 rt_usetools;
2654 playAnim(ANIM_HAND);
2655 end;
2656 else
2657 begin
2658 resetToolProgerss;
2659 cancelAnim(ANIM_HAND);
2660 end;
2662 if pressedKey(KEY_PLR_UP) then
2663 player.gotoUP;
2664 if pressedKey(KEY_PLR_DOWN) then
2665 player.gotoDOWN;
2666 if pressedKey(KEY_PLR_LEFT) then
2667 player.gotoLEFT;
2668 if pressedKey(KEY_PLR_RIGHT) then
2669 player.gotoRIGHT;
2670 end;
2671 else
2672 if keymode=1 then
2673 begin
2674 keyInventory;
2675 keyFastInv;
2676 keyConsole;
2678 if clickedKey(KEY_PLR_UP) then
2679 begin
2680 cury:=cury-1;
2681 if cury<0 then
2682 cury:=0;
2683 end;
2684 if clickedKey(KEY_PLR_DOWN) then
2685 begin
2686 cury:=cury+1;
2687 if cury>127 then
2688 cury:=127;
2689 end;
2690 if clickedKey(KEY_PLR_LEFT) then
2691 begin
2692 curx:=curx-1;
2693 if curx<0 then
2694 curx:=0;
2695 end;
2696 if clickedKey(KEY_PLR_RIGHT) then
2697 begin
2698 curx:=curx+1;
2699 if curx>255 then
2700 curx:=255;
2701 end;
2703 if clickedKey(KEY_PLR_EDITMODE) then
2704 keymode:=0;
2706 if clickedKey(KEY_PLR_USE) then
2707 actionUse(invslot, curx, cury);
2709 if pressedKey(KEY_PLR_ATTACK) then
2710 begin
2711 usetools(invslot, curx, cury);
2712 playAnim(ANIM_HAND);
2713 end;
2714 else
2715 begin
2716 resetToolProgerss;
2717 cancelAnim(ANIM_HAND);
2718 end;
2720 if clickedKey(KEY_MENU) then
2721 fast_menu;
2722 end;
2724 end;
2726 end;
2728 procedure phyhandler;
2729 var
2730 i:integer;
2731 begin
2732 player.calcPhysics;
2733 mob.updatePhy;
2734 drop.calcPhy;
2735 end;
2737 procedure light_fillrect(l,x,y,r:integer);
2738 var
2739 ix,iy,ym,yp,xm,xp:integer;
2740 begin
2741 ym:=y-r;
2742 yp:=y+r;
2743 xm:=x-r;
2744 xp:=x+r;
2745 for ix:=xm to xp do
2746 for iy:=ym to yp do
2747 setmaplight(getmaplight(ix,iy)+l,ix,iy);
2748 end;
2750 procedure light_rect(l,x,y,r:integer);
2751 var
2752 ix,iy,ym,yp,xm,xp:integer;
2753 begin
2754 ym:=y-r;
2755 yp:=y+r;
2756 xm:=x-r;
2757 xp:=x+r;
2758 for ix:=xm to xp do
2759 begin
2760 setmaplight(getmaplight(ix,ym)+l,ix,ym);
2761 setmaplight(getmaplight(ix,yp)+l,ix,yp);
2762 end;
2763 for iy:=ym+1 to yp-1 do
2764 begin
2765 setmaplight(getmaplight(xm,iy)+l,xm,iy);
2766 setmaplight(getmaplight(xp,iy)+l,xp,iy);
2767 end;
2768 end;
2770 procedure calc_light(m,x,y:integer);
2771 var
2772 ix,iy,l,ss,sf:integer;
2773 begin
2774 if light_type=1 then light_fillrect(m,x,y,m/2); else
2775 for l:=m downto 1 do
2776 begin
2777 if ss mod 2=0 then light_rect(l,x,y,ss/2);
2778 ss:=ss+1;
2779 end;
2780 end;
2782 procedure calc_sun(ix,m:integer);
2783 var
2784 iy,ss:integer;
2785 begin
2786 ss:=m;
2787 for iy:=0 to 127 do
2788 begin
2789 setmaplight(ss,ix,iy);
2790 if ss=0 then break;
2791 ss:=ss-getBlockTr(getmap(ix,iy));
2792 if ss<0 then ss:=0;
2793 end;
2794 for iy:=iy+1 to 127 do
2795 begin
2796 setmaplight(0,ix,iy);
2797 end;
2798 end;
2800 procedure kill_plr;
2801 var
2802 i:integer;
2803 begin
2804 hp:=0;
2805 for i:=0 to INV_SIZE do
2806 begin
2807 if inv.isNull(i)=false then
2808 player.dropItem(inv.getItem(i), inv.getSum(i));
2809 inv.setItem(0, i);
2810 inv.setSum(0, i);
2811 end;
2812 if gamemode<2 then plr_is_dead; else plr_is_dead_hardcore;
2813 end;
2815 procedure hunger_and_air;
2816 var
2817 x, y:integer;
2818 begin
2819 x:=player.getX;
2820 y:=player.getY;
2821 if gamemode<>1 then
2822 begin
2823 if getrelativetimems-hung_time>=90000/(gamemode+1) then
2824 begin
2825 hung_time:=getrelativetimems;
2826 hunger:=hunger-1;
2827 end;
2828 if getrelativetimems-hp_time>=5000*(gamemode+1) then
2829 begin
2830 if hunger>16 then
2831 begin
2832 hp_time:=getrelativetimems;
2833 hp:=hp+1;