DEADSOFTWARE

Rewrited module for particles
[cavecraft.git] / src / CAVE.mpsrc
index 6de766ba1a2b5bb5536d231afc86dd059fc144ec..0d305849e358ef1108de30fb24a68376cf90e8e9 100644 (file)
@@ -6,14 +6,13 @@ uses
  drop,\r
  invui,\r
  vars,\r
- particles_store,\r
  randoms,\r
  memory,\r
  worldgen,\r
  canvas,\r
  items,\r
  safeload,\r
- mob,\r
+ mobs,\r
  console,\r
  effects,\r
  particles,\r
@@ -32,8 +31,7 @@ uses
  video;\r
 \r
 const\r
- version = 'BETA 9';\r
- version_map = 9;\r
+  version_map = 9;\r
 \r
 var\r
  keymode,updx,updy:integer;\r
@@ -54,7 +52,7 @@ var
  moon_phase:integer;\r
  toolus,toolind:integer;\r
  osadki_ani:integer;\r
- sd,sav_fl:string;\r
+ sav_fl:string;\r
  global_light:integer;\r
  world_typ:integer;\r
  float:image;\r
@@ -108,68 +106,59 @@ procedure maxfps;
   delay(del);\r
  end;\r
 \r
-procedure cleartextures;\r
- var\r
-  no:image;\r
-  ix,iy,iz:integer;\r
- begin\r
-  bg[0]:=no;\r
-  bg[1]:=no;\r
-  float:=no;\r
-  compas:=no;\r
-  for ix:=0 to 7 do clock[ix]:=no;\r
-\r
-  {for ix:=0 to maxBlockTex do\r
-   begin\r
-    tex[ix]:=no;\r
-    tex8[ix]:=no;\r
-   end;\r
-  for ix:=0 to maxItemTex do\r
-   begin\r
-    item[ix]:=no;\r
-    item8[ix]:=no;\r
-   end;}\r
- for ix:=0 to 8 do back[ix]:=no;\r
-\r
-  player.freeSkin;\r
-\r
-  for ix:=0 to 34 do\r
-   gui[ix]:=no;\r
-\r
-  for ix:=0 to 9 do tue[ix]:=no;\r
-\r
-  for ix:=0 to 7 do osad[0,ix]:=no;\r
-  for ix:=0 to 7 do osad[1,ix]:=no;\r
-\r
-  for ix:=0 to 15 do light[ix]:=no;\r
+procedure ClearTextures;\r
+  var\r
+    no : image;\r
+    ix, iy, iz : integer;\r
+  begin\r
+    bg[0] := no;\r
+    bg[1] := no;\r
+    float := no;\r
+    compas := no;\r
+    for ix := 0 to 7 do\r
+      clock[ix] := no;\r
+\r
+    for ix := 0 to maxBlockTex do\r
+      begin\r
+        tex[ix] := no;\r
+        tex8[ix] := no;\r
+      end;\r
+    for ix := 0 to maxItemTex do\r
+      begin\r
+        item[ix] := no;\r
+        item8[ix] := no;\r
+      end;\r
 \r
-  for ix:=0 to 7 do\r
-   begin\r
-    pr_1[ix]:=no;\r
-    pr_2[ix]:=no;\r
-    pr_3[ix]:=no;\r
-    pr_4[ix]:=no;\r
-    pr_5[ix]:=no;\r
-   end;\r
-  bubble:=no;\r
+    for ix := 0 to 8 do\r
+      back[ix]:=no;\r
 \r
-  for ix:=0 to 15 do\r
-   pr_boom[ix]:=no;\r
+    player.freeSkin;\r
 \r
-  mob.freeSkin;\r
+    for ix := 0 to 34 do\r
+      gui[ix] := no;\r
+    for ix := 0 to 9 do\r
+      tue[ix] := no;\r
+    for ix := 0 to 7 do\r
+      osad[0, ix] := no;\r
+    for ix := 0 to 7 do\r
+      osad[1, ix] := no;\r
 \r
-  sky:=no;\r
+    for ix := 0 to 15 do\r
+      light[ix] := no;\r
 \r
-  sun:=no;\r
-  moon:=no;\r
+    Particles.FreeTextures;\r
+    Mobs.FreeTextures;\r
 \r
