Git Product home page Git Product logo

rusty_engine's Introduction

Rusty Engine

Rusty Engine is a simple, 2D game engine for those who are learning Rust. Create simple game prototypes using straightforward Rust code without needing to learning difficult game engine concepts! It works on macOS, Linux, and Windows. Rusty Engine is a simplification wrapper over Bevy, which I encourage you to use directly for more serious game engine needs.

Questions, bug reports, and contributions are most welcome!

RoadRace.mp4

Documentation

Features

  • Asset pack included (sprites, music, sound effects, and fonts)
  • Sprites (2D images)
    • Use sprites from the included asset pack, or bring your own
    • Collision detection with custom colliders
  • Audio (music & sound effects)
    • Looping music
    • Multi-channel sound effects
  • Text
    • 2 fonts included, or bring your own
  • Input handling (keyboard, mouse)
  • Timers
  • Custom game state
  • Window customization

Courses

If you like Rusty Engine, please sponsor me on GitHub or on Patreon, or take one of my courses below!

The following courses use Rusty Engine in their curriculum:

Linux Dependencies (Including WSL 2)

If you are using Linux or Windows Subsystem for Linux 2, please visit Bevy's Installing Linux Dependencies page and follow the instructions to install needed dependencies.

Quick Start

You MUST download the assets separately!!!

Here are three different ways to download the assets (pick any of them--it should end up the same in the end):

  • Clone the rusty_engine repository and copy/move the assets/ directory over to your own project
  • Download a zip file or tarball of the rusty_engine repository, extract it, and copy/move the assets/ directory over to your own project.
  • (My favorite!) On a posix compatible shell, run this command inside your project directory:
curl -L https://github.com/CleanCut/rusty_engine/archive/refs/heads/main.tar.gz | tar -zxv --strip-components=1 rusty_engine-main/assets

Add rusty_engine as a dependency

# In your [dependencies] section of Cargo.toml
rusty_engine = "6.0.0"

Write your game!

// in src/main.rs
 use rusty_engine::prelude::*;

 // Define a struct to hold custom data for your game (it can be a lot more complicated than this one!)
 #[derive(Resource)]
 struct GameState {
     health: i32,
 }

 fn main() {
     // Create a game
     let mut game = Game::new();
     // Set up your game. `Game` exposes all of the methods and fields of `Engine`.
     let sprite = game.add_sprite("player", SpritePreset::RacingCarBlue);
     sprite.scale = 2.0;
     game.audio_manager.play_music(MusicPreset::Classy8Bit, 0.1);
     // Add one or more functions with logic for your game. When the game is run, the logic
     // functions will run in the order they were added.
     game.add_logic(game_logic);
     // Run the game, with an initial state
     let initial_game_state = GameState { health: 100 };
     game.run(initial_game_state);
 }

 // Your game logic functions can be named anything, but the first parameter is always a
 // `&mut Engine`, and the second parameter is a mutable reference to your custom game
 // state struct (`&mut GameState` in this case).
 //
 // This function will be run once each frame.
 fn game_logic(engine: &mut Engine, game_state: &mut GameState) {
     // The `Engine` contains all sorts of built-in goodies.
     // Get access to the player sprite...
     let player = engine.sprites.get_mut("player").unwrap();
     // Rotate the player...
     player.rotation += std::f32::consts::PI * engine.delta_f32;
     // Damage the player if it is out of bounds...
     if player.translation.x > 100.0 {
         game_state.health -= 1;
     }
 }

Run your game with cargo run --release!

example screenshot

See also the tutorial, game scenarios, code examples and the API documentation

Student Showcase

Show off the project you made with Rusty Engine! Learning Rust can be fun. πŸ˜„ Just send me a link and I'll add it to the list!

Contribution

All software contributions are assumed to be dual-licensed under MIT/Apache-2. All asset contributions must be under licenses compatible with the software license, and explain their license(s) in a README.md file in the same directory as the source files.

Asset Licenses

All assets included with this game engine have the appropriate license described and linked to in a README.md file in the same directory as the source files. In most cases, the license is CC0 1.0 Universal--meaning you may do whatever you wish with the asset.

One notable exception is some of the music files, which are under a different license and include specific attribution requirements that must be met in order to be used legally when distributed. Please see this README.md file for more information.

Software License

Distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See license/APACHE and license/MIT.

rusty_engine's People

Contributors

cleancut avatar dajamante avatar dawody avatar etnt avatar follower avatar just-do-halee avatar rozkerim avatar webbertakken avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rusty_engine's Issues

game setup

