/[enigma]/enigma/data/levels/ant.lua
ViewVC logotype

Diff of /enigma/data/levels/ant.lua

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by ant_39, Sat Jan 11 17:15:08 2003 UTC revision 1.4 by ant_39, Sat Jan 18 00:28:52 2003 UTC
# Line 4  Line 4 
4  --  --
5  -- 2003-01-07 -- special floor types and train support  -- 2003-01-07 -- special floor types and train support
6  -- 2003-01-11 -- multiples support (groups of doors, bolders etc.)  -- 2003-01-11 -- multiples support (groups of doors, bolders etc.)
7    -- 2003-01-14 -- bugfixes and error reporting, some new map-creating funcs
8    
9    
10  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# Line 14  TRANSPOSE_MAP = 1 Line 15  TRANSPOSE_MAP = 1
15  NO_TRANSPOSE_MAP = not(TRANSPOSE_MAP)  NO_TRANSPOSE_MAP = not(TRANSPOSE_MAP)
16    
17  -- each item:  -- each item:
18  --  + face - name of stone/floor/item  --  + face - name of stone/floor/item object
19  --  + attr - set of attributes of stone/floor/item  --  + attr - set of attributes of given object
20  function cell_item(it)  function cell_item(it)
21     local n_it = {}     local n_it = {}
22     n_it.face = (it.face or "")     n_it.face = (it.face or "")
# Line 27  end Line 28  end
28  --  + stone - if present, the stone shall be added to defined position  --  + stone - if present, the stone shall be added to defined position
29  --  + floor - the same, but for floor  --  + floor - the same, but for floor
30  --  + item  - the same, but for item  --  + item  - the same, but for item
31  --    ++ actor - if actor=1 is set at item, set_actor shall be used instead of set_item  --   ++ actor - if actor=1 is set at item, set_actor shall be used instead of set_item
32  function cell(structure)  function cell(structure)
33     local cell = {}     local cell0 = {}
34    
35     cell.tag = (structure.tag or "?")     cell0.tag = (structure.tag or "?")
36     cell.setactor = structure.setactor     cell0.setactor = structure.setactor
37     cell.floor = cell_item(structure.floor or {})     cell0.floor = cell_item(structure.floor or {})
38     cell.stone = cell_item(structure.stone or {})     cell0.stone = cell_item(structure.stone or {})
39     cell.item =  cell_item(structure.item or {})     cell0.item =  cell_item(structure.item or {})
40    
41     local parent =structure.parent     local parent =structure.parent
42     local partype=type(parent)     local partype=type(parent)
# Line 66  function cell(structure) Line 67  function cell(structure)
67               end               end
68    
69               --map elements               --map elements
70               if (%structure.stone) then set_stone(%cell.stone.face, x, y, %cell.stone.attr) end               if (%structure.stone) then set_stone(%cell0.stone.face, x, y, %cell0.stone.attr) end
71               if (%structure.floor) then set_floor(%cell.floor.face, x, y, %cell.floor.attr) end               if (%structure.floor) then set_floor(%cell0.floor.face, x, y, %cell0.floor.attr) end
72               if (%structure.item) then               if (%structure.item) then
73                  if (%structure.item.actor) then                  if (%structure.item.actor) then
74                     set_actor(%cell.item.face, x+0.5, y+0.5, %cell.item.attr)                     set_actor(%cell0.item.face, x+0.5, y+0.5, %cell0.item.attr)
75                  else                  else
76                     set_item(%cell.item.face, x, y, %cell.item.attr)                     set_item(%cell0.item.face, x, y, %cell0.item.attr)
77                  end                  end
78               end               end
79            end            end
# Line 101  function get_map_size(level) Line 102  function get_map_size(level)
102  end  end
103    
104  -- this draws the map to the position [x0,y0]  -- this draws the map to the position [x0,y0]
105  function draw_map(x0, y0, map, swap_coords)  function draw_map(x0, y0, map, swap_coords, cellfuncs)
106       local funcs = cellfuncs or cells or {}; --we hope that if nil is passed, global cells is defined.
107    
108     for y,str in map do     for y,str in map do
109        for x = 1,strlen(str) do        for x = 1,strlen(str) do
110           cell = strchar(strbyte(str,x))           cell = strchar(strbyte(str,x))
111           if (swap_coords) then           func = funcs[cell]
112              cells[cell](y+y0-1, x+x0-1)  
113             if (type(func) == "function") then
114                if (swap_coords) then
115                   func(y+y0-1, x+x0-1)
116                else
117                   funcs[cell](x+x0-1, y+y0-1)
118                end
119           else           else
120              cells[cell](x+x0-1, y+y0-1)              print("warning: [ant.lua]: function doesn't exist for map element: '"..cell.."'")
121           end           end
122        end        end
123     end     end
# Line 116  end Line 125  end
125    
126  -- this prepares enigma world and draws given map  -- this prepares enigma world and draws given map
127  -- swap_coords is optional  -- swap_coords is optional
128  --- REPAIR> swap_coords => swap also levelw, levelh!!!  function create_world_by_map(level, swap_coords, cellfuncs)
 function create_world_by_map(level, swap_coords)  
