mochi

Crates.iomochi
lib.rsmochi
version0.0.5
sourcesrc
created_at2020-08-02 04:21:19.890242
updated_at2020-08-04 02:21:47.301299
descriptionA mobile game engine based on Gtk & Cairo
homepage
repositoryhttps://github.com/richardanaya/mochi
max_upload_size
id272110
size3,168,276
richardanaya2_2048b.Q6_K.gguf (richardanaya)

documentation

README

Mochi :dango:

A game engine oriented toward low power mobile linux phones/tablets. It's written in Rust and uses Gtk and Cairo! All drawing is done with an Cairo Context that this library has extended to do some really common graphics operations.

This project is super alpha but usable. If you want to join in, feel free to open up an issue or make a PR!

docs.rs docs

Features

  • touch
  • screen rotation
  • atlases
  • animated sprites

Limitations

  • Only support for for 8bpc RGBA png images

Example

pong

[dependencies]
mochi = "0.0"
init(include_bytes!("game.gresource"));

let img_mochi = image_from_resource("/game/mochi.png");
let img_mochi_eaten = image_from_resource("/game/mochi_eaten.png");

run_game(move |window, ctx, pointer, delta_time| {
    if pointer.is_down() {
        ctx.draw_image_centered(window.width / 2.0, window.height / 2.0, img_mochi_eaten);
    } else {
        ctx.draw_image_centered(window.width / 2.0, window.height / 2.0, img_mochi);
    }
});

How to build a game

Mochi works off resources put into a Glib resource file. This is pretty simple to do. Just make an xml file that references your images:

<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/pong">
    <file>ball.png</file>
    <file>paddle.png</file>
  </gresource>
</gresources>

Build into a gresource file that Glib can understand:

glib-compile-resources game.xml

Inline the bytes of the game.gresource into your code during init:

init(include_bytes!("game.gresource"));

Now your game has everything it needs in it's binary! The images can be acquired as needed using the resource paths you setup.

let img_ball = image_from_resource("/pong/ball.png");

Dependencies

for gtk/cairo:


for sound:

sudo dnf install openal-soft-devel libsndfile-devel

Running out of memory while compiling on PinePhone?

You can expand your swap using zram

sudo swapoff /dev/zram0 
sudo zramctl --reset /dev/zram0 
sudo zramctl --find --size 2048M
sudo mkswap /dev/zram0 
sudo swapon /dev/zram0

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in mochi by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 41

cargo fmt