From 020525945484921c642dbeebd9406fe791c0d3e3 Mon Sep 17 00:00:00 2001 From: Muhammad Nauman Raza Date: Mon, 4 Dec 2023 21:02:59 +0000 Subject: [PATCH] feat: add basic player movement Former-commit-id: 5efbf1711d0021bb86ec96b01419c43d5ca839e8 --- assets/black-square.png | Bin 5077 -> 0 bytes assets/player/player.png | Bin 0 -> 397 bytes assets/player/player.svg | 68 ++++++++++++++++++++++++++++ src/main.rs | 93 +++++++++++++++++++++++++++++++++------ 4 files changed, 148 insertions(+), 13 deletions(-) delete mode 100644 assets/black-square.png create mode 100644 assets/player/player.png create mode 100644 assets/player/player.svg diff --git a/assets/black-square.png b/assets/black-square.png deleted file mode 100644 index bf155803ba333fc6e87e55bc0dd6869e26e7edc7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5077 zcmeAS@N?(olHy`uVBq!ia0y~yVDQ}9s()O0*}aI1_r((Aj~*bn@^g7 zLAc%1#WAE}&fA-YU8?R&-3;TRtTPH3Fe4L&3 zKv1Nl;J#(r!T9*f!jr!~ef;=weQ5Eyr?(B;Vt1Fly|p#_`ntRRcm96=q{_e$Em+3D zAb5z6LBZ(;BZCWvHA4eOB0GbC;u{7Ar50HRhn5Y@3>^X_DS9-cSWmv+a9TdZE|8^l z@7C#)WCroBsrmWiM}*zHV!iu)hHt>016%lrW){i-!}77=u}^Cep?Uu9*P~PoLb&%k z^yTH{PansOKAKsWd~Ror&9R7mpkxB^;qRTh_Yspg9{spi?{Fc${_ofC_v`;ZZoj{; zHu_&{{QkOFm|@@V{C(IiU-#?f@~819{;RyPyZ?Uw|9{Wt*Vnz@&&06p+iCs%e?A_U zzyEvvijV6fh)jwd$vqouY@WyL<9%;;ezOfDL;j;(>%`@sp1uEfZCUL`l9Mky?D1s; zcp5*v`+23FKf{69JKq03>R$P|ync0TJO!BtpY0aMBp^xQ!@JKmr-d0lsI7Zl^)c|? zpS$<7u8UJ6>teCJ&+_@Fj}pm0&GuB!d;W=qVNd7peepF@%AA0xs@1M`-|NlK){#zsm z(qpZ=rnmkx(cMRUy*zMJXSBah$zTw?wFnO9k53;zPX1W|9AdCOwgEA~&`I0?1FBg> xxvKDt<@EmJ5~sIA2flzK8usPn^p*cHN1u9cp2s4u2^^s{pSlF!~W+leCr77v)%JUB%D65Db zw6f6ftg^D;Xxi9$@#UPafBrmw%r||8WTgA=X5ok}DPCV6uaTX?>cFt`;0KWd58XNE z&is1Ij(O$jAZ8AQ@}jGZpASyI+WPd)`^*dXPU!1x?fFl*y`#fS+e?Gywt8cb-zsyu$Z4VJfz4t zyIbbJOTwBrD^^{fwcgWGJG1gj#de|Min-q`7z6@lx_&!h(;p^Wyw3i_Kfxyko%#w4 mj2sROOacuIEC}Ym + + + + + + + + + + diff --git a/src/main.rs b/src/main.rs index 0aee83f..d97a60b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,10 +49,11 @@ fn main() { .init_resource::() .init_resource::() .add_systems(Startup, (setup, setup_ui)) - .add_systems(Update, render_ui) + .add_systems(Update, (render_ui, movement)) .run(); } +// Define UI resources #[derive(Default, Resource)] struct UiState { username: String, @@ -64,6 +65,13 @@ struct OpenWindows { login_open: bool, } +// Define the player component +#[derive(Component)] +struct Player { + movement_speed: f32, + rotation_speed: f32, +} + // Bevy engine setup fn setup(mut commands: Commands, asset_server: Res) { commands.spawn(Camera2dBundle { @@ -76,10 +84,13 @@ fn setup(mut commands: Commands, asset_server: Res) { }); commands.spawn(( SpriteBundle { - texture: asset_server.load("black-square.png"), - transform: Transform::from_xyz(100., 0., 0.), + texture: asset_server.load("player/player.png"), ..default() - } + }, + Player { + movement_speed: 1024., + rotation_speed: f32::to_radians(360.), + }, )); } @@ -99,13 +110,72 @@ fn setup_ui(mut contexts: EguiContexts) { contexts.ctx_mut().set_fonts(fonts); } +// Define the player movement system +fn movement( + time: Res