DEADSOFTWARE

Fix ArrayIndexOutOfBoundsException
[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.getY);
518 //Matrix
519 SaveMapRLE;
520 SaveMapInfoRLE;
521 drw_load_line('Background',50);
522 //Background and biomes
523 for ix:=0 to 255 do
524 begin
525 write_byte(getBackMap(ix));
526 write_byte(getBiomMap(ix));
527 end;
528 drw_load_line('Chests',55);
529 //Chests
530 chest.saveData;
531 drw_load_line('Furnaces',60);
532 //Furnaces
533 /* for ix:=0 to 15 do
534 begin
535 writebool(b_furnace[ix]);
536 writeint(furnace_gg[ix].f_gor);
537 writeint(furnace_gg[ix].f_got);
538 for iy:=0 to 4 do
539 begin
540 write_byte(furnace[ix,iy].item_i);
541 writeint(furnace[ix,iy].sum_i);
542 end;
543 end;*/
544 drw_load_line('Mobs',70);
545 //Mobs
546 mob.saveData;
547 drw_load_line('Drop',80);
548 //Drop
549 drop.saveData;
550 drw_load_line('Particles',85);
551 //Particles
552 writeint(max_particles);
553 write_byte(gb_up_pa);
554 for ix:=0 to max_particles do
555 begin
556 write_byte(get_particle_type(ix));
557 write_byte(get_particle_ani(ix));
558 writeint(get_particle_x(ix));
559 writeint(get_particle_y(ix));
560 end;
561 drw_load_line('Other',90);
562 //Other
563 write_byte(updx);
564 write_byte(updy);
565 writebool(osadki);
566 write_byte(osadki_ani);
567 write_byte(global_light);
568 writebool(fly);
569 writeint(game_time);
570 write_byte(clock_stage);
571 for ix:=0 to 31 do
572 begin
573 writebool(b_sign[ix]);
574 writestr(t_sign[ix]);
575 end;
576 flush;
577 drw_load_line('Ready',100);
578 if close_file(path+world_name)=1 then debug('World Saved!');
579 end;
580 end;
582 procedure savegame(path:string);
583 var
584 ix,iy:integer;
585 begin
586 drw_load_line('Basic',0);
587 if file_exists(path+'player.dat')=1 then delete_file(path+'player.dat');
588 if file_exists(path)<>1 then if create_folder(path)=1 then debug('Folder created!');
589 if file_exists(path+'player.dat')<>1 then file_create(path+'player.dat');
590 if open_file(path+'player.dat')=1 then
591 begin
592 //Head
593 write_byte(version_map);
594 write_byte(gamemode);
595 writebool(cheats);
596 writeint(seed);
597 write_byte(pl_world);
598 //Player
599 writeint(last_sleep_x);
600 writeint(last_sleep_y);
601 write_byte(velx);
602 write_byte(vely);
603 write_byte(invslot);
604 write_byte(posi);
605 write_byte(hp);
606 write_byte(hunger);
607 write_byte(moon_phase);
608 writebool(jmp);
609 inv.saveData;
610 if close_file(path+'player.dat')=1 then debug('Saved!');
611 drw_load_line('Matrix',10);
612 saveworld(path);
613 end;
614 end;
617 function version_err(ver:integer):boolean;
618 var
619 ix,iy:integer;
620 begin
621 for ix:=0 to getWidth/16 do
622 for iy:=0 to getHeight/16 do
623 begin
624 drawimage(bg[0],ix*16,iy*16);
625 end;
626 if version_map=ver then version_err:=true; else
627 if version_map>ver then
628 begin
629 drawfonttext('Old save format!',(getWidth/2)-60,(getHeight/2)-4);
630 drawVideo;
631 delay(3000);
632 version_err:=false;
633 end; else
634 if version_map<ver then
635 begin
636 drawfonttext('New save format!',(getWidth/2)-60,(getHeight/2)-4);
637 drawVideo;
638 delay(3000);
639 version_err:=false;
640 end;
641 end;
644 function loadworld(path:string):boolean;
645 var
646 ix,iy,ver:integer;
647 world_name:string;
648 begin
649 if pl_world=0 then world_name:='world.sav';
650 else
651 if pl_world=1 then world_name:='nether.sav';
652 if file_exists(path)=1 then
653 begin
654 if file_exists(path+world_name)=1 then
655 begin
656 if open_file(path+world_name)=1 then
657 begin
658 player.setX(readint);
659 player.setY(readint);
660 //Matrix
661 LoadMapRLE;
662 LoadMapInfoRLE;
663 drw_load_line('Background',50);
664 //Background and biomes
665 for ix:=0 to 255 do
666 begin
667 setBackMap(read_byte, ix);
668 setBiomMap(read_byte, ix);
669 end;
670 drw_load_line('Chests',55);
671 //Chests
672 chest.loadData;
673 drw_load_line('Furnaces',60);
674 //Furnaces
675 /* for ix:=0 to 15 do
676 begin
677 b_furnace[ix]:=readbool;
678 furnace_gg[ix].f_gor:=readint;
679 furnace_gg[ix].f_got:=readint;
680 for iy:=0 to 4 do
681 begin
682 furnace[ix,iy].item_i:=read_byte;
683 furnace[ix,iy].sum_i:=readint;
684 end;
685 end;*/
686 drw_load_line('Mobs',70);
687 //Mobs
688 mob.loadData;
689 drw_load_line('Drop',80);
690 //Drop
691 drop.loadData;
692 drw_load_line('Particles',85);
693 //Particles
694 max_particles:=readint;
695 reset_particles(max_particles+1);
696 gb_up_pa:=read_byte;
697 for ix:=0 to max_particles do
698 begin
699 set_particle_type(ix,read_byte);
700 set_particle_ani(ix,read_byte);
701 set_particle_x(ix,readint);
702 set_particle_y(ix,readint);
703 end;
704 drw_load_line('Other',90);
705 //Other
706 updx:=read_byte;
707 updy:=read_byte;
708 osadki:=readbool;
709 osadki_ani:=read_byte;
710 global_light:=read_byte;
711 fly:=readbool;
712 game_time:=readint;
713 clock_stage:=read_byte;
714 for ix:=0 to 31 do
715 begin
716 b_sign[ix]:=readbool;
717 t_sign[ix]:=readstr;
718 end;
719 drw_load_line('Ready',100);
720 ///////////////////////
721 if close_file(path+world_name)=1 then begin loadworld:=true; debug('World loaded!'); end;
722 end; else begin loadworld:=false; debug('File not opened!'); end;
723 end; else begin loadworld:=false; debug('File not exists!'); end;
724 end; else begin loadworld:=false; debug('Folder not exists!'); end;
725 end;
727 function loadgame(path:string):boolean;
728 var
729 ix,iy,ver:integer;
730 begin
731 drw_load_line('Basic',0);
732 if file_exists(path)=1 then
733 begin
734 if file_exists(path+'player.dat')=1 then
735 begin
736 if open_file(path+'player.dat')=1 then
737 begin
738 //Head
739 ver:=read_byte;
740 if version_err(ver)=false then
741 begin
742 if close_file(path+'player.dat')=1 then loadgame:=false;
743 exit;
744 end;
745 gamemode:=read_byte;
746 cheats:=readbool;
747 seed:=readint;
748 pl_world:=read_byte;
749 //Player;
750 last_sleep_x:=readint;
751 last_sleep_y:=readint;
752 velx:=read_byte;
753 vely:=read_byte;
754 invslot:=read_byte;
755 posi:=read_byte;
756 hp:=read_byte;
757 hunger:=read_byte;
758 moon_phase:=read_byte;
759 jmp:=readbool;
760 inv.loadData;
761 drw_load_line('Matrix',10);
762 if close_file(path+'player.dat')=1 then loadgame:=loadworld(path);
763 end; else loadgame:=false;
764 end; else loadgame:=false;
765 end; else loadgame:=false;
766 end;
768 procedure drawdeadlogo;
769 var
770 dead:image;
771 begin
772 setcolor(0,0,0);
773 fillrect(0,0,getWidth,getHeight);
774 dead:=loadimage('/dl');
775 drawimage(dead,(getWidth/2)-(getimagewidth(dead)/2),(getHeight/2)-(getimageheight(dead)/2));
776 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));
777 drawfonttext('Loading...',(getWidth/2)-(40),getHeight-8);
778 drawVideo;
779 delay(500);
780 end;
782 procedure newgame;
783 var
784 ix,iy:integer;
785 begin
786 for ix:=0 to getWidth/16 do
787 for iy:=0 to getHeight/16 do
788 begin
789 drawimage(bg[0],ix*16,iy*16);
790 end;
791 drawfonttext('Generation World...',(getWidth/2)-(76),(getHeight/2)-4);
792 drawVideo;
793 delay(1);
794 cleargame;
795 game_time:=45000;
796 newworld;
797 //if s_spawn_mob then begin if pl_world=0 then begin megaspawn; end; else begin netherspawn; end; end;
798 if gamemode=1 then fly:=true else fly:=false;
799 debug('New game!');
800 end;
802 function gettext(text,text_f:string; max,typ:integer;):string;
803 var
804 textField_id:integer;
805 exitCmd,cli:command;
806 begin
807 clearForm;
808 exitCmd:=createCommand('Ok',CM_OK,1);
809 showForm;
810 addCommand(exitCmd);
811 textField_id:=formAddTextField(text,text_f,max,typ);
812 drawVideo;
813 delay(100);
814 repeat
815 cli:=getClickedCommand;
816 until cli=exitCmd;
817 gettext:=formGetText(textField_id);
818 showCanvas;
819 end;
821 procedure drw_btn(text:string; cur,ccur,h,ty:integer);
822 var
823 m_x,m_y,i:integer;
824 begin
825 m_x:=(getWidth/2)-(120/2);
826 m_y:=h+((getHeight/2))-((getimageheight(gui[7])-2*cur)/2)+((getimageheight(gui[7])+2)*cur);
827 if ty=0 then
828 begin
829 if ccur=cur then drawimage(gui[22],m_x+i*4,m_y); else drawimage(gui[6],m_x+i*8,m_y);
830 end; else
831 if ty=1 then
832 begin
833 if ccur=cur then drawimage(gui[8],m_x+i*8,m_y); else drawimage(gui[7],m_x+i*8,m_y);
834 end;
835 setclip(0,0,getwidth,getheight);
836 m_x:=(getWidth/2)-(length(text)*8/2);
837 m_y:=h+((getHeight/2))-((getimageheight(gui[7])-2*cur)/2)+((getimageheight(gui[7])+2)*cur)+((getimageheight(gui[7])-8)/2);
838 drawfonttext(text,m_x,m_y);
839 end;
841 procedure drw_txt(str:string; xx,n,t:integer);
842 var
843 m_x,m_y:integer;
844 begin
845 m_x:=(getWidth/2)-(length(str)*8/2);
846 m_y:=xx+32+(8*n);
847 if t=0 then drawfonttext(str,0,m_y); else
848 if t=1 then drawfonttext(str,m_x,m_y);
849 end;
851 function pos_end(s:string; c:char):integer;
852 var
853 i:integer;
854 begin
855 for i:=length(s)-1 downto 0 do
856 begin
857 if getchar(s,i)=c then
858 begin
859 pos_end:=i;
860 exit;
861 end;
862 end;
863 pos_end:=-1;
864 end;
866 function getroot(cancel_b:boolean):string;
867 var
868 m_cur,max_r,pars,ix,iy:integer;
869 rr:string;
870 im:image;
871 roots:array [0..15] of string;
872 begin
873 im:=rotate_image_from_image(ld_tex('background.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','title/'),16,0,16,16,0);
874 rr:=get_roots;
875 if cancel_b then roots[0]:='<CANCEL>';
876 if cancel_b then max_r:=1; else max_r:=0;
877 while pos(rr,'|')<>-1 do
878 begin
879 pars:=pos(rr,'|');
880 roots[max_r]:=copy(rr,0,pars-1);
881 rr:=copy(rr,pars+1,length(rr));
882 max_r:=max_r+1;
883 end;
884 max_r:=max_r-1;
885 repeat
886 updateKeys;
887 if clickedKey(KEY_FM_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=max_r; end;
888 if clickedKey(KEY_FM_DOWN) then begin m_cur:=m_cur+1; if m_cur>max_r then m_cur:=0; end;
889 if clickedKey(KEY_FM_SELECT) then
890 begin
891 if (m_cur=0) and (cancel_b) then
892 begin
893 getroot:='';
894 exit;
895 end;
896 else
897 begin
898 getroot:=roots[m_cur];
899 exit;
900 end;
901 end;
903 for ix:=0 to getWidth/16 do
904 for iy:=0 to getHeight/16 do
905 drawimage(im,ix*16,iy*16);
907 setcolor(0,0,0);
908 fillrect(0,m_cur*8,getWidth-1,8);
909 for ix:=0 to max_r do
910 begin
911 drawfonttext(roots[ix],0,ix*8);
912 end;
913 setcolor(255,255,255);
914 drawrect(0,m_cur*8,getWidth-1,8);
916 drawVideo;
917 delay(1);
918 until false;
919 end;
921 function filemanager(cancel_b:boolean):string;
922 var
923 m_cur,ix,iy,max_r,pars:integer;
924 im:image;
925 last,rr,root,path:string;
926 names:array [0..255] of string;
927 begin
928 im:=rotate_image_from_image(ld_tex('background.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','title/'),16,0,16,16,0);
929 names[0]:='<..>';
930 names[1]:='<OK>';
931 root:=getroot(cancel_b);
932 if root='' then
933 begin
934 filemanager:='';
935 exit;
936 end;
937 path:=root;
938 if cancel_b then names[2]:='<CANCEL>';
939 rr:=get_dirs(path);
940 if cancel_b then max_r:=3; else max_r:=2;
941 while pos(rr,'|')<>-1 do
942 begin
943 pars:=pos(rr,'|');
944 names[max_r]:=copy(rr,0,pars-1);
945 rr:=copy(rr,pars+1,length(rr));
946 max_r:=max_r+1;
947 end;
948 max_r:=max_r-1;
950 repeat
951 updateKeys;
952 if clickedKey(KEY_FM_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=max_r; end;
953 if clickedKey(KEY_FM_DOWN) then begin m_cur:=m_cur+1; if m_cur>max_r then m_cur:=0; end;
954 if clickedKey(KEY_FM_SELECT) then
955 begin
956 if m_cur=0 then
957 begin
958 debug('path:'+path);
959 debug('lol:'+pos_end(path,'/'));
960 if (path=root) or (path=root+'/') then
961 begin
962 root:=getroot(cancel_b);
963 if root='' then
964 begin
965 filemanager:='';
966 exit;
967 end;
968 path:=root;
969 end;
970 else
971 begin
972 path:=copy(path,0,pos_end(path,'/'));
973 if cancel_b then names[2]:='<CANCEL>';
974 rr:=get_dirs(path);
975 if cancel_b then max_r:=3; else max_r:=2;
976 while pos(rr,'|')<>-1 do
977 begin
978 pars:=pos(rr,'|');
979 names[max_r]:=copy(rr,0,pars-1);
980 rr:=copy(rr,pars+1,length(rr));
981 max_r:=max_r+1;
982 end;
983 max_r:=max_r-1;
984 end;
985 end; else
986 if m_cur=1 then
987 begin
988 debug('<OK>');
989 filemanager:=path;
990 exit;
991 end; else
992 if (m_cur=2) and (cancel_b) then
993 begin
994 debug('<CANCEL>');
995 filemanager:='';
996 exit;
997 end; else
998 begin
999 path:=path+'/'+names[m_cur];
1001 if cancel_b then names[2]:='<CANCEL>';
1002 rr:=get_dirs(path);
1003 if cancel_b then max_r:=3; else max_r:=2;
1004 while pos(rr,'|')<>-1 do
1005 begin
1006 pars:=pos(rr,'|');
1007 names[max_r]:=copy(rr,0,pars-1);
1008 rr:=copy(rr,pars+1,length(rr));
1009 max_r:=max_r+1;
1010 end;
1011 max_r:=max_r-1;
1012 m_cur:=0;
1013 debug('path:'+path);
1014 end;
1015 end;
1017 for ix:=0 to getWidth/16 do
1018 for iy:=0 to getHeight/16 do
1019 drawimage(im,ix*16,iy*16);
1021 setcolor(0,0,0);
1022 fillrect(0,m_cur*8,getWidth-1,8);
1023 for ix:=0 to max_r do
1024 begin
1025 drawfonttext(names[ix],0,ix*8);
1026 end;
1027 setcolor(255,255,255);
1028 drawrect(0,m_cur*8,getWidth-1,8);
1030 drawVideo;
1031 delay(1);
1033 until false;
1034 end;
1036 procedure setsd(cancel_b:boolean);
1037 var
1038 s:string;
1039 t:integer;
1040 rs:recordstore;
1041 begin
1042 s:=filemanager(cancel_b);
1043 if s<>'' then
1044 begin
1045 sd:=s;
1046 if file_exists('/'+sd+'/cavecraft')<>1 then
1047 if create_folder('/'+sd+'/cavecraft')=1 then debug('/cavecraft created!');
1049 if file_exists('/'+sd+'/cavecraft/saves')<>1 then
1050 if create_folder('/'+sd+'/cavecraft/saves')=1 then debug('/saves created!');
1052 if file_exists('/'+sd+'/cavecraft/screenshots')<>1 then
1053 if create_folder('/'+sd+'/cavecraft/screenshots')=1 then debug('/screenshots created!');
1055 if file_exists('/'+sd+'/cavecraft/texturepacks')<>1 then
1056 if create_folder('/'+sd+'/cavecraft/texturepacks')=1 then debug('/texturepacks created!');
1058 deleteRecordStore('SD');
1059 rs:=openRecordStore('SD');
1060 t:=addRecordStoreEntry(rs,sd);
1061 closeRecordStore(rs);
1062 end;
1063 end;
1065 procedure start_uu;
1066 var
1067 rs:recordstore;
1068 ss:string;
1069 begin
1070 drawdeadlogo;
1071 //Load SD
1072 rs:=openRecordStore('SD');
1073 sd:=readRecordStoreEntry(rs,1);
1074 closeRecordStore(rs);
1075 console.exec('autoexec.cfg', 'AUTO', true);
1076 if sd='' then
1077 begin
1078 init_touch;
1079 if touchscreen then
1080 load_key_tex:=1;
1081 else
1082 load_key_tex:=0;
1083 //load_virt_tex(loadimage('/gui/touch.png'));
1084 setsd(false);
1085 end;
1087 if file_exists('/'+sd+'/cavecraft')<>1 then
1088 if create_folder('/'+sd+'/cavecraft')=1 then debug('/cavecraft created!');
1090 if file_exists('/'+sd+'/cavecraft/saves')<>1 then
1091 if create_folder('/'+sd+'/cavecraft/saves')=1 then debug('/saves created!');
1093 if file_exists('/'+sd+'/cavecraft/screenshots')<>1 then
1094 if create_folder('/'+sd+'/cavecraft/screenshots')=1 then debug('/screenshots created!');
1096 if file_exists('/'+sd+'/cavecraft/texturepacks')<>1 then
1097 if create_folder('/'+sd+'/cavecraft/texturepacks')=1 then debug('/texturepacks created!');
1099 rs:=openRecordStore('TX');
1100 ss:=readRecordStoreEntry(rs,1);
1101 closeRecordStore(rs);
1103 if ss<>'' then
1104 begin
1105 tex_pack:=ss;
1106 LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1107 loadtexture('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1108 end;
1109 else
1110 begin
1111 LoadDrawFont('/');
1112 loadtexture('/');
1113 end;
1114 end;
1116 function question(text:string):boolean;
1117 var
1118 ix,iy,m_cur:integer;
1119 begin
1120 repeat
1121 updateKeys;
1122 if clickedKey(KEY_MENU_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=1; end;
1123 if clickedKey(KEY_MENU_DOWN) then begin m_cur:=m_cur+1; if m_cur>1 then m_cur:=0; end;
1124 if clickedKey(KEY_MENU_SELECT) then begin if m_cur=0 then question:=true; else question:=false; exit; end;
1125 for ix:=0 to getwidth/16 do for iy:=0 to getheight/16 do drawimage(bg[0],ix*16,iy*16);
1126 drawfonttext(text,getwidth/2-(length(text)*8)/2,getheight/2-16);
1127 drw_btn('Yes',0,m_cur,0,1);
1128 drw_btn('No',1,m_cur,0,1);
1129 drawVideo;
1130 delay(1);
1131 until false;
1132 end;
1134 function menu_game_new:boolean;
1135 var
1136 m_cur,tmp_gm,ix,iy,lol:integer;
1137 tmp_cheats,tmp_bon_chest:boolean;
1138 newgametxt:array[0..4] of string;
1139 name,tmp:string;
1140 begin
1141 m_cur:=-2;
1142 newgametxt[0]:='Survival';
1143 newgametxt[1]:='Creative';
1144 newgametxt[2]:='Hardcore';
1145 newgametxt[3]:='Normal';
1146 newgametxt[4]:='Flat';
1147 name:='New World';
1148 repeat
1149 updateKeys;
1150 if clickedKey(KEY_MENU_UP) then begin m_cur:=m_cur-1; if m_cur<-2 then m_cur:=5; end;
1151 if clickedKey(KEY_MENU_DOWN) then begin m_cur:=m_cur+1; if m_cur>5 then m_cur:=-2; end;
1152 if clickedKey(KEY_MENU_SELECT) then
1153 begin
1154 if m_cur=-2 then
1155 begin
1156 name:=gettext('Name:',name,10,TF_ANY);
1157 end; else
1158 if m_cur=-1 then
1159 begin
1160 tmp_gm:=tmp_gm+1; if tmp_gm>2 then tmp_gm:=0;
1161 if tmp_gm=0 then tmp_cheats:=false;
1162 if tmp_gm=1 then tmp_cheats:=true;
1163 if tmp_gm=2 then begin tmp_cheats:=false; tmp_bon_chest:=false; end;
1164 end; else
1165 if m_cur=0 then
1166 begin
1167 nextseed:=stringtointeger(gettext('Seed:',''+nextseed,10,TF_NUMERIC));
1168 end; else
1169 if m_cur=1 then
1170 begin
1171 world_typ:=world_typ+1;
1172 if world_typ>1 then world_typ:=0;
1173 end; else
1174 if m_cur=2 then
1175 begin
1176 if tmp_gm<2 then tmp_cheats:= not tmp_cheats;
1177 end; else
1178 if m_cur=3 then
1179 begin
1180 if tmp_gm<2 then tmp_bon_chest:= not tmp_bon_chest;
1181 end; else
1182 if m_cur=4 then
1183 begin
1184 gamemode:=tmp_gm;
1185 cheats:=tmp_cheats;
1186 bon_chest:=tmp_bon_chest;
1187 tmp:=name;
1188 while file_exists('/'+sd+'/cavecraft/saves/'+name)=1 do
1189 begin
1190 lol:=lol+1;
1191 name:=tmp+' '+lol;
1192 end;
1193 sav_fl:=name;
1194 newgame;
1195 menu_game_new:=true;
1196 break;
1197 end; else
1198 if m_cur=5 then
1199 begin
1200 break;
1201 end; else
1202 end;
1203 for ix:=0 to getWidth/16 do
1204 for iy:=0 to getHeight/16 do
1205 drawimage(bg[0],ix*16,iy*16);
1207 drw_btn('Name:'+name,-2,m_cur,0,1);
1208 drw_btn('Mode:'+newgametxt[tmp_gm],-1,m_cur,0,1);
1209 drw_btn('Seed:'+nextseed,0,m_cur,0,1);
1210 drw_btn('Type:'+newgametxt[world_typ+3],1,m_cur,0,1);
1211 if tmp_gm<2 then
1212 drw_btn('Cheats:'+tmp_cheats,2,m_cur,0,1);
1213 else
1214 drw_btn('Cheats:'+tmp_cheats,2,m_cur,0,0);
1215 if tmp_gm<2 then
1216 drw_btn('Chest:'+tmp_bon_chest,3,m_cur,0,1);
1217 else
1218 drw_btn('Chest:'+tmp_bon_chest,3,m_cur,0,0);
1219 drw_btn('Create',4,m_cur,0,1);
1220 drw_btn('Cancel',5,m_cur,0,1);
1222 drawVideo;
1223 delay(1);
1224 until false;
1225 end;
1227 procedure deleteworld(path:string);
1228 begin
1229 if file_exists(path+'player.dat')=1 then delete_file(path+'player.dat');
1230 if file_exists(path+'world.sav')=1 then delete_file(path+'world.sav');
1231 if file_exists(path+'nether.sav')=1 then delete_file(path+'nether.sav');
1232 if file_exists(path+'pic.png')=1 then delete_file(path+'pic.png');
1233 if file_exists(path)=1 then delete_file(path);
1234 if file_exists(path)=0 then debug('World deleted!');
1235 end;
1237 function menu_game:boolean;
1238 var
1239 ix,iy,pars,max_r,cur_name,m_cur:integer;
1240 mm_t_b:boolean;
1241 im_game:image;
1242 rr:string;
1243 names:array[0..255] of string;
1244 begin
1245 rr:=get_dirs('/'+sd+'/cavecraft/saves/');
1246 while pos(rr,'|')<>-1 do
1247 begin
1248 pars:=pos(rr,'|');
1249 names[max_r]:=copy(rr,0,pars-1);
1250 rr:=copy(rr,pars+1,length(rr));
1251 if file_exists('/'+sd+'/cavecraft/saves/'+names[max_r]+'/player.dat')=1 then max_r:=max_r+1;
1252 end;
1253 max_r:=max_r-1;
1254 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1255 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1256 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1258 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/player.dat')=1 then
1259 mm_t_b:=true; else mm_t_b:=false;
1261 repeat
1262 updateKeys;
1263 if clickedKey(KEY_MENU_UP) then
1264 begin
1265 m_cur:=m_cur-1;
1266 if m_cur<0 then m_cur:=3;
1267 end;
1268 if clickedKey(KEY_MENU_DOWN) then
1269 begin
1270 m_cur:=m_cur+1;
1271 if m_cur>3 then m_cur:=0;
1272 end;
1274 if (max_r >= 0) and clickedKey(KEY_MENU_LEFT) then
1275 begin
1276 cur_name:=cur_name-1;
1277 if cur_name<0 then cur_name:=0;
1278 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1279 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1280 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1282 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/player.dat')=1 then
1283 end;
1284 if (max_r >= 0) and clickedKey(KEY_MENU_RIGHT) then
1285 begin
1286 cur_name:=cur_name+1;
1287 if cur_name>max_r then cur_name:=max_r;
1288 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1289 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1290 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1292 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/player.dat')=1 then
1293 end;
1294 if clickedKey(KEY_MENU_SELECT) then
1295 begin
1296 if m_cur=0 then
1297 begin
1298 if max_r>-1 then
1299 if loadgame('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/') then
1300 begin
1301 sav_fl:=names[cur_name];
1302 menu_game:=true;
1303 break;
1304 end;
1305 end; else
1306 if m_cur=1 then
1307 begin
1308 if menu_game_new then begin menu_game:=true; break; end;
1309 end; else
1310 if m_cur=2 then
1311 begin
1312 debug('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/');
1313 if max_r>-1 then
1314 if question('Are you sure?')=true then deleteworld('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/');
1315 cur_name:=0;
1316 max_r:=0;
1317 rr:=get_dirs('/'+sd+'/cavecraft/saves/');
1318 while pos(rr,'|')<>-1 do
1319 begin
1320 pars:=pos(rr,'|');
1321 names[max_r]:=copy(rr,0,pars-1);
1322 rr:=copy(rr,pars+1,length(rr));
1323 max_r:=max_r+1;
1324 end;
1325 max_r:=max_r-1;
1326 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1327 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1328 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1329 end; else
1330 if m_cur=3 then
1331 begin
1332 break;
1333 end;
1334 end;
1336 for ix:=0 to getWidth/16 do
1337 for iy:=1 to 7 do
1338 drawimage(bg[1],ix*16,iy*16);
1339 for ix:=0 to getWidth/16 do
1340 drawimage(bg[0],ix*16,0);
1341 for ix:=0 to getWidth/16 do
1342 for iy:=8 to getHeight/16 do
1343 drawimage(bg[0],ix*16,iy*16);
1345 if max_r>-1 then
1346 begin
1347 setcolor(0,0,0);
1348 fillrect(32,24,getWidth-64,96);
1349 setclip(32,24,getWidth-64,96);
1350 drawimage(im_game,(getWidth/2)-(32),32);
1351 drawfonttext(names[cur_name],(getWidth/2)-(length(names[cur_name])*8/2),104);
1352 setclip(0,0,getWidth,getHeight);
1353 setcolor(128,128,128);
1354 drawrect(32,24,getWidth-64,96);
1355 if cur_name>0 then drawimage(gui[20],0,58);
1356 if cur_name<max_r then drawimage(gui[21],getWidth-9,58);
1357 end;
1358 else
1359 begin
1360 setcolor(0,0,0);
1361 fillrect(32,24,getWidth-64,96);
1362 setclip(32,24,getWidth-64,96);
1363 drawfonttext('No saves!',(getWidth/2)-(length('No saves!')*8/2),104);
1364 setclip(0,0,getWidth,getHeight);
1365 setcolor(128,128,128);
1366 drawrect(32,24,getWidth-64,96);
1367 end;
1369 if mm_t_b then drw_btn('Play',0,m_cur,32,1); else drw_btn('Play',0,m_cur,32,0);
1370 drw_btn('Create new',1,m_cur,32,1);
1371 if mm_t_b then drw_btn('Delete',2,m_cur,32,1); else drw_btn('Delete',2,m_cur,32,0);
1372 drw_btn('Back',3,m_cur,32,1);
1373 if not mm_t_b then cur_name:=cur_name+1;
1375 drawVideo;
1376 delay(1);
1377 until false;
1378 end;
1380 procedure menu_tex;
1381 var
1382 ix,iy,pars,max_r,cur_name,m_cur,t:integer;
1383 im_game:image;
1384 rr:string;
1385 names:array[0..255] of string;
1386 rs:recordstore;
1387 begin
1388 rr:=get_dirs('/'+sd+'/cavecraft/texturepacks/');
1389 names[0]:='Default';
1390 max_r:=1;
1391 while pos(rr,'|')<>-1 do
1392 begin
1393 pars:=pos(rr,'|');
1394 names[max_r]:=copy(rr,0,pars-1);
1395 rr:=copy(rr,pars+1,length(rr));
1396 max_r:=max_r+1;
1397 end;
1398 max_r:=max_r-1;
1399 im_game:=loadimage('/pack.png');
1401 repeat
1402 updateKeys;
1403 if clickedKey(KEY_MENU_UP) then
1404 begin
1405 m_cur:=m_cur-1;
1406 if m_cur<0 then m_cur:=1;
1407 end;
1408 if clickedKey(KEY_MENU_DOWN) then
1409 begin
1410 m_cur:=m_cur+1;
1411 if m_cur>1 then m_cur:=0;
1412 end;
1414 if clickedKey(KEY_MENU_LEFT) then
1415 begin
1416 cur_name:=cur_name-1;
1417 if cur_name<0 then cur_name:=0;
1418 im_game:=ld_tex('pack.png','/'+sd+'/cavecraft/texturepacks/'+names[cur_name]+'/','');
1419 end;
1420 if clickedKey(KEY_MENU_RIGHT) then
1421 begin
1422 cur_name:=cur_name+1;
1423 if cur_name>max_r then cur_name:=max_r;
1424 im_game:=ld_tex('pack.png','/'+sd+'/cavecraft/texturepacks/'+names[cur_name]+'/','');
1425 end;
1426 if clickedKey(KEY_MENU_SELECT) then
1427 begin
1428 if m_cur=0 then begin
1429 if cur_name>0 then
1430 begin
1431 tex_pack:=names[cur_name];
1432 LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1433 loadtexture('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1434 deleteRecordStore('TX');
1435 rs:=openRecordStore('TX');
1436 t:=addRecordStoreEntry(rs,tex_pack);
1437 closeRecordStore(rs);
1438 end;
1439 else
1440 begin
1441 tex_pack:='';
1442 loadtexture('/');
1443 deleteRecordStore('TX');
1444 rs:=openRecordStore('TX');
1445 t:=addRecordStoreEntry(rs,'');
1446 closeRecordStore(rs);
1447 end;
1448 end;
1449 if m_cur=1 then break;
1450 break;
1451 end;
1453 for ix:=0 to getWidth/16 do
1454 for iy:=1 to 7 do
1455 drawimage(bg[1],ix*16,iy*16);
1456 for ix:=0 to getWidth/16 do
1457 drawimage(bg[0],ix*16,0);
1458 for ix:=0 to getWidth/16 do
1459 for iy:=8 to getHeight/16 do
1460 drawimage(bg[0],ix*16,iy*16);
1462 if max_r>-1 then
1463 begin
1464 setcolor(0,0,0);
1465 fillrect(32,24,getWidth-64,96);
1466 setclip(32,24,getWidth-64,96);
1467 drawimage(im_game,(getWidth/2)-(32),32);
1468 drawfonttext(names[cur_name],(getWidth/2)-(length(names[cur_name])*8/2),104);
1469 setclip(0,0,getWidth,getHeight);
1470 setcolor(128,128,128);
1471 drawrect(32,24,getWidth-64,96);
1472 if cur_name>0 then drawimage(gui[20],0,58);
1473 if cur_name<max_r then drawimage(gui[21],getWidth-9,58);
1474 end;
1476 drw_btn('Done',0,m_cur,32,1);
1477 drw_btn('Back',1,m_cur,32,1);
1479 drawVideo;
1480 delay(1);
1481 until false;
1482 end;
1484 procedure menu_sett;
1485 var
1486 ix,iy,m_cur:integer;
1487 begin
1488 m_cur:=-3;
1489 repeat
1490 updateKeys;
1491 if clickedKey(KEY_MENU_UP) then
1492 begin
1493 m_cur:=m_cur-1;
1494 if m_cur<-3 then m_cur:=5;
1495 end;
1496 if clickedKey(KEY_MENU_DOWN) then
1497 begin
1498 m_cur:=m_cur+1;
1499 if m_cur>5 then m_cur:=-3;
1500 end;
1501 if clickedKey(KEY_MENU_SELECT) then
1502 begin
1503 if m_cur=-3 then
1504 begin
1505 light_type:=light_type+1;
1506 if light_type>2 then light_type:=0;
1507 end; else
1508 if m_cur=-2 then
1509 begin
1510 ifosad:=not ifosad;
1511 end; else
1512 if m_cur=-1 then
1513 begin
1514 s_particles:=not s_particles;
1515 end; else
1516 if m_cur=0 then
1517 begin
1518 drawgui:=not drawgui;
1519 end; else
1520 if m_cur=1 then
1521 begin
1522 if question('Are you sure?')=true then
1523 begin
1524 if load_key_tex=0 then
1525 begin
1526 load_key_tex:=1;
1527 init_touch;
1528 //load_virt_tex(ld_tex('touch.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','gui/'));
1529 end;
1530 else
1531 if load_key_tex=1 then
1532 begin
1533 load_key_tex:=0;
1534 resetVirtualKeyboard(-1);
1535 end;
1536 end;
1537 end;
1538 if m_cur=2 then
1539 begin
1540 s_jpeg_quality:=stringtointeger(gettext('JPEG quality:',''+s_jpeg_quality,3,TF_NUMERIC));
1541 if s_jpeg_quality>100 then s_jpeg_quality:=100; else
1542 if s_jpeg_quality<0 then s_jpeg_quality:=0;
1543 end; else
1544 if m_cur=3 then
1545 begin
1546 setsd(true);
1547 end; else
1548 if m_cur=4 then
1549 begin
1550 deleteRecordStore('S');
1551 deleteRecordStore('SD');
1552 deleteRecordStore('TX');
1553 halt;
1554 end; else
1555 if m_cur=5 then
1556 begin
1557 save_settings;
1558 break;
1559 end; else
1560 end;
1562 for ix:=0 to getWidth/16 do
1563 for iy:=0 to getHeight/16 do
1564 drawimage(bg[0],ix*16,iy*16);
1566 drw_btn('Light:'+light_type,-3,m_cur,0,1);
1567 drw_btn('Weather:'+ifosad,-2,m_cur,0,1);
1568 drw_btn('Particles:'+s_particles,-1,m_cur,0,1);
1569 drw_btn('Hide GUI:'+not drawgui,0,m_cur,0,1);
1570 drw_btn('Touch:'+(load_key_tex>0),1,m_cur,0,1);
1571 drw_btn('JPEG:'+s_jpeg_quality,2,m_cur,0,1);
1572 drw_btn('Set Root',3,m_cur,0,1);
1573 drw_btn('Reset',4,m_cur,0,1);
1574 drw_btn('Back',5,m_cur,0,1);
1576 drawVideo;
1577 delay(1);
1578 until false;
1579 end;
1581 procedure menu_help;
1582 var
1583 ix,iy,cur:integer;
1584 begin
1585 repeat
1586 updateKeys;
1587 if clickedKey(KEY_MENU_SELECT) then break;
1588 if pressedKey(KEY_MENU_UP) then cur:=cur+1;
1589 if pressedKey(KEY_MENU_DOWN) then cur:=cur-1;
1591 for ix:=0 to getWidth/16 do
1592 for iy:=2 to (getHeight/16)-2 do
1593 drawimage(bg[1],ix*16,iy*16);
1595 for ix:=0 to getWidth/16 do
1596 for iy:=0 to 1 do
1597 drawimage(bg[0],ix*16,iy*16);
1599 for ix:=0 to getWidth/16 do
1600 for iy:=(getHeight/16)-2 to getHeight/16 do
1601 drawimage(bg[0],ix*16,iy*16);
1603 setclip(0,32,getWidth,(getHeight/16-4)*16);
1605 drw_txt('Controls:',cur,0,1);
1606 drw_txt('Left - Move left',cur,1,0);
1607 drw_txt('Right - Move right',cur,2,0);
1608 drw_txt('Up - Jump',cur,3,0);
1609 drw_txt('Down - Put a block under you',cur,4,0);
1610 drw_txt('1 - Inventory',cur,5,0);
1611 drw_txt('Duble 1 - Craft',cur,6,0);
1612 drw_txt('3 - Use block',cur,7,0);
1613 drw_txt('7 - Debug info',cur,8,0);
1614 drw_txt('Hold 7 - Console',cur,9,0);
1615 drw_txt('9 - Pause',cur,10,0);
1616 drw_txt('*, # - Browse inventory',cur,11,0);
1617 drw_txt('0 - Edit mode',cur,12,0);
1619 drw_txt('In inventory/chest:',cur,14,1);
1620 drw_txt('3 - Enject object',cur,15,0);
1621 drw_txt('Hold 3 - Enject stack',cur,16,0);
1622 drw_txt('5 - Move the stack',cur,17,0);
1623 drw_txt('Hold 5 - Divide stack',cur,18,0);
1625 setclip(0,0,getWidth,getHeight);
1627 drw_btn('Back',0,0,getHeight-getHeight/2-16-6,1);
1629 drawVideo;
1630 delay(1);
1631 until false;
1632 end;
1634 procedure menu_about;
1635 var
1636 ix,iy,cur:integer;
1637 begin
1638 repeat
1639 updateKeys;
1640 if clickedKey(KEY_MENU_SELECT) then break;
1641 if pressedKey(KEY_MENU_UP) then cur:=cur+1;
1642 if pressedKey(KEY_MENU_DOWN) then cur:=cur-1;
1644 for ix:=0 to getWidth/16 do
1645 for iy:=2 to (getHeight/16)-2 do
1646 drawimage(bg[1],ix*16,iy*16);
1648 for ix:=0 to getWidth/16 do
1649 for iy:=0 to 1 do
1650 drawimage(bg[0],ix*16,iy*16);
1652 for ix:=0 to getWidth/16 do
1653 for iy:=(getHeight/16)-2 to getHeight/16 do
1654 drawimage(bg[0],ix*16,iy*16);
1656 setclip(0,32,getWidth,(getHeight/16-4)*16);
1658 drw_txt('Developers:',cur,0,1);
1659 drw_txt(#68+#101+#97+#68+#68+#111+#111+#77+#69+#82+' - Programmer',cur,1,0);//dead
1660 drw_txt(#102+#114+#101+#100+#45+#98+#111+#121+' - Programmer',cur,2,0);//fred-boy
1661 drw_txt(#65+#110+#100+#114+#101+#121+#53+#57+' - Programmer',cur,3,0);//andrey59
1662 drw_txt(#89+#117+#82+#97+#78+#110+#78+#122+#90+#90+' - Artist',cur,4,0);//yura
1663 drw_txt(#83+#97+#115+#104+#97+#71+' - Artist and idea generator',cur,5,0);//sasha
1664 drw_txt(#66+#97+#74+#108+#101+#72+#84+#105+#72+' - Artist and tester',cur,6,0);//valentin
1665 drw_txt(#65+#103+#114+#101+#115+#115+#111+#82+' - Tester',cur,7,0);//agressor
1666 drw_txt(#118+#111+#108+#121+#97+#95+#110+#97+#115+#116+#97+#110+#101+' - Tester',cur,8,0);//volya
1667 drw_txt(#97+#98+#97+#100+#111+#110+' - Tester',cur,9,0);//abadon
1668 drw_txt(#77+#111+#110+#111+#103+#114+#111+#109+' - Tester',cur,10,0);//monogrom
1669 drw_txt(#75+#97+#108+#116+#101+#114+' - Tester',cur,11,0);//kalter
1671 drw_txt('Thanks:',cur,12,1);
1672 drw_txt('Piligrim and 0vZ - Lib_jsr75i',cur,13,0);
1673 drw_txt('Piligrim - Lib_effects',cur,14,0);
1674 drw_txt('Kurdt - Lib_canvas',cur,15,0);
1675 drw_txt('ViNT - Lib_png and Lib_bmp',cur,16,0);
1676 drw_txt('aleshka - Lib_jpeg',cur,17,0);
1677 drw_txt('Roman_V - Lib_safeload',cur,18,0);
1679 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);
1680 drw_txt(#68+#101+#97+#68+#83+#111+#102+#116+#87+#97+#114+#101+' 2012-'+getyear(getcurrenttime),cur,22,0);
1682 drw_txt('Hello! :D',cur,100,1);
1684 setclip(0,0,getWidth,getHeight);
1686 drw_btn('Back',0,0,getHeight-getHeight/2-16-6,1);
1688 drawVideo;
1689 delay(1);
1690 until false;
1691 end;
1693 function sm_siz:integer;
1694 begin
1695 sm_siz:=(getWidth+getHeight)/5;
1696 end;
1698 function sm_siz4:integer;
1699 begin
1700 sm_siz4:=sm_siz/4;
1701 end;
1703 procedure draw_menu_back;
1704 var
1705 ix, iy:integer;
1706 begin
1707 for ix:=0 to getWidth/16 do
1708 for iy:=0 to getHeight/16 do
1709 drawimage(bg[0],ix*16,iy*16);
1710 end;
1712 procedure menu;
1713 var
1714 m_cur,ix,iy,iz:integer;
1715 key,spl_i:integer;
1716 splash:string;
1717 res:resource;
1718 time:integer;
1719 cavelogo:image;
1720 spl_y,spl_del:integer;
1721 spl_y_b:boolean;
1722 begin
1723 cavelogo:=ld_tex('cavelogo.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','title/');
1724 splash:='#ERROR';
1725 spl_y:=getimageheight(cavelogo);
1726 spl_y_b:=true;
1727 spl_del:=getrelativetimems;
1728 res:=openResource('/title/splashes.txt');
1729 if ResourceAvailable(res) then
1730 begin
1731 spl_i:=stringtointeger(readline(res));
1732 iy:=random(spl_i-1)+1;
1733 debug('SPLASH #'+iy);
1734 for ix:=1 to iy do
1735 splash:=readline(res);
1736 closeresource(res);
1737 end;
1738 time:=getcurrenttime;
1739 if (getmonth(time)=5) and (getday(time)=7) then splash:='Happy birthday, DeaDDooMER!';
1740 if ((getmonth(time)=0) and (getday(time)<3)) or ((getmonth(time)=11) and (getday(time)>29)) then splash:='Happy New Year!';
1741 repeat
1742 proc_fps;
1743 updateKeys;
1744 if clickedKey(KEY_MENU_UP) then
1745 begin
1746 m_cur:=m_cur-1;
1747 if m_cur<0 then m_cur:=5;
1748 end;
1749 if clickedKey(KEY_MENU_DOWN) then
1750 begin
1751 m_cur:=m_cur+1;
1752 if m_cur>5 then m_cur:=0;
1753 end;
1754 if clickedKey(KEY_MENU_SELECT) then
1755 begin
1756 if m_cur=0 then begin if menu_game then break; end;
1757 else
1758 if m_cur=1 then menu_tex;
1759 else
1760 if m_cur=2 then menu_sett;
1761 else
1762 if m_cur=3 then menu_help;
1763 else
1764 if m_cur=4 then menu_about;
1765 else
1766 if m_cur=5 then begin save_settings; halt; end;
1767 end;
1769 draw_menu_back;
1771 drawimage(cavelogo,(getWidth/2)-(getimagewidth(cavelogo)/2),0);
1772 setcolor(255,255,0);
1774 DrawFontTextSpec(splash, (getWidth/2)-(length(splash)*FONT_SYM_SIZE/2), spl_y, FONT_YELLOW_COLOR, true);
1776 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;
1777 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;
1778 drawfonttext(version,0,getHeight-8);
1780 drw_btn('Singleplayer',0,m_cur,0,1);
1781 drw_btn('Texture Packs',1,m_cur,0,1);
1782 drw_btn('Options',2,m_cur,0,1);
1783 drw_btn('Help',3,m_cur,0,1);
1784 drw_btn('About',4,m_cur,0,1);
1785 drw_btn('Quit Game',5,m_cur,0,1);
1787 drawVideo;
1788 maxfps;
1789 until false;
1790 end;
1792 function setBlock(invcur, x, y:integer):boolean;
1793 var
1794 item, sum, block, sblock:integer;
1795 begin
1796 item:=inv.getItem(invcur);
1797 sum:=inv.getSum(invcur);
1798 block:=getMap(x, y);
1799 sblock:=getItemInfo(item);
1801 if getItemType(item)=ITEM_TYPE_BLOCK then
1802 if inv.isNull(invcur)=false then
1803 if getBlockSet(block)=true then
1804 // if (coll_xy(x, y)=false) or (getBlockColl(item)=0) then
1805 begin
1806 if set_block_code(sblock, x, y)=false then
1807 begin
1809 setmap(sblock, x, y);
1810 if gamemode<>1 then
1811 begin
1812 inv.setSum(inv.getSum(invcur)-1, invcur);
1813 inv.fixNull(invcur);
1814 end;
1816 setBlock:=true;
1817 end;
1818 end;
1819 end;
1821 procedure fishing;
1822 var
1823 x, y:integer;
1824 begin
1825 x:=player.getX;
1826 y:=player.getY;
1827 if (getrelativetimems-fish_time>5000) and (getmap(fx,fy)=50) then
1828 begin
1829 if (random(3)=2) and (getmap(fx,fy)=50) then
1830 begin
1831 drop.create(210,1,x,y);
1832 fish:=false;
1833 end;
1834 inv.setSum(inv.getSum(invslot)-1, invslot);
1835 inv.fixNull(invslot);
1836 fish:=false;
1837 end; else
1838 if (getrelativetimems-fish_time<5000) and (getmap(fx,fy)=50) and (fish=true) then
1839 begin
1840 if getmap(fx,fy-1)=50 then fy:=fy-1;
1841 end;
1842 end;
1844 procedure drawminimap;
1845 var
1846 ix,iy,tmp_gx,tmp_gy,minx,miny,maxx,maxy,loc_camx,loc_camy,x,y:integer;
1847 begin
1848 x:=player.getX;
1849 y:=player.getY;
1850 if load_minimap_tex then
1851 begin
1852 tmp_gx:=(getWidth/2)-(getimagewidth(gui[16])/2);
1853 tmp_gy:=(getHeight/2)-(getimageheight(gui[16])/2);
1854 end;
1855 else
1856 begin
1857 tmp_gx:=(getWidth/2)-(64/2);
1858 tmp_gy:=(getHeight/2)-(64/2);
1859 end;
1861 loc_camx:=(x+4)-(864/2);
1862 loc_camy:=(y+4)-(864/2);
1863 if loc_camx<0 then loc_camx:=0;
1864 if loc_camx>4096-864 then loc_camx:=4096-864;
1865 if loc_camy<0 then loc_camy:=0;
1866 if loc_camy>2048-864 then loc_camy:=2048-864;
1867 minx:=loc_camx/16;
1868 miny:=loc_camy/16;
1869 maxx:=(loc_camx+864)/16;
1870 maxy:=(loc_camy+864)/16;
1871 if minx<0 then minx:=0;
1872 if miny<0 then miny:=0;
1873 if maxx>255 then maxx:=255;
1874 if maxy>127 then maxy:=127;
1876 if load_minimap_tex then
1877 drawimage(gui[16],tmp_gx,tmp_gy);
1878 else
1879 begin
1880 setcolor(214,190,150);
1881 fillrect(tmp_gx,tmp_gy,64,64);
1882 end;
1884 for ix:=minx to maxx do
1885 for iy:=miny to maxy do
1886 begin
1887 if (getmap(ix,iy)=1) or (getmap(ix,iy)=2) or (getmap(ix,iy)=74) then setcolor(121,85,58); else
1888 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
1889 if (getmap(ix,iy)=50) or (getmap(ix,iy)=62) then setcolor(38,92,255); else
1890 if getmap(ix,iy)=51 then setcolor(255,0,0); else
1891 if (getmap(ix,iy)=61) or (getmap(ix,iy)=32) then setcolor(255,255,255); else
1892 setcolor(127,127,127);
1894 if (getmap(ix,iy)<>0) then plot(tmp_gx+4+ix-minx,tmp_gy+4+iy-miny);
1895 end;
1896 setcolor(0,0,255);
1897 end;
1899 procedure draw_sign;
1900 var
1901 tmp:string;
1902 str:array[0..3] of string;
1903 i,j,tmp_gx,tmp_gy:integer;
1904 begin
1905 if load_gui_tex then
1906 begin
1907 tmp_gx:=(getWidth/2)-(getimagewidth(sign_im)/2);
1908 tmp_gy:=(getHeight/2)-(getimageheight(sign_im)/2);
1909 end;
1910 else
1911 begin
1912 tmp_gx:=(getWidth/2)-(120/2);
1913 tmp_gy:=(getHeight/2)-(60/2);
1914 end;
1916 tmp:=t_sign[getmapinfo(curx,cury)];
1917 while pos(tmp,#13)<>-1 do
1918 begin
1919 i:=pos(tmp,#13);
1920 str[j]:=copy(tmp,0,i);
1921 tmp:=copy(tmp,i+1,length(tmp));
1922 j:=j+1;
1923 end;
1925 if load_gui_tex then
1926 drawimage(sign_im,tmp_gx,tmp_gy);
1927 else
1928 begin
1929 setcolor(159,132,77);
1930 fillrect(tmp_gx,tmp_gy,120,60);
1931 end;
1933 drawfonttext(str[0],tmp_gx+(120/2)-(length(str[0])*8/2),tmp_gy+(60/4/2)+4);
1934 drawfonttext(str[1],tmp_gx+(120/2)-(length(str[1])*8/2),tmp_gy+(60/4/2)+8+4);
1935 drawfonttext(str[2],tmp_gx+(120/2)-(length(str[2])*8/2),tmp_gy+(60/4/2)+16+4);
1936 drawfonttext(str[3],tmp_gx+(120/2)-(length(str[3])*8/2),tmp_gy+(60/4/2)+24+4);
1937 end;
1939 procedure draw_back(ix,iy:integer);
1940 begin
1941 if getBiomMap(ix)=0 then
1942 begin
1943 if (getBackMap(ix)=iy) then drawimage(back[0],(ix*16)-camx,(iy*16)-camy); else
1944 if (getBackMap(ix)+1=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1945 if (getBackMap(ix)+2=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1946 if (getBackMap(ix)+3=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1947 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1948 end; else
1949 if getBiomMap(ix)=1 then
1950 begin
1951 if (getBackMap(ix)=iy) then drawimage(back[4],(ix*16)-camx,(iy*16)-camy); else
1952 if (getBackMap(ix)+1=iy) then drawimage(back[4],(ix*16)-camx,(iy*16)-camy); else
1953 if (getBackMap(ix)+2=iy) then drawimage(back[6],(ix*16)-camx,(iy*16)-camy); else
1954 if (getBackMap(ix)+3=iy) then drawimage(back[6],(ix*16)-camx,(iy*16)-camy); else
1955 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1956 end; else
1957 if getBiomMap(ix)=2 then
1958 begin
1959 if (getBackMap(ix)=iy) then drawimage(back[5],(ix*16)-camx,(iy*16)-camy); else
1960 if (getBackMap(ix)+1=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1961 if (getBackMap(ix)+2=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1962 if (getBackMap(ix)+3=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1963 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1964 end; else
1965 if getBiomMap(ix)=3 then
1966 begin
1967 if (getBackMap(ix)=iy) then drawimage(back[7],(ix*16)-camx,(iy*16)-camy); else
1968 if (getBackMap(ix)+1=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1969 if (getBackMap(ix)+2=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1970 if (getBackMap(ix)+3=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1971 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1972 end; else
1973 if getBiomMap(ix)=4 then
1974 begin
1975 drawimage(back[8],(ix*16)-camx,(iy*16)-camy);
1976 end;
1977 end;
1979 procedure draw;
1980 var
1981 ix,iy,iz,minx,miny,maxx,maxy,tmp_ax,tim,smy,pa_xo, x, y:integer;
1982 begin
1983 x:=player.getX;
1984 y:=player.getY;
1985 {===================[sky]===================}
1986 tim:=10000*getimagewidth(sky)/600000*game_time/10000;
1987 setcolor(effects.get(sky,tim,0,1),effects.get(sky,tim,0,2),effects.get(sky,tim,0,3));
1988 fillrect(0,0,getWidth,getHeight);
1989 srand(seed);
1990 if drw_stars then
1991 begin
1992 setcolor(effects.get(sky,tim,2,1),effects.get(sky,tim,2,2),effects.get(sky,tim,2,3));
1993 smy:=10000*getWidth*2/600000*game_time/10000;
1994 for iz:=1 to getWidth do
1995 begin
1996 ix:=rnd(getWidth*2)-getWidth+smy;
1997 if ix>getWidth then ix:=ix-getWidth*2;
1998 iy:=rnd(getHeight);
1999 if (ix>-1) and (ix<getWidth) then plot(ix,iy);
2000 end;
2001 end;
2003 if drw_sm then
2004 begin
2005 if load_sm>0 then
2006 begin
2007 smy:=10000*(getWidth+getimagewidth(sun))/300000*game_time/10000;
2008 drawimage(sun,smy-getimagewidth(sun),getHeight/2-getimageheight(sun)/2);
2009 end;
2010 else
2011 begin
2012 setcolor(255,213,74);
2013 smy:=10000*(getWidth+sm_siz)/300000*game_time/10000;
2014 fillrect(smy-sm_siz+sm_siz4,getHeight/2-sm_siz/2+sm_siz4,sm_siz-sm_siz4,sm_siz-sm_siz4);
2015 end;
2017 if load_sm>0 then
2018 begin
2019 smy:=10000*(getWidth+getimagewidth(moon))/300000*(game_time-300000)/10000;
2020 drawimage(moon,smy-getimagewidth(moon),getHeight/2-getimageheight(moon)/2);
2021 end;
2022 else
2023 begin
2024 setcolor(175,184,204);
2025 smy:=10000*(getWidth+sm_siz)/300000*(game_time-300000)/10000;
2026 fillrect(smy-sm_siz+sm_siz4,getHeight/2-sm_siz/2+sm_siz4,sm_siz-sm_siz4,sm_siz-sm_siz4);
2027 end;
2028 end;
2029 {===================[camera]===================}
2030 camx:=(x+4)-(getWidth/2);
2031 camy:=(y+4)-(getHeight/2);
2032 if camx<0 then camx:=0;
2033 if camx>4096-getWidth then camx:=4096-getWidth;
2034 if camy>2048-getHeight then camy:=2048-getHeight;
2035 {===================[max_draw]===================}
2036 minx:=camx/16;
2037 miny:=camy/16;
2038 maxx:=(camx+getWidth)/16;
2039 maxy:=(camy+getHeight)/16;
2040 if minx<0 then minx:=0;
2041 if miny<0 then miny:=0;
2042 if maxx>255 then maxx:=255;
2043 if maxy>127 then maxy:=127;
2044 {===================[draw_back]===================}
2045 for ix:=minx to maxx do
2046 for iy:=miny to maxy do
2047 begin
2048 if ifosad then if (getBackMap(ix)>=iy) and (osadki=true) and getBlockTrans(getmap(ix,iy)) then
2049 begin
2050 if getBiomMap(ix)=0 then drawimage(osad[0,osadki_ani],(ix*16)-camx,(iy*16)-camy);
2051 else
2052 if getBiomMap(ix)=2 then drawimage(osad[1,osadki_ani],(ix*16)-camx,(iy*16)-camy);
2053 else
2054 if getBiomMap(ix)=3 then drawimage(osad[0,osadki_ani],(ix*16)-camx,(iy*16)-camy);
2055 end;
2056 if drw_back then
2057 if getBlockTrans(getmap(ix,iy)) then
2058 draw_back(ix,iy);
2060 if getBlockFore(getmap(ix,iy))=false then
2061 draw_block(ix,iy);
2062 end;
2063 {===================[drop]===================}
2064 drop.draw(camx, camy);
2065 {===================[particles]===================}
2066 if s_particles then draw_particle;
2067 {===================[player]===================}
2068 if hp>0 then
2069 begin
2070 player.draw(camx, camy);
2071 end;
2073 {===================[mobs]===================}
2074 mob.draw(camx, camy);
2075 {===================[draw_blocks]===================}
2076 for ix:=minx to maxx do
2077 for iy:=miny to maxy do
2078 begin
2079 if getBlockFore(getmap(ix,iy))=true then
2080 draw_block(ix,iy);
2082 setcolor(0,0,0);
2083 if (light_type=1) then begin if getmaplight(ix,iy)=0 then fillrect((ix*16)-camx,(iy*16)-camy,16,16); end;
2084 else
2085 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;
2086 end;
2087 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;
2088 {===================[gui]===================}
2089 if drawgui then
2090 begin
2091 tmp_ax:=(getWidth/2)-(getImageWidth(gui[1])/2);
2093 if keymode=1 then
2094 drawimage(gui[0],curx*16-camx,cury*16-camy);
2096 DrawWindows;
2097 /*if keymode=2 then
2098 if gamemode<>1 then
2099 DrawPlayerInventory;
2100 else
2101 drawinv_c; else
2102 if keymode=3 then drawcraft; else
2103 if keymode=4 then drawchest; else
2104 if keymode=5 then draw_sign; else
2105 if keymode=6 then drawfurnace; else
2106 if ifminimap then drawminimap;*/
2108 drawimage(gui[1],tmp_ax,0);
2109 for ix:=0 to 8 do
2110 begin
2111 drawItem(inv.getItem(ix), inv.getSum(ix), (ix*16)+tmp_ax+ix*2+4, 1, true);
2112 end;
2113 drawimage(gui[17],(invslot*16)+tmp_ax+invslot*2+2,0);
2115 if gamemode<>1 then
2116 begin
2117 if gamemode=0 then
2118 begin
2119 for ix:=0 to (hp div 2)-1 do drawimage(gui[13],ix*9,getHeight-9);
2120 if (hp mod 2)<>0 then begin drawimage(gui[14],ix*9,getHeight-9); ix:=ix+1 end;
2121 for ix:=ix to 9 do drawimage(gui[15],ix*9,getHeight-9);
2122 end; else
2123 if gamemode=2 then
2124 begin
2125 for ix:=0 to (hp div 2)-1 do drawimage(gui[31],ix*9,getHeight-9);
2126 if (hp mod 2)<>0 then begin drawimage(gui[32],ix*9,getHeight-9); ix:=ix+1 end;
2127 for ix:=ix to 9 do drawimage(gui[33],ix*9,getHeight-9);
2128 end;
2130 for ix:=0 to (hunger div 2)-1 do drawimage(gui[26],ix*9,getHeight-18);
2131 if (hunger mod 2)<>0 then begin drawimage(gui[27],ix*9,getHeight-18); ix:=ix+1 end;
2132 for ix:=ix to 9 do drawimage(gui[28],ix*9,getHeight-18);
2134 if getmap((x+4)/16,y/16)=50 then
2135 begin
2136 for ix:=0 to (air div 2)-1 do drawimage(gui[29],ix*9,getHeight-27);
2137 if (air mod 2)<>0 then begin drawimage(gui[30],ix*9,getHeight-27); ix:=ix+1 end;
2138 end;
2139 end;
2141 for ix:=0 to 3 do
2142 begin
2143 drawfonttext(msg[ix],0,getHeight-20-ix*9);
2144 if getrelativetimems-msg_time[ix]>5000 then msg[ix]:='';
2145 end;
2146 end;
2147 end;
2149 procedure load_moon(path:string;phase:integer);
2150 var
2151 no:image;
2152 begin
2153 moon:=no;
2154 if load_sm=1 then
2155 begin
2156 moon:=ld_tex('moon_phase_'+phase+'.png',path,'terrain/moon_phases/');
2157 end; else
2158 if load_sm=2 then
2159 begin
2160 moon:=resize_image(ld_tex('moon_phase_'+phase+'.png',path,'terrain/moon_phases/'),(getWidth+getHeight)/5,(getWidth+getHeight)/5);
2161 end;
2162 end;
2164 procedure sleep;
2165 var
2166 i,ix,iy:integer;
2167 begin
2168 if game_time>300000 then
2169 begin
2170 if load_light_tex then
2171 begin
2172 keymode:=0;
2173 i:=15;
2174 while i>0 do
2175 begin
2176 for iy:=0 to getheight/16 do
2177 for ix:=0 to getwidth/16 do
2178 drawimage(light[i],ix*16,iy*16);
2179 i:=i-1;
2180 drawVideo;
2181 delay(100);
2182 end;
2183 moon_phase:=moon_phase+1;
2184 if moon_phase>7 then moon_phase:=0;
2185 load_moon('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/',moon_phase);
2186 game_time:=50000;
2187 last_sleep_x:=curx;
2188 last_sleep_y:=cury-1;
2189 i:=1;
2190 while i<15 do
2191 begin
2192 draw;
2193 for iy:=0 to getheight/16 do
2194 for ix:=0 to getwidth/16 do
2195 drawimage(light[i],ix*16,iy*16);
2196 i:=i+1;
2197 drawVideo;
2198 delay(100);
2199 end;
2200 end;
2201 else
2202 begin
2203 keymode:=0;
2204 i:=0;
2205 while i<=getheight do
2206 begin
2207 setcolor(0,0,0);
2208 fillrect(0,0,getwidth,i);
2209 i:=i+5;
2210 drawVideo;
2211 delay(50);
2212 end;
2213 moon_phase:=moon_phase+1;
2214 if moon_phase>7 then moon_phase:=0;
2215 load_moon('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/',moon_phase);
2216 game_time:=50000;
2217 last_sleep_x:=curx;
2218 last_sleep_y:=cury-1;
2219 i:=0;
2220 while i<=getheight do
2221 begin
2222 draw;
2223 setcolor(0,0,0);
2224 fillrect(0,i,getwidth,getheight);
2225 i:=i+5;
2226 drawVideo;
2227 delay(50);
2228 end;
2229 end;
2230 end; else create_msg('You can sleep only at night');
2231 end;
2233 procedure resetToolProgerss;
2234 begin
2235 toolus:=0;
2236 toolind:=0;
2237 end;
2239 procedure usetools(invcur, x, y:integer);
2240 var
2241 item, sum, block:integer;
2242 begin
2243 block:=getmap(x, y);
2244 item:=inv.getItem(invcur);
2245 sum:=inv.getSum(invcur);
2247 if gamemode=1 then
2248 destroy_block_cr(block, x, y);
2249 else
2250 if (block>0) then
2251 begin
2252 if (getItemType(item)=ITEM_TYPE_TOOL) and (getBlockTool(block)=getToolType(item)) then
2253 toolus:=toolus+getToolSpeed(item);
2254 else
2255 toolus:=toolus+1;
2257 if toolus>=getBlockHP(block) then
2258 begin
2259 if ((getItemType(item)=ITEM_TYPE_TOOL) and (getBlockTool(block)=getToolType(item)) and (getToolLvl(item)>=getBlockLvl(block))) or (getBlockLvl(block)<=0) then
2260 begin
2261 setMap(0, x, y);
2262 destroy_block_1(block, x, y);
2263 setMapInfo(0, x, y);
2264 end;
2265 else
2266 begin
2267 setMap(0, x, y);
2268 destroy_block_0(block, x, y);
2269 setMapInfo(0, x, y);
2270 end;
2272 if getItemType(item)=ITEM_TYPE_TOOL then
2273 begin
2274 inv.setSum(inv.getSum(invcur)-1, invcur);
2275 inv.fixNull(invcur);
2276 end;
2278 toolus:=0;
2279 toolind:=0;
2280 end;
2281 end;
2283 if (toolus>0) and (toolus<=getBlockHP(block)) then
2284 toolind:=((toolus*100) div getBlockHP(block)) div 10;
2285 end;
2287 function rt_useweap:boolean;
2288 var
2289 x, y, w, h, i, damg:integer;
2290 item:integer;
2291 begin
2292 x:=player.getX;
2293 y:=player.getY;
2294 w:=player.getW;
2295 h:=player.getH;
2296 item:=inv.getItem(invslot);
2298 if getItemType(item)=1 then
2299 damg:=getToolDamg(item);
2300 else
2301 damg:=1;
2303 if posi=0 then
2304 i:=mob.findAndHit(damg, x-TILE_SIZE, y, TILE_SIZE+(w/2), h, -2, -3);
2305 else
2306 i:=mob.findAndHit(damg, x+(w/2), y, TILE_SIZE+(w/2), h, 2, -3);
2308 if i<>-1 then
2309 begin
2310 inv.setSum(inv.getSum(invslot)-1, invslot);
2311 inv.fixNull(invslot);
2312 rt_useweap:=true;
2313 end;
2314 end;
2316 procedure rt_usetools;
2317 var
2318 x, y:integer;
2319 begin
2320 x:=player.getX;
2321 y:=player.getY;
2323 if posi=0 then curx:=(x div 16)-1; else curx:=(x div 16)+1;
2324 cury:=y div 16;
2325 if getmap(curx,cury)=0 then cury:=cury+1;
2327 if curx<0 then curx:=0;
2328 if curx>255 then curx:=255;
2329 if cury<0 then cury:=0;
2330 if cury>127 then cury:=127;
2332 usetools(invslot, curx, cury);
2333 end;
2335 procedure rt_usemob;
2336 var
2337 x, y:integer;
2338 begin
2339 x:=player.getX;
2340 y:=player.getY;
2342 if posi=0 then curx:=(x div 16)-1; else curx:=(x div 16)+1;
2343 cury:=y div 16;
2344 if getmap(curx,cury)=0 then cury:=cury+1;
2346 if curx<0 then curx:=0;
2347 if curx>255 then curx:=255;
2348 if cury<0 then cury:=0;
2349 if cury>127 then cury:=127;
2351 //usemob(curx,cury);
2352 end;
2354 procedure actionUse(invcur, x, y:integer);
2355 begin
2356 if setBlock(invcur, x, y)=false then
2357 if useBlock(invcur, x, y) then
2358 if useItem(invcur, x, y) then
2359 end;
2361 procedure rt_useblock;
2362 var
2363 x, y:integer;
2364 begin
2365 x:=player.getX;
2366 y:=player.getY;
2368 if posi=0 then curx:=(x div 16)-1; else curx:=(x div 16)+1;
2369 cury:=y div 16;
2370 if getmap(curx,cury)=0 then cury:=cury+1;
2372 if curx<0 then curx:=0;
2373 if curx>255 then curx:=255;
2374 if cury<0 then cury:=0;
2375 if cury>127 then cury:=127;
2377 actionUse(invslot, curx, cury);
2378 end;
2380 procedure go_to_nether;
2381 var
2382 ix:integer;
2383 begin
2384 portal_time:=getrelativetimems;
2385 savegame('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2386 pl_world:=1;
2387 drw_load_line('Matrix',10);
2388 if loadworld('/'+sd+'/cavecraft/saves/'+sav_fl+'/')=true then
2389 begin
2390 player.setX(get_spawn_x*16+4);
2391 player.setY((get_up(get_spawn_x)-1)*16);
2392 end;
2393 else
2394 begin
2395 {for ix:=0 to 31 do
2396 begin
2397 mob[ix].m_type:=0;
2398 mob[ix].m_x:=0;
2399 mob[ix].m_y:=0;
2400 mob[ix].m_posi:=0;
2401 mob[ix].m_velx:=0;
2402 mob[ix].m_vely:=0;
2403 mob[ix].m_ani:=0;
2404 mob[ix].m_min_vely:=0;
2405 mob[ix].m_hp:=0;
2406 mob[ix].m_del:=0;
2407 mob[ix].m_fall:=false;
2408 mob[ix].m_jmp:=false;
2409 mob[ix].m_velani:=false;
2410 end;}
2412 drop.resetData;
2413 gennether;
2414 //netherspawn;
2415 end;
2416 end;
2418 procedure go_to_world;
2419 begin
2420 portal_time:=getrelativetimems;
2421 savegame('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2422 pl_world:=0;
2423 drw_load_line('Matrix',10);
2424 if loadworld('/'+sd+'/cavecraft/saves/'+sav_fl+'/')=true then
2425 begin
2426 pl_world:=0;
2427 end;
2428 else
2429 begin
2430 debug('ERROR!!!');
2431 pl_world:=0;
2432 genworld;
2433 //megaspawn;
2434 end;
2435 end;
2437 procedure plr_is_dead_hardcore;
2438 begin
2439 keymode:=0;
2440 toolus:=0;
2441 toolind:=0;
2443 repeat
2444 updateKeys;
2445 if clickedKey(KEY_MENU_SELECT) then
2446 begin
2447 deleteworld('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2448 menu;
2449 exit;
2450 end;
2451 draw;
2452 drawfonttext('You died!',getwidth/2-32,getheight/2-16);
2454 drw_btn('Delete world',0,0,0,1);
2456 drawVideo;
2457 delay(1);
2458 until false;
2460 end;
2462 procedure plr_is_dead;
2463 var
2464 m_cur:integer;
2465 x, y:integer;
2466 begin
2467 x:=player.getX;
2468 y:=player.getY;
2469 keymode:=0;
2470 toolus:=0;
2471 toolind:=0;
2472 repeat
2473 updateKeys;
2474 if clickedKey(KEY_MENU_UP) then
2475 begin
2476 m_cur:=m_cur-1;
2477 if m_cur<0 then m_cur:=1;
2478 end;
2479 if clickedKey(KEY_MENU_DOWN) then
2480 begin
2481 m_cur:=m_cur+1;
2482 if m_cur>1 then m_cur:=0;
2483 end;
2484 if clickedKey(KEY_MENU_SELECT) then
2485 begin
2486 if m_cur=0 then
2487 begin
2488 if pl_world=0 then
2489 begin
2490 if last_sleep_x=0 then
2491 begin
2492 x:=get_spawn_x*16+4;
2493 y:=get_spawn_y*16;
2494 end; else
2495 begin
2496 x:=last_sleep_x*16+4;
2497 y:=last_sleep_y*16;
2498 end;
2499 end; else
2500 if pl_world=1 then
2501 begin
2502 go_to_world;
2503 if last_sleep_x=0 then
2504 begin
2505 x:=get_spawn_x*16+4;
2506 y:=get_spawn_y*16;
2507 end; else
2508 begin
2509 x:=last_sleep_x*16+4;
2510 y:=last_sleep_y*16;
2511 end;
2512 end;
2513 posi:=0;
2514 curx:=0;
2515 cury:=0;
2516 vely:=0;
2517 jmp:=false;
2518 hp:=20;
2519 hunger:=20;
2520 exit;
2521 end;
2522 else
2523 if m_cur=1 then begin menu; exit; end;
2524 end;
2526 draw;
2528 drawfonttext('You died!',getwidth/2-32,getheight/2-16);
2530 drw_btn('Respawn',0,m_cur,0,1);
2531 drw_btn('Main menu',1,m_cur,0,1);
2533 drawVideo;
2534 delay(1);
2535 until false;
2536 end;
2538 procedure fast_menu;
2539 var
2540 m_cur,i:integer;
2541 begin
2542 repeat
2543 updateKeys;
2544 if clickedKey(KEY_MENU_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=3; end;
2545 if clickedKey(KEY_MENU_DOWN) then begin m_cur:=m_cur+1; if m_cur>3 then m_cur:=0; end;
2546 if clickedKey(KEY_MENU_SELECT) then
2547 begin
2548 if m_cur=0 then
2549 begin
2550 exit;
2551 end; else
2552 if m_cur=1 then
2553 begin
2554 savegame('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2555 exit;
2556 end; else
2557 if m_cur=2 then
2558 begin
2559 menu_sett;
2560 end; else
2561 if m_cur=3 then
2562 begin
2563 //clear_gui(keymode);
2564 menu;
2565 exit;
2566 end;
2567 end;
2568 draw;
2569 drawfonttext('Game menu',getwidth/2-36,getheight/2-20);
2570 drw_btn('Back to Game',0,m_cur,0,1);
2571 drw_btn('Save Game',1,m_cur,0,1);
2572 drw_btn('Options',2,m_cur,0,1);
2573 drw_btn('Quit to Title',3,m_cur,0,1);
2575 drawVideo;
2576 delay(1);
2577 until false;
2578 end;
2580 procedure keyFastInv;
2581 begin
2582 if clickedKey(KEY_FASTINV_NEXT) then
2583 begin
2584 invslot:=invslot-1;
2585 if invslot<0 then
2586 invslot:=8;
2587 end;
2589 if clickedKey(KEY_FASTINV_PREV) then
2590 begin
2591 invslot:=invslot+1;
2592 if invslot>8 then
2593 invslot:=0;
2594 end;
2595 end;
2597 procedure keyConsole;
2598 begin
2599 if clickedKey(KEY_CHAT) then
2600 SetTimer(1000,T_CONSOLE);
2602 if pressedKey(KEY_CHAT) then
2603 begin
2604 if GetTimer(T_CONSOLE)=TIMER_OK then
2605 begin
2606 call_console;
2607 ResetTimer(T_CONSOLE);
2608 end;
2609 end;
2610 else
2611 begin
2612 if GetTimer(T_CONSOLE)>TIMER_OK then
2613 begin
2614 deb:= not deb;
2615 ResetTimer(T_CONSOLE);
2616 end;
2617 end;
2618 end;
2620 procedure keyInventory;
2621 begin
2622 if clickedKey(KEY_PLR_OPENINV) then
2623 if gamemode<>1 then
2624 OpenPlayerInventory;
2625 else
2626 OpenCreativeWindow;
2627 end;
2629 procedure keyhandler;
2630 begin
2631 updateKeys;
2633 if WindowKeyHanler then
2634 begin
2635 if keymode=0 then
2636 begin
2637 keyInventory;
2638 keyFastInv;
2639 keyConsole;
2641 if clickedKey(KEY_PLR_EDITMODE) then
2642 begin
2643 keymode:=1;
2644 curx:=player.getX div 16;
2645 cury:=player.getY div 16;
2646 end;
2648 if clickedKey(KEY_PLR_USE) then
2649 rt_usemob;
2651 if clickedKey(KEY_MENU) then
2652 fast_menu;
2654 if clickedKey(KEY_PLR_ATTACK) then
2655 if rt_useweap=false then
2656 debug('useweap');
2658 if pressedKey(KEY_PLR_ATTACK) then
2659 begin
2660 rt_usetools;
2661 playAnim(ANIM_HAND);
2662 end;
2663 else
2664 begin
2665 resetToolProgerss;
2666 cancelAnim(ANIM_HAND);
2667 end;
2669 if pressedKey(KEY_PLR_UP) then
2670 player.gotoUP;
2671 if pressedKey(KEY_PLR_DOWN) then
2672 player.gotoDOWN;
2673 if pressedKey(KEY_PLR_LEFT) then
2674 player.gotoLEFT;
2675 if pressedKey(KEY_PLR_RIGHT) then
2676 player.gotoRIGHT;
2677 end;
2678 else
2679 if keymode=1 then
2680 begin
2681 keyInventory;
2682 keyFastInv;
2683 keyConsole;
2685 if clickedKey(KEY_PLR_UP) then
2686 begin
2687 cury:=cury-1;
2688 if cury<0 then
2689 cury:=0;
2690 end;
2691 if clickedKey(KEY_PLR_DOWN) then
2692 begin
2693 cury:=cury+1;
2694 if cury>127 then
2695 cury:=127;
2696 end;
2697 if clickedKey(KEY_PLR_LEFT) then
2698 begin
2699 curx:=curx-1;
2700 if curx<0 then
2701 curx:=0;
2702 end;
2703 if clickedKey(KEY_PLR_RIGHT) then
2704 begin
2705 curx:=curx+1;
2706 if curx>255 then
2707 curx:=255;
2708 end;
2710 if clickedKey(KEY_PLR_EDITMODE) then
2711 keymode:=0;
2713 if clickedKey(KEY_PLR_USE) then
2714 actionUse(invslot, curx, cury);
2716 if pressedKey(KEY_PLR_ATTACK) then
2717 begin
2718 usetools(invslot, curx, cury);
2719 playAnim(ANIM_HAND);
2720 end;
2721 else
2722 begin
2723 resetToolProgerss;
2724 cancelAnim(ANIM_HAND);
2725 end;
2727 if clickedKey(KEY_MENU) then
2728 fast_menu;
2729 end;
2731 end;
2733 end;
2735 procedure phyhandler;
2736 var
2737 i:integer;
2738 begin
2739 player.calcPhysics;
2740 mob.updatePhy;
2741 drop.calcPhy;
2742 end;
2744 procedure light_fillrect(l,x,y,r:integer);
2745 var
2746 ix,iy,ym,yp,xm,xp:integer;
2747 begin
2748 ym:=y-r;
2749 yp:=y+r;
2750 xm:=x-r;
2751 xp:=x+r;
2752 for ix:=xm to xp do
2753 for iy:=ym to yp do
2754 setmaplight(getmaplight(ix,iy)+l,ix,iy);
2755 end;
2757 procedure light_rect(l,x,y,r:integer);
2758 var
2759 ix,iy,ym,yp,xm,xp:integer;
2760 begin
2761 ym:=y-r;
2762 yp:=y+r;
2763 xm:=x-r;
2764 xp:=x+r;
2765 for ix:=xm to xp do
2766 begin
2767 setmaplight(getmaplight(ix,ym)+l,ix,ym);
2768 setmaplight(getmaplight(ix,yp)+l,ix,yp);
2769 end;
2770 for iy:=ym+1 to yp-1 do
2771 begin
2772 setmaplight(getmaplight(xm,iy)+l,xm,iy);
2773 setmaplight(getmaplight(xp,iy)+l,xp,iy);
2774 end;
2775 end;
2777 procedure calc_light(m,x,y:integer);
2778 var
2779 ix,iy,l,ss,sf:integer;
2780 begin
2781 if light_type=1 then light_fillrect(m,x,y,m/2); else
2782 for l:=m downto 1 do
2783 begin
2784 if ss mod 2=0 then light_rect(l,x,y,ss/2);
2785 ss:=ss+1;
2786 end;
2787 end;
2789 procedure calc_sun(ix,m:integer);
2790 var
2791 iy,ss:integer;
2792 begin
2793 ss:=m;
2794 for iy:=0 to 127 do
2795 begin
2796 setmaplight(ss,ix,iy);
2797 if ss=0 then break;
2798 ss:=ss-getBlockTr(getmap(ix,iy));
2799 if ss<0 then ss:=0;
2800 end;
2801 for iy:=iy+1 to 127 do
2802 begin
2803 setmaplight(0,ix,iy);
2804 end;
2805 end;
2807 procedure kill_plr;
2808 var
2809 i:integer;
2810 begin
2811 hp:=0;
2812 for i:=0 to INV_SIZE do
2813 begin
2814 if inv.isNull(i)=false then
2815 player.dropItem(inv.getItem(i), inv.getSum(i));
2816 inv.setItem(0, i);
2817 inv.setSum(0, i);
2818 end;
2819 if gamemode<2 then plr_is_dead; else plr_is_dead_hardcore;
2820 end;
2822 procedure hunger_and_air;
2823 var
2824 x, y:integer;
2825 begin
2826 x:=player.getX;
2827 y:=player.getY;
2828 if gamemode<>1 then
2829 begin
2830 if getrelativetimems-hung_time>=90000/(gamemode+1) then
2831 begin
2832 hung_time:=getrelativetimems;
2833 hunger:=hunger-