Skip to content

Generic Interface Collision Detection

Lojemiru edited this page Oct 17, 2021 · 1 revision

While the core of the Loj Hadron Collider is built around lhc_move(), there are still situations where it may be useful to check for Interface-based collisions with the built-in collision function types.

These functions offer replacement for most built-in collision functions, but will run slower, so use them sparingly.


lhc_place_meeting

Interface-based place_meeting().

Syntax:

lhc_place_meeting(x, y, interface);

Returns: Boolean

Argument Type Description
x Real The x position to check for interfaces.
y Real The y position to check for interfaces.
interface String/String Array The interface (or array of interfaces) to check for collisions.

Example:

if (lhc_place_meeting(x + 1, y, "ISolid")) {
    // Do stuff!
}

lhc_position_meeting

Interface-based position_meeting().

Syntax:

lhc_position_meeting(x, y, interface);

Returns: Boolean

Argument Type Description
x Real The x position to check for interfaces.
y Real The y position to check for interfaces.
interface String/String Array The interface (or array of interfaces) to check for collisions.

Example:

if (lhc_position_meeting(x + 23, y - 27, "ISolid")) {
    // Do stuff!
}

lhc_collision_circle

Interface-based collision_circle().

Syntax:

lhc_collision_circle(x, y, rad, interface, [prec] = false, [notme] = true);

Returns: Boolean

Argument Type Description
x Real The x coordinate of the center of the circle to check.
y Real The y coordinate of the center of the circle to check.
rad Real The radius (distance in pixels from its center to its edge).
interface String/String Array The interface (or array of interfaces) to check for collisions.
[prec] Boolean Whether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster). Defaults to false.
[notme] Boolean Whether the calling instance, if relevant, should be excluded (true) or not (false). Defaults to true.

Example:

if (lhc_collision_circle(x, y, 10, "ISolid")) {
    // Do stuff!
}

lhc_collision_ellipse

Interface-based collision_ellipse().

Syntax:

lhc_collision_ellipse(x1, y1, x2, y2, interface, [prec] = false, [notme] = true);

Returns: Boolean

Argument Type Description
x1 Real The x coordinate of the left side of the ellipse to check.
y1 Real The y coordinate of the top side of the ellipse to check.
x2 Real The x coordinate of the right side of the ellipse to check.
y2 Real The y coordinate of the bottom side of the ellipse to check.
interface String/String Array The interface (or array of interfaces) to check for collisions.
[prec] Boolean Whether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster). Defaults to false.
[notme] Boolean Whether the calling instance, if relevant, should be excluded (true) or not (false). Defaults to true.

Example:

if (lhc_collision_ellipse(x - 10, y - 17, x + 10, y + 17, "ISolid")) {
    // Do stuff!
}

lhc_collision_line

Interface-based collision_line().

Syntax:

lhc_collision_line(x1, y1, x2, y2, interface, [prec] = false, [notme] = true);

Returns: Boolean

Argument Type Description
x1 Real The x coordinate of the start of the line.
y1 Real The y coordinate of the start of the line.
x2 Real The x coordinate of the end of the line.
y2 Real The y coordinate of the end of the line.
interface String/String Array The interface (or array of interfaces) to check for collisions.
[prec] Boolean Whether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster). Defaults to false.
[notme] Boolean Whether the calling instance, if relevant, should be excluded (true) or not (false). Defaults to true.

Example:

if (lhc_collision_line(x, y, x + 37, y + 14, "ISolid")) {
    // Do stuff!
}

lhc_collision_point

Interface-based collision_point().

Syntax:

lhc_collision_point(x, y, interface, [prec] = false, [notme] = true);

Returns: Boolean

Argument Type Description
x Real The x coordinate of the point to check.
y Real The y coordinate of the point to check.
interface String/String Array The interface (or array of interfaces) to check for collisions.
[prec] Boolean Whether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster). Defaults to false.
[notme] Boolean Whether the calling instance, if relevant, should be excluded (true) or not (false). Defaults to true.

Example:

if (lhc_collision_point(x + 27, y, "ISolid")) {
    // Do stuff!
}

lhc_collision_rectangle

Interface-based collision_rectangle().

Syntax:

lhc_collision_rectangle(x1, y1, x2, y2, interface, [prec] = false, [notme] = true);

Returns: Boolean

Argument Type Description
x1 Real The x coordinate of the left side of the rectangle to check.
y1 Real The y coordinate of the top side of the rectangle to check.
x2 Real The x coordinate of the right side of the rectangle to check.
y2 Real The y coordinate of the bottom side of the rectangle to check.
interface String/String Array The interface (or array of interfaces) to check for collisions.
[prec] Boolean Whether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster). Defaults to false.
[notme] Boolean Whether the calling instance, if relevant, should be excluded (true) or not (false). Defaults to true.

Example:

if (lhc_collision_rectangle(x - 5, y - 5, x + 5, y + 5, "ISolid")) {
    // Do stuff!
}