Difference between revisions of "Modding:Coord"
From DoomRL Wiki
Game Hunter (Talk | contribs) m (so you don't have to use huge <font-decoration> tags for it) |
Game Hunter (Talk | contribs) m (drltable used) |
||
(One intermediate revision by one user not shown) | |||
Line 4: | Line 4: | ||
Although coords are technically userdata, they can be indexed like normal tables. | Although coords are technically userdata, they can be indexed like normal tables. | ||
− | {| | + | {{drltable|Coord|3|{{Table3Col |
− | + | ||
− | + | ||
|es=background: #333; | |es=background: #333; | ||
|c1=font-weight:bold; text-align:right; vertical-align:top; padding:0px 3px; | |c1=font-weight:bold; text-align:right; vertical-align:top; padding:0px 3px; | ||
Line 14: | Line 12: | ||
|'''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. | |'''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 == | == API == | ||
− | {| | + | {{drltable|Coord Interface|2|{{Table2Col |
− | + | ||
− | + | ||
|es=background: #333; | |es=background: #333; | ||
|c1=font-weight:bold; text-align:right; vertical-align:top; padding:0px 2px; | |c1=font-weight:bold; text-align:right; vertical-align:top; padding:0px 2px; | ||
Line 40: | Line 36: | ||
|'''void'''|[[Modding:Coord|Coord]]:[[#coord_random_shift|random_shift]]('''integer''' value) | |'''void'''|[[Modding:Coord|Coord]]:[[#coord_random_shift|random_shift]]('''integer''' value) | ||
|[[Modding:Coord|Coord]]|[[Modding:Coord|Coord]]:[[#coord_random_shifted|random_shifted]]('''integer''' value) | |[[Modding:Coord|Coord]]|[[Modding:Coord|Coord]]:[[#coord_random_shifted|random_shifted]]('''integer''' value) | ||
+ | |[[Modding:Coord|CoordIterator]]|[[Modding:Coord|Coord]]:[[#coord_cross_coords|cross_coords]]() | ||
+ | |[[Modding:Coord|CoordIterator]]|[[Modding:Coord|Coord]]:[[#coord_around_coords|around_coords]]() | ||
|}} | |}} | ||
− | + | }} | |
{{Anchor|coord_new}} | {{Anchor|coord_new}} | ||
Line 111: | Line 109: | ||
;[[Modding:Coord|Coord]]:random_shifted('''integer''' value) → [[Modding:Coord|Coord]] | ;[[Modding:Coord|Coord]]:random_shifted('''integer''' value) → [[Modding:Coord|Coord]] | ||
:As random_shift, except instead of changing the existing coord, a new coord is returned. | :As random_shift, except instead of changing the existing coord, a new coord is returned. | ||
− | + | ---- | |
− | + | {{Anchor|coord_cross_coords}} | |
+ | ;[[Modding:Coord|Coord]]:cross_coords() → [[Modding:Coord|Coord]] '''iterator''' | ||
+ | :Gives an iterator over all coords that are orthogonally adjacent to the given coord (i.e., not diagonals). This is ordered as follows: west, east, north, then south. | ||
+ | ---- | ||
+ | {{Anchor|coord_around_coords}} | ||
+ | ;[[Modding:Coord|Coord]]:around_coords() → [[Modding:Coord|Coord]] '''iterator''' | ||
+ | :Gives an iterator over all coords adjacent to the given coord. It begins at the coord above and to the left of the given coord, then follows clockwise around the given coord. | ||
+ | === Constants === | ||
{|style="border: 2px solid darkred; border-spacing: 0; font-size: 90%; margin: 0.25em 0.5em;" | {|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"|'''Constant Coords''' | |colspan=3 style="background: darkred; color: yellow; font-size: 120%; text-align: center"|'''Constant Coords''' |
Latest revision as of 22:06, 24 March 2012
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) |
CoordIterator | Coord:cross_coords() |
CoordIterator | Coord:around_coords() |
- 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.
- Coord:cross_coords() → Coord iterator
- Gives an iterator over all coords that are orthogonally adjacent to the given coord (i.e., not diagonals). This is ordered as follows: west, east, north, then south.
- Coord:around_coords() → Coord iterator
- Gives an iterator over all coords adjacent to the given coord. It begins at the coord above and to the left of the given coord, then follows clockwise around the given coord.
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. |