Cauldron2D.GameMaker.PartSystems (Cauldron2D.GameMaker v0.2.1)

Copy Markdown View Source

GameMaker's particle systems as its runtime runs them: systems that hold particles, particle types that say how each particle starts, moves, changes and draws, and emitters that set particles loose over a region. The functions are the game code's part_system_*, part_type_*, part_emitter_* and part_particles_create, each taking and giving the world; random draws come from the world's generator (Cauldron2D.GameMaker.Random), in the runtime's order.

{world, system} = PartSystems.system_create(world)
{world, dust} = PartSystems.type_create(world)
world = PartSystems.type_sprite(world, dust, sprite, true, false, false)
{world, emitter} = PartSystems.emitter_create(world, system)
world =
  world
  |> PartSystems.emitter_region(system, emitter, {x - 4, x + 4, y, y}, :rectangle, :linear)
  |> PartSystems.emitter_burst(system, emitter, dust, 1)

A particle starts with a speed, direction, angle, size and life drawn from its type's ranges, its type's first colour and alpha, and, for a type with a random start frame, a frame drawn from 0–9999. system_update/2 then, for every particle:

  1. ages it a step; one whose life is up dies, setting loose its type's death particles where it was, and every living one sets loose its step particles
  2. adds the type's speed increment (never below 0), direction increment and angle increment, turns its motion by the type's gravity, and moves it by its speed and direction, each shaken by its wiggle
  3. adds the size increment (never below 0), sets its colour, and fades its alpha along the type's three alphas, the second at half its life

and then lets every emitter with a stream burst. A wiggle is a triangle wave from −1 to 1 times the type's wiggle amount, whose phase is the particle's age plus a multiple of a number from 0–99999 drawn when it was made.

items/2 gives a system's particles as draw list items in its draw order; a system drawn automatically is drawn by Cauldron2D.GameMaker.Draw at its depth, and one updated automatically is updated with each step.

Summary

Functions

Every automatically drawn system's particles as draw list items, at the system's depth.

number particles of type type set loose over emitter emitter's region; a negative number sets one loose by a 1 in |number| chance (part_emitter_burst).

A new emitter of system system; {world, emitter} (part_emitter_create).

The world without emitter emitter of system system (part_emitter_destroy).

Emitter emitter's region {xmin, xmax, ymin, ymax}, its shape and how particles spread over it (part_emitter_region).

System system's particles as draw list items, in its draw order (part_system_drawit).

number particles of type type set loose at {x, y} (part_particles_create).

The world with every automatically updated system one step on.

System system drawn by itself, or only through items/2 (part_system_automatic_draw).

System system updated by itself each step, or only by system_update/2 (part_system_automatic_update).

A new particle system; {world, system} (part_system_create).

System system drawn at depth (part_system_depth).

The world without system system and its particles (part_system_destroy).

Whether system system exists (part_system_exists).

The world with system system one step on (part_system_update).

Type type's alpha, the same all its life (part_type_alpha1).

Type type's alpha at its start, half its life and its end (part_type_alpha3).

Type type drawn added to what is under it, or over it (part_type_blend).

Type type coloured colour {r, g, b} (part_type_colour1).

Type type coloured from hue, saturation and value each drawn from its range when a particle is made, 0–255 (part_type_colour_hsv).

A new particle type with GameMaker's defaults; {world, type} (part_type_create).

number particles of type death set loose where a particle of type dies (part_type_death).

The world without particle type type (part_type_destroy).

Type type's direction range, increment a step and wiggle, in degrees (part_type_direction).

Type type's gravity: amount a step towards direction (part_type_gravity).

Type type's life, from low to high steps (part_type_life).

Type type's angle range, increment a step and wiggle, and whether the angle is added to the direction of motion (part_type_orientation).

Type type's scale {x, y} (part_type_scale).

Type type's size range, increment a step and wiggle (part_type_size).

Type type's speed range, increment a step and wiggle (part_type_speed).

