A GameMaker game running: its data, its code, the room it is in and the instances in that room, as one value.
world = Cauldron2D.GameMaker.World.new(data, MyGame.Code)
world = Cauldron2D.GameMaker.Step.run(world, input)
{world, items} = Cauldron2D.GameMaker.Draw.run(world)Instances are kept by id, and order lists their ids in creation order, the order
GameMaker runs every event in. An object without code for an event runs its parent's,
up the chain.
Code changes the world through the functions here: fetch/2, update/3, create/4,
destroy/2, goto/2, put_global/3, emit/2, put_view/3, put_layer/3. Instances
code creates are numbered from one past the highest id any room places, as GameMaker
numbers them, so they never take a placed instance's id. views
are the room's views as the game has moved them, scroll how far each of the room's
layers has scrolled by its speed since the room was entered, by layer id, and layers
the changes code has made to the room's layers, by layer name (layers/1 applies
them), and hidden_tiles the depths of the GameMaker Studio 1 tiles code has hidden
(hide_tiles/3); added_tiles the tiles code has added (add_tile/5). particles are those Cauldron2D.GameMaker.Particles has set loose; surfaces
the rasters code draws onto, by id, with the next id to give (Cauldron2D.GameMaker.Surfaces
keeps them; Surfaces.rasters/1 reads them), drawn with the picture lookup pictures. outbox collects what the step sends
out — sounds to play and the like — in the order it was sent; take_outbox/1 empties
it. random is the game's random number generator (Cauldron2D.GameMaker.Random),
seeded with the :seed option. object_depths are the depths code creates objects
at, by object index, where they differ from the objects' own (:object_depths).
Summary
Functions
The world with a tile added by code (tile_add): the part {left, top, width, height} of frame 0 of sprite sprite, its top-left corner at {x, y}, at depth
depth. It is drawn until the room is left, hidden with the room's tiles at its depth
(hide_tiles/3).
A new instance of object at {x, y}, its pre-create and create events run, and its
id. fields are instance variables set before those events run (scale, angle and so
on, as a room places an instance).
Whether object object is ancestor or descends from it.
The world after instance id's destroy and clean-up events, without it.
The world with message added to its outbox.
The instance id, nil once it is gone.
The global variable name, default when unset.
The world going to room room once the current step ends.
Whether instance id's object, or an ancestor, has code for the event.
The world with the room's GameMaker Studio 1 tiles at depth depth hidden (hidden
true, tile_layer_hide) or shown again (tile_layer_show). Entering a room shows
every tile.
The world after instance id runs the code the parent of object (an object name)
has for the event: GameMaker's event_inherited, called from object's own code.
The ids, in creation order, of the instances of object and of every object that
descends from it; :all for every instance.
The room's layers with the changes code has made to them (put_layer/3).
The game in its first room, its instances created and the room started. Options:
:room, a room index to start in instead of the first in the room order;
:pictures, the function from a draw list picture key to its raster that drawing
onto surfaces uses; :seed, the random number generator's seed (default 0);
:object_depths, a map from object name to the depth create/4 gives its instances —
a GameMaker Studio 2 game converted from GameMaker: Studio 1 keeps its objects' old
depths in such a table and creates instances at them (object_get_depth); an object
it does not name keeps its own depth.
The object definition at index.
The index of the object called name.
The world after instance id runs its code for the event type with subtype,
other being the other instance of a collision. Nothing runs when the instance is
gone or has no code for the event.
The world with global variable name set to value.
The world with the room's layer name changed, as GameMaker's layer_set_visible,
layer_x, layer_y, layer_hspeed, layer_vspeed, layer_depth and
layer_background_* change it: changes has any of :visible, :offset {x, y},
:speed {x, y}, :depth, :background, a map of the background layer's own
fields (:sprite, :colour {r, g, b, a}, :tiled, :stretch, :xscale, :yscale,
…), and
:tile_blend {r, g, b}, the colour every tile of an asset layer is drawn with, its
alpha kept (layer_tile_blend on each of the layer's tiles). Changes add up until the
room is left.
The world with view index's view rectangle {x, y, width, height} set: GameMaker's
view_xview, view_yview, view_wview and view_hview.
The world without instance id, no events run.
The world after running the code named name, if the game has any.
The sprite at index, nil for a negative index.
The outbox's messages in the order sent, and the world with it empty.
The world with instance id replaced by fun of it; unchanged when it is gone.
Types
@type t() :: %Cauldron2D.GameMaker.World{ added_tiles: [map()], code: module(), created: non_neg_integer(), data: Cauldron2D.GameMaker.Data.t(), descendants: tuple(), drawing: list(), globals: map(), hidden_tiles: MapSet.t(number()), hovered: MapSet.t(), input: input(), instances: %{required(non_neg_integer()) => Cauldron2D.GameMaker.Instance.t()}, layers: %{required(String.t()) => map()}, members: %{ required(non_neg_integer()) => [{non_neg_integer(), non_neg_integer()}] }, next_id: non_neg_integer(), object_depths: %{required(non_neg_integer()) => number()}, objects: tuple(), order: [non_neg_integer()], outbox: list(), outside: MapSet.t(), owners: tuple(), part_systems: map(), particles: [map()], pending_room: non_neg_integer() | nil, pictures: (term() -> FrenchCurve.Raster.t() | nil) | nil, random: Cauldron2D.GameMaker.Random.t(), room: non_neg_integer() | nil, scroll: %{required(non_neg_integer()) => {number(), number()}}, sprites: tuple(), steps: non_neg_integer(), surfaces: %{ rasters: %{required(non_neg_integer()) => FrenchCurve.Raster.t()}, next: non_neg_integer() }, views: [Cauldron2D.GameMaker.Room.View.t()] }
Functions
@spec add_tile( t(), non_neg_integer(), {number(), number(), number(), number()}, {number(), number()}, number() ) :: t()
The world with a tile added by code (tile_add): the part {left, top, width, height} of frame 0 of sprite sprite, its top-left corner at {x, y}, at depth
depth. It is drawn until the room is left, hidden with the room's tiles at its depth
(hide_tiles/3).
@spec create(t(), non_neg_integer(), {number(), number()}, map()) :: {t(), non_neg_integer()}
A new instance of object at {x, y}, its pre-create and create events run, and its
id. fields are instance variables set before those events run (scale, angle and so
on, as a room places an instance).
@spec descends?(t(), non_neg_integer() | nil, non_neg_integer()) :: boolean()
Whether object object is ancestor or descends from it.
@spec destroy(t(), non_neg_integer()) :: t()
The world after instance id's destroy and clean-up events, without it.
The world with message added to its outbox.
@spec fetch(t(), non_neg_integer() | nil) :: Cauldron2D.GameMaker.Instance.t() | nil
The instance id, nil once it is gone.
The global variable name, default when unset.
@spec goto(t(), non_neg_integer()) :: t()
The world going to room room once the current step ends.
@spec handles?(t(), non_neg_integer(), Cauldron2D.GameMaker.Event.type(), term()) :: boolean()
Whether instance id's object, or an ancestor, has code for the event.
The world with the room's GameMaker Studio 1 tiles at depth depth hidden (hidden
true, tile_layer_hide) or shown again (tile_layer_show). Entering a room shows
every tile.
@spec inherited( t(), non_neg_integer(), String.t(), Cauldron2D.GameMaker.Event.type(), term(), non_neg_integer() | nil ) :: t()
The world after instance id runs the code the parent of object (an object name)
has for the event: GameMaker's event_inherited, called from object's own code.
@spec instances_of(t(), non_neg_integer() | :all) :: [non_neg_integer()]
The ids, in creation order, of the instances of object and of every object that
descends from it; :all for every instance.
@spec layers(t()) :: [Cauldron2D.GameMaker.Room.Layer.t()]
The room's layers with the changes code has made to them (put_layer/3).
@spec new(Cauldron2D.GameMaker.Data.t(), module(), keyword()) :: t()
The game in its first room, its instances created and the room started. Options:
:room, a room index to start in instead of the first in the room order;
:pictures, the function from a draw list picture key to its raster that drawing
onto surfaces uses; :seed, the random number generator's seed (default 0);
:object_depths, a map from object name to the depth create/4 gives its instances —
a GameMaker Studio 2 game converted from GameMaker: Studio 1 keeps its objects' old
depths in such a table and creates instances at them (object_get_depth); an object
it does not name keeps its own depth.
@spec object(t(), non_neg_integer()) :: Cauldron2D.GameMaker.Object.t()
The object definition at index.
@spec object_index(t(), String.t()) :: non_neg_integer() | nil
The index of the object called name.
@spec perform( t(), non_neg_integer(), Cauldron2D.GameMaker.Event.type(), term(), non_neg_integer() | nil ) :: t()
The world after instance id runs its code for the event type with subtype,
other being the other instance of a collision. Nothing runs when the instance is
gone or has no code for the event.
The world with global variable name set to value.
The world with the room's layer name changed, as GameMaker's layer_set_visible,
layer_x, layer_y, layer_hspeed, layer_vspeed, layer_depth and
layer_background_* change it: changes has any of :visible, :offset {x, y},
:speed {x, y}, :depth, :background, a map of the background layer's own
fields (:sprite, :colour {r, g, b, a}, :tiled, :stretch, :xscale, :yscale,
…), and
:tile_blend {r, g, b}, the colour every tile of an asset layer is drawn with, its
alpha kept (layer_tile_blend on each of the layer's tiles). Changes add up until the
room is left.
The world with view index's view rectangle {x, y, width, height} set: GameMaker's
view_xview, view_yview, view_wview and view_hview.
@spec remove(t(), non_neg_integer()) :: t()
The world without instance id, no events run.
@spec run_named(t(), String.t(), non_neg_integer() | nil, non_neg_integer() | nil) :: t()
The world after running the code named name, if the game has any.
@spec sprite(t(), integer()) :: Cauldron2D.GameMaker.Sprite.t() | nil
The sprite at index, nil for a negative index.
The outbox's messages in the order sent, and the world with it empty.
@spec update(t(), non_neg_integer(), (Cauldron2D.GameMaker.Instance.t() -> Cauldron2D.GameMaker.Instance.t())) :: t()
The world with instance id replaced by fun of it; unchanged when it is gone.