Cauldron2D.GameMaker.Collide (Cauldron2D.GameMaker v0.2.1)

Copy Markdown View Source

Collisions between instances, as GameMaker decides them.

An instance collides with the mask of its mask_index sprite, or of its sprite_index sprite when it has no mask sprite, at the frame image_index shows, placed at its position with its scale and angle. A sprite without masks collides as its collision box. An instance with neither sprite collides with nothing.

events/1 runs the step's collision events: for every instance, in creation order, and every object it has a collision event for, each other instance of that object (or of an object descending from it) that overlaps it runs the event with that instance as other. When the other instance is solid, the instance is first put back where it was at the start of the step; after the event it moves by its speed again and goes back once more if it still overlaps.

Summary

Functions

The first instance of target whose shape holds the point {x, y} (collision_point, instance_position, position_meeting); nil for none. target is an object index (its descendants count), :all, or {:id, id} for one instance.

The world with instance id bounced as GameMaker's move_bounce_solid(advanced) (against :solid) or move_bounce_all(advanced) (:all) bounces it. Overlapping something it bounces against, it first goes back to xprevious, yprevious. Simple bouncing reverses hspeed where a move across is blocked and vspeed where a move down is blocked, both when both are blocked or when only the move along both is blocked. Advanced bouncing turns from its direction, rounded to 10°, both ways in steps of 10° until a move of its speed is clear, and when anything was blocked takes direction 180 + left + right − direction.

The world after the step's collision events.

Whether instance id, moved to {x, y}, overlaps no solid instance.

Whether instance id, moved to {x, y}, overlaps an instance of object (:all for any).

The first instance of target the segment from from to to passes through (collision_line); nil for none. target as for at_point/3.

The first instance of object that instance id, moved to {x, y}, overlaps; nil for none.

The shape instance instance collides with at {x, y}, nil for none.

Types

target()

@type target() :: non_neg_integer() | :all | {:id, non_neg_integer()}

Functions

at_point(world, point, target)

@spec at_point(Cauldron2D.GameMaker.World.t(), {number(), number()}, target()) ::
  non_neg_integer() | nil

The first instance of target whose shape holds the point {x, y} (collision_point, instance_position, position_meeting); nil for none. target is an object index (its descendants count), :all, or {:id, id} for one instance.

bounce(world, id, advanced, against)

The world with instance id bounced as GameMaker's move_bounce_solid(advanced) (against :solid) or move_bounce_all(advanced) (:all) bounces it. Overlapping something it bounces against, it first goes back to xprevious, yprevious. Simple bouncing reverses hspeed where a move across is blocked and vspeed where a move down is blocked, both when both are blocked or when only the move along both is blocked. Advanced bouncing turns from its direction, rounded to 10°, both ways in steps of 10° until a move of its speed is clear, and when anything was blocked takes direction 180 + left + right − direction.

events(world)

The world after the step's collision events.

free?(world, id, position)

Whether instance id, moved to {x, y}, overlaps no solid instance.

meeting?(world, id, position, object)

@spec meeting?(
  Cauldron2D.GameMaker.World.t(),
  non_neg_integer(),
  {number(), number()},
  non_neg_integer() | :all
) :: boolean()

Whether instance id, moved to {x, y}, overlaps an instance of object (:all for any).

on_line(world, from, to, target)

@spec on_line(
  Cauldron2D.GameMaker.World.t(),
  {number(), number()},
  {number(), number()},
  target()
) ::
  non_neg_integer() | nil

The first instance of target the segment from from to to passes through (collision_line); nil for none. target as for at_point/3.

place(world, id, position, object)

The first instance of object that instance id, moved to {x, y}, overlaps; nil for none.

shape(world, instance, position)

The shape instance instance collides with at {x, y}, nil for none.