in your udemy course your code is like this

let mut game = new Game();
game.run();

I tried this and it didn't compile (error about something not implementing a Resource trait)

below is what is now the bare minimum to run the empty screen game

use rusty_engine::prelude::*;

#[derive(Resource)]
struct GameState {}

fn main() {
    let mut game = Game::new();
    let initial_game_state = GameState {};
    game.run(initial_game_state);
}

Replace glium (OpenGL subsystem)

OpenGL has been deprecated on macOS, which means it will someday be removed.

It would be really nice if we could replace glium with something else.

Required:

  • Supported on Mac/Linux/Windoms

Optimize for:

  • Least dependencies need to be installed

So far, I have tried vulkano, but I can't get the examples working on the master branch, or version 0.10.0, or 0.9.0. vulkano-rs/vulkano#1019

Rusty Engine 1.0

Goal: Provide a fun, easy to use, well-documented 2D game engine suitable for developers who are just starting to learn Rust. Ideally, the approach taken would not expose any complex concepts such as ECS, shaders, plugins, serialization, etc. in favor of sticking to as close to fundamental Rust concepts as much as possible.

The implementation plan for the (eventual) Rusty Engine v1.0 is to start over from scratch, wrapping a real game engine,
Bevy, in a way that hides most of the complexity of the engine behind a simplified interface. As my goal is entirely about providing a tool to use in Rust learning environments (rather than on producing a Fancy Game Engineβ„’), this should be a much more straightforward and maintainable approach than trying to build an engine from the ground up.

I have switched to publishing just a single rusty_engine crate without publishing any separate sub-crates that may be part of it, with one exception: I have broken rusty_audio back out into a completely separate and unrelated project. do use rusty_audio for other projects, so I'd like to keep it around until there is some other de-facto standard Rust audio playback library that I can rely on to continue working. The rest of the current sub-crates have been discarded.

Feature Wish List

  • Meta Items
    • Well-documented API
    • Examples
    • Scenarios
  • GameState
  • Text (2d, in-scene)
  • Actors
    • name
    • built-in sprite
    • transform
      • layers
    • collision
  • Easy Input Handling
    • Mouse
    • Keyboard
  • Sprites
    • Image loading
    • Sprite asset pack built-in (from Kenney assets)
      • Racing
      • Rolling
  • Audio
    • Sound effect asset pack (from Kenney assets)
    • Looping music asset pack
    • Audio subsystem to play the sound effects and music
  • Utilities
    • Timer
  • ECS
    • Some form of simplified approach to systems
    • Movement
  • Stretch goals
    • Tutorial
    • User-defined GameState
    • Cross-fade the music when it switches
    • User-provided sprite
    • Animated sprite support
    • Gamepad support
    • Configurable input mappings
    • Physics

If this sounds interesting to work on, I would love to collaborate with you! Let me know. πŸ˜„

Issue building cpal dependency

I'm following your (excellent) Ultimate Rust 2 course and just reached the game prototype stage, but immediately hit an issue when building a fresh project with only rusty_engine as a dependency. Here's my Cargo.toml file:

[package]
name = "tutorial"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rusty_engine = "5.2.0"

Here are the abbreviated error logs:

error[E0308]: mismatched types
   --> /home//.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.13.5/src/host/alsa/mod.rs:245:21
    |
