A lightweight 2d game engine for the web. In gleam.
Find a file
bgw f58c5f6b4f
Some checks failed
test / test (push) Has been cancelled
feat(draw): add function to draw_sprite by tilemap id
2024-09-10 18:28:54 +01:00
.github/workflows initial commit 2024-07-27 23:25:23 +01:00
examples feat: add support for Tiled .json output 2024-09-07 19:35:50 +01:00
src feat(draw): add function to draw_sprite by tilemap id 2024-09-10 18:28:54 +01:00
test initial commit 2024-07-27 23:25:23 +01:00
.gitignore add image loading and auto canvas resizing 2024-07-27 23:31:43 +01:00
flake.lock build(nix): update flake for gleam 1.4.1 2024-08-20 18:27:55 +01:00
flake.nix initial commit 2024-07-27 23:25:23 +01:00
gleam.toml feat: add support for Tiled .json output 2024-09-07 19:35:50 +01:00
LICENSE initial commit 2024-07-27 23:25:23 +01:00
manifest.toml feat: add support for Tiled .json output 2024-09-07 19:35:50 +01:00
README.md feat: add support for Tiled .json output 2024-09-07 19:35:50 +01:00

paper

Package Version Hex Docs

gleam add paper@1
import gleam/int
import paper

const width = 64.0

const height = 64.0

pub fn main() {
  paper.Spec("canvas", width, height, False, False, init, view, update) |> paper.start
}

pub type State {
  State(count: Int)
}

fn init() -> State {
  State(0)
}

fn update(state: State, input: paper.Input) -> State {
  let state = case paper.is_pressed(input, "w") {
    True -> State(state.count + 1)
    False -> state
  }
  let state = case paper.is_pressed(input, "s") {
    True -> State(state.count - 1)
    False -> state
  }

  state
}

fn view(state: State) -> paper.Draws {
  [
    paper.draw_text_center(
      width *. 0.5,
      height *. 0.5,
      int.to_string(state.count),
      "#ffaff3",
    ),
  ]
}

You will need to create an index.html with a canvas element with the id specified in paper.Spec.

See the examples directory for reference on index.html files (in public/) as well as building and bundling (in Makefile).

Development

gleam run   # Run the project
gleam test  # Run the tests