# `Cauldron2D.Player`
[🔗](https://github.com/jaman/cauldron/blob/v0.1.3/cauldron_2d/lib/cauldron_2d/player.ex#L1)

A player's side of a `Cauldron2D.World`: join, send input, receive frames, leave.

Anything that runs in a process can be a player — a terminal session, a computer
player, a test.

    :ok = Cauldron2D.Player.join(world, :alice, %{username: "alice"})
    Cauldron2D.Player.input(world, :alice, Cauldron2D.Input.state(input))

    receive do
      {:cauldron_frame, %{tick: tick, view: view, events: events}} -> ...
    end

Frames arrive once per tick for as long as the player is joined. Leaving, or the
process exiting, stops them.

# `input`

```elixir
@spec input(
  GenServer.server(),
  Cauldron2D.World.player_id(),
  Cauldron2D.Input.state()
) :: :ok
```

Send what the player is doing now; applied before the next tick.

# `join`

```elixir
@spec join(GenServer.server(), Cauldron2D.World.player_id(), map()) ::
  :ok | {:error, term()}
```

Join `world` as `id` from the calling process.

# `leave`

```elixir
@spec leave(GenServer.server(), Cauldron2D.World.player_id()) :: :ok
```

Leave `world`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
