first commit

This commit is contained in:
WanderingPenwing 2024-10-05 08:41:37 +02:00
commit a9a8166b46
8 changed files with 4579 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

4305
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

15
Cargo.toml Normal file
View file

@ -0,0 +1,15 @@
[package]
name = "bevy-test"
version = "0.1.0"
edition = "2021"
[dependencies]
bevy = { version = "0.14.2", features = [ "dynamic_linking" ] }
# Enable a small amount of optimization in the dev profile.
[profile.dev]
opt-level = 1
# Enable a large amount of optimization in the dev profile for dependencies.
[profile.dev.package."*"]
opt-level = 3

1
README.md Normal file
View file

@ -0,0 +1 @@
https://bevyengine.org/learn/quick-start/getting-started/ecs/

BIN
assets/test.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

110
flake.lock Normal file
View file

@ -0,0 +1,110 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixgl": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1713543440,
"narHash": "sha256-lnzZQYG0+EXl/6NkGpyIz+FEOc/DSEG57AP1VsdeNrM=",
"owner": "guibou",
"repo": "nixGL",
"rev": "310f8e49a149e4c9ea52f1adf70cdc768ec53f8a",
"type": "github"
},
"original": {
"owner": "guibou",
"repo": "nixGL",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1660551188,
"narHash": "sha256-a1LARMMYQ8DPx1BgoI/UN4bXe12hhZkCNqdxNi6uS0g=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "441dc5d512153039f19ef198e662e4f3dbb9fd65",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1704290814,
"narHash": "sha256-LWvKHp7kGxk/GEtlrGYV68qIvPHkU9iToomNFGagixU=",
"rev": "70bdadeb94ffc8806c0570eb5c2695ad29f0e421",
"revCount": 492897,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2305.492897%2Brev-70bdadeb94ffc8806c0570eb5c2695ad29f0e421/018ce318-b896-7d27-b495-cc2cdb39d680/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/NixOS/nixpkgs/0.2305.491812.tar.gz"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1718428119,
"narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e6cea36f83499eb4e9cd184c8a8e823296b50ad5",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixgl": "nixgl",
"nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1727836133,
"narHash": "sha256-JE0zciM5IGWvK8J/pE2VldNBf7oyMH5WrU8tZArefbg=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "02321540b0c8000b36889b1b974d1fec585b25a4",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

90
flake.nix Normal file
View file

@ -0,0 +1,90 @@
{
description = "Rust dev shell for Hertog's bevy project (YAY!)";
# Flake inputs
inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2305.491812.tar.gz";
rust-overlay.url = "github:oxalica/rust-overlay"; # A helper for Rust + Nix
nixgl.url = "github:guibou/nixGL"; # Allows you to run OpenGL and or Vulkan applications in a nix shell
};
# Flake outputs
outputs = { self, nixpkgs, rust-overlay, nixgl, ... }:
let
# Overlays enable you to customize the Nixpkgs attribute set
overlays = [
# Makes a `rust-bin` attribute available in Nixpkgs
(import rust-overlay)
nixgl.overlay
# Provides a `rustToolchain` attribute for Nixpkgs that we can use to
# create a Rust environment
(self: super: {
rustToolchain = super.rust-bin.stable.latest.default;
})
];
# Systems supported
allSystems = [
"x86_64-linux" # 64-bit Intel/AMD Linux
"aarch64-linux" # 64-bit ARM Linux
"x86_64-darwin" # 64-bit Intel macOS
"aarch64-darwin" # 64-bit ARM macOS
];
# Helper to provide system-specific attributes
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
pkgs = import nixpkgs { inherit overlays system; };
});
in
{
# Development environment output
devShells = forAllSystems ({ pkgs }: {
default = pkgs.mkShell {
# The Nix packages provided in the environment
packages = (with pkgs; [
# Fluff
cargo-mommy
onefetch
# Bevy
pkg-config
alsa-lib
vulkan-tools
vulkan-headers
vulkan-loader
vulkan-validation-layers
udev
clang
lld
# If using an intel GPU
pkgs.nixgl.nixVulkanIntel
# If on x11
xorg.libX11
xorg.libX11
xorg.libXcursor
xorg.libXi
xorg.libXrandr
# If on wayland
libxkbcommon
wayland
# Rust
rustup
rustToolchain
]) ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ libiconv ]);
shellHook = ''
# Required
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pkgs.lib.makeLibraryPath [
pkgs.alsaLib
pkgs.udev
pkgs.vulkan-loader
pkgs.libxkbcommon
]}"
# Aliases and other fluff/ease of use
alias runIntel="nixVulkanIntel cargo run"
alias runMommyIntel="nixVulkanIntel cargo mommy run"
onefetch
echo "Welcome to nix-hell uh nix-shell!"
'';
};
});
};
}

57
src/main.rs Normal file
View file

@ -0,0 +1,57 @@
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, move_player)
.run();
}
#[derive(Bundle)]
struct PlayerBundle {
core: Player,
sprite: SpriteBundle,
}
#[derive(Component)]
struct Player;
fn setup(
//mut materials: ResMut<Assets<ColorMaterial>>,
//mut meshes: ResMut<Assets<Mesh>>,
mut commands: Commands,
asset_server: Res<AssetServer>
) {
commands.spawn(Camera2dBundle::default());
commands.spawn(PlayerBundle {
core: Player,
sprite: SpriteBundle {
texture: asset_server.load("../assets/test.png"),
..default()
},
});
}
const MOVE_SPEED: f32 = 6.0;
fn move_player(
mut transforms: Query<&mut Transform, With<Player>>,
keys: Res<ButtonInput<KeyCode>>,
) {
for mut transform in transforms.iter_mut() {
let mut direction = Vec3::ZERO;
if keys.pressed(KeyCode::KeyW) { direction.y += 1.0; }
if keys.pressed(KeyCode::KeyA) { direction.x -= 1.0; }
if keys.pressed(KeyCode::KeyS) { direction.y -= 1.0; }
if keys.pressed(KeyCode::KeyD) { direction.x += 1.0; }
if 0.0 < direction.length() {
transform.translation += MOVE_SPEED * direction.normalize();
}
}
}