8 = Details = |
8 = Details = |
9 |
9 |
10 First, a couple of convenience functions for drawing to the map. |
10 First, a couple of convenience functions for drawing to the map. |
11 <code lang="lua"> |
11 <code lang="lua"> |
12 PointsBuffer = '' -- A string to accumulate points in |
12 PointsBuffer = '' -- A string to accumulate points in |
13 function AddPoint(x, y, new, size, erase) |
13 function AddPoint(x, y, size, erase) |
14 PointsBuffer = PointsBuffer .. string.char(band(x,0xff00) / 256 , band(x,0xff) , band(y,0xff00) / 256 , band(y,0xff)) |
14 PointsBuffer = PointsBuffer .. string.char(band(x,0xff00) / 256 , band(x,0xff) , band(y,0xff00) / 256 , band(y,0xff)) |
15 if new then |
15 if size then |
16 size = bor(size,0x80) |
16 size = bor(size,0x80) |
17 if erase then |
17 if erase then |
18 size = bor(size,0x40) |
18 size = bor(size,0x40) |
19 end |
19 end |
20 PointsBuffer = PointsBuffer .. string.char(size) |
20 PointsBuffer = PointsBuffer .. string.char(size) |
31 ParseCommand('draw '..PointsBuffer) |
31 ParseCommand('draw '..PointsBuffer) |
32 PointsBuffer = '' |
32 PointsBuffer = '' |
33 end |
33 end |
34 end |
34 end |
35 </code> |
35 </code> |
36 AddPoint takes an x and y location for the point, 2 booleans: new (start of a line or not), erase (whether the line is erasing from the map) and size (size of the line - a value from 1 to 63) |
36 AddPoint takes an x and y location for the point, a size (required to start a line) and erase (whether the line is erasing from the map) |
37 FlushPoints writes out any values from PointsBuffer that had not already been sent to the engine. It would be called at the end of a drawing session. |
37 FlushPoints writes out any values from PointsBuffer that had not already been sent to the engine. It would be called at the end of a drawing session. |
38 |
38 |
39 A simple example below. |
39 A simple example below. |
40 |
40 |
41 <code lang="lua"> |
41 <code lang="lua"> |
42 function onGameInit() |
42 function onGameInit() |
43 MapGen = 2 |
43 MapGen = 2 |
44 TemplateFilter = 0 |
44 TemplateFilter = 0 |
45 |
45 |
46 AddPoint(100,100,true,10) |
46 AddPoint(100,100,10) |
47 AddPoint(2000,2000) |
47 AddPoint(2000,2000) |
48 AddPoint(2000,100,true,10) |
48 AddPoint(2000,100,10) |
49 AddPoint(100,2000) |
49 AddPoint(100,2000) |
50 AddPoint(1000,1000,true,63,true) |
50 AddPoint(1000,1000,63,true) |
51 |
51 |
52 for i = 63,2,-4 do |
52 for i = 63,2,-4 do |
53 AddPoint(2000,1000,true,i) |
53 AddPoint(2000,1000,i) |
54 AddPoint(2000,1000,true,i-2,true) |
54 AddPoint(2000,1000,i-2,true) |
55 end |
55 end |
56 |
56 |
57 for i = 1,2000,50 do |
57 for i = 1,2000,50 do |
58 AddPoint(i+2000,2000,true,1) |
58 AddPoint(i+2000,2000,1) |
59 AddPoint(4000,2000-i) |
59 AddPoint(4000,2000-i) |
60 end |
60 end |
61 |
61 |
62 AddPoint(2000,2000,true,1) |
62 AddPoint(2000,2000,1) |
63 AddPoint(4000,2000) |
63 AddPoint(4000,2000) |
64 AddPoint(4000,0,true,1) |
64 AddPoint(4000,0,1) |
65 AddPoint(4000,2000) |
65 AddPoint(4000,2000) |
66 |
66 |
67 FlushPoints() |
67 FlushPoints() |
68 end |
68 end |
69 </code> |
69 </code> |