equal
deleted
inserted
replaced
2 |
2 |
3 = Drawing maps with Lua (OUTDATED) = |
3 = Drawing maps with Lua (OUTDATED) = |
4 |
4 |
5 == Overview == |
5 == Overview == |
6 Starting in 0.9.18 it is possible to reliably use drawn map mode to draw maps with scripts. |
6 Starting in 0.9.18 it is possible to reliably use drawn map mode to draw maps with scripts. |
7 A simple example is given below. Note that Drawn maps use an area of 4096x2048. The examples below are static, but obviously this could be used for a random map variation - for example, simulating the Cave map by doing the fill below, then drawing random tunnels using circles that shift their course smoothly. |
7 A simple example is given below. Note that Drawn maps use an area of 4096×2048. The examples below are static, but obviously this could be used for a random map variation—for example, simulating the Cave map by doing the fill below, then drawing random tunnels using circles that shift their course smoothly. |
8 |
8 |
9 == Details == |
9 == Details == |
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 |
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, a width (indicates the start of a new line) and erase (whether the line is erasing from the map). The width calculation is described in [DrawnMapFormat]. |
36 `AddPoint` takes an x and y location for the point, a width (indicates the start of a new line) and `erase` (whether the line is erasing from the map). The width calculation is described in [DrawnMapFormat]. |
37 |
37 |
38 FlushPoints writes out any values from PointsBuffer that have not already been sent to the engine. |
38 `FlushPoints` writes out any values from `PointsBuffer` that have not already been sent to the engine. |
39 It would be called at the end of a drawing session. |
39 It would be called at the end of a drawing session. |
40 |
40 |
41 A simple example below. |
41 A simple example below. |
42 |
42 |
43 <code lang="lua"> |
43 <code lang="lua"> |
68 AddPoint(4000,2000) |
68 AddPoint(4000,2000) |
69 |
69 |
70 FlushPoints() |
70 FlushPoints() |
71 end |
71 end |
72 </code> |
72 </code> |
73 The first set of AddPoints draws a large X and erases the centre. |
73 The first set of `AddPoint`s draws a large X and erases the centre. |
74 The following loop draws a set of nested points, alternating erasure and fill, which results in a set of concentric circles. |
74 The following loop draws a set of nested points, alternating erasure and fill, which results in a set of concentric circles. |
75 The 2nd loop draws a web of lines and frames it using some final AddPoints. |
75 The 2nd loop draws a web of lines and frames it using some final `AddPoint`s. |
76 |
76 |
77 <a href="http://m8y.org/hw/draw1.jpeg">screenshot here</a> |
77 <a href="http://m8y.org/hw/draw1.jpeg">screenshot here</a> |
78 |
78 |
79 Another brief example. |
79 Another brief example: |
80 <code lang="lua"> |
80 <code lang="lua"> |
81 for i = 200,2000,600 do |
81 for i = 200,2000,600 do |
82 AddPoint(1,i,63) |
82 AddPoint(1,i,63) |
83 AddPoint(4000,i) |
83 AddPoint(4000,i) |
84 end |
84 end |