├── .cargo └── config_fast_builds.toml ├── .editorconfig ├── .github └── workflows │ ├── ci.yaml │ ├── release.yaml │ └── release.yaml.template ├── .gitignore ├── .idea ├── .gitignore └── runConfigurations │ ├── Run_Native_Debug.xml │ ├── Run_Native_dev.xml │ ├── Run_Native_release.xml │ ├── Run_Web_dev.xml │ └── Run_Web_release.xml ├── .vscode ├── bevy.code-snippets ├── extensions.json ├── settings.json └── tasks.json ├── Cargo.lock ├── Cargo.lock.template ├── Cargo.toml ├── Cargo.toml.template ├── LICENSE-Apache-2.0.txt ├── LICENSE-CC0-1.0.txt ├── LICENSE-MIT.txt ├── README.md ├── README.md.template ├── assets ├── audio │ ├── music │ │ ├── Fluffing A Duck.ogg │ │ └── Monkeys Spinning Monkeys.ogg │ └── sound_effects │ │ ├── button_click.ogg │ │ ├── button_hover.ogg │ │ ├── step1.ogg │ │ ├── step2.ogg │ │ ├── step3.ogg │ │ └── step4.ogg └── images │ ├── ducky.png │ └── splash.png ├── cargo-generate.toml ├── clippy.toml ├── docs ├── design.md ├── img │ ├── readme-manual-setup.png │ ├── thumbnail.png │ ├── workflow-dispatch-release.png │ ├── workflow-itch-release.png │ ├── workflow-ruleset.png │ └── workflow-secrets.png ├── known-issues.md ├── tooling.md └── workflows.md ├── post-generate.rhai └── src ├── asset_tracking.rs ├── audio.rs ├── demo ├── animation.rs ├── level.rs ├── mod.rs ├── movement.rs └── player.rs ├── dev_tools.rs ├── main.rs ├── main.rs.template ├── menus ├── credits.rs ├── main.rs ├── mod.rs ├── pause.rs └── settings.rs ├── screens ├── gameplay.rs ├── loading.rs ├── mod.rs ├── splash.rs └── title.rs └── theme ├── interaction.rs ├── mod.rs ├── palette.rs └── widget.rs /.cargo/config_fast_builds.toml: -------------------------------------------------------------------------------- 1 | # Copy this file to `config.toml` to speed up your builds. 2 | # 3 | # # Faster linker 4 | # 5 | # One of the slowest aspects of compiling large Rust programs is the linking time. This file configures an 6 | # alternate linker that may improve build times. When choosing a new linker, you have two options: 7 | # 8 | # ## LLD 9 | # 10 | # LLD is a linker from the LLVM project that supports Linux, Windows, MacOS, and WASM. It has the greatest 11 | # platform support and the easiest installation process. It is enabled by default in this file for Linux 12 | # and Windows. On MacOS, the default linker yields higher performance than LLD and is used instead. 13 | # 14 | # To install, please scroll to the corresponding table for your target (eg. `[target.x86_64-pc-windows-msvc]` 15 | # for Windows) and follow the steps under `LLD linker`. 16 | # 17 | # For more information, please see LLD's website at . 18 | # 19 | # ## Mold 20 | # 21 | # Mold is a newer linker written by one of the authors of LLD. It boasts even greater performance, specifically 22 | # through its high parallelism, though it only supports Linux. 23 | # 24 | # Mold is disabled by default in this file. If you wish to enable it, follow the installation instructions for 25 | # your corresponding target, disable LLD by commenting out its `-Clink-arg=...` line, and enable Mold by 26 | # *uncommenting* its `-Clink-arg=...` line. 27 | # 28 | # There is a fork of Mold named Sold that supports MacOS, but it is unmaintained and is about the same speed as 29 | # the default ld64 linker. For this reason, it is not included in this file. 30 | # 31 | # For more information, please see Mold's repository at . 32 | # 33 | # # Nightly configuration 34 | # 35 | # Be warned that the following features require nightly Rust, which is experimental and may contain bugs. If you 36 | # are having issues, skip this section and use stable Rust instead. 37 | # 38 | # There are a few unstable features that can improve performance. To use them, first install nightly Rust 39 | # through Rustup: 40 | # 41 | # ``` 42 | # rustup toolchain install nightly 43 | # ``` 44 | # 45 | # Finally, uncomment the lines under the `Nightly` heading for your corresponding target table (eg. 46 | # `[target.x86_64-unknown-linux-gnu]` for Linux) to enable the following features: 47 | # 48 | # ## `share-generics` 49 | # 50 | # Usually rustc builds each crate separately, then combines them all together at the end. `share-generics` forces 51 | # crates to share monomorphized generic code, so they do not duplicate work. 52 | # 53 | # In other words, instead of crate 1 generating `Foo` and crate 2 generating `Foo` separately, 54 | # only one crate generates `Foo` and the other adds on to the pre-exiting work. 55 | # 56 | # Note that you may have some issues with this flag on Windows. If compiling fails due to the 65k symbol limit, 57 | # you may have to disable this setting. For more information and possible solutions to this error, see 58 | # . 59 | # 60 | # ## `threads` 61 | # 62 | # This option enables rustc's parallel frontend, which improves performance when parsing, type checking, borrow 63 | # checking, and more. We currently set `threads=0`, which defaults to the amount of cores in your CPU. 64 | # 65 | # For more information, see the blog post at . 66 | 67 | [target.x86_64-unknown-linux-gnu] 68 | linker = "clang" 69 | rustflags = [ 70 | # LLD linker 71 | # 72 | # You may need to install it: 73 | # 74 | # - Ubuntu: `sudo apt-get install lld clang` 75 | # - Fedora: `sudo dnf install lld clang` 76 | # - Arch: `sudo pacman -S lld clang` 77 | "-Clink-arg=-fuse-ld=lld", 78 | 79 | # Mold linker 80 | # 81 | # You may need to install it: 82 | # 83 | # - Ubuntu: `sudo apt-get install mold clang` 84 | # - Fedora: `sudo dnf install mold clang` 85 | # - Arch: `sudo pacman -S mold clang` 86 | # "-Clink-arg=-fuse-ld=/usr/bin/mold", 87 | 88 | # Nightly 89 | # "-Zshare-generics=y", 90 | # "-Zthreads=0", 91 | ] 92 | 93 | [target.x86_64-apple-darwin] 94 | rustflags = [ 95 | # LLD linker 96 | # 97 | # The default ld64 linker is faster, you should continue using it instead. 98 | # 99 | # You may need to install it: 100 | # 101 | # Brew: `brew install llvm` 102 | # Manually: 103 | # "-Clink-arg=-fuse-ld=/usr/local/opt/llvm/bin/ld64.lld", 104 | 105 | # Nightly 106 | # "-Zshare-generics=y", 107 | # "-Zthreads=0", 108 | ] 109 | 110 | [target.aarch64-apple-darwin] 111 | rustflags = [ 112 | # LLD linker 113 | # 114 | # The default ld64 linker is faster, you should continue using it instead. 115 | # 116 | # You may need to install it: 117 | # 118 | # Brew: `brew install llvm` 119 | # Manually: 120 | # "-Clink-arg=-fuse-ld=/opt/homebrew/opt/llvm/bin/ld64.lld", 121 | 122 | # Nightly 123 | # "-Zshare-generics=y", 124 | # "-Zthreads=0", 125 | ] 126 | 127 | [target.x86_64-pc-windows-msvc] 128 | # LLD linker 129 | # 130 | # You may need to install it: 131 | # 132 | # ``` 133 | # cargo install -f cargo-binutils 134 | # rustup component add llvm-tools 135 | # ``` 136 | linker = "rust-lld.exe" 137 | rustdocflags = ["-Clinker=rust-lld.exe"] 138 | rustflags = [ 139 | # Nightly 140 | # "-Zshare-generics=n", # This needs to be off if you use dynamic linking on Windows. 141 | # "-Zthreads=0", 142 | ] 143 | 144 | # Optional: Uncommenting the following improves compile times, but reduces the amount of debug info to 'line number tables only' 145 | # In most cases the gains are negligible, but if you are on macos and have slow compile times you should see significant gains. 146 | # [profile.dev] 147 | # debug = 1 148 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | charset = utf-8 7 | indent_style = space 8 | indent_size = 4 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [.github/workflows/*.{yaml,yml}] 15 | indent_size = 2 16 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | 9 | concurrency: 10 | group: ${{ github.workflow }}-${{ github.ref || github.run_id }} 11 | cancel-in-progress: true 12 | 13 | env: 14 | # Reduce compile time and cache size. 15 | RUSTFLAGS: -Dwarnings -Zshare-generics=y -Zthreads=0 16 | RUSTDOCFLAGS: -Dwarnings -Zshare-generics=y -Zthreads=0 17 | # Use the same Rust toolchain across jobs so they can share a cache. 18 | toolchain: nightly-2025-04-03 19 | 20 | jobs: 21 | # Check formatting. 22 | format: 23 | name: Format 24 | runs-on: ubuntu-latest 25 | timeout-minutes: 10 26 | steps: 27 | - name: Checkout repository 28 | uses: actions/checkout@v4 29 | 30 | - name: Install Rust toolchain 31 | uses: dtolnay/rust-toolchain@master 32 | with: 33 | toolchain: ${{ env.toolchain }} 34 | components: rustfmt 35 | 36 | - name: Check formatting 37 | run: cargo fmt --all -- --check 38 | 39 | # Check documentation. 40 | docs: 41 | name: Docs 42 | runs-on: ubuntu-latest 43 | timeout-minutes: 20 44 | steps: 45 | - name: Checkout repository 46 | uses: actions/checkout@v4 47 | 48 | - name: Install Rust toolchain 49 | uses: dtolnay/rust-toolchain@master 50 | with: 51 | toolchain: ${{ env.toolchain }} 52 | 53 | - name: Restore Rust cache 54 | id: cache 55 | uses: Swatinem/rust-cache@v2 56 | with: 57 | shared-key: ci 58 | save-if: false 59 | 60 | - name: Install build dependencies 61 | if: steps.cache.outputs.cache-hit != 'true' 62 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev 63 | 64 | - name: Check documentation 65 | run: cargo doc --locked --workspace --profile ci --all-features --document-private-items --no-deps 66 | 67 | # Run Clippy lints. 68 | clippy-lints: 69 | name: Clippy lints 70 | runs-on: ubuntu-latest 71 | timeout-minutes: 20 72 | steps: 73 | - name: Checkout repository 74 | uses: actions/checkout@v4 75 | 76 | - name: Install Rust toolchain 77 | uses: dtolnay/rust-toolchain@master 78 | with: 79 | toolchain: ${{ env.toolchain }} 80 | components: clippy 81 | 82 | - name: Restore Rust cache 83 | id: cache 84 | uses: Swatinem/rust-cache@v2 85 | with: 86 | shared-key: ci 87 | save-if: ${{ github.ref == 'refs/heads/main' }} 88 | 89 | - name: Install build dependencies 90 | if: steps.cache.outputs.cache-hit != 'true' 91 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev 92 | 93 | - name: Run Clippy lints 94 | run: cargo clippy --locked --workspace --all-targets --profile ci --all-features 95 | 96 | # Run Bevy lints. 97 | bevy-lints: 98 | name: Bevy lints 99 | runs-on: ubuntu-latest 100 | timeout-minutes: 20 101 | steps: 102 | - name: Checkout repository 103 | uses: actions/checkout@v4 104 | 105 | - name: Install Rust toolchain (plus bevy_lint) 106 | uses: TheBevyFlock/bevy_cli/bevy_lint@lint-v0.3.0 107 | 108 | - name: Restore Rust cache 109 | id: cache 110 | uses: Swatinem/rust-cache@v2 111 | with: 112 | shared-key: ci 113 | save-if: false 114 | 115 | - name: Install build dependencies 116 | if: steps.cache.outputs.cache-hit != 'true' 117 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev 118 | 119 | - name: Run Bevy lints 120 | run: bevy_lint --locked --workspace --all-targets --profile ci --all-features 121 | 122 | # Run tests. 123 | tests: 124 | name: Tests 125 | runs-on: ubuntu-latest 126 | timeout-minutes: 40 127 | steps: 128 | - name: Checkout repository 129 | uses: actions/checkout@v4 130 | 131 | - name: Set up environment 132 | run: echo "RUSTFLAGS=${RUSTFLAGS:+$RUSTFLAGS }-Zcodegen-backend=cranelift" >> "${GITHUB_ENV}" 133 | 134 | - name: Install Rust toolchain 135 | uses: dtolnay/rust-toolchain@master 136 | with: 137 | toolchain: ${{ env.toolchain }} 138 | components: rustc-codegen-cranelift-preview 139 | 140 | - name: Restore Rust cache 141 | uses: Swatinem/rust-cache@v2 142 | with: 143 | shared-key: test 144 | cache-directories: ${{ env.LD_LIBRARY_PATH }} 145 | save-if: ${{ github.ref == 'refs/heads/main' }} 146 | 147 | - name: Install build dependencies 148 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev 149 | 150 | - name: Run tests 151 | run: cargo test --locked --workspace --all-targets --profile ci --no-fail-fast 152 | 153 | # Check that the web build compiles. 154 | check-web: 155 | name: Check web 156 | runs-on: ubuntu-latest 157 | timeout-minutes: 20 158 | steps: 159 | - name: Checkout repository 160 | uses: actions/checkout@v4 161 | 162 | - name: Install Rust toolchain 163 | uses: dtolnay/rust-toolchain@master 164 | with: 165 | toolchain: ${{ env.toolchain }} 166 | targets: wasm32-unknown-unknown 167 | 168 | - name: Restore Rust cache 169 | id: cache 170 | uses: Swatinem/rust-cache@v2 171 | with: 172 | shared-key: web-ci 173 | save-if: ${{ github.ref == 'refs/heads/main' }} 174 | 175 | - name: Install build dependencies 176 | if: steps.cache.outputs.cache-hit != 'true' 177 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev 178 | 179 | - name: Check web 180 | run: cargo check --config 'profile.web.inherits="dev"' --profile ci --no-default-features --features dev --target wasm32-unknown-unknown 181 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | # Trigger this workflow on a manual workflow dispatch. 5 | workflow_dispatch: 6 | inputs: 7 | version: 8 | description: "Version number in the format `v1.2.3`" 9 | required: true 10 | type: string 11 | build_for_windows: 12 | description: "Build for Windows (WARNING: slow!)" 13 | default: true 14 | type: boolean 15 | build_for_macos: 16 | description: "Build for macOS" 17 | default: true 18 | type: boolean 19 | build_for_linux: 20 | description: "Build for Linux" 21 | default: true 22 | type: boolean 23 | build_for_web: 24 | description: "Build for web" 25 | default: true 26 | type: boolean 27 | upload_to_github: 28 | description: "Upload to GitHub releases" 29 | default: true 30 | type: boolean 31 | upload_to_itch: 32 | description: "Upload to itch.io (if configured)" 33 | default: true 34 | type: boolean 35 | deny_warnings: 36 | description: "Deny warnings" 37 | default: false 38 | type: boolean 39 | 40 | # Cancel the release workflow when a more recent workflow begins. 41 | concurrency: 42 | group: ${{ github.workflow }}-${{ github.ref || github.run_id }} 43 | cancel-in-progress: true 44 | 45 | # Configure the release workflow by editing the following values. 46 | env: 47 | # The base filename of the binary produced by `cargo build`. 48 | cargo_build_binary_name: bevy_new_2d 49 | 50 | # The path to the assets directory. 51 | assets_path: assets 52 | 53 | # The itch.io project to upload to in the format `user-name/project-name`. 54 | # There will be no upload to itch.io if this is commented out. 55 | itch_page: the-bevy-flock/bevy-new-2d 56 | 57 | # The ID of the app produced by this workflow. 58 | # Applies to macOS releases. 59 | # Must contain only A-Z, a-z, 0-9, hyphen, and period: . 60 | app_id: the-bevy-flock.bevy-new-2d 61 | 62 | # The base filename of the binary in the package produced by this workflow. 63 | # Applies to Windows, macOS, and Linux releases. 64 | # Defaults to `cargo_build_binary_name` if commented out. 65 | #app_binary_name: bevy_new_2d 66 | 67 | # The name of the `.zip` or `.dmg` file produced by this workflow. 68 | # Defaults to `app_binary_name` if commented out. 69 | app_package_name: bevy-new-2d 70 | 71 | # The display name of the app produced by this workflow. 72 | # Applies to macOS releases. 73 | # Defaults to `app_package_name` if commented out. 74 | app_display_name: Bevy New 2D 75 | 76 | # The short display name of the app produced by this workflow. 77 | # Applies to macOS releases. 78 | # Must be 15 or fewer characters: . 79 | # Defaults to `app_display_name` if commented out. 80 | #app_short_name: Bevy New 2D 81 | 82 | # Before enabling LFS, please take a look at GitHub's documentation for costs and quota limits: 83 | # 84 | git_lfs: false 85 | 86 | # Enabling this only helps with consecutive releases to the same version (and takes up cache storage space). 87 | # See: . 88 | use_github_cache: false 89 | 90 | jobs: 91 | # Forward some environment variables as outputs of this job. 92 | # This is needed because the `env` context can't be used in the `if:` condition of a job: 93 | # 94 | forward-env: 95 | runs-on: ubuntu-latest 96 | steps: 97 | - name: Do nothing 98 | run: "true" 99 | outputs: 100 | itch_page: ${{ env.itch_page }} 101 | 102 | # Determine the version number for this workflow. 103 | get-version: 104 | runs-on: ubuntu-latest 105 | steps: 106 | - name: Determine version number 107 | id: tag 108 | run: echo "ref=${GITHUB_REF#refs/*/}" >> "${GITHUB_OUTPUT}" 109 | outputs: 110 | # Use the input from workflow dispatch, or fall back to the git ref. 111 | version: ${{ inputs.version || steps.ref.outputs.ref }} 112 | 113 | # Build and package a release for each platform. 114 | build: 115 | needs: 116 | - get-version 117 | env: 118 | version: ${{ needs.get-version.outputs.version }} 119 | # Avoid rate-limiting. See: . 120 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 121 | strategy: 122 | matrix: 123 | include: 124 | - platform: web 125 | targets: wasm32-unknown-unknown 126 | package_ext: .zip 127 | runner: ubuntu-latest 128 | 129 | - platform: linux 130 | targets: x86_64-unknown-linux-gnu 131 | package_ext: .zip 132 | runner: ubuntu-latest 133 | 134 | - platform: windows 135 | targets: x86_64-pc-windows-msvc 136 | binary_ext: .exe 137 | package_ext: .zip 138 | runner: windows-latest 139 | 140 | - platform: macos 141 | targets: x86_64-apple-darwin aarch64-apple-darwin 142 | app_suffix: .app/Contents/MacOS 143 | package_ext: .dmg 144 | runner: macos-latest 145 | runs-on: ${{ matrix.runner }} 146 | permissions: 147 | # Required to create a GitHub release: . 148 | contents: write 149 | defaults: 150 | run: 151 | shell: bash 152 | 153 | steps: 154 | - name: Set up environment 155 | run: | 156 | # Default values: 157 | echo "app_binary_name=${app_binary_name:=${{ env.cargo_build_binary_name }}}" >> "${GITHUB_ENV}" 158 | echo "app_package_name=${app_package_name:=${app_binary_name}}" >> "${GITHUB_ENV}" 159 | echo "app_display_name=${app_display_name:=${app_package_name}}" >> "${GITHUB_ENV}" 160 | echo "app_short_name=${app_short_name:=${app_display_name}}" >> "${GITHUB_ENV}" 161 | 162 | # File paths: 163 | echo "app=tmp/app/${app_package_name}"'${{ matrix.app_suffix }}' >> "${GITHUB_ENV}" 164 | echo "package=${app_package_name}-"'${{ matrix.platform }}${{ matrix.package_ext }}' >> "${GITHUB_ENV}" 165 | 166 | # Rustflags: 167 | RUSTFLAGS='-Zthreads=0' 168 | if [ '${{ matrix.platform }}' != 'windows' ]; then 169 | RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }"'-Zshare-generics=y' 170 | fi 171 | if [ '${{ inputs.deny_warnings }}' = 'true' ]; then 172 | RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }"'-Dwarnings' 173 | fi 174 | echo "RUSTFLAGS=${RUSTFLAGS}" >> "${GITHUB_ENV}" 175 | 176 | # macOS environment: 177 | if [ '${{ matrix.platform }}' = 'macos' ]; then 178 | echo 'MACOSX_DEPLOYMENT_TARGET=11.0' >> "${GITHUB_ENV}" # macOS 11.0 Big Sur is the first version to support universal binaries. 179 | echo "SDKROOT=$(xcrun --sdk macosx --show-sdk-path)" >> "${GITHUB_ENV}" 180 | fi 181 | 182 | # Check if building for this platform is enabled. 183 | echo 'is_platform_enabled=${{ 184 | (matrix.platform == 'web' && inputs.build_for_web) || 185 | (matrix.platform == 'linux' && inputs.build_for_linux) || 186 | (matrix.platform == 'windows' && inputs.build_for_windows) || 187 | (matrix.platform == 'macos' && inputs.build_for_macos) 188 | }}' >> "${GITHUB_ENV}" 189 | 190 | - name: Checkout repository 191 | if: ${{ env.is_platform_enabled == 'true' }} 192 | uses: actions/checkout@v4 193 | with: 194 | lfs: ${{ env.git_lfs }} 195 | 196 | - name: Install Rust toolchain 197 | if: ${{ env.is_platform_enabled == 'true' }} 198 | uses: dtolnay/rust-toolchain@nightly 199 | with: 200 | targets: ${{ matrix.targets }} 201 | 202 | - name: Restore Rust cache 203 | if: ${{ env.is_platform_enabled == 'true' && env.use_github_cache == 'true' }} 204 | uses: Swatinem/rust-cache@v2 205 | with: 206 | shared-key: release 207 | save-if: ${{ github.ref == 'refs/heads/main' }} 208 | 209 | - name: Install build dependencies (Linux) 210 | if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'linux' }} 211 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev 212 | 213 | - name: Prepare output directories 214 | if: ${{ env.is_platform_enabled == 'true' }} 215 | run: rm -rf tmp; mkdir -p tmp/binary '${{ env.app }}' 216 | 217 | - name: Install cargo-binstall 218 | if: ${{ env.is_platform_enabled == 'true' }} 219 | uses: cargo-bins/cargo-binstall@main 220 | 221 | - name: Install Bevy CLI 222 | if: ${{ env.is_platform_enabled == 'true' }} 223 | run: cargo binstall --locked --no-confirm --force --git='https://github.com/TheBevyFlock/bevy_cli' bevy_cli 224 | 225 | - name: Build and add web bundle to app (Web) 226 | if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'web' }} 227 | run: | 228 | cargo binstall --locked --no-confirm --force wasm-bindgen-cli 229 | cargo binstall --locked --no-confirm --force wasm-opt 230 | bevy build --locked --release --features='${{ matrix.features }}' --yes web --bundle 231 | mv 'target/bevy_web/web-release/${{ env.cargo_build_binary_name }}' '${{ env.app }}' 232 | 233 | - name: Build and add binaries to app (non-Web) 234 | if: ${{ env.is_platform_enabled == 'true' && matrix.platform != 'web' }} 235 | run: | 236 | for target in ${{ matrix.targets }}; do 237 | bevy build --locked --release --target="${target}" --features='${{ matrix.features }}' 238 | mv target/"${target}"/release/'${{ env.cargo_build_binary_name }}${{ matrix.binary_ext }}' tmp/binary/"${target}"'${{ matrix.binary_ext }}' 239 | done 240 | if [ '${{ matrix.platform }}' = 'macos' ]; then 241 | lipo tmp/binary/*'${{ matrix.binary_ext }}' -create -output '${{ env.app }}/${{ env.app_binary_name }}${{ matrix.binary_ext }}' 242 | else 243 | mv tmp/binary/*'${{ matrix.binary_ext }}' '${{ env.app }}/${{ env.app_binary_name }}${{ matrix.binary_ext }}' 244 | fi 245 | 246 | - name: Add assets to app (non-Web) 247 | if: ${{ env.is_platform_enabled == 'true' && matrix.platform != 'web' }} 248 | run: cp -R ./'${{ env.assets_path }}' '${{ env.app }}' || true # Ignore error if assets folder does not exist. 249 | 250 | - name: Add metadata to app (macOS) 251 | if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'macos' }} 252 | run: | 253 | cat >'${{ env.app }}/../Info.plist' < 255 | 256 | 257 | 258 | CFBundleDevelopmentRegion 259 | en 260 | CFBundleDisplayName 261 | ${{ env.app_display_name }} 262 | CFBundleExecutable 263 | ${{ env.app_binary_name }} 264 | CFBundleIdentifier 265 | ${{ env.app_id }} 266 | CFBundleName 267 | ${{ env.app_short_name }} 268 | CFBundleShortVersionString 269 | ${{ env.version }} 270 | CFBundleVersion 271 | ${{ env.version }} 272 | CFBundleInfoDictionaryVersion 273 | 6.0 274 | CFBundlePackageType 275 | APPL 276 | CFBundleSupportedPlatforms 277 | 278 | MacOSX 279 | 280 | 281 | 282 | EOF 283 | 284 | - name: Package app (non-Windows) 285 | if: ${{ env.is_platform_enabled == 'true' && matrix.platform != 'windows' }} 286 | working-directory: tmp/app 287 | run: | 288 | if [ '${{ matrix.platform }}' = 'macos' ]; then 289 | ln -s /Applications . 290 | hdiutil create -fs HFS+ -volname '${{ env.app_package_name }}' -srcfolder . '${{ env.package }}' 291 | else 292 | zip --recurse-paths '${{ env.package }}' '${{ env.app_package_name }}' 293 | fi 294 | 295 | - name: Package app (Windows) 296 | if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'windows' }} 297 | working-directory: tmp/app 298 | shell: pwsh 299 | run: Compress-Archive -Path '${{ env.app_package_name }}' -DestinationPath '${{ env.package }}' 300 | 301 | - name: Upload package to workflow artifacts 302 | if: ${{ env.is_platform_enabled == 'true' }} 303 | uses: actions/upload-artifact@v4 304 | with: 305 | path: tmp/app/${{ env.package }} 306 | name: package-${{ matrix.platform }} 307 | retention-days: 1 308 | 309 | - name: Upload package to GitHub release 310 | if: ${{ env.is_platform_enabled == 'true' && env.upload_to_github == 'true' }} 311 | uses: svenstaro/upload-release-action@v2 312 | with: 313 | repo_token: ${{ secrets.GITHUB_TOKEN }} 314 | file: tmp/app/${{ env.package }} 315 | asset_name: ${{ env.package }} 316 | release_name: ${{ env.version }} 317 | tag: ${{ env.version }} 318 | overwrite: true 319 | 320 | # Upload all packages to itch.io. 321 | upload-to-itch: 322 | runs-on: ubuntu-latest 323 | needs: 324 | - forward-env 325 | - get-version 326 | - build 327 | if: ${{ inputs.upload_to_itch && needs.forward-env.outputs.itch_page != '' }} 328 | 329 | steps: 330 | - name: Download all packages 331 | uses: actions/download-artifact@v4 332 | with: 333 | pattern: package-* 334 | path: tmp 335 | 336 | - name: Install butler 337 | run: | 338 | curl -L -o butler.zip 'https://broth.itch.zone/butler/linux-amd64/LATEST/archive/default' 339 | unzip butler.zip 340 | chmod +x butler 341 | ./butler -V 342 | 343 | - name: Upload all packages to itch.io 344 | env: 345 | BUTLER_API_KEY: ${{ secrets.BUTLER_CREDENTIALS }} 346 | run: | 347 | for channel in $(ls tmp); do 348 | ./butler push \ 349 | --fix-permissions \ 350 | --userversion='${{ needs.get-version.outputs.version }}' \ 351 | tmp/"${channel}"/* \ 352 | '${{ env.itch_page }}':"${channel#package-}" 353 | done 354 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml.template: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | # Trigger this workflow on a manual workflow dispatch. 5 | workflow_dispatch: 6 | inputs: 7 | version: 8 | description: "Version number in the format `v1.2.3`" 9 | required: true 10 | type: string 11 | build_for_windows: 12 | description: "Build for Windows (WARNING: slow!)" 13 | default: true 14 | type: boolean 15 | build_for_macos: 16 | description: "Build for macOS" 17 | default: true 18 | type: boolean 19 | build_for_linux: 20 | description: "Build for Linux" 21 | default: true 22 | type: boolean 23 | build_for_web: 24 | description: "Build for web" 25 | default: true 26 | type: boolean 27 | upload_to_github: 28 | description: "Upload to GitHub releases" 29 | default: true 30 | type: boolean 31 | upload_to_itch: 32 | description: "Upload to itch.io (if configured)" 33 | default: true 34 | type: boolean 35 | deny_warnings: 36 | description: "Deny warnings" 37 | default: false 38 | type: boolean 39 | 40 | {% raw -%} 41 | # Cancel the release workflow when a more recent workflow begins. 42 | concurrency: 43 | group: ${{ github.workflow }}-${{ github.ref || github.run_id }} 44 | cancel-in-progress: true 45 | {%- endraw %} 46 | 47 | # Configure the release workflow by editing the following values. 48 | env: 49 | # The base filename of the binary produced by `cargo build`. 50 | cargo_build_binary_name: {{project-name}} 51 | 52 | # The path to the assets directory. 53 | assets_path: assets 54 | 55 | # The itch.io project to upload to in the format `user-name/project-name`. 56 | # There will be no upload to itch.io if this is commented out. 57 | {%- if itch_username != "" %} 58 | {%- if itch_project != "" %} 59 | itch_page: {{itch_username}}/{{itch_project}} 60 | {%- else %} 61 | itch_page: {{itch_username}}/{{project-name}} 62 | {%- endif %} 63 | {%- else %} 64 | #itch_page: your-itch-username/{{project-name}} 65 | {%- endif %} 66 | 67 | # The ID of the app produced by this workflow. 68 | # Applies to macOS releases. 69 | # Must contain only A-Z, a-z, 0-9, hyphen, and period: . 70 | app_id: {{itch_username | kebab_case}}.{{project-name | kebab_case}} 71 | 72 | # The base filename of the binary in the package produced by this workflow. 73 | # Applies to Windows, macOS, and Linux releases. 74 | # Defaults to `cargo_build_binary_name` if commented out. 75 | #app_binary_name: {{project-name}} 76 | 77 | # The name of the `.zip` or `.dmg` file produced by this workflow. 78 | # Defaults to `app_binary_name` if commented out. 79 | #app_package_name: {{project-name | kebab_case}} 80 | 81 | # The display name of the app produced by this workflow. 82 | # Applies to macOS releases. 83 | # Defaults to `app_package_name` if commented out. 84 | #app_display_name: {{project-name | title_case}} 85 | 86 | # The short display name of the app produced by this workflow. 87 | # Applies to macOS releases. 88 | # Must be 15 or fewer characters: . 89 | # Defaults to `app_display_name` if commented out. 90 | #app_short_name: {{project-name | title_case | truncate: 15, "…"}} 91 | 92 | # Before enabling LFS, please take a look at GitHub's documentation for costs and quota limits: 93 | # 94 | git_lfs: false 95 | 96 | # Enabling this only helps with consecutive releases to the same version (and takes up cache storage space). 97 | # See: . 98 | use_github_cache: false 99 | 100 | {% raw -%} 101 | jobs: 102 | # Forward some environment variables as outputs of this job. 103 | # This is needed because the `env` context can't be used in the `if:` condition of a job: 104 | # 105 | forward-env: 106 | runs-on: ubuntu-latest 107 | steps: 108 | - name: Do nothing 109 | run: "true" 110 | outputs: 111 | itch_page: ${{ env.itch_page }} 112 | 113 | # Determine the version number for this workflow. 114 | get-version: 115 | runs-on: ubuntu-latest 116 | steps: 117 | - name: Determine version number 118 | id: tag 119 | run: echo "ref=${GITHUB_REF#refs/*/}" >> "${GITHUB_OUTPUT}" 120 | outputs: 121 | # Use the input from workflow dispatch, or fall back to the git ref. 122 | version: ${{ inputs.version || steps.ref.outputs.ref }} 123 | 124 | # Build and package a release for each platform. 125 | build: 126 | needs: 127 | - get-version 128 | env: 129 | version: ${{ needs.get-version.outputs.version }} 130 | # Avoid rate-limiting. See: . 131 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 132 | strategy: 133 | matrix: 134 | include: 135 | - platform: web 136 | targets: wasm32-unknown-unknown 137 | package_ext: .zip 138 | runner: ubuntu-latest 139 | 140 | - platform: linux 141 | targets: x86_64-unknown-linux-gnu 142 | package_ext: .zip 143 | runner: ubuntu-latest 144 | 145 | - platform: windows 146 | targets: x86_64-pc-windows-msvc 147 | binary_ext: .exe 148 | package_ext: .zip 149 | runner: windows-latest 150 | 151 | - platform: macos 152 | targets: x86_64-apple-darwin aarch64-apple-darwin 153 | app_suffix: .app/Contents/MacOS 154 | package_ext: .dmg 155 | runner: macos-latest 156 | runs-on: ${{ matrix.runner }} 157 | permissions: 158 | # Required to create a GitHub release: . 159 | contents: write 160 | defaults: 161 | run: 162 | shell: bash 163 | 164 | steps: 165 | - name: Set up environment 166 | run: | 167 | # Default values: 168 | echo "app_binary_name=${app_binary_name:=${{ env.cargo_build_binary_name }}}" >> "${GITHUB_ENV}" 169 | echo "app_package_name=${app_package_name:=${app_binary_name}}" >> "${GITHUB_ENV}" 170 | echo "app_display_name=${app_display_name:=${app_package_name}}" >> "${GITHUB_ENV}" 171 | echo "app_short_name=${app_short_name:=${app_display_name}}" >> "${GITHUB_ENV}" 172 | 173 | # File paths: 174 | echo "app=tmp/app/${app_package_name}"'${{ matrix.app_suffix }}' >> "${GITHUB_ENV}" 175 | echo "package=${app_package_name}-"'${{ matrix.platform }}${{ matrix.package_ext }}' >> "${GITHUB_ENV}" 176 | 177 | # Rustflags: 178 | RUSTFLAGS='-Zthreads=0' 179 | if [ '${{ matrix.platform }}' != 'windows' ]; then 180 | RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }"'-Zshare-generics=y' 181 | fi 182 | if [ '${{ inputs.deny_warnings }}' = 'true' ]; then 183 | RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }"'-Dwarnings' 184 | fi 185 | echo "RUSTFLAGS=${RUSTFLAGS}" >> "${GITHUB_ENV}" 186 | 187 | # macOS environment: 188 | if [ '${{ matrix.platform }}' = 'macos' ]; then 189 | echo 'MACOSX_DEPLOYMENT_TARGET=11.0' >> "${GITHUB_ENV}" # macOS 11.0 Big Sur is the first version to support universal binaries. 190 | echo "SDKROOT=$(xcrun --sdk macosx --show-sdk-path)" >> "${GITHUB_ENV}" 191 | fi 192 | 193 | # Check if building for this platform is enabled. 194 | echo 'is_platform_enabled=${{ 195 | (matrix.platform == 'web' && inputs.build_for_web) || 196 | (matrix.platform == 'linux' && inputs.build_for_linux) || 197 | (matrix.platform == 'windows' && inputs.build_for_windows) || 198 | (matrix.platform == 'macos' && inputs.build_for_macos) 199 | }}' >> "${GITHUB_ENV}" 200 | 201 | - name: Checkout repository 202 | if: ${{ env.is_platform_enabled == 'true' }} 203 | uses: actions/checkout@v4 204 | with: 205 | lfs: ${{ env.git_lfs }} 206 | 207 | - name: Install Rust toolchain 208 | if: ${{ env.is_platform_enabled == 'true' }} 209 | uses: dtolnay/rust-toolchain@nightly 210 | with: 211 | targets: ${{ matrix.targets }} 212 | 213 | - name: Restore Rust cache 214 | if: ${{ env.is_platform_enabled == 'true' && env.use_github_cache == 'true' }} 215 | uses: Swatinem/rust-cache@v2 216 | with: 217 | shared-key: release 218 | save-if: ${{ github.ref == 'refs/heads/main' }} 219 | 220 | - name: Install build dependencies (Linux) 221 | if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'linux' }} 222 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev 223 | 224 | - name: Prepare output directories 225 | if: ${{ env.is_platform_enabled == 'true' }} 226 | run: rm -rf tmp; mkdir -p tmp/binary '${{ env.app }}' 227 | 228 | - name: Install cargo-binstall 229 | if: ${{ env.is_platform_enabled == 'true' }} 230 | uses: cargo-bins/cargo-binstall@main 231 | 232 | - name: Install Bevy CLI 233 | if: ${{ env.is_platform_enabled == 'true' }} 234 | run: cargo binstall --locked --no-confirm --force --git='https://github.com/TheBevyFlock/bevy_cli' bevy_cli 235 | 236 | - name: Build and add web bundle to app (Web) 237 | if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'web' }} 238 | run: | 239 | cargo binstall --locked --no-confirm --force wasm-bindgen-cli 240 | cargo binstall --locked --no-confirm --force wasm-opt 241 | bevy build --locked --release --features='${{ matrix.features }}' --yes web --bundle 242 | mv 'target/bevy_web/web-release/${{ env.cargo_build_binary_name }}' '${{ env.app }}' 243 | 244 | - name: Build and add binaries to app (non-Web) 245 | if: ${{ env.is_platform_enabled == 'true' && matrix.platform != 'web' }} 246 | run: | 247 | for target in ${{ matrix.targets }}; do 248 | bevy build --locked --release --target="${target}" --features='${{ matrix.features }}' 249 | mv target/"${target}"/release/'${{ env.cargo_build_binary_name }}${{ matrix.binary_ext }}' tmp/binary/"${target}"'${{ matrix.binary_ext }}' 250 | done 251 | if [ '${{ matrix.platform }}' = 'macos' ]; then 252 | lipo tmp/binary/*'${{ matrix.binary_ext }}' -create -output '${{ env.app }}/${{ env.app_binary_name }}${{ matrix.binary_ext }}' 253 | else 254 | mv tmp/binary/*'${{ matrix.binary_ext }}' '${{ env.app }}/${{ env.app_binary_name }}${{ matrix.binary_ext }}' 255 | fi 256 | 257 | - name: Add assets to app (non-Web) 258 | if: ${{ env.is_platform_enabled == 'true' && matrix.platform != 'web' }} 259 | run: cp -R ./'${{ env.assets_path }}' '${{ env.app }}' || true # Ignore error if assets folder does not exist. 260 | 261 | - name: Add metadata to app (macOS) 262 | if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'macos' }} 263 | run: | 264 | cat >'${{ env.app }}/../Info.plist' < 266 | 267 | 268 | 269 | CFBundleDevelopmentRegion 270 | en 271 | CFBundleDisplayName 272 | ${{ env.app_display_name }} 273 | CFBundleExecutable 274 | ${{ env.app_binary_name }} 275 | CFBundleIdentifier 276 | ${{ env.app_id }} 277 | CFBundleName 278 | ${{ env.app_short_name }} 279 | CFBundleShortVersionString 280 | ${{ env.version }} 281 | CFBundleVersion 282 | ${{ env.version }} 283 | CFBundleInfoDictionaryVersion 284 | 6.0 285 | CFBundlePackageType 286 | APPL 287 | CFBundleSupportedPlatforms 288 | 289 | MacOSX 290 | 291 | 292 | 293 | EOF 294 | 295 | - name: Package app (non-Windows) 296 | if: ${{ env.is_platform_enabled == 'true' && matrix.platform != 'windows' }} 297 | working-directory: tmp/app 298 | run: | 299 | if [ '${{ matrix.platform }}' = 'macos' ]; then 300 | ln -s /Applications . 301 | hdiutil create -fs HFS+ -volname '${{ env.app_package_name }}' -srcfolder . '${{ env.package }}' 302 | else 303 | zip --recurse-paths '${{ env.package }}' '${{ env.app_package_name }}' 304 | fi 305 | 306 | - name: Package app (Windows) 307 | if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'windows' }} 308 | working-directory: tmp/app 309 | shell: pwsh 310 | run: Compress-Archive -Path '${{ env.app_package_name }}' -DestinationPath '${{ env.package }}' 311 | 312 | - name: Upload package to workflow artifacts 313 | if: ${{ env.is_platform_enabled == 'true' }} 314 | uses: actions/upload-artifact@v4 315 | with: 316 | path: tmp/app/${{ env.package }} 317 | name: package-${{ matrix.platform }} 318 | retention-days: 1 319 | 320 | - name: Upload package to GitHub release 321 | if: ${{ env.is_platform_enabled == 'true' && env.upload_to_github == 'true' }} 322 | uses: svenstaro/upload-release-action@v2 323 | with: 324 | repo_token: ${{ secrets.GITHUB_TOKEN }} 325 | file: tmp/app/${{ env.package }} 326 | asset_name: ${{ env.package }} 327 | release_name: ${{ env.version }} 328 | tag: ${{ env.version }} 329 | overwrite: true 330 | 331 | # Upload all packages to itch.io. 332 | upload-to-itch: 333 | runs-on: ubuntu-latest 334 | needs: 335 | - forward-env 336 | - get-version 337 | - build 338 | if: ${{ inputs.upload_to_itch && needs.forward-env.outputs.itch_page != '' }} 339 | 340 | steps: 341 | - name: Download all packages 342 | uses: actions/download-artifact@v4 343 | with: 344 | pattern: package-* 345 | path: tmp 346 | 347 | - name: Install butler 348 | run: | 349 | curl -L -o butler.zip 'https://broth.itch.zone/butler/linux-amd64/LATEST/archive/default' 350 | unzip butler.zip 351 | chmod +x butler 352 | ./butler -V 353 | 354 | - name: Upload all packages to itch.io 355 | env: 356 | BUTLER_API_KEY: ${{ secrets.BUTLER_CREDENTIALS }} 357 | run: | 358 | for channel in $(ls tmp); do 359 | ./butler push \ 360 | --fix-permissions \ 361 | --userversion='${{ needs.get-version.outputs.version }}' \ 362 | tmp/"${channel}"/* \ 363 | '${{ env.itch_page }}':"${channel#package-}" 364 | done 365 | {%- endraw %} 366 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Rust builds 2 | /target 3 | # This file contains environment-specific configuration like linker settings 4 | .cargo/config.toml 5 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations/Run_Native_Debug.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/runConfigurations/Run_Native_dev.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/runConfigurations/Run_Native_release.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/runConfigurations/Run_Web_dev.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/runConfigurations/Run_Web_release.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 17 | 18 | -------------------------------------------------------------------------------- /.vscode/bevy.code-snippets: -------------------------------------------------------------------------------- 1 | { 2 | "Bevy: New top-level function Plugin": { 3 | "scope": "rust", 4 | "prefix": "plugin", 5 | "body": [ 6 | "use bevy::prelude::*;", 7 | "", 8 | "pub(super) fn plugin(app: &mut App) {", 9 | "\t$0", 10 | "}" 11 | ] 12 | }, 13 | "Bevy: New Component": { 14 | "scope": "rust", 15 | "prefix": "component", 16 | "body": [ 17 | "#[derive(Component, Reflect, Debug)]", 18 | "#[reflect(Component)]", 19 | "struct $1;" 20 | ] 21 | }, 22 | "Bevy: New Resource": { 23 | "scope": "rust", 24 | "prefix": "resource", 25 | "body": [ 26 | "#[derive(Resource, Reflect, Debug, Default)]", 27 | "#[reflect(Resource)]", 28 | "struct $1;" 29 | ] 30 | }, 31 | "Bevy: New Event": { 32 | "scope": "rust", 33 | "prefix": "event", 34 | "body": [ 35 | "#[derive(Event, Debug)]", 36 | "struct $1;" 37 | ] 38 | }, 39 | "Bevy: New SystemSet": { 40 | "scope": "rust", 41 | "prefix": "systemset", 42 | "body": [ 43 | "#[derive(SystemSet, Copy, Clone, Eq, PartialEq, Hash, Debug)]", 44 | "enum $1 {", 45 | "\t$0", 46 | "}" 47 | ] 48 | }, 49 | "Bevy: New Schedule": { 50 | "scope": "rust", 51 | "prefix": "schedule", 52 | "body": [ 53 | "#[derive(ScheduleLabel, Copy, Clone, Eq, PartialEq, Hash, Debug)]", 54 | "struct $1;" 55 | ] 56 | }, 57 | "Bevy: New States": { 58 | "scope": "rust", 59 | "prefix": "states", 60 | "body": [ 61 | "#[derive(States, Copy, Clone, Eq, PartialEq, Hash, Debug, Default)]", 62 | "enum $1 {", 63 | "\t#[default]", 64 | "\t$0", 65 | "}" 66 | ] 67 | } 68 | } -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "fill-labs.dependi", 4 | "editorconfig.editorconfig", 5 | "tamasfe.even-better-toml", 6 | "rust-lang.rust-analyzer", 7 | "a5huynh.vscode-ron" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | // Allow `rust-analyzer` and `cargo` to run simultaneously. 3 | // This uses extra storage space, so consider commenting it out. 4 | "rust-analyzer.cargo.targetDir": true, 5 | // Display the directory of `mod.rs` files in the tab above the text editor. 6 | "workbench.editor.customLabels.patterns": { 7 | "**/mod.rs": "${dirname}/mod.rs" 8 | }, 9 | } 10 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "Run native dev", 6 | "type": "process", 7 | "command": "bevy", 8 | "args": [ 9 | "run" 10 | ], 11 | "options": { 12 | "env": { 13 | "RUST_BACKTRACE": "full" 14 | } 15 | }, 16 | "presentation": { 17 | "clear": true 18 | }, 19 | "problemMatcher": [ 20 | "$rustc" 21 | ], 22 | "group": { 23 | "kind": "build", 24 | "isDefault": true 25 | } 26 | }, 27 | { 28 | "label": "Run native release", 29 | "type": "process", 30 | "command": "bevy", 31 | "args": [ 32 | "run", 33 | "--release" 34 | ], 35 | "presentation": { 36 | "clear": true 37 | }, 38 | "problemMatcher": [ 39 | "$rustc" 40 | ], 41 | "group": "build" 42 | }, 43 | { 44 | "label": "Run web dev", 45 | "type": "process", 46 | "command": "bevy", 47 | "args": [ 48 | "run", 49 | "--yes", 50 | "web" 51 | ], 52 | "options": { 53 | "env": { 54 | "RUST_BACKTRACE": "full" 55 | } 56 | }, 57 | "presentation": { 58 | "clear": true 59 | }, 60 | "problemMatcher": [ 61 | "$rustc" 62 | ], 63 | "group": "build" 64 | }, 65 | { 66 | "label": "Run web release", 67 | "type": "process", 68 | "command": "bevy", 69 | "args": [ 70 | "run", 71 | "--yes", 72 | "--release", 73 | "web" 74 | ], 75 | "presentation": { 76 | "clear": true 77 | }, 78 | "problemMatcher": [ 79 | "$rustc" 80 | ], 81 | "group": "build" 82 | } 83 | ] 84 | } 85 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bevy_new_2d" 3 | version = "0.1.0" 4 | edition = "2024" 5 | license = "MIT OR Apache-2.0 OR CC0-1.0" 6 | 7 | [dependencies] 8 | bevy = { version = "0.16", features = ["wayland"] } 9 | rand = "0.8" 10 | # Compile low-severity logs out of native builds for performance. 11 | log = { version = "0.4", features = [ 12 | "max_level_debug", 13 | "release_max_level_warn", 14 | ] } 15 | # Compile low-severity logs out of web builds for performance. 16 | tracing = { version = "0.1", features = [ 17 | "max_level_debug", 18 | "release_max_level_warn", 19 | ] } 20 | 21 | # Your web builds will start failing if you add a dependency that pulls in `getrandom` v0.3+. 22 | # To fix this, you should tell `getrandom` to use the `wasm_js` backend on Wasm. 23 | # See: . 24 | #[target.wasm32-unknown-unknown.dependencies] 25 | #getrandom = { version = "0.3", features = ["wasm_js"] } 26 | # In addition to enabling the `wasm_js` feature, you need to include `--cfg 'getrandom_backend="wasm_js"'` 27 | # in your rustflags for both local and CI/CD web builds, taking into account that rustflags specified in 28 | # multiple places are NOT combined (see ). 29 | # Alternatively, you can opt out of the rustflags check with this patch: 30 | #[patch.crates-io] 31 | #getrandom = { git = "https://github.com/benfrankel/getrandom" } 32 | 33 | [features] 34 | # Default to a native dev build. 35 | default = ["dev_native"] 36 | dev = [ 37 | # Improve compile times for dev builds by linking Bevy as a dynamic library. 38 | "bevy/dynamic_linking", 39 | "bevy/bevy_dev_tools", 40 | "bevy/bevy_ui_debug", 41 | # Improve error messages coming from Bevy 42 | "bevy/track_location", 43 | ] 44 | dev_native = [ 45 | "dev", 46 | # Enable asset hot reloading for native dev builds. 47 | "bevy/file_watcher", 48 | # Enable embedded asset hot reloading for native dev builds. 49 | "bevy/embedded_watcher", 50 | ] 51 | 52 | 53 | [package.metadata.bevy_cli.release] 54 | # Disable dev features for release builds. 55 | default-features = false 56 | 57 | [package.metadata.bevy_cli.web] 58 | # Disable native features for web builds. 59 | default-features = false 60 | 61 | [package.metadata.bevy_cli.web.dev] 62 | features = ["dev"] 63 | 64 | 65 | [lints.rust] 66 | # Mark `bevy_lint` as a valid `cfg`, as it is set when the Bevy linter runs. 67 | unexpected_cfgs = { level = "warn", check-cfg = ["cfg(bevy_lint)"] } 68 | 69 | [lints.clippy] 70 | # Bevy supplies arguments to systems via dependency injection, so it's natural for systems to 71 | # request more than 7 arguments, which would undesirably trigger this lint. 72 | too_many_arguments = "allow" 73 | # Queries may access many components, which would undesirably trigger this lint. 74 | type_complexity = "allow" 75 | # Make sure macros use their standard braces, such as `[]` for `bevy_ecs::children!`. 76 | nonstandard_macro_braces = "warn" 77 | 78 | # You can configure the warning levels of Bevy lints here. For a list of all lints, see: 79 | # 80 | [package.metadata.bevy_lint] 81 | # panicking_methods = "deny" 82 | # pedantic = "warn" 83 | 84 | 85 | # Compile with Performance Optimizations: 86 | # 87 | 88 | # Enable a small amount of optimization in the dev profile. 89 | [profile.dev] 90 | opt-level = 1 91 | 92 | # Enable a large amount of optimization in the dev profile for dependencies. 93 | [profile.dev.package."*"] 94 | opt-level = 3 95 | 96 | # Remove expensive debug assertions due to 97 | [profile.dev.package.wgpu-types] 98 | debug-assertions = false 99 | 100 | [profile.release] 101 | # Compile the entire crate as one unit. 102 | # Slows compile times, marginal improvements. 103 | codegen-units = 1 104 | # Do a second optimization pass over the entire program, including dependencies. 105 | # Slows compile times, marginal improvements. 106 | lto = "thin" 107 | 108 | # This profile will be used by `bevy run web` automatically. 109 | [profile.web-release] 110 | # Default to release profile values. 111 | inherits = "release" 112 | # Optimize with size in mind (also try "z", sometimes it is better). 113 | # Slightly slows compile times, great improvements to file size and runtime performance. 114 | opt-level = "s" 115 | # Strip all debugging information from the binary to slightly reduce file size. 116 | strip = "debuginfo" 117 | 118 | # Optimize for build time in CI. 119 | [profile.ci] 120 | inherits = "dev" 121 | opt-level = 0 122 | debug = "line-tables-only" 123 | codegen-units = 4 124 | 125 | [profile.ci.package."*"] 126 | opt-level = 0 127 | -------------------------------------------------------------------------------- /Cargo.toml.template: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "{{project-name}}" 3 | authors = ["{{authors}}"] 4 | version = "0.1.0" 5 | edition = "2024" 6 | 7 | [dependencies] 8 | bevy = { version = "0.16", features = ["wayland"] } 9 | rand = "0.8" 10 | # Compile low-severity logs out of native builds for performance. 11 | log = { version = "0.4", features = [ 12 | "max_level_debug", 13 | "release_max_level_warn", 14 | ] } 15 | # Compile low-severity logs out of web builds for performance. 16 | tracing = { version = "0.1", features = [ 17 | "max_level_debug", 18 | "release_max_level_warn", 19 | ] } 20 | 21 | # Your web builds will start failing if you add a dependency that pulls in `getrandom` v0.3+. 22 | # To fix this, you should tell `getrandom` to use the `wasm_js` backend on Wasm. 23 | # See: . 24 | #[target.wasm32-unknown-unknown.dependencies] 25 | #getrandom = { version = "0.3", features = ["wasm_js"] } 26 | # In addition to enabling the `wasm_js` feature, you need to include `--cfg 'getrandom_backend="wasm_js"'` 27 | # in your rustflags for both local and CI/CD web builds, taking into account that rustflags specified in 28 | # multiple places are NOT combined (see ). 29 | # Alternatively, you can opt out of the rustflags check with this patch: 30 | #[patch.crates-io] 31 | #getrandom = { git = "https://github.com/benfrankel/getrandom" } 32 | 33 | [features] 34 | # Default to a native dev build. 35 | default = ["dev_native"] 36 | dev = [ 37 | # Improve compile times for dev builds by linking Bevy as a dynamic library. 38 | "bevy/dynamic_linking", 39 | "bevy/bevy_dev_tools", 40 | "bevy/bevy_ui_debug", 41 | # Improve error messages coming from Bevy 42 | "bevy/track_location", 43 | ] 44 | dev_native = [ 45 | "dev", 46 | # Enable asset hot reloading for native dev builds. 47 | "bevy/file_watcher", 48 | # Enable embedded asset hot reloading for native dev builds. 49 | "bevy/embedded_watcher", 50 | ] 51 | 52 | 53 | [package.metadata.bevy_cli.release] 54 | # Disable dev features for release builds. 55 | default-features = false 56 | 57 | [package.metadata.bevy_cli.web] 58 | # Disable native features for web builds. 59 | default-features = false 60 | 61 | [package.metadata.bevy_cli.web.dev] 62 | features = ["dev"] 63 | 64 | 65 | [lints.rust] 66 | # Mark `bevy_lint` as a valid `cfg`, as it is set when the Bevy linter runs. 67 | unexpected_cfgs = { level = "warn", check-cfg = ["cfg(bevy_lint)"] } 68 | 69 | [lints.clippy] 70 | # Bevy supplies arguments to systems via dependency injection, so it's natural for systems to 71 | # request more than 7 arguments, which would undesirably trigger this lint. 72 | too_many_arguments = "allow" 73 | # Queries may access many components, which would undesirably trigger this lint. 74 | type_complexity = "allow" 75 | # Make sure macros use their standard braces, such as `[]` for `bevy_ecs::children!`. 76 | nonstandard_macro_braces = "warn" 77 | 78 | # You can configure the warning levels of Bevy lints here. For a list of all lints, see: 79 | # 80 | [package.metadata.bevy_lint] 81 | # panicking_methods = "deny" 82 | # pedantic = "warn" 83 | 84 | 85 | # Compile with Performance Optimizations: 86 | # 87 | 88 | # Enable a small amount of optimization in the dev profile. 89 | [profile.dev] 90 | opt-level = 1 91 | 92 | # Enable a large amount of optimization in the dev profile for dependencies. 93 | [profile.dev.package."*"] 94 | opt-level = 3 95 | 96 | # Remove expensive debug assertions due to 97 | [profile.dev.package.wgpu-types] 98 | debug-assertions = false 99 | 100 | [profile.release] 101 | # Compile the entire crate as one unit. 102 | # Slows compile times, marginal improvements. 103 | codegen-units = 1 104 | # Do a second optimization pass over the entire program, including dependencies. 105 | # Slows compile times, marginal improvements. 106 | lto = "thin" 107 | 108 | # This profile will be used by `bevy run web` automatically. 109 | [profile.web-release] 110 | # Default to release profile values. 111 | inherits = "release" 112 | # Optimize with size in mind (also try "z", sometimes it is better). 113 | # Slightly slows compile times, great improvements to file size and runtime performance. 114 | opt-level = "s" 115 | # Strip all debugging information from the binary to slightly reduce file size. 116 | strip = "debuginfo" 117 | 118 | # Optimize for build time in CI. 119 | [profile.ci] 120 | inherits = "dev" 121 | opt-level = 0 122 | debug = "line-tables-only" 123 | codegen-units = 4 124 | 125 | [profile.ci.package."*"] 126 | opt-level = 0 127 | -------------------------------------------------------------------------------- /LICENSE-Apache-2.0.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /LICENSE-CC0-1.0.txt: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /LICENSE-MIT.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bevy New 2D 2 | 3 | This template is a great way to get started on a new 2D [Bevy](https://bevyengine.org/) game! 4 | Start with a [basic project](#write-your-game) and [CI / CD](#release-your-game) that can deploy to [itch.io](https://itch.io). 5 | You can [try this template in your browser!](https://the-bevy-flock.itch.io/bevy-new-2d) 6 | 7 | ## Prerequisites 8 | 9 | We assume that you're familiar with Bevy and have already seen the [official Quick Start Guide](https://bevyengine.org/learn/quick-start/introduction/). 10 | 11 | If you're new to Bevy, the patterns used in this template may look a bit weird at first glance. 12 | See our [Design Document](./docs/design.md) for more information on how we structured the code and why. 13 | 14 | ## Create a new game 15 | 16 | Install [`bevy_cli`](https://github.com/TheBevyFlock/bevy_cli/) and run the following command: 17 | 18 | ```sh 19 | bevy new my_game --template 2d 20 | ``` 21 | 22 | Then [create a GitHub repository](https://github.com/new) and push your local repository to it. 23 | 24 | ## Write your game 25 | 26 | The best way to get started is to play around with the code you find in [`src/demo/`](./src/demo). 27 | 28 | This template comes with a basic project structure that you may find useful: 29 | 30 | | Path | Description | 31 | | -------------------------------------------------- | ------------------------------------------------------------------ | 32 | | [`src/main.rs`](./src/main.rs) | App setup | 33 | | [`src/asset_tracking.rs`](./src/asset_tracking.rs) | A high-level way to load collections of asset handles as resources | 34 | | [`src/audio.rs`](./src/audio.rs) | Marker components for sound effects and music | 35 | | [`src/dev_tools.rs`](./src/dev_tools.rs) | Dev tools for dev builds (press \` aka backtick to toggle) | 36 | | [`src/demo/`](./src/demo) | Example game mechanics & content (replace with your own code) | 37 | | [`src/menus/`](./src/menus) | Main menu, pause menu, settings menu, etc. | 38 | | [`src/screens/`](./src/screens) | Splash screen, title screen, loading screen, etc. | 39 | | [`src/theme/`](./src/theme) | Reusable UI widgets & theming | 40 | 41 | Feel free to move things around however you want, though. 42 | 43 | > [!TIP] 44 | > Be sure to check out the [3rd-party tools](./docs/tooling.md) we recommend! 45 | 46 | ## Run your game 47 | 48 | We recommend using the [Bevy CLI](https://github.com/TheBevyFlock/bevy_cli) to run your game. 49 | 50 | Running your game locally is very simple: 51 | 52 | - Use `bevy run` to run a native dev build. 53 | - Use `bevy run web` to run a web dev build. 54 | 55 | This template also comes with [VS Code tasks](./.vscode/tasks.json) and [JetBrains run configurations](./.idea/runConfigurations/) 56 | to help run your game from your IDE. 57 | 58 |
59 | Running release builds 60 | 61 | - Use `bevy run --release` to run a native release build. 62 | - Use `bevy run --release web` to run a web release build. 63 |
64 | 65 |
66 | Installing Linux dependencies 67 | 68 | If you're using Linux, make sure you've installed Bevy's [Linux dependencies](https://github.com/bevyengine/bevy/blob/main/docs/linux_dependencies.md). 69 | Note that this template enables Wayland support, which requires additional dependencies as detailed in the link above. 70 | Wayland is activated by using the `bevy/wayland` feature in the [`Cargo.toml`](./Cargo.toml). 71 |
72 | 73 |
74 | (Optional) Improving compile times 75 | 76 | [`.cargo/config_fast_builds.toml`](./.cargo/config_fast_builds.toml) contains documentation on how to set up your environment to improve compile times. 77 | After you've fiddled with it, rename it to `.cargo/config.toml` to enable it. 78 |
79 | 80 |
81 | (Optional) Hot-patching with subsecond 82 | 83 | Hot-patching is an experimental feature that allows you to edit your game's code _while it's running_ 84 | and see the changes without having to recompile or restart. 85 | 86 | To set this up, follow the instructions in [`bevy_simple_subsecond_system`](https://github.com/TheBevyFlock/bevy_simple_subsecond_system/). 87 | Make sure to read the [`Known Limitations`](https://github.com/TheBevyFlock/bevy_simple_subsecond_system/?tab=readme-ov-file#known-limitations) 88 | section and update your [`Cargo.toml`](./Cargo.toml): 89 | 90 | ```diff 91 | [dependencies] 92 | + bevy_simple_subsecond_system = { version = "0.1", optional = true } 93 | 94 | [features] 95 | dev_native = [ 96 | + "dep:bevy_simple_subsecond_system", 97 | ] 98 | ``` 99 | 100 | Annotate your systems to enable hot-patching. 101 | The functions they call can be hot-patched too; no additional annotations required! 102 | 103 | ```rust 104 | #[cfg_attr(feature = "dev_native", hot)] 105 | fn my_system() {} 106 | ``` 107 | 108 | Run your game with hot-patching enabled: 109 | 110 | ```shell 111 | dx serve --hot-patch 112 | ``` 113 | 114 | Now edit an annotated system's code while the game is running, and save the file. 115 | You should see `Status: Hot-patching...` in the CLI if you've got it working. 116 |
117 | 118 | ## Release your game 119 | 120 | This template uses [GitHub workflows](https://docs.github.com/en/actions/using-workflows) to run tests and build releases. 121 | See [Workflows](./docs/workflows.md) for more information. 122 | 123 | ## Known Issues 124 | 125 | There are some known issues in Bevy that can require arcane workarounds. 126 | To keep this template simple, we've opted to leave these workarounds out. 127 | You can read about them in the [Known Issues](./docs/known-issues.md) document. 128 | 129 | ## License 130 | 131 | The source code in this repository is licensed under any of the following at your option: 132 | 133 | - [CC0-1.0 License](./LICENSE-CC0-1.0.txt) 134 | - [MIT License](./LICENSE-MIT.txt) 135 | - [Apache License, Version 2.0](./LICENSE-Apache-2.0.txt) 136 | 137 | The CC0 license explicitly does not waive patent rights, but we confirm that we hold no patent rights to anything presented in this repository. 138 | 139 | ## Credits 140 | 141 | The [assets](./assets) in this repository are all 3rd-party. See the [credits menu](./src/menus/credits.rs) for more information. 142 | -------------------------------------------------------------------------------- /README.md.template: -------------------------------------------------------------------------------- 1 | # {{project-name | title_case}} 2 | 3 | This project was generated using the [Bevy New 2D](https://github.com/TheBevyFlock/bevy_new_2d) template. 4 | Check out the [documentation](https://github.com/TheBevyFlock/bevy_new_2d/blob/main/README.md) to get started! 5 | -------------------------------------------------------------------------------- /assets/audio/music/Fluffing A Duck.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/assets/audio/music/Fluffing A Duck.ogg -------------------------------------------------------------------------------- /assets/audio/music/Monkeys Spinning Monkeys.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/assets/audio/music/Monkeys Spinning Monkeys.ogg -------------------------------------------------------------------------------- /assets/audio/sound_effects/button_click.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/assets/audio/sound_effects/button_click.ogg -------------------------------------------------------------------------------- /assets/audio/sound_effects/button_hover.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/assets/audio/sound_effects/button_hover.ogg -------------------------------------------------------------------------------- /assets/audio/sound_effects/step1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/assets/audio/sound_effects/step1.ogg -------------------------------------------------------------------------------- /assets/audio/sound_effects/step2.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/assets/audio/sound_effects/step2.ogg -------------------------------------------------------------------------------- /assets/audio/sound_effects/step3.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/assets/audio/sound_effects/step3.ogg -------------------------------------------------------------------------------- /assets/audio/sound_effects/step4.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/assets/audio/sound_effects/step4.ogg -------------------------------------------------------------------------------- /assets/images/ducky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/assets/images/ducky.png -------------------------------------------------------------------------------- /assets/images/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/assets/images/splash.png -------------------------------------------------------------------------------- /cargo-generate.toml: -------------------------------------------------------------------------------- 1 | [template] 2 | cargo_generate_version = "0.23" 3 | include = ["*.template"] 4 | ignore = [ 5 | "docs", 6 | "target", 7 | "LICENSE-Apache-2.0.txt", 8 | "LICENSE-CC0-1.0.txt", 9 | "LICENSE-MIT.txt", 10 | ] 11 | 12 | [hooks] 13 | post = ["post-generate.rhai"] 14 | 15 | [placeholders.itch_username] 16 | prompt = "Enter your itch.io username. Leave blank to disable itch.io upload." 17 | type = "string" 18 | default = "" 19 | 20 | [conditional.'itch_username != ""'.placeholders] 21 | itch_project = { type = "string", prompt = "Enter the project name used in the itch.io URL. Leave blank to use this crate's `project-name`.", default = "" } 22 | -------------------------------------------------------------------------------- /clippy.toml: -------------------------------------------------------------------------------- 1 | # Require `bevy_ecs::children!` to use `[]` braces, instead of `()` or `{}`. 2 | standard-macro-braces = [{ name = "children", brace = "[" }] 3 | -------------------------------------------------------------------------------- /docs/design.md: -------------------------------------------------------------------------------- 1 | # Design philosophy 2 | 3 | The high-level goal of this template is to feel like the official template that Bevy is currently missing. 4 | There's an [official CI template](https://github.com/bevyengine/bevy_github_ci_template), but its goal is to 5 | demonstrate how to accomplish a particular task with Bevy (setting up CI), which makes it better aligned to 6 | serve as an [example](https://bevyengine.org/examples/) than as a template. 7 | 8 | ## Principles 9 | 10 | So, what would an official template built for real-world game development look like? 11 | The Bevy Jam working group has agreed on the following guiding design principles: 12 | 13 | - Have no 3rd-party dependencies besides Bevy to make it easy for users to pull in whatever they prefer. 14 | - Include some basic game code to give users something to work with. 15 | - Answer common questions like how you should structure your codebase, load assets, or write reusable UI code. 16 | - Configure development tools to work well out-of-the-box, for example: 17 | - Support creating a new project with [`bevy new`](https://github.com/TheBevyFlock/bevy_cli/) or [`cargo generate`](https://github.com/cargo-generate/cargo-generate). 18 | - Integrate with the most common IDEs (e.g. VS Code and RustRover). 19 | - Provide robust GitHub CI and CD workflows (including an option to automatically publish to [itch.io](https://itch.io)). 20 | - Configure dev builds for fast compile times and release builds for performance. 21 | 22 | As a result, this template has to make some decisions that are necessarily opinionated. 23 | 24 | These opinions are based on the experience of the Bevy Jam working group from working on our own projects. 25 | If you disagree with any of the decisions made, please feel free to change them to your liking. 26 | 27 | Bevy is still young, and many design patterns are still being discovered and refined. 28 | For some prior work in this area that inspired us, see [the Unofficial Bevy Cheatbook](https://bevy-cheatbook.github.io/) 29 | and [bevy_best_practices](https://github.com/tbillington/bevy_best_practices). 30 | 31 | ## Pattern Table of Contents 32 | 33 | - [Plugin Organization](#plugin-organization) 34 | - [Screen States](#screen-states) 35 | - [Bundle Functions](#bundle-functions) 36 | - [Asset Preloading](#asset-preloading) 37 | - [Dev Tools](#dev-tools) 38 | 39 | When referring to one of these patterns, you can use their name followed by "pattern", 40 | like "the plugin organization pattern", or "the screen states pattern". 41 | 42 | ## Plugin Organization 43 | 44 | ### Pattern 45 | 46 | Structure your code into plugins like so: 47 | 48 | ```rust 49 | // game.rs 50 | mod enemy; 51 | mod player; 52 | mod powerup; 53 | 54 | use bevy::prelude::*; 55 | 56 | pub(super) fn plugin(app: &mut App) { 57 | app.add_plugins((enemy::plugin, player::plugin, powerup::plugin)); 58 | } 59 | ``` 60 | 61 | ```rust 62 | // player.rs / enemy.rs / powerup.rs 63 | use bevy::prelude::*; 64 | 65 | pub(super) fn plugin(app: &mut App) { 66 | app.add_systems(Update, (your, systems, here)); 67 | } 68 | ``` 69 | 70 | ### Reasoning 71 | 72 | Bevy is great at organizing code into plugins. The most lightweight way to do this is by using simple functions as plugins. 73 | By splitting your code like this, you can easily keep all your systems and resources locally grouped. Everything that belongs to the `player` is only in `player.rs`, and so on. 74 | 75 | A good rule of thumb is to always have one plugin per file, but feel free to omit plugins that would be empty. 76 | 77 | ## Screen States 78 | 79 | ### Pattern 80 | 81 | Use the [`Screen`](../src/screen/mod.rs) enum to represent your game's screens as states: 82 | 83 | ```rust 84 | #[derive(States, Debug, Hash, PartialEq, Eq, Clone, Default)] 85 | pub enum Screen { 86 | #[default] 87 | Splash, 88 | Loading, 89 | Title, 90 | Gameplay, 91 | Victory, 92 | Leaderboard, 93 | MultiplayerLobby, 94 | } 95 | ``` 96 | 97 | For each screen, create a plugin that handles the setup and teardown in the 98 | [`OnEnter`](https://docs.rs/bevy/latest/bevy/prelude/struct.OnEnter.html) and 99 | [`OnExit`](https://docs.rs/bevy/latest/bevy/prelude/struct.OnExit.html) schedules. 100 | You should mark the screen's entities to despawn on exit by giving them the 101 | [`StateScoped`](https://docs.rs/bevy/latest/bevy/prelude/struct.StateScoped.html) component. 102 | 103 | ```rust 104 | // victory.rs 105 | pub(super) fn plugin(app: &mut App) { 106 | app.add_systems(OnEnter(Screen::Victory), spawn_victory_screen); 107 | app.add_systems(OnExit(Screen::Victory), reset_highscore); 108 | } 109 | 110 | fn spawn_victory_screen(mut commands: Commands) { 111 | commands.spawn(( 112 | widget::ui_root("Victory Screen"), 113 | StateScoped(Screen::Victory), 114 | children![ 115 | // UI elements. 116 | ], 117 | )); 118 | } 119 | 120 | fn reset_highscore(mut highscore: ResMut) { 121 | *highscore = default(); 122 | } 123 | ``` 124 | 125 | Transition between screens by setting the [`NextState`](https://docs.rs/bevy/latest/bevy/prelude/enum.NextState.html) resource: 126 | 127 | ```rust 128 | pub(super) fn plugin(app: &mut App) { 129 | app.add_systems(Update, enter_title_screen.run_if(input_just_pressed(KeyCode::Escape))); 130 | } 131 | 132 | fn enter_title_screen(mut next_state: ResMut>) { 133 | next_state.set(Screen::Title); 134 | } 135 | ``` 136 | 137 | ### Reasoning 138 | 139 | "Screen" is not meant as the physical screen, but as "what kind of screen is the game showing right now", e.g. the title screen, the loading screen, the victory screen, etc. 140 | These screens usually correspond to different logical states of your game that have different systems running. 141 | 142 | By using a dedicated `State` type for your screens, you can easily manage systems and entities that are only relevant for a specific screen and flexibly transition between 143 | them whenever your game logic requires it. 144 | 145 | ## Bundle Functions 146 | 147 | ### Pattern 148 | 149 | Write functions that return `impl Bundle` to define simple entity templates. 150 | 151 | ```rust 152 | pub fn monster(health: u32, transform: Transform) -> impl Bundle { 153 | ( 154 | Name::new("Monster"), 155 | Health::new(health), 156 | transform, 157 | // other components 158 | ) 159 | } 160 | ``` 161 | 162 | You can extend a bundle function with additional components that are not present in the original bundle: 163 | 164 | ```rust 165 | pub fn boss_monster(transform: Transform) -> impl Bundle { 166 | ( 167 | monster(1000, transform), 168 | Better, 169 | Faster, 170 | Stronger, 171 | ) 172 | } 173 | ``` 174 | 175 | You can compose bundle functions to define simple entity hierarchies: 176 | 177 | ```rust 178 | pub fn dangerous_forest() -> impl Bundle { 179 | ( 180 | Name::new("Dangerous Forest"), 181 | Transform::default(), 182 | children![ 183 | monster(100, Transform::from_xyz(10.0, 0.0, 0.0)), 184 | monster(200, Transform::from_xyz(20.0, 0.0, 0.0)), 185 | boss_monster(Transform::from_xyz(30.0, 0.0, 0.0)), 186 | ], 187 | ) 188 | } 189 | ``` 190 | 191 | And finally, you can spawn entities using your bundle functions: 192 | 193 | ```rust 194 | fn spawn_dangerous_forest(mut commands: Commands) { 195 | commands.spawn(dangerous_forest()); 196 | } 197 | ``` 198 | 199 | ### Reasoning 200 | 201 | By encapsulating the definition of an entity in a bundle function, you can save on boilerplate 202 | and make it easier to change its behavior, even if you spawn it in many different places in your code. 203 | 204 | This approach comes with a few limitations, however: 205 | 206 | - **No dependency injection:** If you want to use data from the world when creating a bundle, you have to pass it as an argument (e.g. `&AssetServer`) 207 | all the way down the entity hierarchy to the particular bundle function that needs it. 208 | - **No replacing components:** If you want to extend a bundle function by _replacing_ one of its components (e.g. to modify its `Node::width`), 209 | you have to add an argument to the function to explicitly allow for it, or remove the component from the original bundle, or use `Commands` to access `insert` (like 210 | `commands.spawn(foo()).insert(Replacement)`), which is not compatible with `children![]`-style composition. 211 | 212 | These limitations are expected to be [lifted in future Bevy versions](https://github.com/bevyengine/bevy/discussions/9538). 213 | 214 | ## Asset Preloading 215 | 216 | ### Pattern 217 | 218 | Define an asset collection resource to load and store your asset `Handle`s: 219 | 220 | ```rust 221 | #[derive(Resource, Asset, Clone, Reflect)] 222 | #[reflect(Resource)] 223 | struct ActorAssets { 224 | // This #[dependency] attribute marks the field as a dependency of the Asset. 225 | // This means that it will not finish loading until the labeled asset is also loaded. 226 | #[dependency] 227 | player: Handle, 228 | #[dependency] 229 | enemies: Vec>, 230 | } 231 | 232 | impl FromWorld for ActorAssets { 233 | fn from_world(world: &mut World) -> Self { 234 | let assets = world.resource::(); 235 | Self { 236 | player: assets.load("images/player.png"), 237 | enemies: vec![ 238 | assets.load("images/enemy1.png"), 239 | assets.load("images/enemy2.png"), 240 | assets.load("images/enemy3.png"), 241 | ], 242 | } 243 | } 244 | } 245 | ``` 246 | 247 | Then start preloading in `actor::plugin`: 248 | 249 | ```rust 250 | pub(super) fn plugin(app: &mut App) { 251 | app.register_type::(); 252 | app.load_resource::(); 253 | } 254 | ``` 255 | 256 | Note that `app.load_resource` comes from an extension trait defined in [src/asset_tracking.rs](../src/asset_tracking.rs). 257 | 258 | ### Reasoning 259 | 260 | This pattern is inspired by [bevy_asset_loader](https://github.com/NiklasEi/bevy_asset_loader). 261 | By preloading your assets, you can avoid hitches during gameplay. 262 | Assets will begin loading immediately at startup, and the loading screen will wait until they're done. 263 | 264 | ## Dev Tools 265 | 266 | ### Pattern 267 | 268 | Add all systems that are only relevant while developing the game to the [`dev_tools` plugin](../src/dev_tools.rs): 269 | 270 | ```rust 271 | // dev_tools.rs 272 | pub(super) fn plugin(app: &mut App) { 273 | app.add_systems(Update, (draw_debug_lines, show_debug_console, show_fps_counter)); 274 | } 275 | ``` 276 | 277 | ### Reasoning 278 | 279 | The `dev_tools` plugin is only included in dev builds. 280 | By adding your dev tools here, you guarantee that they won't be included in release builds. 281 | -------------------------------------------------------------------------------- /docs/img/readme-manual-setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/docs/img/readme-manual-setup.png -------------------------------------------------------------------------------- /docs/img/thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/docs/img/thumbnail.png -------------------------------------------------------------------------------- /docs/img/workflow-dispatch-release.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/docs/img/workflow-dispatch-release.png -------------------------------------------------------------------------------- /docs/img/workflow-itch-release.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/docs/img/workflow-itch-release.png -------------------------------------------------------------------------------- /docs/img/workflow-ruleset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/docs/img/workflow-ruleset.png -------------------------------------------------------------------------------- /docs/img/workflow-secrets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheBevyFlock/bevy_new_2d/2b1172261bb00cfb202f22baab1a9d8ab6f488d8/docs/img/workflow-secrets.png -------------------------------------------------------------------------------- /docs/known-issues.md: -------------------------------------------------------------------------------- 1 | # Known Issues 2 | 3 | ## My audio is stuttering on web 4 | 5 | There are a number of issues with audio on web, so this is not an exhaustive list. The short version is that you can try the following: 6 | 7 | - If you're using materials, you should force your render pipelines to [load at the start of the game](https://github.com/rparrett/bevy_pipelines_ready/blob/main/src/lib.rs). 8 | - Optimize your game as much as you can to keep its FPS high. 9 | - Apply the suggestions from the blog post [Workaround for the Choppy Music in Bevy Web Builds](https://necrashter.github.io/bevy-choppy-music-workaround). 10 | - Advise your users to try a Chromium-based browser if there are still issues. 11 | 12 | ## My game window flashes white for a split second when I start the game on Windows 13 | 14 | The game window is created before the GPU is ready to render everything. 15 | This means that it'll start with a white screen for a few frames. 16 | The workaround is to [spawn the Window hidden](https://github.com/bevyengine/bevy/blob/release-0.14.0/examples/window/window_settings.rs#L29-L32) 17 | and only [make it visible a few frames later](https://github.com/bevyengine/bevy/blob/release-0.14.0/examples/window/window_settings.rs#L56-L64). 18 | 19 | ## My character or camera movement is choppy 20 | 21 | Choppy character movement is often caused by movement updates being tied to the frame rate. 22 | See the [`physics_in_fixed_timestep`](https://github.com/bevyengine/bevy/blob/main/examples/movement/physics_in_fixed_timestep.rs) example 23 | for how to fix this. 24 | 25 | Choppy camera movement is almost always caused by the camera being tied too tightly to a moving target position. 26 | You can use [`smooth_nudge`](https://github.com/bevyengine/bevy/blob/main/examples/movement/smooth_follow.rs#L127-L142) to make your camera 27 | smoothly approach its target position instead. 28 | -------------------------------------------------------------------------------- /docs/tooling.md: -------------------------------------------------------------------------------- 1 | # Recommended 3rd-party tools 2 | 3 | None of these are required, but they can save you a lot of time and effort. 4 | 5 | Check out the [Bevy Assets](https://bevyengine.org/assets/) page for more great options. 6 | 7 | ## Libraries 8 | 9 | A few libraries that the authors of this template have vetted and think you might find useful: 10 | 11 | | Name | Category | Description | 12 | | -------------------------------------------------------------------------------------- | -------------- | ------------------------------------- | 13 | | [`leafwing-input-manager`](https://github.com/Leafwing-Studios/leafwing-input-manager) | Input | Input -> Action mapping | 14 | | [`bevy-inspector-egui`](https://github.com/jakobhellermann/bevy-inspector-egui) | Debugging | Live entity inspector | 15 | | [`bevy_mod_debugdump`](https://github.com/jakobhellermann/bevy_mod_debugdump) | Debugging | Schedule inspector | 16 | | [`inline_tweak`](https://github.com/Uriopass/inline_tweak/) | Debugging | Live tweaking of literal values | 17 | | [`avian`](https://github.com/Jondolf/avian) | Physics | Physics engine | 18 | | [`bevy_rapier`](https://github.com/dimforge/bevy_rapier) | Physics | Physics engine (not ECS-driven) | 19 | | [`bevy_common_assets`](https://github.com/NiklasEi/bevy_common_assets) | Asset loading | Asset loaders for common file formats | 20 | | [`bevy_asset_loader`](https://github.com/NiklasEi/bevy_asset_loader) | Asset loading | Asset management tools | 21 | | [`iyes_progress`](https://github.com/IyesGames/iyes_progress) | Asset loading | Progress tracking | 22 | | [`bevy_kira_audio`](https://github.com/NiklasEi/bevy_kira_audio) | Audio | Advanced audio features | 23 | | [`bevy_cobweb_ui`](https://github.com/UkoeHB/bevy_cobweb_ui) | UI | UI framework | 24 | | [`bevy_egui`](https://github.com/mvlabat/bevy_egui) | UI / Debugging | UI framework (great for debug UI) | 25 | | [`tiny_bail`](https://github.com/benfrankel/tiny_bail) | Error handling | Error handling convenience macros | 26 | 27 | In particular: 28 | 29 | - `leafwing-input-manager` is very likely to be upstreamed into Bevy in the near future. 30 | - `bevy-inspector-egui`, `bevy_mod_debugdump`, and `inline_tweak` help fill the gap until Bevy has its own editor. 31 | - `avian` or `bevy_rapier` helps fill the gap until Bevy has its own physics engine. `avian` is easier to use, while `bevy_rapier` is more performant. 32 | - `bevy_cobweb_ui` is well-aligned with `bevy_ui` and helps fill the gap until Bevy has a full collection of UI widgets and features. 33 | 34 | ## CLI tools 35 | 36 | A few command-line tools that you may find useful: 37 | 38 | | Name | Description | 39 | |-------------------------------------------------------------------|---------------------------------------------------------------| 40 | | [`bevy_lint`](https://thebevyflock.github.io/bevy_cli/bevy_lint/) | Checks for good practices and footguns specific to Bevy | 41 | | [`oxipng`](https://github.com/shssoichiro/oxipng) | Lossless PNG compression (may help reduce file sizes for web) | 42 | | [`gifski`](https://github.com/ImageOptim/gifski) | High-quality GIF encoder (good for animated itch.io content) | 43 | 44 | > [!NOTE] 45 | > 46 | > `bevy_lint` already runs in CI by default (see [workflows](./workflows.md)). 47 | 48 | ## Other templates 49 | 50 | There are many other Bevy templates out there. 51 | You can find some of them in the [templates category](https://bevyengine.org/assets/#templates) on Bevy Assets. 52 | 53 | > [!TIP] 54 | > Even if you don't end up using them directly, they can be very helpful as learning material! 55 | 56 | # IDE integration 57 | 58 | ## VS Code extensions 59 | 60 | If you're using [VS Code](https://code.visualstudio.com/), the following extensions are highly recommended: 61 | 62 | | Name | Description | 63 | |-----------------------------------------------------------------------------------------------------------|-----------------------------------| 64 | | [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) | Rust support | 65 | | [Even Better TOML](https://marketplace.visualstudio.com/items?itemName=tamasfe.even-better-toml) | TOML support | 66 | | [vscode-ron](https://marketplace.visualstudio.com/items?itemName=a5huynh.vscode-ron) | RON support | 67 | | [Dependi](https://marketplace.visualstudio.com/items?itemName=fill-labs.dependi) | `crates.io` dependency resolution | 68 | | [EditorConfig for VS Code](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig) | `.editorconfig` support | 69 | 70 | > [!NOTE] 71 | >
72 | > About the included rust-analyzer settings 73 | > 74 | > This template sets [`rust-analyzer.cargo.targetDir`](https://rust-analyzer.github.io/generated_config.html#rust-analyzer.cargo.targetDir) 75 | > to `true` in [`.vscode/settings.json`](../.vscode/settings.json). 76 | > 77 | > This makes `rust-analyzer` use a different `target` directory than `cargo`, 78 | > which means that you can run commands like `cargo run` even while `rust-analyzer` is still indexing. 79 | > As a trade-off, this will use more disk space. 80 | > 81 | > If that is an issue for you, you can set it to `false` or remove the setting entirely. 82 | >
83 | 84 | ## RustRover Live Templates 85 | 86 | If you're using [RustRover](https://www.jetbrains.com/rust/), you may want to set up [Live Templates](https://www.jetbrains.com/help/rust/using-live-templates.html) to provide autocomplete for common boilerplate code. 87 | 88 | Unfortunately, it is not really possible at this time to share Live Templates on a per-project basis, as they are global, however you can still set them up yourself. 89 | 90 | Here's a quick guide for porting this template's [VS Code snippets](../.vscode/bevy.code-snippets) to Live Templates: 91 | 92 | - Replace any instances of `$0` in the template with `$END$` 93 | - Replace any instances of `$1` in the template with `$NAME$` or something similar. 94 | - For the `plugin` template, you might want to set the applicability to rust modules. 95 | - For the other templates, you might want to set the applicability to rust modules, statements, and expressions. 96 | 97 | To make it easier to enable or disable these live templates for different projects, you can put them in a template group called `Bevy`. 98 | 99 | ## Debugging with RustRover 100 | 101 | This template comes with a Cargo Run Configuration that disables dynamic linking (and dev tools) so that the debugger will work out of the box. If you'd like to enable those features in the debugger, it'll require some setup: 102 | 103 | 1. Run `rustc --print target-libdir` and copy the output. You can specify a channel here with e.g. `rustc +nightly --print target-libdir` 104 | 2. Edit the Cargo Run Configuration named "Run Native Debug" (it should be the one without a terminal icon). 105 | 3. Add the following Environment Variable: 106 | a. Linux or Mac: `LD_LIBRARY_PATH` = `./target/debug/deps:` where `` is the output from step 1. 107 | b. Windows: `PATH` = `.\target\debug\deps:`, where `` is the output from step 1. 108 | 3. Remove `--no-default-features` from the command in the Run Configuration. 109 | 4. Click Apply and then Debug, and if everything is correct it should launch the game. 110 | 111 | If you want to use multiple different channels for the same project, you will need to add in a `LIBDIR_PATH` for every channel you intend on using. 112 | 113 | If you're still having issues, please ensure that the channels in the path and the Run Configuration match, and that there are no extra spaces (especially at the beginning or end). 114 | 115 | > [!NOTE] 116 | >
117 | > Attaching the debugger to a running game 118 | > 119 | > If you started your game with a Shell Script Run Configuration, you can attach the debugger to it while it's running by using `Run > Attach to Process` and selecting the process with the same name as your game (not the one named `bevy`). 120 | > 121 | > This does not work for web builds. 122 | >
123 | -------------------------------------------------------------------------------- /docs/workflows.md: -------------------------------------------------------------------------------- 1 | # Workflows 2 | 3 | This template uses [GitHub workflows](https://docs.github.com/en/actions/using-workflows) for [CI / CD](https://www.redhat.com/en/topics/devops/what-is-ci-cd), defined in [`.github/workflows/`](../.github/workflows). 4 | 5 | > [!WARNING] 6 | > GitHub puts a limit on free CI usage for [private repositories](https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for--private-repositories), so tune your workflows accordingly! 7 | 8 | ## CI (testing) 9 | 10 | The [CI workflow](.github/workflows/ci.yaml) will trigger on every commit or PR to `main`, and it will: 11 | 12 | - Check formatting. 13 | - Check documentation. 14 | - Run Clippy lints. 15 | - Run [Bevy lints](https://thebevyflock.github.io/bevy_cli/bevy_lint/). 16 | - Run tests. 17 | - Check that the web build compiles. 18 | 19 | > [!TIP] 20 | >
21 | > Consider setting up a GitHub ruleset to require that all commits to main pass CI. 22 | > 23 | > A screenshot showing a GitHub ruleset with status checks enabled 24 | >
25 | 26 | ## CD (releasing) 27 | 28 | The [CD workflow](../.github/workflows/release.yaml) will trigger on manual workflow dispatch, and it will: 29 | 30 | - (Optional) Create a release build for Windows, macOS, Linux, and web. 31 | - (Optional) Upload to [GitHub releases](https://docs.github.com/en/repositories/releasing-projects-on-github). 32 | - (Optional) Upload to [itch.io](https://itch.io). 33 | 34 |
35 | Triggering a release 36 | 37 | In your GitHub repository, navigate to `Actions > Release > Run workflow`: 38 | 39 | ![A screenshot showing a manually triggered workflow on GitHub Actions](./img/workflow-dispatch-release.png) 40 | 41 | Enter a version number in the format `v1.2.3`, then hit the green `Run workflow` button. 42 |
43 | 44 | > [!IMPORTANT] 45 | > Using this workflow requires some setup. We'll go through this now. 46 | 47 | ### Configure environment variables 48 | 49 | The release workflow can be configured by tweaking the environment variables in [`.github/workflows/release.yaml`](../.github/workflows/release.yaml). 50 | 51 |
52 | List of environment variables and how they're used 53 | 54 | ```yaml 55 | # The base filename of the binary produced by `cargo build`. 56 | cargo_build_binary_name: bevy_new_2d 57 | 58 | # The path to the assets directory. 59 | assets_path: assets 60 | 61 | # The itch.io project to upload to in the format `user-name/project-name`. 62 | # There will be no upload to itch.io if this is commented out. 63 | itch_page: the-bevy-flock/bevy-new-2d 64 | 65 | # The ID of the app produced by this workflow. 66 | # Applies to macOS releases. 67 | # Must contain only A-Z, a-z, 0-9, hyphen, and period: . 68 | app_id: the-bevy-flock.bevy-new-2d 69 | 70 | # The base filename of the binary in the package produced by this workflow. 71 | # Applies to Windows, macOS, and Linux releases. 72 | # Defaults to `cargo_build_binary_name` if commented out. 73 | app_binary_name: bevy_new_2d 74 | 75 | # The name of the `.zip` or `.dmg` file produced by this workflow. 76 | # Defaults to `app_binary_name` if commented out. 77 | app_package_name: bevy-new-2d 78 | 79 | # The display name of the app produced by this workflow. 80 | # Applies to macOS releases. 81 | # Defaults to `app_package_name` if commented out. 82 | app_display_name: Bevy New 2D 83 | 84 | # The short display name of the app produced by this workflow. 85 | # Applies to macOS releases. 86 | # Must be 15 or fewer characters: . 87 | # Defaults to `app_display_name` if commented out. 88 | app_short_name: Bevy New 2D 89 | 90 | # Before enabling LFS, please take a look at GitHub's documentation for costs and quota limits: 91 | # 92 | git_lfs: false 93 | 94 | # Enabling this only helps with consecutive releases to the same version (and takes up cache storage space). 95 | # See: . 96 | use_github_cache: false 97 | ``` 98 |
99 | 100 | The initial values are set automatically by `bevy new`, but you can edit them yourself and push a commit. 101 | 102 | ### Set up itch.io upload 103 | 104 | #### Add butler credentials 105 | 106 |
107 | In your GitHub repository, navigate to Settings > Secrets and variables > Actions. 108 | 109 | ![A screenshot showing where to add secrets in the GitHub Actions settings](./img/workflow-secrets.png) 110 |
111 | 112 | Hit `New repository secret` and enter the following values, then hit `Add secret`: 113 | 114 | - **Name:** `BUTLER_CREDENTIALS` 115 | - **Secret:** Your [itch.io API key](https://itch.io/user/settings/api-keys) (create a new one if necessary) 116 | 117 | #### Create itch.io project 118 | 119 | Create a new itch.io project with the same user and project name as in the `upload_to_itch` variable in [`.github/workflows/release.yaml`](../.github/workflows/release.yaml). 120 | Hit `Save & view page` at the bottom of the page. 121 | 122 | Trigger the [release workflow](#cd-releasing) for the first time. Once it's done, go back to itch.io and hit `Edit game` in the top left. 123 | 124 | Set `Kind of project` to `HTML`, then find the newly uploaded `web` build and tick the box that says `This file will be played in the browser`. 125 | 126 | ![A screenshot showing a web build selected in the itch.io uploads](img/workflow-itch-release.png) 127 | -------------------------------------------------------------------------------- /post-generate.rhai: -------------------------------------------------------------------------------- 1 | // Rename template files. 2 | file::rename(".github/workflows/release.yaml.template", ".github/workflows/release.yaml"); 3 | file::rename("Cargo.toml.template", "Cargo.toml"); 4 | file::rename("Cargo.lock.template", "Cargo.lock"); 5 | file::rename("README.md.template", "README.md"); 6 | file::rename("src/main.rs.template", "src/main.rs"); 7 | -------------------------------------------------------------------------------- /src/asset_tracking.rs: -------------------------------------------------------------------------------- 1 | //! A high-level way to load collections of asset handles as resources. 2 | 3 | use std::collections::VecDeque; 4 | 5 | use bevy::prelude::*; 6 | 7 | pub(super) fn plugin(app: &mut App) { 8 | app.init_resource::(); 9 | app.add_systems(PreUpdate, load_resource_assets); 10 | } 11 | 12 | pub trait LoadResource { 13 | /// This will load the [`Resource`] as an [`Asset`]. When all of its asset dependencies 14 | /// have been loaded, it will be inserted as a resource. This ensures that the resource only 15 | /// exists when the assets are ready. 16 | fn load_resource(&mut self) -> &mut Self; 17 | } 18 | 19 | impl LoadResource for App { 20 | fn load_resource(&mut self) -> &mut Self { 21 | self.init_asset::(); 22 | let world = self.world_mut(); 23 | let value = T::from_world(world); 24 | let assets = world.resource::(); 25 | let handle = assets.add(value); 26 | let mut handles = world.resource_mut::(); 27 | handles 28 | .waiting 29 | .push_back((handle.untyped(), |world, handle| { 30 | let assets = world.resource::>(); 31 | if let Some(value) = assets.get(handle.id().typed::()) { 32 | world.insert_resource(value.clone()); 33 | } 34 | })); 35 | self 36 | } 37 | } 38 | 39 | /// A function that inserts a loaded resource. 40 | type InsertLoadedResource = fn(&mut World, &UntypedHandle); 41 | 42 | #[derive(Resource, Default)] 43 | pub struct ResourceHandles { 44 | // Use a queue for waiting assets so they can be cycled through and moved to 45 | // `finished` one at a time. 46 | waiting: VecDeque<(UntypedHandle, InsertLoadedResource)>, 47 | finished: Vec, 48 | } 49 | 50 | impl ResourceHandles { 51 | /// Returns true if all requested [`Asset`]s have finished loading and are available as [`Resource`]s. 52 | pub fn is_all_done(&self) -> bool { 53 | self.waiting.is_empty() 54 | } 55 | } 56 | 57 | fn load_resource_assets(world: &mut World) { 58 | world.resource_scope(|world, mut resource_handles: Mut| { 59 | world.resource_scope(|world, assets: Mut| { 60 | for _ in 0..resource_handles.waiting.len() { 61 | let (handle, insert_fn) = resource_handles.waiting.pop_front().unwrap(); 62 | if assets.is_loaded_with_dependencies(&handle) { 63 | insert_fn(world, &handle); 64 | resource_handles.finished.push(handle); 65 | } else { 66 | resource_handles.waiting.push_back((handle, insert_fn)); 67 | } 68 | } 69 | }); 70 | }); 71 | } 72 | -------------------------------------------------------------------------------- /src/audio.rs: -------------------------------------------------------------------------------- 1 | use bevy::prelude::*; 2 | 3 | pub(super) fn plugin(app: &mut App) { 4 | app.register_type::(); 5 | app.register_type::(); 6 | 7 | app.add_systems( 8 | Update, 9 | apply_global_volume.run_if(resource_changed::), 10 | ); 11 | } 12 | 13 | /// An organizational marker component that should be added to a spawned [`AudioPlayer`] if it's in the 14 | /// general "music" category (e.g. global background music, soundtrack). 15 | /// 16 | /// This can then be used to query for and operate on sounds in that category. 17 | #[derive(Component, Reflect, Default)] 18 | #[reflect(Component)] 19 | pub struct Music; 20 | 21 | /// A music audio instance. 22 | pub fn music(handle: Handle) -> impl Bundle { 23 | (AudioPlayer(handle), PlaybackSettings::LOOP, Music) 24 | } 25 | 26 | /// An organizational marker component that should be added to a spawned [`AudioPlayer`] if it's in the 27 | /// general "sound effect" category (e.g. footsteps, the sound of a magic spell, a door opening). 28 | /// 29 | /// This can then be used to query for and operate on sounds in that category. 30 | #[derive(Component, Reflect, Default)] 31 | #[reflect(Component)] 32 | pub struct SoundEffect; 33 | 34 | /// A sound effect audio instance. 35 | pub fn sound_effect(handle: Handle) -> impl Bundle { 36 | (AudioPlayer(handle), PlaybackSettings::DESPAWN, SoundEffect) 37 | } 38 | 39 | /// [`GlobalVolume`] doesn't apply to already-running audio entities, so this system will update them. 40 | fn apply_global_volume( 41 | global_volume: Res, 42 | mut audio_query: Query<(&PlaybackSettings, &mut AudioSink)>, 43 | ) { 44 | for (playback, mut sink) in &mut audio_query { 45 | sink.set_volume(global_volume.volume * playback.volume); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/demo/animation.rs: -------------------------------------------------------------------------------- 1 | //! Player sprite animation. 2 | //! This is based on multiple examples and may be very different for your game. 3 | //! - [Sprite flipping](https://github.com/bevyengine/bevy/blob/latest/examples/2d/sprite_flipping.rs) 4 | //! - [Sprite animation](https://github.com/bevyengine/bevy/blob/latest/examples/2d/sprite_animation.rs) 5 | //! - [Timers](https://github.com/bevyengine/bevy/blob/latest/examples/time/timers.rs) 6 | 7 | use bevy::prelude::*; 8 | use rand::prelude::*; 9 | use std::time::Duration; 10 | 11 | use crate::{ 12 | AppSystems, PausableSystems, 13 | audio::sound_effect, 14 | demo::{movement::MovementController, player::PlayerAssets}, 15 | }; 16 | 17 | pub(super) fn plugin(app: &mut App) { 18 | // Animate and play sound effects based on controls. 19 | app.register_type::(); 20 | app.add_systems( 21 | Update, 22 | ( 23 | update_animation_timer.in_set(AppSystems::TickTimers), 24 | ( 25 | update_animation_movement, 26 | update_animation_atlas, 27 | trigger_step_sound_effect, 28 | ) 29 | .chain() 30 | .run_if(resource_exists::) 31 | .in_set(AppSystems::Update), 32 | ) 33 | .in_set(PausableSystems), 34 | ); 35 | } 36 | 37 | /// Update the sprite direction and animation state (idling/walking). 38 | fn update_animation_movement( 39 | mut player_query: Query<(&MovementController, &mut Sprite, &mut PlayerAnimation)>, 40 | ) { 41 | for (controller, mut sprite, mut animation) in &mut player_query { 42 | let dx = controller.intent.x; 43 | if dx != 0.0 { 44 | sprite.flip_x = dx < 0.0; 45 | } 46 | 47 | let animation_state = if controller.intent == Vec2::ZERO { 48 | PlayerAnimationState::Idling 49 | } else { 50 | PlayerAnimationState::Walking 51 | }; 52 | animation.update_state(animation_state); 53 | } 54 | } 55 | 56 | /// Update the animation timer. 57 | fn update_animation_timer(time: Res