Glove

Glove is a framework for making games. It is implemented in Crystal.

⚠ Caution! ⚠ Glove is experimental. Expect breaking changes. There are few tests. Do not use this for your own projects (yet).

Usage

To use this shard, add the following lines to your shard.yml:

dependencies:
  glove:
    git: git@github.com:ddfreyne/glove.git

Glove comes with shaders in its shaders/ directory, which needs to be copied to where the executable is located. For example, the following will create a target/ directory that contains the executable and the shaders directory:

rm -rf target/
mkdir -p target

crystal build -o target/mygame src/mygame.cr

cp -r lib/glove/src/shaders target/shaders

It is useful to let the executable cd to the directory it is located in, before doing anything else, so that it can find the shaders easily:

if full_path = Process.executable_path
  Dir.cd(File.dirname(full_path))
end

The target/ directory should also include any assets that the game needs to run; a more complete build script could therefore look as follows:

rm -rf target/
mkdir -p target

crystal build -o target/mygame src/mygame.cr

cp -r lib/glove/src/shaders target/shaders
cp -r assets target/assets # <- added

Example code

Here is a trivial example that renders a card (from assets/card.png):

require "glove"

if full_path = Process.executable_path
  Dir.cd(File.dirname(full_path))
end

card =
  Glove::Entity.new.tap do |e|
    e << Glove::Components::Texture.new("assets/card.png")
    e << Glove::Components::Transform.new.tap do |t|
      t.width = 140_f32
      t.height = 190_f32
      t.translate_x = 400_f32
      t.translate_y = 300_f32
    end
  end

scene =
  Glove::Scene.new.tap do |scene|
    scene.spaces << Glove::Space.new.tap do |space|
      space.entities << card
    end
  end

game = Glove::EntityApp.new(800, 600, "Inari")
game.clear_color = Glove::Color::WHITE
game.replace_scene(scene)
game.run

Architecture

`crystal game = Glove::EntityApp.new(800, 600, "Inari") game.clear_color = Glove::Color::WHITE scene = Glove::Scene.new.tap do |scene|

# … build scene here …

end game.replace_scene(scene) game.run `

There are also a handful of simple data classes:

Acknowledgements

This project started out by playing with crystal-gl by Gustavo Giráldez.