244 |         let handle = match handle_result {
    |                            ------------- this expression has type `std::result::Result<host::alsa::alsa::PCM, (host::alsa::alsa::Error, host::alsa::alsa::nix::errno::Errno)>`
245 |             Err((_, nix::errno::Errno::EBUSY)) => return Err(BuildStreamError::DeviceNotAvailable),
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `host::alsa::alsa::nix::errno::Errno`, found enum `nix::errno::Errno`
    |
    = note: perhaps two different versions of crate `nix` are being used?

error[E0308]: mismatched types
   --> /home//.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.13.5/src/host/alsa/mod.rs:246:21
    |
244 |         let handle = match handle_result {
    |                            ------------- this expression has type `std::result::Result<host::alsa::alsa::PCM, (host::alsa::alsa::Error, host::alsa::alsa::nix::errno::Errno)>`
245 |             Err((_, nix::errno::Errno::EBUSY)) => return Err(BuildStreamError::DeviceNotAvailable),
246 |             Err((_, nix::errno::Errno::EINVAL)) => return Err(BuildStreamError::InvalidArgument),
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `host::alsa::alsa::nix::errno::Errno`, found enum `nix::errno::Errno`
    |
    = note: perhaps two different versions of crate `nix` are being used?

error[E0308]: mismatched types
   --> /home//.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.13.5/src/host/alsa/mod.rs:302:21
    |
301 |         let handle = match handle_result {
    |                            ------------- this expression has type `std::result::Result<&mut host::alsa::alsa::PCM, (host::alsa::alsa::Error, host::alsa::alsa::nix::errno::Errno)>`
302 |             Err((_, nix::errno::Errno::ENOENT)) | Err((_, nix::errno::Errno::EBUSY)) => {
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `host::alsa::alsa::nix::errno::Errno`, found enum `nix::errno::Errno`
    |
    = note: perhaps two different versions of crate `nix` are being used?

This also happens when depending only on cpal = "0.14.0", so I know this is most likely some kind of issue with the dependency chain rather than rusty_engine, but I'm not familiar enough with Rust and cargo to be able to narrow it down much further. I'm able to build cpal from source, but not rodio, and no amount of futzing about with overridden/patched dependencies worked for me, so I'm completely at a loss. Apologies for laying this at your doorstep, but I figure you may be in a better position to get things building again.

I'm building using WSL2 on Windows with cargo version 1.64.0 (387270bc7 2022-09-16).

Feature List

This issue is to hash out what features rusty_engine will ultimately support for version 1.0 -- we'll keep updating the list in this comment until we reach a good stopping point, and then transfer the list onto the readme.

Goal: Provide a fun, easy to use, minimalist, 2D game engine that works well to play with while learning Rust.
Not a goal: Being a commercially-viable game engine, or providing every possible feature.

Features

  • Well-documented API
  • Tutorial
  • Examples
  • Graphics-accelerated window (currently OpenGL)
  • Input Presets
    • Mouse
    • Keyboard
  • Provide a set of drawing primitives
    • Images
    • Shapes (outline and filled)
      • Circle
      • Rectangle
      • Line
  • Audio
    • Multi-channel
    • Threaded
  • Utilities
    • Timer

To consider:

  • Switch from glium/glium to either gfx-rs/wgpu or amethyst/rendy so we can use Metal/Vulkan/DirectX backends (and hopefully WASM support for free at some point) - this means a breaking rewrite of most of the engine, but it ensures a stable future (OpenGL is deprecated on macOS and will be removed at some point).
  • Switch shapes to shaders - might be required if we make the above backend switch
  • Alternately, punt on shapes by switching them to images, in which case shapes could be an asset pack
  • Asset packs for sounds, images bundled with the engine.
  • More configurable input mappings instead of only preset mappings
  • Gamepad input
  • Design that works well with an ECS (note that actually integrating an ECS is outside the scope
  • Text rendering support

missing dependency (pkg-config)

when I tried to build a rust project which depend on rusty_audio using cargo build, I got the following error :

error: failed to run custom build command for alsa-sys v0.1.2
thread 'main' panicked at 'called Result::unwrap() on an Err value: "Failed to run \"pkg-config\" \"--libs\" \"--cflags\" \"alsa\": No such file or directory (os error 2)"', /home/dawod/.cargo/registry/src/github.com-1ecc6299db9ec823/alsa-sys-0.1.2/build.rs:4:38
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

but I fixed it by installing pkg-config in addition to libasound2-dev.
My OS is Ubuntu 18.04.2 LTS.

Questions regarding this game engine

Hey mate, this game engine so far looks very interesting and I am considering using it over Bevy to make my game. I kinda don't like Bevy's approach as it "locks" you into a framework whereas your game engine doesn't.

I have some questions regarding this game engine though:

  1. Does it support 3D, if not will it support 3D in the near future?
  2. BevyUI will come out and according to the devs you will be able to make normal GUI applications, would this game engine support BevyUI as well (as this game engine is based on BevyUI)?
  3. Does it do multi-threading like Bevy?
  4. If a full GUI game editor comes out for Bevy, would this game engine support it (or will support it)?
  5. Can I please directly chat with you on Discord (as I know you have a Discord account)?
  6. What can Bevy do but this game engine can't?
  7. Does this game engine aim to become as powerful as Bevy in the near future?

Realistic physics would be nice

It'd be nice to incorporate bevy_rapier2d for realistic physics (and also replacing the custom collision detection solution I manually implemented).

Compliation fails on MacOS

Attemping to compile this on MacOS fails, even after adding the undocumented argument in the TOML file:

release = "2"

Compile error follows.

   Compiling wgpu-hal v0.12.5
error: DX12 API enabled on non-Windows OS. If your project is not using resolver="2" in Cargo.toml, it should.
  --> /Users/dwheeler/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-hal-0.12.5/src/lib.rs:53:1
   |
53 | compile_error!("DX12 API enabled on non-Windows OS. If your project is not using resolver=\"2\" in Cargo.toml, it should.");
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0432]: unresolved import `super::dx12`
  --> /Users/dwheeler/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-hal-0.12.5/src/lib.rs:68:20
   |
68 |     pub use super::dx12::Api as Dx12;
   |                    ^^^^ could not find `dx12` in the crate root

Ability to create shapes

There are many times where we don't wanna load assets for a sprite but rather, make a shape and use it as a sprite (for example, a circle or a square). I believe this would be a nice addition to the game engine

Rusty Engine 3.0

Big Important Stuff for 3.0

  • Volume for sound effects, done in #14
  • Make it so users can access a user-defined custom state struct instead of using generic vectors and hash maps on the GameState struct. Work in progress in #15
  • Enable users to bring their own assets
    • sfx & music - done in #20
    • sprites - done in #24
    • fonts - done in #19

Other stuff that I managed to get done for 3.0

  • As part of this, I'd like the constants to show up on the index page of the documentation - done in #23
  • Write a proper tutorial, resolves #10, done in #25 and #26
  • I don't really like the Actor and TextActor abstractions. The point of this engine is to avoid abstractions. Let's rename them Sprite and Text, respectively. Done in #21 and #22

Decided to do later

  • #17
  • Complete more scenarios references and/or instructions
    • Began one in #12
  • Make sure everything is documented (this is mostly done, but I need to do a final pass)
  • A supported way to load/save state

Consider use of GitHub Workflow for Rust tests

Hi!

Thanks for creating such a fun game engine! πŸ₯³

In an effort to set a consistent bar for contributions, would you consider adding a Workflow for Rust tests, rather than just relying on local Git hooks before contributing.

I've provided a sample here for consideration as a starting point πŸ‘‰ #2

wgpu-hal : Fails to compile

NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

https://gist.github.com/lightydo/6b3a6fcb2f6c4b6f03eae7c2985af627

I tried this: https://github.com/bevyengine/bevy/blob/main/docs/linux_dependencies.md
but it did not help

Question regarding compiler error because of borrowing of: engine

Hi,

I'm following your Ultimate Rust 2 course and have completed the first basic Road Race task.
(great fun btw :-)

Now I've started to experiment with shooting. So in my game_logic code I want to set the
rotation of the Shot to be the same as the Player at the time the shot fires, then I think I have
figured out how to use the rotation to figure out the direction (y = tan(v) * x).

Anyway, I get hold of the "player" and want to create a shot like in:

let player = engine.sprites.get_mut("player").unwrap();                                                                                                                                      
game_state.shot_counter += 1;                                                                                                                                                                
let sprite = engine.add_sprite(                                                                                                                                                              
      format!("shot{}", game_state.shot_counter),                                                                                                                                              
      SpritePreset::RollingBallRed,);
 sprite.rotation = player.rotation;
 ...etc...                                                                                                                                                              

But I get a second mutable borrow occurs here error at the second reference to engine,
and now I'm stuck...still struggling with the basics of Rust I guess...

How to change filepath of Sprite

I want to change filepath of Sprite when I click to it (handle in game_logic). But it's not allowed because Sprite.filepath is READONLY.
So is there any way to do it?

Documentation typo / misattribution

Hi, I just noticed that these three fields have their documentation permuted incorrectly:

rusty_engine/src/game.rs

Lines 83 to 96 in 12a0d15

/// INFO - All the keyboard input events. These are text-processor-like events. If you are
/// looking for keyboard events to control movement in a game character, you should use
/// [`Engine::keyboard_state`] instead. For example, one pressed event will fire when you
/// start holding down a key, and then after a short delay additional pressed events will occur
/// at the same rate that additional letters would show up in a word processor. When the key is
/// finally released, a single released event is emitted.
pub keyboard_state: KeyboardState,
/// INFO - The delta time (time between frames) for the current frame as a [`Duration`], perfect
/// for use with [`Timer`](crate::prelude::Timer)s
pub keyboard_events: Vec<KeyboardInput>,
/// INFO - The current state of all the keys on the keyboard. Use this to control movement in
/// your games! A [`KeyboardState`] has helper methods you should use to query the state of
/// specific [`KeyCode`](crate::prelude::KeyCode)s.
pub delta: Duration,

The field order seems decent, so I suppose the documentation should be moved to fix this.

Too slow to compile

Hi,

Every time I run "cargo run" after making even a small change it takes too long to compile the code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.