- atom.Px(P), atom.Py(P) - The absolute pixel position of the bottom-left of this atom. Include a P percentage (0 to 1) to add a percentage of the atom's size.
- atom.Cx(), atom.Cy() - The absolute pixel position of the center of this atom. Equivalent to atom.Px(0.5), atom.Py(0.5).
- movable.SetLoc(Loc, StepX, StepY) - A function to directly set the loc, step_x, and step_y variables. Good for overriding; call ..() to actually do the thing.
- movable.SetPosition(Px, Py, Z) - Set the absolute pixel position of the bottom-left corner of your movable atom's bounding box.
- movable.SetCenter(Cx, Cy, Z) - Set the absolute pixel position of the center of the movable atom.
- movable.Translate(Dx, Dy, Dir) - Move a movable atom by a certain number of pixels in the x and y direction. By including this library, you're able to move at less-than-pixel distances, e.g. Translate(0.5, 0.5) moves half a pixel north and east. You can provide a Dir for the mover to end up with.
- movable.Project(Distance, Angle, Dir) - Move a movable atom by a certain distance and angle. 0 degrees is north and 90 degrees is east. This uses Translate().
Example
proc/move_towards(atom/movable/a, atom/b, speed)
// speed defaults to the mover's step size
if(isnull(speed)) speed = a.step_size
// if speed turns out to be 0, then there's no movement
if(!speed) return
// a simple vector
// from: the center of 'a'
// to: the center of 'b'
var delta_x = b.Cx() - a.Cx()
var delta_y = b.Cy() - a.Cy()
// a and b are in the same position!
if(!(delta_x || delta_y)) return
// if the delta vector is larger than speed,
// we need to scale it down to speed.
// we do this by dividing by the magnitude of the delta vector,
// which results in a unit vector,
// and then scaling that up by the speed.
var distance = sqrt(delta_x*delta_x + delta_y*delta_y)
if(distance > speed)
var s = speed / distance
delta_x *= s
delta_y *= s
a.Translate(delta_x, delta_y)
Thanks for noticing. I started using that convention on purpose for that exact reason. Libraries should be used (and made) with the intention of extending (or abstracting) the language.
I actually have more unlisted libraries that I made hubs for just so I could include them with a checkbox... This was around when I went an entire week making one small game every day. Most of them used this library. It's easier to directly use my knowledge of vector math and trigonometry when I don't have to actively deal with BYOND always rounding my positions.