Cauldron2D.Wx.View (Cauldron2D.Wx v0.1.3)

Copy Markdown View Source

A wx panel that shows a world: the canvas drawn from the sheet around the focus, the hud beside or below it if the game sends one, the keys and the pointer as input, the sound through the speaker.

view = Cauldron2D.Wx.View.new(parent, keymap: keymap, steering: [:left, :right], on_over: fn over -> ... end)
Cauldron2D.Wx.View.join(view, {:socket, url: url, token: token, topic: "world:main", params: %{}})
Cauldron2D.Wx.View.join(view, {:local, game: MyGame.Web, world: pid, name: "alice", props: %{}})
Cauldron2D.Wx.View.leave(view)

Options

  • :keymap — wx key codes and {:mouse, button} to actions, as Cauldron2D.Wx.Input.new/2 takes
  • :steering — the actions the pointer also drives
  • :size — the least the canvas is, in pixels, default {800, 600}; it grows with the window
  • :scale — pixels per sheet pixel, default 1
  • :hud — where the hud rows go: :right (default), :bottom, or :none for no hud panel
  • :hud_size — the hud panel's width (right) or height (bottom) in pixels, default 300
  • :hud_colours%{background: rgb, text: rgb} for the hud panel, default a dark panel with light text
  • :font — the hud's font in points, default 12
  • :on_over — called with the outcome when the round is over for this player; the game draws what it likes then, the canvas draws nothing of its own
  • :on_closed — called with the reason when the link ends
  • :on_refused — called with the reason when the join is refused
  • :on_key — called with the wx key code of a key that went down and means no action
  • :soundfalse for no sound
  • :input_every — milliseconds between input messages, default 100
  • :pointer — whether the pointer aims, default true; pointer/2 changes it later
  • :zoomtrue lets the player zoom: +/= in, - out, 0 back to the game's scale, the wheel either way, from a tile of 2 pixels (or the whole map in view, whichever is larger) to 64; zoom/2 sets a tile size from outside. Default false. A whole map that fits in 4096 pixels a side is drawn from one bitmap of it at the current size, so zooming out to see all of it costs nothing a frame; the sheet at each size is kept for the view's life, its bitmaps in one table the painter reads, so a zoom never takes a sheet from under a paint in progress. Watching — joined with spectate among the link's props or params — the view can also be panned: the arrows and a drag with the left button move it, the wheel zooms about the pointer, 0 recentres it as well, and a frame whose subject is not the one the pan was taken on drops the pan
  • :on_stats — called once a second with %{frames: n, draws: n}, the frames received and the times the canvas was painted in that second
  • :show_stats — draw those numbers in the canvas's top left corner, default false; show_stats/2 changes it later

The canvas is cleared to the sheet's void colour. Input goes to the link on every change and every :input_every ms.

Summary

Functions

Give the canvas the keyboard.

Join a world through a link: {:socket, opts} or {:local, opts}, the options of the link module less :owner.

Read keys by another keymap from now on, as new/2's :keymap; what was held is let go.

Leave the world.

The effects and music levels, 0.0 to 1.0.

The arena panel under parent.

Pause or resume a world of the player's own, through the link.

Whether the pointer aims from now on.

Whether the frames and draws a second are drawn on the canvas from now on.

The panel's wx window.

Draw tiles pixels wide from now on, within the zoom's limits.

Functions

focus(arena)

@spec focus(term()) :: :ok

Give the canvas the keyboard.

join(arena, link)

@spec join(term(), {:socket | :local, keyword()}) :: :ok

Join a world through a link: {:socket, opts} or {:local, opts}, the options of the link module less :owner.

keymap(view, keymap)

@spec keymap(term(), map()) :: :ok

Read keys by another keymap from now on, as new/2's :keymap; what was held is let go.

leave(arena)

@spec leave(term()) :: :ok

Leave the world.

levels(arena, sfx, music)

@spec levels(term(), number(), number()) :: :ok

The effects and music levels, 0.0 to 1.0.

new(parent, opts \\ [])

@spec new(term(), keyword()) :: term()

The arena panel under parent.

pause(arena)

@spec pause(term()) :: :ok

Pause or resume a world of the player's own, through the link.

pointer(view, on?)

@spec pointer(term(), boolean()) :: :ok

Whether the pointer aims from now on.

show_stats(view, on?)

@spec show_stats(term(), boolean()) :: :ok

Whether the frames and draws a second are drawn on the canvas from now on.

window(arena)

@spec window(term()) :: term()

The panel's wx window.

zoom(view, pixels)

@spec zoom(term(), pos_integer()) :: :ok

Draw tiles pixels wide from now on, within the zoom's limits.