diff --git a/Cargo.toml b/Cargo.toml index ac4a93b..bdaa6bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ authors = ["James Gayfer"] repository = "https://github.com/jgayfer/bevy_light_2d" license-file = "LICENSE" readme = "README.md" +exclude = ["assets/*", "static/*"] [dependencies] bevy = { version = "0.13", default-features = false, features = [ @@ -15,6 +16,7 @@ bevy = { version = "0.13", default-features = false, features = [ "bevy_core_pipeline", "bevy_winit", "bevy_sprite", + "png", "x11" ] } @@ -34,3 +36,7 @@ path = "examples/basic.rs" [[example]] name = "multiple" path = "examples/multiple.rs" + +[[example]] +name = "dungeon" +path = "examples/dungeon.rs" diff --git a/README.md b/README.md index 17ea3ad..3457b7e 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ A general purpose 2d lighting plugin for [`bevy`](https://bevyengine.org/). Designed to be simple to use, yet expressive enough to fit a variety of needs. +![Dungeon example](./static/dungeon.gif) + ## Features - Component driven design @@ -79,3 +81,7 @@ I'd like to thank the authors of the below crates; they were a significant sourc - [`bevy-magic-light-2d`](https://github.com/zaycev/bevy-magic-light-2d) - [`bevy_2d_screen_space_lightmaps`](https://github.com/goto64/bevy_2d_screen_space_lightmaps) - [`bevy_incandescent`](https://github.com/443eb9/bevy_incandescent) + +## Asset credits + +- [Pixel Dungeon](https://pixel-poem.itch.io/dungeon-assetpuck) by [`pixel_poem`](https://pixel-poem.itch.io/) diff --git a/assets/candle.png b/assets/candle.png new file mode 100644 index 0000000..fd50466 Binary files /dev/null and b/assets/candle.png differ diff --git a/assets/dungeon_tiles.png b/assets/dungeon_tiles.png new file mode 100644 index 0000000..28bad76 Binary files /dev/null and b/assets/dungeon_tiles.png differ diff --git a/examples/candle.rs b/examples/candle.rs new file mode 100644 index 0000000..0d92793 --- /dev/null +++ b/examples/candle.rs @@ -0,0 +1,250 @@ +use bevy::prelude::*; +use bevy_light_2d::prelude::*; + +const TILE_INDEX: f32 = 0.0; +const ENTITY_INDEX: f32 = 1.0; + +fn main() { + App::new() + .add_plugins(( + DefaultPlugins.set(ImagePlugin::default_nearest()), + Light2dPlugin, + )) + .init_resource::() + .init_resource::() + .add_systems(Startup, (setup_camera, set_clear_color)) + .add_systems(Startup, (setup_dungeon_tileset, spawn_tiles).chain()) + .add_systems(Startup, (setup_candle_spritesheet, spawn_candles).chain()) + .add_systems(Update, animate_candles) + .run() +} + +#[derive(Resource, Default)] +struct DungeonTileset { + layout: Handle, + texture: Handle, +} + +#[derive(Resource, Default)] +struct CandleSpritesheet { + layout: Handle, + texture: Handle, +} + +#[derive(Component)] +struct Candle; + +#[derive(Component, Deref, DerefMut)] +struct AnimationTimer(Timer); + +fn setup_camera(mut commands: Commands) { + let mut camera = Camera2dBundle::default(); + camera.projection.scale = 0.25; + commands.spawn(( + camera, + AmbientLight2d { + brightness: 0.1, + ..default() + }, + )); +} + +fn set_clear_color(mut clear_color: ResMut) { + clear_color.0 = Color::rgb_u8(37, 19, 26); +} + +fn animate_candles( + time: Res