DEV Community

loading...

Coffee - An opinionated 2D game engine for Rust

hecrj profile image Héctor Ramón ・2 min read

Coffee is an opinionated 2D game engine for Rust focused on simplicity, explicitness, and type-safety.

Coffee is in a very early stage of development. Active development is
planned during 2019 (and hopefully beyond that!). Many basic features are still
missing
, some dependencies are experimental, and there are probably many
bugs. Feel free to contribute!

Features

  • Declarative, type-safe asset loading
  • Loading screens with progress tracking
  • Built-in debug view with performance metrics
  • Fixed timestep
  • Explicit, easy to use, hardware-accelerated 2D graphics API
  • Multiplatform support leveraging OpenGL, Vulkan, Metal, D3D11, and D3D12
  • Texture array support
  • Explicit and efficient batched draws
  • Off-screen rendering
  • TrueType font rendering

Overview

Here is a minimal example that will open a window:

use coffee::{Game, Result, Timer};
use coffee::graphics::{Color, Window, WindowSettings};

fn main() -> Result<()> {
    MyGame::run(WindowSettings {
        title: String::from("A caffeinated game"),
        size: (1280, 1024),
        resizable: true,
    })
}

struct MyGame {
    // Your game state goes here...
}

impl Game for MyGame {
    type View = (); // No view data.
    type Input = (); // No input data.

    const TICKS_PER_SECOND: u16 = 60; // Update rate

    fn new(_window: &mut Window) -> Result<(MyGame, Self::View, Self::Input)> {
        // Load your game assets here. Check out the `load` module!
        Ok((MyGame { /* ... */ }, (), ()))
    }

    fn update(&mut self, _view: &Self::View, _window: &Window) {
        // Update your game here
    }

    fn draw(&self, _view: &mut Self::View, window: &mut Window, _timer: &Timer) {
        // Clear the current frame
        let mut frame = window.frame();
        frame.clear(Color::BLACK);

        // Draw your game here. Check out the `graphics` module!
    }
}

Repository

If you want to know more, check out the repository on GitHub!

GitHub logo hecrj / coffee

An opinionated 2D game engine for Rust

Coffee

Integration status Documentation Crates.io License Gitter chat

An opinionated 2D game engine for Rust focused on simplicity, explicitness, and type-safety.

Coffee is in a very early stage of development. Many basic features are still missing, some dependencies are experimental, and there are probably many bugs. Feel free to contribute!

Features

And more! Check out the examples to see them in action.

Usage

Add coffee as a dependency in your Cargo.toml and enable a graphics backend feature (opengl, vulkan, metal, dx11, or dx12):

coffee = { version = "0.4", features = ["

Discussion

pic
Editor guide
Collapse
mdenchev profile image
Michail Denchev

Looks interesting! What are the plans for WASM support? I see there is experimental wgpu support, is the goal to wait for webgpu to become browser supported?

Collapse
hecrj profile image
Héctor Ramón Author

For now, I am trying keep a narrow (and opinionated) scope while the API is shaping up. I want coffee to be great for building (some) games for desktop.

I see WASM support as a nice thing that could happen as a side-effect. I have no clue what kind of compromises need to be made when targeting WASM (any guidance is appreciated!), but maybe a subset of the final API ends up being compatible without too many of them.

That said, I am trying to have clear boundaries between dependencies and engine code, which should help in the future if there is a need to swap a dependency or mock it somehow.