-  sign_im:=no;\r
+    sky := no;\r
+    sun := no;\r
+    moon := no;\r
+    sign_im := no;\r
 \r
-  for ix:=0 to CONST_MAX_CURS do\r
-   LoadCurImg(no, ix);\r
+    for ix := 0 to CONST_MAX_CURS do\r
+      LoadCurImg(no, ix);\r
 \r
-  //resetVirtualKeyboard(-1);\r
- end;\r
+    //resetVirtualKeyboard(-1);\r
 end;\r
 \r
 procedure create_msg(s:string);\r
  var\r
@@ -205,8 +194,10 @@ procedure loadtexture(path:string);
     for ix:=0 to 8 do back[ix]:=rotate_image_from_image(im,ix*16,0,16,16,0);\r
    end;\r
 \r
-  player.loadSkin('char_ani.png', path);\r
-  mob.loadSkin(path);\r
+  console.exec('textures.cfg', 'AUTO');\r
+\r
+  Player.LoadSkin('char_ani.png', path);\r
+  Mobs.LoadTextures(path);\r
 \r
   im:=ld_tex('gui.png',path,'gui/');\r
   gui[0]:=rotate_image_from_image(im,0,0,16,16,0);\r
@@ -255,22 +246,7 @@ procedure loadtexture(path:string);
     for ix:=0 to 15 do light[ix]:=rotate_image_from_image(im,16*ix,0,16,16,0);\r
    end;\r
 \r
-  if load_particles_tex then\r
-   begin\r
-    im:=ld_tex('particles.png',path,'terrain/');\r
-    for ix:=0 to 7 do\r
-     begin\r
-      pr_1[ix]:=rotate_image_from_image(im,8*ix,0,8,8,0);\r
-      pr_2[ix]:=rotate_image_from_image(im,8*ix,8,8,8,0);\r
-      pr_3[ix]:=rotate_image_from_image(im,8*ix,16,8,8,0);\r
-      pr_4[ix]:=rotate_image_from_image(im,8*ix,24,8,8,0);\r
-      pr_5[ix]:=rotate_image_from_image(im,8*ix,32,8,8,0);\r
-     end;\r
-    bubble:=rotate_image_from_image(im,0,40,8,8,0);\r
-    im:=ld_tex('explosion.png',path,'terrain/');\r
-    for ix:=0 to 15 do\r
-     pr_boom[ix]:=rotate_image_from_image(im,32*ix,0,32,32,0);\r
-   end;\r
+  Particles.LoadTextures(path);\r
 \r
   im:=ld_tex('partition.png',path,'gui/');\r
   gui[18]:=rotate_image_from_image(im,0,0,84,42,0);\r
@@ -335,18 +311,12 @@ procedure cleargame;
 \r
   //anim_del2:=0;\r
 \r
-  inv.resetData;\r
-\r
-  chest.resetData;\r
-\r
-  furnace.resetData;\r
-\r
-  drop.resetData;\r
-\r
-  mob.resetData;\r
-\r
-  //gb_up_pa:=0;\r
-  reset_particles(max_particles+1);\r
+  Inv.ResetData;\r
+  Chest.ResetData;\r
+  Furnace.ResetData;\r
+  Drop.ResetData;\r
+  Mobs.ResetData;\r
+  Particles.ResetData;\r
 \r
   for ix:=0 to 255 do\r
    begin\r
@@ -513,31 +483,19 @@ procedure saveworld(path:string);
        write_byte(getBackMap(ix));\r
        write_byte(getBiomMap(ix));\r
       end;\r