129     local levelw, levelh = get_map_size(level)     local levelw, levelh = get_map_size(level)
130    
131       if (swap_coords==TRANSPOSE_MAP) then
132          temp, levelw, levelh = levelw, levelh, temp
133       end
134    
135     create_world(levelw, levelh)     create_world(levelw, levelh)
136     draw_map(0, 0, level, swap_coords)     draw_map(0, 0, level, swap_coords, cellfuncs)
137    end
138    
139    -- to fill each square of map with given function
140    function fill_world_func(fillfunc)
141       for x=0,level_width-1 do
142          for y=0,level_height-1 do
143             fillfunc(x, y)
144          end
145       end
146    end
147    
148    -- to draw border of map by given function
149    function draw_border_func(fillfunc)
150       for x=0,level_width-1 do
151          fillfunc(x, 0)
152          fillfunc(x, level_height-1)
153       end
154    
155       for y=0,level_height-1 do
156          fillfunc(0, y)
157          fillfunc(level_width-1, y)
158       end
159  end  end
160    
161    
# Line 247  end Line 282  end
282  -- count: number of checker textures  -- count: number of checker textures
283  -- items: table of checker textures [1,2,3,...]  -- items: table of checker textures [1,2,3,...]
284  -- x,y:   coordinates of checker field  -- x,y:   coordinates of checker field
285  function mcheckerfloor(sidex, sidey, count, items, x, y)  function mcheckerfloor(sidex, sidey, offsetx, offsety, count, items, x, y)
286     local x0, y0 = floor(x/sidex), floor(y/sidey)     local x0, y0 = floor((x-offsetx+sidex)/sidex), floor((y-offsety+sidey)/sidey)
287     local remainder = mod(x0+y0, count)     local remainder = mod(x0+y0, count)
288     items[remainder+1](x,y)     items[remainder+1](x,y)
289  end  end
# Line 268  function checkerfloor(items, x, y) Line 303  function checkerfloor(items, x, y)
303     local count = getn(items)     local count = getn(items)
304     local remainder = mod(x+y, count)     local remainder = mod(x+y, count)
305     local sidex, sidey = 1, 1     local sidex, sidey = 1, 1
306       local offsetx, offsety = 0, 0
307    
308     if (items.side~=nil) then     if (items.side~=nil) then
309        sidex = items.side        sidex = items.side
# Line 282  function checkerfloor(items, x, y) Line 318  function checkerfloor(items, x, y)
318        sidey = items.sidey        sidey = items.sidey
319     end     end
320    
321     mcheckerfloor(sidex, sidey, getn(items), items, x, y)     if (items.offset~=nil) then
322          offsetx = items.offset
323          offsety = offsetx
324       end
325    
326       if (items.offsetx~=nil) then
327          offsetx = items.offsetx
328       end
329    
330       if (items.offsety~=nil) then
331          offsety = items.offsety
332       end
333    
334       mcheckerfloor(sidex, sidey, offsetx, offsety, getn(items), items, x, y)
335  end  end
336    
337  -- the random floor parent  -- the random floor parent

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26