项目作者: Bombfuse

项目描述 :
A 2D rust game engine focused on portability.
高级语言: Rust
项目地址: git://github.com/Bombfuse/emerald.git
创建时间: 2020-04-04T18:26:36Z
项目社区:https://github.com/Bombfuse/emerald

开源协议:MIT License

下载


Emerald
Crates.io
License: MIT
Discord chat

The Cross Platform Engine

Emerald is designed to be as lightweight as possible, while remaining a fully-featured and cross-platform game engine.

The api is simple and powerful, giving you direct access to physics, audio, graphics, game worlds, and asset loading.

Supported Platforms


MacOS
Linux
Windows
RaspberryPi

—- Work in progress —-


Android
HTML5

Asset Loading

  1. let my_sprite = emd.loader()
  2. .sprite("my_sprite.png")
  3. .unwrap();
  4. let my_audio = emd.loader()
  5. .sound("my_sound.wav")
  6. .unwrap();

Physics

Creating Bodies

  1. let entity = emd.world().spawn((Transform::from_translation((0.0, 0.0))));
  2. let body_handle = emd.world().physics().build_body(
  3. entity,
  4. RigidBodyBuilder::dynamic()
  5. );
  6. emd.world().physics().build_collider(
  7. body_handle,
  8. ColliderDesc::cuboid(6.0, 6.0)
  9. );
  10. // You can alternatively build both the entity and body at once.
  11. let (entity, body_handle) = emd.world()
  12. .spawn_with_body(
  13. (Transform::from_translation((0.0, 0.0))),
  14. RigidBodyBuilder::dynamic()
  15. )?;

Physics Stepping

  1. emd.world()
  2. .physics()
  3. .step();

You decide when physics steps!
This makes it very easy to “pause” the game without needing to alter any data.

Graphics

The default method to draw the game is to draw all of the entities in the current world. However, you can write your own draw function if you need to do more!

  1. fn draw(&mut self, mut emd: Emerald) {
  2. emd.graphics().begin();
  3. emd.graphics().draw_world();
  4. emd.graphics().render();
  5. }

Audio

  1. let my_sound = emd.loader().sound("sounds/my_song.ogg")?;
  2. emd.audio().mixer("background_music")?.play_and_loop(my_sound);

ECS

Emerald uses the Entity Component System paradigm for creating, managing, and updating game entities.

Emerald uses Hecs under the hood for fast entity iteration, and a remarkably clean query Api.

More detailed features can be found in the Hecs documentation.

  1. for (id, (sprite, mut position)) in emd.world().query::<(&Sprite, &mut Position)>().iter() {
  2. position.x += 10.0;
  3. }

Aseprite

Emerald has built in aseprite loading and rendering. Simply load in the file, then tell it which animations to play.

  1. let mut aseprite = emd.loader().aseprite("my_sprite.aseprite").unwrap();
  2. aseprite.play("some_aseprite_animation");
  3. emd.world().spawn((aseprite, Position::zero()));

Alternatively, Emerald can load a sprite sheet exported from aseprite.

  1. let mut aseprite = emd.loader()
  2. .aseprite_with_animations("my_texture.png", "my_animation.json").unwrap();

Export settings
Preferred export settings

WASM (WIP, PROBABLY BROKEN RIGHT NOW)

Build

cargo build --target wasm32-unknown-unknown

Asset Loading

In order to keep a clean, simple API, and avoid network requests for assets. Emerald takes the approach of packing all necessary assets into the WASM binary.

This same method can be used to pack all assets into the game binary regardless of which platform you target.

Use the pack_asset_bytes function to load data into the engine.

  1. fn initialize(&mut self, mut emd: Emerald) {
  2. /// Pack all game files into WASM binary with path references
  3. /// so that the regular file loading Api is supported.
  4. #[cfg(target_arch = "wasm32")]
  5. {
  6. emd.loader()
  7. .pack_asset_bytes(
  8. "bunny.png",
  9. include_bytes!(".bunny.png").to_vec()
  10. );
  11. }
  12. /// We can now load texture/sprites via the normal Api,
  13. /// regardless of which platform we're targeting.
  14. let sprite = emd.loader()
  15. .sprite("bunny.png")
  16. .unwrap();
  17. // Default transform at 0.0, 0.0
  18. let mut transform = Transform::default();
  19. self.count = 1000;
  20. emd.world().spawn_batch(
  21. (0..1000).map(|_| {
  22. transform.translation.x += 6.0;
  23. transform.translation.y += 1.0;
  24. let mut s = sprite.clone();
  25. (transform.clone(), s, Vel { x: 5.0, y: 3.0 })
  26. })
  27. );
  28. }

Android (WIP, PROBABLY BROKEN RIGHT NOW)

Asset Loading

Add following to Cargo.toml and load assets as usual:

  1. [package.metadata.android]
  2. assets = "YOUR_ASSETS_DIRECTORY/"