-     drw_load_line('Chests',55);\r
-     //Chests\r
-     chest.saveData;\r
-     drw_load_line('Furnaces',60);\r
-     //Furnaces\r
-     furnace.saveData;\r
-     drw_load_line('Mobs',70);\r
-     //Mobs\r
-     mob.saveData;\r
-     drw_load_line('Drop',80);\r
-     //Drop\r
-     drop.saveData;\r
-      drw_load_line('Particles',85);\r
-     //Particles\r
-     writeint(max_particles);\r
-     write_byte(gb_up_pa);\r
-     for ix:=0 to max_particles do\r
-      begin\r
-       write_byte(get_particle_type(ix));\r
-       write_byte(get_particle_ani(ix));\r
-       writeint(get_particle_x(ix));\r
-       writeint(get_particle_y(ix));\r
-      end;\r
-     drw_load_line('Other',90);\r
-     //Other\r
+\r
+     drw_load_line('Chests', 55);\r
+     Chest.SaveData;\r
+     drw_load_line('Furnaces', 60);\r
+     Furnace.SaveData;\r
+     drw_load_line('Mobs', 70);\r
+     Mobs.SaveData;\r
+     drw_load_line('Drop', 80);\r
+     Drop.SaveData;\r
+     drw_load_line('Particles', 85);\r
+     Particles.SaveData;\r
+\r
+     drw_load_line('Other', 90);\r
      write_byte(updx);\r
      write_byte(updy);\r
      writebool(osadki);\r
@@ -645,31 +603,17 @@ function loadworld(path:string):boolean;
        setBackMap(read_byte, ix);\r
        setBiomMap(read_byte, ix);\r
       end;\r
-     drw_load_line('Chests',55);\r
-     //Chests\r
-     chest.loadData;\r
-     drw_load_line('Furnaces',60);\r
-     //Furnaces\r
-     furnace.loadData;\r
-     //Mobs\r
-     mob.loadData;\r
-     drw_load_line('Drop',80);\r
-     //Drop\r
-     drop.loadData;\r
-     drw_load_line('Particles',85);\r
-     //Particles\r
-     max_particles:=readint;\r
-     reset_particles(max_particles+1);\r
-     gb_up_pa:=read_byte;\r
-     for ix:=0 to max_particles do\r
-      begin\r
-       set_particle_type(ix,read_byte);\r
-       set_particle_ani(ix,read_byte);\r
-       set_particle_x(ix,readint);\r
-       set_particle_y(ix,readint);\r
-      end;\r
-      drw_load_line('Other',90);\r
-     //Other\r
+     drw_load_line('Chests', 55);\r
+     Chest.LoadData;\r
+     drw_load_line('Furnaces', 60);\r
+     Furnace.LoadData;\r
+     Mobs.LoadData;\r
+     drw_load_line('Drop', 80);\r
+     Drop.LoadData;\r
+     drw_load_line('Particles', 85);\r
+     Particles.LoadData;\r
+\r
+     drw_load_line('Other',90);\r
      updx:=read_byte;\r
      updy:=read_byte;\r
      osadki:=readbool;\r
@@ -1039,7 +983,7 @@ procedure start_uu;
   rs:=openRecordStore('SD');\r
   sd:=readRecordStoreEntry(rs,1);\r
   closeRecordStore(rs);\r
-  console.exec('autoexec.cfg', 'AUTO', true);\r
+  console.exec('autoexec.cfg', 'AUTO');\r
   if sd='' then\r
    begin\r
     init_touch;\r
@@ -1395,6 +1339,7 @@ procedure menu_tex;
     if m_cur=0 then begin\r
      if cur_name>0 then\r
       begin\r
+       debug("Select TexturePack @ /" + sd + "/cavecraft/texturepacks/" + names[cur_name]);\r
        tex_pack:=names[cur_name];\r
        LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');\r
        loadtexture('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');\r
@@ -1402,9 +1347,13 @@ procedure menu_tex;
        rs:=openRecordStore('TX');\r
        t:=addRecordStoreEntry(rs,tex_pack);\r
        closeRecordStore(rs);\r
+\r
+       LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');\r
+       loadtexture('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');\r
       end;\r
      else\r
       begin\r
+       debug("Cancel Select TecturePack");\r
        tex_pack:='';\r
        loadtexture('/');\r
        deleteRecordStore('TX');\r
@@ -1478,7 +1427,7 @@ var
       end; else\r
      if m_cur=-1 then\r
       begin\r
-       s_particles:=not s_particles;\r
+       Particles.enabled := not Particles.enabled;\r
       end; else\r
      if m_cur=0 then\r
       begin\r
@@ -1532,7 +1481,7 @@ var
 \r
    drw_btn('Light:'+light_type,-3,m_cur,0,1);\r
    drw_btn('Weather:'+ifosad,-2,m_cur,0,1);\r
