The coord datum is similar to the vector2 datum, but also contains a z coordinate. z coordinates ignore arithmetic, which is how they are distinct from a vector3.
operators supported:
- + - * / Arithmetic operators return a new vector
- += -= *= /= Assignment operators modify the left operand's x, y values
- ~= ~! Equivalence operators check if x, y, and z are the same on two coords
- [] indexing is used to pull coordinate conversions out of coords.
conversions:
coord[1],coord["absolute_x"],coord["abs_x"]: x
coord[2],coord["absolute_y"],coord["abs_y"]: y
coord[3],coord["z"]: z
coord["x"],coord["tile_x"]: round(x / TILE_WIDTH) + 1
coord["y"],coord["tile_y"]: round(y / TILE_HEIGHT) + 1
coord["step_x"]: x - round(x / TILE_WIDTH) * TILE_WIDTH
coord["step_y"]: y - round(y / TILE_HEIGHT) * TILE_HEIGHT
coord procs
- getClamped([x=0,y=0,w=1,h=1]) clamps this coord between world max coordinates for the given bounding box
- Step() moves this coord along the distance that would be attempted by a movable's step with the same args
- getStep() like step, but returns a new coord instead of modifying this one
- Bounds([w=1,h=1,x=0,y=0]) returns any objects within the specified bounding region. x,y args offset the position of the vector's x,y values. w,h sets the size of the box used to find overlapping objects in the world.
- Locate() returns the turf at the coord's position.
- getDir(atom|vector2|coord) returns the manhattan direction between this coord and the center of the passed atom, or the vector or coord passed as a target.
- getDirection(atom|vector2|coord) returns the smoothed direction between this coord and the center of the passed atom, or the vector or coord passed as a target. Direction is angular, and along a 45 degree arc segment offset by 22.5 degrees from 0.
- getDist(atom|vector2|coord) returns the manhattan distance between this coord and the center of the passed atom or the vector or coord passed as the target. If the target is a vector, they are assumed to be on the same Z layer. Otherwise, if not on the same Z layer, distance is infinite.
- getDistance(atom|vector2|coord) returns real distance between this vector and the center of the passed atom or the vector or coord passed as the target. If the target is a vector, they are assumed to be on the same Z layer. Otherwise, if not on the same Z layer, distance is infinite.
- getAngle(atom|vector2|coord) returns the angle between this coord and the center of the passed atom or the vector or coord passed as the target. This assumes that we are always on the same Z layer as the target.
- vector2() creates a new vector2 using the coord's x and y values.
iscoord() is a shorthand for istype(v,/coord) that's included in the library.
You can get a coord from any atom by calling atom.coord(anchor)
anchor may be one of:
NORTH (1)
SOUTH (2)
EAST (4)
WEST (8)
NORTHEAST (5)
NORTHWEST (9)
SOUTHEAST (6)
SOUTHWEST (10)
CENTER (0)
The anchored position will result in a coord referencing one of the nine points along the left, center, right, top, middle, and bottom anchor points of the atom's bounding box.
Trace() is a handy little function that acts quite a lot like a Step() or a Relocate() call. But it can return a /trace datum with information about the movement, and can be passed a list of atoms it will ignore collision with, or it can be passed a series of flags that will customize how it functions.
Flags:
TRACE_SLIDE (1) If on, the movement will act like Slide()
TRACE_JUMP (2) If on, the movement will act like Relocate() --If both are off, it will just act like Move(), using step_size to determine jumping or sliding.
TRACE_MOVE (4) If on, the movement will finalize immediately.
TRACE_IGNORE_CROSS (8) Cross failures won't stop this movement, and atom.Cross()/Enter() won't be called by the mover.
TRACE_IGNORE_UNCROSS (16) Uncross failures won't stop this movement, and atom.Uncross()/Exit() won't be called by the mover.
TRACE_DISABLE_CROSSED (32) The mover won't call Crossed()/Entered() on finalization.
TRACE_DISABLE_UNCROSSED (64) The mover won't call Uncrossed()/Exited() on finalization.
TRACE_DISABLE_BUMP (128) The mover won't call Bump() on finalization.
TRACE_RESULTS (256) If on, Trace() returns a /trace datum containing information about the attempted movement. If off, Trace() returns whatever Move() would have (the distance it's possible to move, or 0 on failure)
Trace() Forms:
Trace(turf/ NewLoc,[Dir,step_x,step_y,flags=TRACE_MOVE,ignore=null]) - turf form
Trace(coord,[Dir,flags=TRACE_MOVE,ignore=null]) - coord form
Trace(vector2,[Dir,flags=TRACE_MOVE,ignore=null]) - vector2 form
Trace(direction,[Dir,dist=step_size,flags=TRACE_M OVE,ignore=null]) - directional form
Trace(ang=0..360,[face=0,dist=step_size,flags=TRA CE_MOVE,ignore=null]) - angular form
/trace datum
Trace may return the number of pixels that it was possible to move, 0, or a /trace datum. The trace datum contains a list of variables that will provide information about the movement.
atom/movable/mover - The mover that the trace was run on
coord/old_loc - The mover's coords when the trace was started
coord/new_loc - Where the mover attempted to trace a movement to
coord/loc - The mover's coords when the trace completed or failed
list/crossing - any atoms that would be crossed over during the trace
list/uncrossing - any atoms that would be crossed out of during the trace
atom/collider - the atom that caused the trace to fail
result - what the traced movement would have returned (the number of pixels moved)
Finalize() - This immediately places the mover at the final position of the trace, and calls the Crossed()/Uncrossed()/Entered()/Exited()/Bump() hooks for any crossing or uncrossing atoms in the correct sequence with the correct arguments, as though the movement were really happening. If the trace has already been finalized, nothing happens. As the trace already did the required calls to Cross()/Uncross()/Enter()/Exit() have already been simulated by the Trace(), there is no need to call them again here.