Type type drawn as sprite sprite: animated through its frames, stretched so its frames span the particle's life, starting on a random frame (part_type_sprite).

number particles of type step set loose each step from each particle of type (part_type_step).

Types

distribution()

@type distribution() :: :linear | :gaussian | :invgaussian

shape()

@type shape() :: :rectangle | :ellipse | :diamond | :line

Functions

automatic_items(world)

@spec automatic_items(Cauldron2D.GameMaker.World.t()) :: [map()]

Every automatically drawn system's particles as draw list items, at the system's depth.

emitter_burst(world, system, emitter, type, number)

number particles of type type set loose over emitter emitter's region; a negative number sets one loose by a 1 in |number| chance (part_emitter_burst).

emitter_create(world, system)

A new emitter of system system; {world, emitter} (part_emitter_create).

emitter_destroy(world, system, emitter)

The world without emitter emitter of system system (part_emitter_destroy).

emitter_region(world, system, emitter, region, shape, distribution)

Emitter emitter's region {xmin, xmax, ymin, ymax}, its shape and how particles spread over it (part_emitter_region).

items(world, system)

System system's particles as draw list items, in its draw order (part_system_drawit).

particles_create(world, system, position, type, number)

number particles of type type set loose at {x, y} (part_particles_create).

step(world)

The world with every automatically updated system one step on.

system_automatic_draw(world, system, on)

System system drawn by itself, or only through items/2 (part_system_automatic_draw).

system_automatic_update(world, system, on)

System system updated by itself each step, or only by system_update/2 (part_system_automatic_update).

system_create(world)

A new particle system; {world, system} (part_system_create).

system_depth(world, system, depth)

System system drawn at depth (part_system_depth).

system_destroy(world, system)

The world without system system and its particles (part_system_destroy).

system_exists?(world, system)

@spec system_exists?(Cauldron2D.GameMaker.World.t(), non_neg_integer()) :: boolean()

Whether system system exists (part_system_exists).

system_update(world, system)

The world with system system one step on (part_system_update).

type_alpha1(world, type, alpha)

Type type's alpha, the same all its life (part_type_alpha1).

type_alpha3(world, type, start, middle, finish)

Type type's alpha at its start, half its life and its end (part_type_alpha3).

type_blend(world, type, additive)

Type type drawn added to what is under it, or over it (part_type_blend).

type_colour1(world, type, colour)

Type type coloured colour {r, g, b} (part_type_colour1).

type_colour_hsv(world, type, hue, saturation, value)

Type type coloured from hue, saturation and value each drawn from its range when a particle is made, 0–255 (part_type_colour_hsv).

type_create(world)

A new particle type with GameMaker's defaults; {world, type} (part_type_create).

type_death(world, type, number, death)

number particles of type death set loose where a particle of type dies (part_type_death).

type_destroy(world, type)

The world without particle type type (part_type_destroy).

type_direction(world, type, low, high, increment, wiggle)

Type type's direction range, increment a step and wiggle, in degrees (part_type_direction).

type_gravity(world, type, amount, direction)

Type type's gravity: amount a step towards direction (part_type_gravity).

type_life(world, type, low, high)

Type type's life, from low to high steps (part_type_life).

type_orientation(world, type, low, high, increment, wiggle, relative)

Type type's angle range, increment a step and wiggle, and whether the angle is added to the direction of motion (part_type_orientation).

type_scale(world, type, x, y)

Type type's scale {x, y} (part_type_scale).

type_size(world, type, low, high, increment, wiggle)

Type type's size range, increment a step and wiggle (part_type_size).

type_speed(world, type, low, high, increment, wiggle)

Type type's speed range, increment a step and wiggle (part_type_speed).

type_sprite(world, type, sprite, animate, stretch, random_frame)

Type type drawn as sprite sprite: animated through its frames, stretched so its frames span the particle's life, starting on a random frame (part_type_sprite).

type_step(world, type, number, step)

number particles of type step set loose each step from each particle of type (part_type_step).