Difference between revisions of "Modding:Coord"
From DoomRL Wiki
Game Hunter (Talk | contribs) m (removed 0994 warning) |
Game Hunter (Talk | contribs) m (so you don't have to use huge <font-decoration> tags for it) |
||
Line 2: | Line 2: | ||
== Properties == | == Properties == | ||
− | |||
Although coords are technically userdata, they can be indexed like normal tables. | Although coords are technically userdata, they can be indexed like normal tables. | ||
− | {|style="border: 2px solid darkred; border-spacing: 0; font-size: 90%; margin: 0.25em 0.5em;" | + | |
− | + | {|class="wikitable" style="border: 2px solid darkred; border-spacing: 0; font-size: 90%; margin: 0.25em 0.5em;" | |
− | | | + | ! colspan="3" style="background: darkred; color: yellow; font-size: 120%; text-align: center"|'''Coord''' |
− | | | + | {{Table3Col |
− | | | + | |es=background: #333; |
− | |This is the x-coordinate of the coord. In DoomRL, x increases going from left to right, starting at 1 on the left edge of the map. | + | |c1=font-weight:bold; text-align:right; vertical-align:top; padding:0px 3px; |
− | + | |c2=vertical-align:top; padding:0px 2px; | |
− | + | |c3=padding:0px 2px; | |
− | + | |'''Integer'''|x|This is the x-coordinate of the coord. In DoomRL, x increases going from left to right, starting at 1 on the left edge of the map. | |
− | |This is the y-coordinate of the coord. In DoomRL, y increases going from top to bottom, starting at 1 on the upper edge of the map. | + | |'''Integer'''|y|This is the y-coordinate of the coord. In DoomRL, y increases going from top to bottom, starting at 1 on the upper edge of the map. |
+ | |}} | ||
|} | |} | ||
− | |||
+ | == API == | ||
− | {|style="border: 2px solid darkred; border-spacing: 0; font-size: 90%; margin: 0.25em 0.5em;" | + | {|class="wikitable" style="border: 2px solid darkred; border-spacing: 0; font-size: 90%; margin: 0.25em 0.5em;" |
− | + | ! colspan="2" style="background: darkred; color: yellow; font-size: 120%; text-align: center"|'''Coord Interface''' | |
− | | | + | {{Table2Col |
− | | | + | |es=background: #333; |
− | |coord.[[#coord_new|new]]('''integer''' x, '''integer''' y) | + | |c1=font-weight:bold; text-align:right; vertical-align:top; padding:0px 2px; |
− | + | |c2=padding:0px 2px; | |
− | + | |[[Modding:Coord|Coord]]|coord.[[#coord_new|new]]('''integer''' x, '''integer''' y) | |
− | |coord.[[#coord_unm|unm]]([[Modding:Coord|Coord]] c) | + | |[[Modding:Coord|Coord]]|coord.[[#coord_unm|unm]]([[Modding:Coord|Coord]] c) |
− | + | |[[Modding:Coord|Coord]]|coord.[[#coord_add|add]]([[Modding:Coord|Coord]] lhs, [[Modding:Coord|Coord]] rhs) | |
− | + | |[[Modding:Coord|Coord]]|coord.[[#coord_sub|sub]]([[Modding:Coord|Coord]] lhs, [[Modding:Coord|Coord]] rhs) | |
− | |coord.[[#coord_add|add]]([[Modding:Coord|Coord]] lhs, [[Modding:Coord|Coord]] rhs) | + | |[[Modding:Coord|Coord]]|coord.[[#coord_mul|mul]]([[Modding:Coord|Coord]] or '''integer''' lhs, [[Modding:Coord|Coord]] or '''integer''' rhs) |
− | + | |'''boolean'''|coord.[[#coord_eq|eq]]([[Modding:Coord|Coord]] lhs, [[Modding:Coord|Coord]], rhs) | |
− | + | |[[Modding:Coord|Coord]]|coord.[[#coord_abs|abs]]([[Modding:Coord|Coord]] c) | |
− | |coord.[[#coord_sub|sub]]([[Modding:Coord|Coord]] lhs, [[Modding:Coord|Coord]] rhs) | + | |[[Modding:Coord|Coord]]|coord.[[#coord_sign|sign]]([[Modding:Coord|Coord]] c) |
− | + | |'''integer'''|coord.[[#coord_distance|distance]]([[Modding:Coord|Coord]] c1, [[Modding:Coord|Coord]] c2) | |
− | + | |'''number'''|coord.[[#coord_real_distance|real_distance]]([[Modding:Coord|Coord]] c1, [[Modding:Coord|Coord]] c2) | |
− | |coord.[[#coord_mul|mul]]([[Modding:Coord|Coord]] or '''integer''' lhs, [[Modding:Coord|Coord]] or '''integer''' rhs) | + | |[[Modding:Coord|Coord]]|coord.[[#coord_random|random]]([[Modding:Coord|Coord]] c1, [[Modding:Coord|Coord]] c2) |
− | + | |'''integer''', '''integer'''|[[Modding:Coord|Coord]]:[[#coord_get|get]]() | |
− | + | |'''string'''|[[Modding:Coord|Coord]]:[[#coord_tostring|tostring]]() | |
− | |coord.[[#coord_eq|eq]]([[Modding:Coord|Coord]] lhs, [[Modding:Coord|Coord]], rhs) | + | |[[Modding:Coord|Coord]]|[[Modding:Coord|Coord]]:[[#coord_clone|clone]]() |
− | + | |'''void'''|[[Modding:Coord|Coord]]:[[#coord_random_shift|random_shift]]('''integer''' value) | |
− | + | |[[Modding:Coord|Coord]]|[[Modding:Coord|Coord]]:[[#coord_random_shifted|random_shifted]]('''integer''' value) | |
− | |coord.[[#coord_abs|abs]]([[Modding:Coord|Coord]] c) | + | |}} |
− | + | ||
− | + | ||
− | |coord.[[#coord_sign|sign]]([[Modding:Coord|Coord]] c) | + | |
− | + | ||
− | + | ||
− | |coord.[[#coord_distance|distance]]([[Modding:Coord|Coord]] c1, [[Modding:Coord|Coord]] c2) | + | |
− | + | ||
− | + | ||
− | |coord.[[#coord_real_distance|real_distance]]([[Modding:Coord|Coord]] c1, [[Modding:Coord|Coord]] c2) | + | |
− | + | ||
− | + | ||
− | |coord.[[#coord_random|random]]([[Modding:Coord|Coord]] c1, [[Modding:Coord|Coord]] c2) | + | |
− | + | ||
− | + | ||
− | |[[Modding:Coord|Coord]]:[[#coord_get|get]]() | + | |
− | + | ||
− | + | ||
− | |[[Modding:Coord|Coord]]:[[#coord_tostring|tostring]]() | + | |
− | + | ||
− | + | ||
− | |[[Modding:Coord|Coord]]:[[#coord_clone|clone]]() | + | |
− | + | ||
− | + | ||
− | |[[Modding:Coord|Coord]]:[[#coord_random_shift|random_shift]]('''integer''' value) | + | |
− | + | ||
− | + | ||
− | |[[Modding:Coord|Coord]]:[[#coord_random_shifted|random_shifted]]('''integer''' value) | + | |
|} | |} | ||
Revision as of 20:39, 19 October 2011
Coords (short for coordinates) are used to describe positions on the map. They are also occassionally used to indicate relative positions.
Properties
Although coords are technically userdata, they can be indexed like normal tables.
Coord | ||
---|---|---|
Integer | x | This is the x-coordinate of the coord. In DoomRL, x increases going from left to right, starting at 1 on the left edge of the map. |
Integer | y | This is the y-coordinate of the coord. In DoomRL, y increases going from top to bottom, starting at 1 on the upper edge of the map. |
API
Coord Interface | |
---|---|
Coord | coord.new(integer x, integer y) |
Coord | coord.unm(Coord c) |
Coord | coord.add(Coord lhs, Coord rhs) |
Coord | coord.sub(Coord lhs, Coord rhs) |
Coord | coord.mul(Coord or integer lhs, Coord or integer rhs) |
boolean | coord.eq(Coord lhs, Coord, rhs) |
Coord | coord.abs(Coord c) |
Coord | coord.sign(Coord c) |
integer | coord.distance(Coord c1, Coord c2) |
number | coord.real_distance(Coord c1, Coord c2) |
Coord | coord.random(Coord c1, Coord c2) |
integer, integer | Coord:get() |
string | Coord:tostring() |
Coord | Coord:clone() |
void | Coord:random_shift(integer value) |
Coord | Coord:random_shifted(integer value) |
- coord.new(integer x, integer y) → Coord
- This creates a new coord with the given x and y.
- coord.unm(Coord c) → Coord
- -Coord c → Coord
- This creates a new coord whose coordinates are the inverse (negative) of the original coordinates.
- coord.add(Coord lhs, Coord rhs) → Coord
- Coord lhs + Coord rhs → Coord
- This creates a new coord whose coordinates are the sums of the corresponding coordinates of lhs and rhs.
- coord.sub(Coord lhs, Coord rhs) → Coord
- Coord lhs - Coord rhs → Coord
- This creates a new coord whose coordinates are the differences of the corresponding coordinates of lhs and rhs.
- coord.mul(Coord or integer lhs, Coord or integer rhs) → Coord
- Coord or integer lhs * Coord or integer rhs → Coord
- With two coords, this creates a new coord whose coordinates are the products of the corresponding coordinates of lhs and rhs. With an integer, a new coord is returned with the coordinates of the original coord scaled by the integer. (This doesn't apply to two integers.)
- coord.eq(Coord lhs, Coord, rhs) → boolean
- Coord lhs == Coord rhs → boolean
- This determines if the given coords are coordinate-wise equal. (They might still be different objects! Beware using coords as table keys.)
- coord.abs(Coord c) → Coord
- This creates a new coord with coordinates that are the absolute value of the corresponding original coordinates.
- coord.sign(Coord c) → Coord
- This creates a new coord by applying the sign function (1 for positive, 0 for zero, -1 for negative) to each coordinate of the original coord.
- coord.distance(Coord c1, Coord c2) → integer
- Calculates the distance between the given coords.
- coord.real_distance(Coord c1, Coord c2) → number
- Calculates the (approximate) Euclidean distance between the biven coords.
- coord.random(Coord c1, Coord c2) → Coord
- Returns a new coord uniformly at random whose x is between the x coordinates of c1 and c2 (inclusive) and whose y is between the y coordinates of c1 and c2. The coordinates of c1 should be less than or equal to the corresponding coordinates of c2.
- Coord:get() → integer, integer
- Returns the x and y coordinates of the coord (in order).
- Coord:tostring() → string
- Returns a string containing the x and y coordinates separated by a comma.
- Coord:clone() → Coord
- Returns a copy of the coord.
- Coord:random_shift(integer value)
- Changes the coord uniformly at random to a different coord (or possibly the same coord) whose x and y are within value of the originals. value is optional; it defaults to 1.
- Coord:random_shifted(integer value) → Coord
- As random_shift, except instead of changing the existing coord, a new coord is returned.
Constants
Constant Coords | ||
null | coord.UNIT | This is a coord with 1 in both coordinates. Be careful not to change it. |
null | coord.ZERO | This is a coord with 0 in both coordinates. Be careful not to change it. |