Cauldron2D.Player (Cauldron2D v0.1.3)

Copy Markdown View Source

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.

Summary

Functions

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

Join world as id from the calling process.

Leave world.

Functions

input(world, id, input)

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

join(world, id, props)

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

Join world as id from the calling process.

leave(world, id)

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

Leave world.