-   drw_btn('Particles:'+s_particles,-1,m_cur,0,1);\r
+   drw_btn('Particles:' + Particles.enabled, -1, m_cur, 0, 1);\r
    drw_btn('Hide GUI:'+not drawgui,0,m_cur,0,1);\r
    drw_btn('Touch:'+(load_key_tex>0),1,m_cur,0,1);\r
    drw_btn('JPEG:'+s_jpeg_quality,2,m_cur,0,1);\r
@@ -2028,30 +1977,42 @@ procedure draw;
      draw_block(ix,iy);\r
    end;\r
   {===================[drop]===================}\r
-  drop.draw(camx, camy);\r
+  Drop.Draw(camx, camy);\r
   {===================[particles]===================}\r
-  if s_particles then draw_particle;\r
+  Particles.Draw(camx, camy);\r
   {===================[player]===================}\r
-  if hp>0 then\r
-   begin\r
-    player.draw(camx, camy);\r
-   end;\r
-\r
+  Player.Draw(camx, camy);\r
   {===================[mobs]===================}\r
-  mob.draw(camx, camy);\r
+  Mobs.Draw(camx, camy);\r
   {===================[draw_blocks]===================}\r
   for ix:=minx to maxx do\r
   for iy:=miny to maxy do\r
-   begin\r
-    if getBlockFore(getmap(ix,iy))=true then\r
-     draw_block(ix,iy);\r
+    begin\r
+      if getBlockFore(getmap(ix, iy)) then\r
+        draw_block(ix, iy);\r
 \r
-    setcolor(0,0,0);\r
-    if (light_type=1) then begin if getmaplight(ix,iy)=0 then fillrect((ix*16)-camx,(iy*16)-camy,16,16); end;\r
-     else\r
-    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;\r
-   end;\r
-   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;\r
+      setcolor(0, 0, 0);\r
+      if light_type = 1 then\r
+        begin\r
+          if getmaplight(ix,iy) = 0 then\r
+            fillrect((ix * 16) - camx, (iy * 16) - camy, 16, 16);\r
+        end;\r
+      else if light_type = 2 then\r
+        begin \r
+          if getmaplight(ix, iy) < 15 then\r
+             drawimage(light[getmaplight(ix, iy)], (ix * 16) - camx, (iy * 16) - camy);\r
+        end;\r
+     end;\r
+\r
+   // debug\r
+   // drawimage(light[getmaplight(player.getX div 16, player.getY div 16)], 0, 0);\r
+\r
+   if (toolus > 0) and (toolind < 10) and (getmap(curx,cury) > 0) then\r
+     begin\r
+       if toolind > 9 then\r
+         toolind:=9;\r
+       drawimage(tue[toolind], curx * 16 - camx, cury * 16 - camy);\r
+     end;\r
   {===================[gui]===================}\r
   if drawgui then\r
    begin\r
@@ -2268,9 +2229,9 @@ function rt_useweap:boolean;
    damg:=1;\r
 \r
   if posi=0 then\r
-   i:=mob.findAndHit(damg, x-TILE_SIZE, y, TILE_SIZE+(w/2), h, -2, -3);\r
+   i:=Mobs.findAndHit(damg, x-TILE_SIZE, y, TILE_SIZE+(w/2), h, -2, -3);\r
   else\r
-   i:=mob.findAndHit(damg, x+(w/2), y, TILE_SIZE+(w/2), h, 2, -3);\r
+   i:=Mobs.findAndHit(damg, x+(w/2), y, TILE_SIZE+(w/2), h, 2, -3);\r
 \r
   if i<>-1 then\r
    begin\r
@@ -2705,9 +2666,9 @@ procedure phyhandler;
  var\r
   i:integer;\r
  begin\r
-  player.calcPhysics;\r
-  mob.updatePhy;\r
-  drop.calcPhy;\r
+  Player.CalcPhysics;\r
+  Mobs.UpdatePhy;\r
+  Drop.CalcPhy;\r
  end;\r
 \r
 procedure light_fillrect(l,x,y,r:integer);\r
@@ -2875,6 +2836,9 @@ procedure game;
 \r
   game_time:=game_time+(600000 div (fps_t*1000));\r
 \r
