This commit is contained in:
2022-08-07 17:39:15 +02:00
commit e5a83229f1
9 changed files with 3370 additions and 0 deletions

25
client/.cargo/config.toml Normal file
View File

@@ -0,0 +1,25 @@
# Add the contents of this file to `config.toml` to enable "fast build" configuration. Please read the notes below.
# NOTE: For maximum performance, build using a nightly compiler
# If you are using rust stable, remove the "-Zshare-generics=y" below.
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"]
# NOTE: you must manually install https://github.com/michaeleisel/zld on mac. you can easily do this with the "brew" package manager:
# `brew install michaeleisel/zld/zld`
[target.x86_64-apple-darwin]
rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/zld", "-Zshare-generics=y"]
[target.aarch64-apple-darwin]
rustflags = ["-C", "link-arg=-fuse-ld=/opt/homebrew/bin/zld", "-Zshare-generics=y"]
[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe"
rustflags = ["-Zshare-generics=n"]
# Optional: Uncommenting the following improves compile times, but reduces the amount of debug info to 'line number tables only'
# In most cases the gains are negligible, but if you are on macos and have slow compile times you should see significant gains.
#[profile.dev]
#debug = 1

16
client/Cargo.toml Normal file
View File

@@ -0,0 +1,16 @@
[package]
name = "daggmask"
version = "0.1.0"
edition = "2021"
[dependencies]
bevy = "0.8"
# Enable a small amount of optimization in debug mode
[profile.dev]
opt-level = 1
# Enable high optimizations for dependencies (incl. Bevy), but not for our code:
[profile.dev.package."*"]
opt-level = 3

59
client/src/main.rs Normal file
View File

@@ -0,0 +1,59 @@
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
.add_startup_system(spawn_player)
.add_system(move_player)
.run();
}
fn setup(mut commands: Commands) {
info!("hehe");
let mut camera_bundle = Camera2dBundle::default();
camera_bundle.projection.scale = 1. / 50.;
commands.spawn_bundle(camera_bundle);
}
#[derive(Component)]
struct Player;
fn spawn_player(mut commands: Commands) {
commands
.spawn_bundle(SpriteBundle {
sprite: Sprite {
color: Color::rgb(0., 0.47, 1.),
custom_size: Some(Vec2::new(1., 1.)),
..Default::default()
},
..Default::default()
})
.insert(Player);
}
fn move_player(keys: Res<Input<KeyCode>>, mut player_query: Query<&mut Transform, With<Player>>) {
let mut direction = Vec2::ZERO;
if keys.any_pressed([KeyCode::Up, KeyCode::W]) {
direction.y += 1.;
}
if keys.any_pressed([KeyCode::Down, KeyCode::S]) {
direction.y -= 1.;
}
if keys.any_pressed([KeyCode::Right, KeyCode::D]) {
direction.x += 1.;
}
if keys.any_pressed([KeyCode::Left, KeyCode::A]) {
direction.x -= 1.;
}
if direction == Vec2::ZERO {
return;
}
let move_speed = 0.13;
let move_delta = (direction * move_speed).extend(0.);
for mut transform in player_query.iter_mut() {
transform.translation += move_delta;
}
}