init
This commit is contained in:
commit
68702e358f
9 changed files with 4654 additions and 0 deletions
3
.cargo/config.toml
Normal file
3
.cargo/config.toml
Normal file
|
@ -0,0 +1,3 @@
|
|||
[target.x86_64-unknown-linux-gnu]
|
||||
linker = "clang"
|
||||
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
|
1
.envrc
Normal file
1
.envrc
Normal file
|
@ -0,0 +1 @@
|
|||
use flake . --impure
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
.direnv/
|
||||
.devenv/
|
||||
/target
|
4281
Cargo.lock
generated
Normal file
4281
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
19
Cargo.toml
Normal file
19
Cargo.toml
Normal file
|
@ -0,0 +1,19 @@
|
|||
[package]
|
||||
name = "bin-projekt-evader"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
bevy = {version = "0.13.2", features = ["dynamic_linking"]}
|
||||
bevy_rapier2d = "0.26.0"
|
||||
noise = "0.9.0"
|
||||
some_bevy_tools = "0.2.4"
|
||||
|
||||
[profile.dev]
|
||||
opt-level = 1
|
||||
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 3
|
||||
|
||||
[profile.dev.package.bevy_rapier2d]
|
||||
opt-level = 3
|
121
flake.lock
Normal file
121
flake.lock
Normal file
|
@ -0,0 +1,121 @@
|
|||
{
|
||||
"nodes": {
|
||||
"crane": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1713979152,
|
||||
"narHash": "sha256-apdecPuh8SOQnkEET/kW/UcfjCRb8JbV5BKjoH+DcP4=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "a5eca68a2cf11adb32787fc141cddd29ac8eb79c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"fenix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"rust-analyzer-src": "rust-analyzer-src"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1714026264,
|
||||
"narHash": "sha256-rIRsxOZ/eUnWVHfbJlXXQtYriPICFgHGyao5jxm1FMQ=",
|
||||
"owner": "nix-community",
|
||||
"repo": "fenix",
|
||||
"rev": "4e14e4f21fbd7afae40a492b7d937cbf16f76b11",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "fenix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1714058985,
|
||||
"narHash": "sha256-gD/Ya/oXic+vbQGvmqxm8qaWmOx3HnrKHQtSL6oRW0E=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "bf182c39d9439811484aad0d241ea89619b44bc7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"crane": "crane",
|
||||
"fenix": "fenix",
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"rust-analyzer-src": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1713944769,
|
||||
"narHash": "sha256-CmR7q1UAgW9OaJaahz3gCzzUY4ROvVI92xjfSp9xot4=",
|
||||
"owner": "rust-lang",
|
||||
"repo": "rust-analyzer",
|
||||
"rev": "73a427588a787847fb0e9547d7615200587165db",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "rust-lang",
|
||||
"ref": "nightly",
|
||||
"repo": "rust-analyzer",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
79
flake.nix
Normal file
79
flake.nix
Normal file
|
@ -0,0 +1,79 @@
|
|||
{
|
||||
description = "Build a cargo project without extra checks";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
|
||||
crane = {
|
||||
url = "github:ipetkov/crane";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
fenix = {
|
||||
url = "github:nix-community/fenix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
crane,
|
||||
fenix,
|
||||
flake-utils,
|
||||
...
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (system: let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
|
||||
craneLib = crane.lib.${system};
|
||||
rs-toolchain = with fenix.packages.${system};
|
||||
combine [
|
||||
complete.toolchain
|
||||
# rust-analyzer
|
||||
];
|
||||
my-crate = craneLib.buildPackage {
|
||||
src = craneLib.cleanCargoSource (craneLib.path ./.);
|
||||
strictDeps = true;
|
||||
|
||||
buildInputs =
|
||||
[
|
||||
# Add additional build inputs here
|
||||
]
|
||||
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
|
||||
# Additional darwin specific inputs can be set here
|
||||
pkgs.libiconv
|
||||
];
|
||||
|
||||
# Additional environment variables can be set directly
|
||||
# MY_CUSTOM_VAR = "some value";
|
||||
};
|
||||
in {
|
||||
packages.default = my-crate;
|
||||
|
||||
apps.default = flake-utils.lib.mkApp {
|
||||
drv = my-crate;
|
||||
};
|
||||
|
||||
devShells.default = pkgs.mkShell rec {
|
||||
buildInputs = with pkgs; [
|
||||
pkg-config
|
||||
rs-toolchain
|
||||
udev
|
||||
alsa-lib
|
||||
vulkan-loader
|
||||
xorg.libX11
|
||||
xorg.libXcursor
|
||||
xorg.libXi
|
||||
xorg.libXrandr # To use the x11 feature
|
||||
libxkbcommon
|
||||
wayland
|
||||
mold-wrapped
|
||||
clang
|
||||
];
|
||||
|
||||
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
|
||||
};
|
||||
});
|
||||
}
|
103
src/main.rs
Normal file
103
src/main.rs
Normal file
|
@ -0,0 +1,103 @@
|
|||
use bevy::{
|
||||
prelude::*,
|
||||
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
|
||||
};
|
||||
use bevy_rapier2d::prelude::*;
|
||||
const METER: f32 = 48.;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugins(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(METER))
|
||||
.add_plugins(RapierDebugRenderPlugin::default())
|
||||
.add_systems(Startup, (scene::setup_scene, setup_cam, player::add_player))
|
||||
.add_systems(
|
||||
Update,
|
||||
(player::move_player, player::player_ground_collision),
|
||||
)
|
||||
.run()
|
||||
}
|
||||
|
||||
fn setup_cam(mut commands: Commands) {
|
||||
commands.spawn(Camera2dBundle {
|
||||
transform: Transform::from_xyz(0., 4. * METER, 0.),
|
||||
..default()
|
||||
});
|
||||
}
|
||||
|
||||
mod scene;
|
||||
mod player {
|
||||
use bevy::{
|
||||
prelude::*,
|
||||
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
|
||||
};
|
||||
use bevy_rapier2d::prelude::*;
|
||||
|
||||
use crate::METER;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Player {
|
||||
move_cooldown: Timer,
|
||||
grounded: bool,
|
||||
}
|
||||
|
||||
pub fn add_player(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
) {
|
||||
let shape = Mesh2dHandle(meshes.add(Rectangle::new(0.8 * METER, 1.8 * METER)));
|
||||
commands
|
||||
.spawn(Player {
|
||||
move_cooldown: Timer::from_seconds(0.01, TimerMode::Repeating),
|
||||
grounded: false,
|
||||
})
|
||||
.insert(MaterialMesh2dBundle {
|
||||
mesh: shape,
|
||||
material: materials.add(Color::rgb(0.2, 0.9, 0.2)),
|
||||
transform: Transform::from_xyz(0., 0., 0.),
|
||||
..default()
|
||||
})
|
||||
.insert((
|
||||
RigidBody::Dynamic,
|
||||
Collider::cuboid(0.4 * METER, 0.9 * METER),
|
||||
))
|
||||
.insert(KinematicCharacterController { ..default() });
|
||||
}
|
||||
|
||||
pub fn player_ground_collision(
|
||||
player: Query<Entity, With<Player>>,
|
||||
mut collision_events: EventReader<CollisionEvent>,
|
||||
) {
|
||||
let p = player.single();
|
||||
for collision_event in collision_events.read() {
|
||||
dbg!(p);
|
||||
dbg!(collision_event);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn move_player(
|
||||
kb_input: Res<ButtonInput<KeyCode>>,
|
||||
mut query: Query<(&mut Player, &mut KinematicCharacterController)>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
let (mut player, mut controller) = query.single_mut();
|
||||
if player.move_cooldown.tick(time.delta()).finished() {
|
||||
let mut moved = false;
|
||||
let mut mv = 0;
|
||||
|
||||
if kb_input.pressed(KeyCode::KeyA) {
|
||||
moved = true;
|
||||
mv += 1;
|
||||
}
|
||||
if kb_input.pressed(KeyCode::KeyD) {
|
||||
moved = true;
|
||||
mv -= 1;
|
||||
}
|
||||
|
||||
if moved {
|
||||
controller.translation = Some(Vec2::new(mv as f32 * 6., 0.));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
44
src/scene.rs
Normal file
44
src/scene.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
use bevy::{
|
||||
prelude::*,
|
||||
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
|
||||
};
|
||||
use bevy_rapier2d::prelude::*;
|
||||
|
||||
use crate::METER;
|
||||
|
||||
#[derive(Component)]
|
||||
struct SceneObj;
|
||||
pub fn setup_scene(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
) {
|
||||
let scene_objs = [
|
||||
// Arena walls
|
||||
(Rectangle::new(16. * METER, METER), (0., -2. * METER)),
|
||||
(
|
||||
Rectangle::new(1. * METER, 6. * METER),
|
||||
(7.5 * METER, 1.5 * METER),
|
||||
),
|
||||
(
|
||||
Rectangle::new(1. * METER, 6. * METER),
|
||||
(-7.5 * METER, 1.5 * METER),
|
||||
),
|
||||
];
|
||||
|
||||
for (shape_, pos) in scene_objs {
|
||||
let shape = Mesh2dHandle(meshes.add(shape_));
|
||||
commands
|
||||
.spawn(SceneObj)
|
||||
.insert(MaterialMesh2dBundle {
|
||||
mesh: shape,
|
||||
material: materials.add(Color::rgb(1., 0., 0.)),
|
||||
transform: Transform::from_xyz(pos.0, pos.1, 1.),
|
||||
..default()
|
||||
})
|
||||
.insert((
|
||||
RigidBody::Fixed,
|
||||
Collider::cuboid(shape_.half_size.x, shape_.half_size.y),
|
||||
));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue