Git Product home page Git Product logo

bevy_trauma_shake's Introduction

bevy_trauma_shake

crates.io MIT/Apache 2.0 crates.io docs.rs

Add camera shakes to your 2d Bevy game with three lines of code.

Goals

  • Zero configuration required
  • Sensible defaults
  • Batteries included (default noise)
  • Compatible with bevy_pancam

Usage

Add the plugin:

app.add_plugins(TraumaPlugin);

Simply add a component to your camera:

commands.spawn((Camera2dBundle::default(), Shake::default()));

Make it shake:

fn shake(mut shake: Query<&mut Shake>, keys: Res<Input<KeyCode>>) {
    if keys.just_pressed(KeyCode::Space) {
        shake.single_mut().add_trauma(0.2);
    }
}

There is also a convenience system param for applying trauma to all Shakes:

fn shake(mut shake: Shakes, keys: Res<Input<KeyCode>>) {
    if keys.just_pressed(KeyCode::Space) {
        shakes.add_trauma(0.2);
    }
}

And an event, if you prefer that:

fn shake(mut trauma: EventWriter<TraumaEvent>, keys: Res<Input<KeyCode>>) {
    if keys.just_pressed(KeyCode::Key1) {
        trauma.send(0.2.into());
    }
}

And even a command:

fn shake(mut commands: Commands, keys: Res<Input<KeyCode>>) {
    if keys.just_pressed(KeyCode::Key1) {
        info!("Adding small trauma");
        commands.add_trauma(0.2);
    }
}

Maybe I went a little overboard and I should remove one of those ways, in any case, they can be toggled through the features: system_param, events, commands.

Optional configuration

Optionally add ShakeSettings, if you're not happy with the defaults.

    commands.spawn((
        Name::new("Camera"),
        Camera2dBundle::default(),
        Shake::default(),
        ShakeSettings {
            amplitude: 200.,
            trauma_power: 3.,
            decay_per_second: 0.3,
            frequency: 4.,
            octaves: 2,
        },
        PanCam::default(),
    ));

Bevy Version Support

The main branch targets the latest bevy release.

bevy bevy_trauma_shake
0.13 0.2, main
0.12 0.1

License

bevy_trauma_shake is dual-licensed under either

at your option.

Thanks

Contributions

PRs welcome!

bevy_trauma_shake's People

Contributors

johanhelsing avatar sjmueller avatar

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.