+// Ускорение игрового времени в 10 раз\r
+//  game_time := game_time + (600000 div (fps_t*100));\r
+\r
   if (game_time>600000) or (game_time<0) then\r
    begin\r
     game_time:=0;\r
@@ -2883,8 +2847,8 @@ procedure game;
     load_moon('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/',moon_phase);\r
    end;\r
 \r
-  tim:=10000*getimagewidth(sky)/600000*game_time/10000;\r
-  global_light:=effects.get(sky,tim,1,1) {and $F};\r
+  tim := 10000 * getimagewidth(sky) / 600000 * game_time / 10000;\r
+  global_light := effects.get(sky, tim, 1, 1) div 16;\r
 \r
   if clock_stage<>game_time div 75000 then begin clock_stage:=clock_stage+1; if clock_stage>7 then clock_stage:=0; end;\r
 \r
@@ -2895,7 +2859,7 @@ procedure game;
   osadki_ani:=osadki_ani+1;\r
   if osadki_ani>7 then osadki_ani:=0;\r
 \r
-  if random(20)=random(20) then create_particle(6,x,y);\r
+  if Random(20) = Random(20) then Particles.Create(Particles.bubble, x, y);\r
 \r
   if gamemode=1 then begin hp:=666; hunger:=666; end;\r
 \r
@@ -2906,9 +2870,8 @@ procedure game;
 \r
   //if s_spawn_mob then if random(4096)=1547 then megaspawn;\r
 \r
-  mob.update;\r
-\r
-  if particle_upd then update_particle;\r
+  Mobs.Update;\r
+  Particles.Update;\r
 \r
   if light_type>0 then\r
    begin\r
@@ -3024,6 +2987,27 @@ procedure qt_start;
   menu;\r
  end;\r
 \r
+procedure draw_debug;\r
+  var\r
+    i : Integer;\r
+  begin\r
+    //drawfonttext('X:'+(x div 16-128),0,0);\r
+    //drawfonttext('Y:'+integertostring(127-(y div 16)),0,8);\r
+    drawfonttext('CURX:'+(curx-128),0,16);\r
+    drawfonttext('CURY:'+cury,0,24);\r
+    drawfonttext('UPDX:'+updx,0,32);\r
+    drawfonttext('UPDY:'+updy,0,40);\r
+    drawfonttext('FPS:'+fps,0,56);\r
+    drawfonttext('Free RAM:'+free_ram/1024+' KB',0,64);\r
+    drawfonttext('Total RAM:'+memory.get_totalmemory div 1024+' KB',0,72);\r
+    drawfonttext('SEED:'+seed,0,88);\r
+    drawfonttext('Game time:'+game_time,0,96);\r
+    drawfonttext('Global light:' + global_light, 0, 104);\r
+\r
+    for i := 0 to 15 do\r
+      drawImage(light[i], getWidth - 16, 16 * i);\r
+  end;\r
+\r
 begin\r
  qt_start;\r
  hung_time:=getrelativetimems;\r
@@ -3038,20 +3022,8 @@ begin
   draw;\r
   drawfonttext(version,getWidth-(length(version)*8),getHeight-8);\r
   if getrelativetimems-msg_time[4]>500 then begin free_ram:=memory.get_freememory; if free_ram<0 then free_ram:=-free_ram; msg_time[4]:=getrelativetimems; end;\r
-  if deb=true then\r
-   begin\r
-    //drawfonttext('X:'+(x div 16-128),0,0);\r
-    //drawfonttext('Y:'+integertostring(127-(y div 16)),0,8);\r
-    drawfonttext('CURX:'+(curx-128),0,16);\r
-    drawfonttext('CURY:'+cury,0,24);\r
-    drawfonttext('UPDX:'+updx,0,32);\r
-    drawfonttext('UPDY:'+updy,0,40);\r
-    drawfonttext('FPS:'+fps,0,56);\r
-    drawfonttext('Free RAM:'+free_ram/1024+' KB',0,64);\r
-    drawfonttext('Total RAM:'+memory.get_totalmemory div 1024+' KB',0,72);\r
-    drawfonttext('SEED:'+seed,0,88);\r
-    drawfonttext('Game time:'+game_time,0,96);\r
-   end;\r
+  if deb = true then\r
+    draw_debug;\r
 \r
   drawVideo;\r
   maxfps;\r