DEADSOFTWARE

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