ElixirDoom.Mobj (elixir_doom v0.1.0)

Copy Markdown View Source

Things — players, monsters, missiles, pickups, decorations — and how each moves and changes state every tic.

{world, id} = ElixirDoom.Mobj.spawn(world, :mt_troop, {x, y, :floor}, angle)
world = ElixirDoom.Mobj.set_state(world, id, :s_troo_run1)
world = ElixirDoom.Mobj.tick(world, id)

A thing is a map with its type, position (z its feet), angle in radians, momentum, size, flags (a set of Doom's MF_ names as atoms), health, state, and the bookkeeping monsters use to hunt. States come from ElixirDoom.Info and are run by Cauldron2D.States; their actions by ElixirDoom.Actions.

Summary

Functions

The angle from thing a to b, in radians.

Doom's quick distance: the longer side plus half the shorter.

The body Cauldron2D.Sectors.Move moves for thing mobj.

Thing id, a missile, bursts where it is.

Thing mobj with flag set or cleared.

Whether thing mobj has flag flag.

Thing type mobj's definition.

The movement options for thing mobj.

Put thing id into state name, running its actions; nil removes it.

Spawn a thing of type at {x, y, z}, z a height or :floor or :ceiling.

One tic of thing id: move it, let it fall, count its state down.

Move thing id to point if it fits, picking up what it touches and triggering the lines it crosses: {:ok, world} or {:blocked, world, why}, why as Cauldron2D.Sectors.Move.try/4 reports it, with floats?: true where only its height was wrong.

Functions

angle_to(a, b)

@spec angle_to(map(), map()) :: float()

The angle from thing a to b, in radians.

approx_distance(a, b)

@spec approx_distance(map(), map()) :: float()

Doom's quick distance: the longer side plus half the shorter.

body(mobj)

@spec body(map()) :: Cauldron2D.Sectors.Move.body()

The body Cauldron2D.Sectors.Move moves for thing mobj.

explode_missile(world, id)

@spec explode_missile(ElixirDoom.World.t(), pos_integer()) :: ElixirDoom.World.t()

Thing id, a missile, bursts where it is.

flag(mobj, flag, bool)

@spec flag(map(), atom(), boolean()) :: map()

Thing mobj with flag set or cleared.

flag?(map, flag)

@spec flag?(map(), atom()) :: boolean()

Whether thing mobj has flag flag.

info(map)

@spec info(map()) :: map()

Thing type mobj's definition.

move_opts(world, mobj)

@spec move_opts(ElixirDoom.World.t(), map()) :: keyword()

The movement options for thing mobj.

set_state(world, id, name)

@spec set_state(ElixirDoom.World.t(), pos_integer(), atom() | nil) ::
  ElixirDoom.World.t()

Put thing id into state name, running its actions; nil removes it.

spawn(world, type, arg, angle \\ 0.0)

@spec spawn(
  ElixirDoom.World.t(),
  atom(),
  {number(), number(), number() | :floor | :ceiling},
  number()
) ::
  {ElixirDoom.World.t(), pos_integer()}

Spawn a thing of type at {x, y, z}, z a height or :floor or :ceiling.

tick(world, id)

One tic of thing id: move it, let it fall, count its state down.

try_move(world, id, point)

@spec try_move(ElixirDoom.World.t(), pos_integer(), {number(), number()}) ::
  {:ok, ElixirDoom.World.t()} | {:blocked, ElixirDoom.World.t(), map()}

Move thing id to point if it fits, picking up what it touches and triggering the lines it crosses: {:ok, world} or {:blocked, world, why}, why as Cauldron2D.Sectors.Move.try/4 reports it, with floats?: true where only its height was wrong.