• This repository has been archived on 09/Aug/2022
  • Stars
    star
    69
  • Rank 437,646 (Top 9 %)
  • Language
    Crystal
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Crystal framework for making games

Build status

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). (Or do, and contribute back to Glove? That’d be cool. I’ll give you commit access. You can be one of the first people to write a proper game engine in Crystal.)

Usage

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

dependencies:
  glove:
    git: [email protected]: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

  • Glove::EntityApp is a generic game superclass that provides functionality for handling entities, and everything associated with it. Here is how a typical game would build an instance and run the game:

    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
  • Glove::Entity is a game object that is visible and/or reacts to user input.

  • Glove::Component is a property of an entity. A common component is Glove::Components::Transform, which adds width, height, rotation, scale, … to an entity. Another common component is Glove::Components::Camera, which marks an entity as being a camera, and defines which part of a space (see below) will be rendered, with what rotation, etc.

  • Glove::Action defines a change to an entity. It can either be instant (e.g. remove entity) or act over time (e.g. move).

  • Glove::Space groups entities in a scene that logically belong together and can interact with each other. Entities in different spaces never interact. For example, one space might contain the game entities, and another space might contain UI elements.

  • Glove::Scene describes a scene (such as the main menu, credits, or in-game screen). It contains one or more spaces.

  • Glove::System describes logic for making changes to a space. A common system is a physics system, which would calculate velocities and update positions.

There are also a handful of simple data classes:

  • Glove::Color
  • Glove::Point
  • Glove::Quad
  • Glove::Rect
  • Glove::Size
  • Glove::Vector

Acknowledgements

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

More Repositories

1

cri

A tool for building commandline applications
Ruby
117
star
2

adsf

Web server that you can launch instantly in any directory
Ruby
88
star
3

rcpu

VM emulator and assembler written in Crystal
Crystal
37
star
4

fast-aleck

Fast Aleck is a fast HTML-aware typographical enhancement library that lets your text use proper ellipses, smart quotes, proper dashes and more.
C
18
star
5

d-mark

Semantic markup language
Ruby
18
star
6

inari

A collection of games written in Crystal
Crystal
14
star
7

d-parse

A parser combinator library for Ruby
Ruby
10
star
8

ddmemoize

Memoization for Ruby
Ruby
9
star
9

rcpu-lang

Language that compiles to RCPU assembly
Crystal
6
star
10

cobject

A library that adds support for object-orientation with inheritance, polymorphism, virtual destructors and reference counting to C.
C
6
star
11

ecs-sample

A sample game built using an Entity/Component/System architecture
Ruby
5
star
12

slow_enumerator_tools

provides tools for transforming Ruby enumerators that produce data slowly and unpredictably
Ruby
5
star
13

ddplugin

Plugin management library
Ruby
4
star
14

ddmetrics

In-memory, non-timeseries telemetry for Ruby
Ruby
4
star
15

ddbencode

bencode library written in C
C
3
star
16

yonce

♫ All the single ladies ♪
Ruby
3
star
17

d-stream

Ruby
3
star
18

til

Today I Learned — sharing the things I learn
Ruby
3
star
19

neps

ARCHIVED - Contains all nanoc enhancement proposals (NEPs)
2
star
20

d-mark-rust

D★Mark implementation in Rust
Rust
2
star
21

game-ai.cr

Some board games + common AI
Crystal
1
star
22

d-tech

2D game engine
Lua
1
star
23

nanoc-mermaid-example

HTML
1
star
24

myst-online-site

Source for the Myst Online: Uru Live web site
Ruby
1
star
25

monet

A MVC library for writing hardware-accelerated 2D games.
C
1
star
26

breakout.lua

A Breakout clone written in Lua
Lua
1
star
27

d-tune

Experimental music player
TypeScript
1
star
28

dotfiles-2013

Shell
1
star
29

scrobscrob

Automatically exported from code.google.com/p/scrobscrob
Objective-C
1
star
30

released

Experimental release pipeline
Ruby
1
star
31

fast-aleck-ruby

Ruby bindings for the Fast Aleck typographical enhancement library
Ruby
1
star
32

markbook

A vocabulary for D★Mark for general technical writing
Ruby
1
star