From db2ade8b507da1821d635e499d640c42418c0683 Mon Sep 17 00:00:00 2001 From: James Gayfer <10660608+jgayfer@users.noreply.github.com> Date: Mon, 27 May 2024 21:39:08 -0700 Subject: [PATCH] WIP: Dungeon example --- Cargo.toml | 6 + README.md | 6 + assets/candle.png | Bin 0 -> 422 bytes assets/dungeon_tiles.png | Bin 0 -> 6326 bytes examples/candle.rs | 250 +++++++++++++++++++++++++++++++++++++++ examples/dungeon.rs | 250 +++++++++++++++++++++++++++++++++++++++ static/dungeon.gif | Bin 0 -> 136950 bytes 7 files changed, 512 insertions(+) create mode 100644 assets/candle.png create mode 100644 assets/dungeon_tiles.png create mode 100644 examples/candle.rs create mode 100644 examples/dungeon.rs create mode 100644 static/dungeon.gif 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 0000000000000000000000000000000000000000..fd5046646058a67c8709d727f31d11ea87361eb5 GIT binary patch literal 422 zcmV;X0a^ZuP)McQa*aC8(^pX;(1U#-##Nb5Qd8W(Eva%FhEHcBsQ%%5G(~s0Wd&JN*HSTQBnZN@!54PVE;~S zs)2jFW8GGU#~03n#qb3JOuwvwAwxxwHv=dnK^Bm!ALamLHxXk$1H(U{TkGKN$EP17 z3m^vq$Ri*?jOSstAqN6X45Ggl7$0ngtc&OF6mB}?)uTl64E8zvE;XYf6Tr2 znP<+-J2Pj_d)~Q`n(B&ROfpOW00352lKX&o=lv__sEB9uq%{WsK;o+`C#~g~b!_Bs zPbu&BBL2fL^k`Vgjh16^-cAR6;pw{j*6M8}aT6WXzLtk-LH@yGbDi<7 zUYKJ~4f1+(smPZi0b9UtZpXYeydJfP)EIUDd@{LCnq7*K>C+A7`&6`HGF%POKT>U2 z5X}#fA}&_u)qT#7P0A)_X75-vHtHKKFWkSD!z)rGN6}?C?HwQU5Iw zi)0IWT3UPwM^a1D$8qDP$IED4^y2_6A=9wTk(h&R8NyL>srgsKOYPM$U?`O=2TR$H zQRB=;bwef%n7d{D7{Ua(8M1JX!53vU>HJ75(oGrYamD{i-i_hECjz3Wd zs}CX~Cfre#LEj>3kgninc6QxS&cuUj?P!lFTql+lo@vPR282Y3r6jY>tKQyCRb`$| zvW@-Pv-r7hL6^rDoV-(Lps>i+FJ(M15HFOM6n0G~*|n{w|DJ3VdE0ka&oK4xn;eY0 ztvmF9nAjikCz*vLbe=zfE9KXv-dADc^o-?a7DN>ESrNUmn_|E+e5Mkn5SVE|rM)Su zd4BJ$vQqv-14?9Vss_qAyKt{2Y1fj?d7d%_0e7z^ZJc%%H#QI5TMUf*{n-3CCA)6! zy9Rku)6!ri0!>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/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